How to control that only partial fields are allowed to be updated?
The title is all, Thank you for your help.
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 what are wildcards to rules?
You see the '*'? Thats a wild card. It can take the value of any other string so matching becomes a lot easier.
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 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?
@8byr0?
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 You think you can create a ticket to create an admin ui?
@8byr0 You think you can create a ticket to create an admin ui?
Yup ! https://github.com/spaceuptech/space-cloud/issues/196
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?