Final machine ID permissions depend on the order roles were applied
Describe the bug
When applying multiple roles to a machine ID, the final permissions that machine ID will obtain depends on the order in which the roles are applied.
Moreover, in the "Project Roles" view of a machine identity, the order the roles are display in is alphabetical, rather than the order they were applied in. Thus, there is no way to determine what permissions a machine ID will be granted by looking at the UI. You have to attempt to use the permissions, or re-apply the roles in a known order using the UI.
To Reproduce
Suppose the goal was to allow any machine with role allow-both to Describe Secret and Read Value, but any machine with role deny-read may not Read Value.
- Go to project > Access Management > Project Roles > Add Role and add
allow-bothrole. - Click Add Policies > Secrets > Add Policies and select Permission=
Allow, Actions=[Describe Secret,Read Value] - Click Save on allow-both.
- Go to project > Access Management > Project Roles > Add Role and add
deny-readrole. - Click Add Policies > Secrets > Add Policies and select Permission=
Forbid, Actions=[Read Value] - Click Save on
deny-read. - Go to project > Access Management > Machine Identities > Add Identity and select an identity
- Select Role as
allow-both, and remove all other roles. Click Add. - Click on Edit Role(s) > Add Role and select
deny-read. Click Save Roles. - Add any secret to the project and attempt to read the value while authenticated as the identity. Permission will be denied. The
deny-readrole was saved last. - Click Edit Role(s) > and delete
deny-read. Change the remaining role fromallow-bothtodeny-readand click Save Roles. - Click Add Role and select
allow-both. Click Save Roles. The role order is now reversed - Attempt to read the secret value again. Permission will be granted. The
allow-bothrole was saved last.
Thus, even though both attempts to read the secret had the same roles, the permissions obtained by the machine ID differed. It depends on the order the roles are saved in.
Also note that in the Project Roles view, the roles will appear in alphabetical order (allow-both first and deny-read second) regardless of the order the roles were added in. This means that someone arriving at the Project Roles page has no way to determine what permissions the MID will obtain just by looking at the roles it has.
Expected
It seems that role permissions are applied by summing permissions (with possible inversion) from top to bottom, typically with Forbid coming last. Given that, I would expect that roles follow the same convention, adding permissions top to bottom.
Additionally, I would expect that the roles can be re-ordered in the Edit Role(s) dialog, to avoid having to shuffle the value as described above. The Project Roles view should then preserve this order rather than an alphabetical ordering.
Screenshots
N/A
Platform you are having the issue on:
Running self-hosted in docker x86_64, infisical:v0.146.0-postgres