space-cloud icon indicating copy to clipboard operation
space-cloud copied to clipboard

How to control that only partial fields are allowed to be updated?

Open bysir-zl opened this issue 7 years ago • 10 comments

The title is all, Thank you for your help.

bysir-zl avatar Apr 16 '19 01:04 bysir-zl

Thats a great question!! If i understand this question, you want to prevent the client from updating certain columns?

Assuming that's the case and the field / column you want to protect is named protectMe, you can have a match rule something like this:

rules:
  update:
    rule: match
    eval: ==
    type: bool
    f1: utils.exist(args.update.$set.protectMe)
    f2: false

the solution above is not documented I guess. The utils.exist() function seems to be a well kept secret. @Jayesh333 we should get that done

This will protect you against all set operations. The client still be able to unset it. Thats a security threat. Normally you wouldn't wanna keep protected data in a collection/table which the user has access to. Can you keep it in a separate table where only an admin role or the backend functions can access it? This is what we do. A lil more about your use case would help me give a more accurate answer.

@Jayesh333 another better way of solving this would be introducing wildcards to rules. So basically the new rule would look like this:

Note: this is a proposal and the code below hasn't been implemented

rules:
  update:
    rule: match
    eval: ==
    type: bool
    f1: utils.exist(args.update.*.protectMe)
    f2: false

The above config would prevent any kind of update whatsoever!

YourTechBud avatar Apr 16 '19 01:04 YourTechBud

@YourTechBud what are wildcards to rules?

akshayjj1997 avatar Apr 22 '19 03:04 akshayjj1997

You see the '*'? Thats a wild card. It can take the value of any other string so matching becomes a lot easier.

YourTechBud avatar Apr 22 '19 03:04 YourTechBud

As this issue is related to user authentication, it would be good to have a default admin field in config.yaml. Something like this:

auth:
    email:
      enabled: true
      admin:
            id: [email protected]
            pass: MyLongRand0mPassw0rd

And so in rules you could specify data structure based on role

8byr0 avatar Apr 23 '19 11:04 8byr0

@8byr0 You can do this instead with what we have already implemented

rules:
  update:
    rule: match
    eval: ==
    type: string
    f1: args.auth.role
    f2: admin

Instead of creating a default admin we can have a data explorer to add users from a ui? What say?

YourTechBud avatar Apr 24 '19 03:04 YourTechBud

@8byr0?

YourTechBud avatar Apr 25 '19 09:04 YourTechBud

we can have a data explorer to add users from a ui

That's something you can actually do with a SQL/NoSQL client but you're right, it would be a good thing to have an embedded web server in space cloud to manage users (and why not datas too, allowing to live edit config)

I've not tried your snippet yet but it should to the job !

8byr0 avatar Apr 25 '19 09:04 8byr0

@8byr0 You think you can create a ticket to create an admin ui?

YourTechBud avatar Apr 25 '19 14:04 YourTechBud

@8byr0 You think you can create a ticket to create an admin ui?

Yup ! https://github.com/spaceuptech/space-cloud/issues/196

8byr0 avatar Apr 26 '19 00:04 8byr0

I've already created a ticket for the wild card support! @bysir-zl is there anything we missed out or can we close this issue?

YourTechBud avatar Apr 26 '19 01:04 YourTechBud