Never check a role name in your code
In one of the projects where I worked, we had role checks in many places across the project. Then, we needed to introduce a new role and that was a cumbersome code change in many places.
RBAC stands for Role-Based Access Control. The path we selected was to give users roles and let the code ask "is this user a Manager?"
Yet, the model has one more part. Users get roles, roles get permissions and permissions define what a user can do.
The code should only ask about the permission, for example "can this user approve an invoice?"
Here is the complete flow:
๐ญ. ๐ง๐ต๐ฒ ๐๐ผ๐ธ๐ฒ๐ป ๐ฐ๐ฎ๐ฟ๐ฟ๐ถ๐ฒ๐ ๐ฟ๐ผ๐น๐ฒ๐. We set up the identity provider to add them at sign-in.
๐ฎ. ๐ง๐ต๐ฒ ๐๐ฃ๐ ๐๐๐ฟ๐ป๐ ๐ฟ๐ผ๐น๐ฒ๐ ๐ถ๐ป๐๐ผ ๐ฝ๐ฒ๐ฟ๐บ๐ถ๐๐๐ถ๐ผ๐ป๐. It reads the mapping from its database and keeps a short cache.
๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ. ๐ง๐ต๐ฒ ๐ฒ๐ป๐ฑ๐ฝ๐ผ๐ถ๐ป๐ ๐ฐ๐ต๐ฒ๐ฐ๐ธ๐ ๐ผ๐ป๐ฒ ๐ฝ๐ฒ๐ฟ๐บ๐ถ๐๐๐ถ๐ผ๐ป. It asks for invoices:approve and never names a role.
๐ฐ. ๐๐ป ๐ฎ๐ฑ๐บ๐ถ๐ป ๐ฎ๐ฑ๐ฑ๐ ๐ฎ ๐ป๐ฒ๐ ๐ฟ๐ผ๐น๐ฒ ๐ฎ๐ ๐ฑ๐ฎ๐๐ฎ. The admin creates the Auditor role in the identity provider. One table row maps it to invoices:read. The code stays the same, and nothing gets deployed.
In https://t.co/PLYLs2PAEE Core, the endpoint gets [Authorize(Policy = "invoices:approve")]. It replaces [Authorize(Roles = "Manager")]. Behind it, a policy provider turns that name into a requirement. A handler checks it against the user's permissions.
"I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu)..."
On August 25, 1991, a 21-year-old student sent a message to a Usenet newsgroup. He thought he was just building something fun for himself.
35 years later, that "hobby" is the backbone of global technology:
๐ Powering helicopters in space with NASA
โ๏ธ Running the global cloud and 100% of the worldโs supercomputers
๐ฑ Connecting billions of people
๐ฎ Redefining the future of handheld gaming
What started as one student's side project became the greatest collaborative technology movement in history. Thank you to every maintainer, contributor, and advocate who made it possible.
Happy 35th Birthday, Linux. Hereโs to the power of open source and the next 35 years of building together.
https://t.co/KDN6Coob7F
#Linux35
I donโt know what is going on here but it looks like I am trying to break up a fight!! Interview with @countbinface out soon. Meanwhile new @restispolitics Q&A out now - India protests, Saudi nukes, AI date centres, Trump bonkers speech to White House correspondents dinner &more
I think a lot of people have missed this. Until the police investigation in February last year, Reform UKโs financial structures were all tied up with Cottrell and his Montenegro base
https://t.co/HhfZOB7VEq