Skip to content

SMQ-2609 - Enable superadmin to perform actions over entities #2688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 10, 2025

Conversation

felixgateru
Copy link
Contributor

What type of PR is this?

This is a refactor as it remove DomainUserID encoding.

What does this do?

This pr removes DomainUserID encodinh and makes all authorization on entities to be performed with userID.

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Yes, I have updated tests.

Did you document any new/modified feature?

No,

Notes

None

@felixgateru felixgateru marked this pull request as ready for review February 10, 2025 14:44
@felixgateru felixgateru requested a review from a team as a code owner February 10, 2025 14:44
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 47.27273% with 58 lines in your changes missing coverage. Please review.

Project coverage is 27.58%. Comparing base (a01d257) to head (98a06c0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
auth/service.go 36.95% 27 Missing and 2 partials ⚠️
domains/middleware/authorization.go 0.00% 16 Missing ⚠️
auth/jwt/tokenizer.go 42.10% 7 Missing and 4 partials ⚠️
auth/keys.go 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2688      +/-   ##
==========================================
+ Coverage   27.53%   27.58%   +0.04%     
==========================================
  Files         351      219     -132     
  Lines       55379    44701   -10678     
==========================================
- Hits        15251    12332    -2919     
+ Misses      39372    31775    -7597     
+ Partials      756      594     -162     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dborovcanin
Copy link
Collaborator

@arvindh123 @felixgateru What's the status of this PR?

@@ -141,8 +150,7 @@ func (am *authorizationMiddleware) ListDomains(ctx context.Context, session auth
}

func (am *authorizationMiddleware) SendInvitation(ctx context.Context, session authn.Session, invitation domains.Invitation) (err error) {
domainUserId := auth.EncodeDomainUserID(invitation.DomainID, invitation.InviteeUserID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Invitations related authz middleware functions are removed ?

@arvindh123
Copy link
Contributor

In this PR, we are changing the format from <domain_id>_<user_id> to just <user_id> in Spice DB for subjects.

One side effect/bug that occurs due to this PR is as follows:
I created domain_1 with ID 88724ac6-a569-43c2-a895-d8d3e93ad3df and domain_2 with ID 716a571e-fbe7-4cd2-afdc-fa0780a24531.

Then, I created a client, client_1_of_domain_2, with ID 1729828a-3c3d-4917-8678-b76abd28576a, in domain_2 (ID 716a571e-fbe7-4cd2-afdc-fa0780a24531).

However, when I try to view client_1_of_domain_2 with domain_1 in the URL (e.g., http://localhost/domain_1/clients/client_1_of_domain_2),
it shows the details of client_1_of_domain_2 from domain_2. Ideally, I should see a "not found" message instead. (edited)
image

@arvindh123
Copy link
Contributor

arvindh123 commented Mar 7, 2025

In this PR, we are changing the format from <domain_id>_<user_id> to just <user_id> in Spice DB for subjects.

One side effect/bug that occurs due to this PR is as follows: I created domain_1 with ID 88724ac6-a569-43c2-a895-d8d3e93ad3df and domain_2 with ID 716a571e-fbe7-4cd2-afdc-fa0780a24531.

Then, I created a client, client_1_of_domain_2, with ID 1729828a-3c3d-4917-8678-b76abd28576a, in domain_2 (ID 716a571e-fbe7-4cd2-afdc-fa0780a24531).

However, when I try to view client_1_of_domain_2 with domain_1 in the URL (e.g., http://localhost/domain_1/clients/client_1_of_domain_2), it shows the details of client_1_of_domain_2 from domain_2. Ideally, I should see a "not found" message instead. (edited) image

I think we should find another way to solve the issue.

@felixgateru felixgateru changed the title SMQ-2609 - Remove DomainUserID encoding from session and authn SMQ-2609 - Enable superadmin to perform actions over entities Mar 13, 2025
@felixgateru felixgateru force-pushed the smq2609 branch 2 times, most recently from 0f04178 to f9e1685 Compare March 13, 2025 14:55
@@ -39,7 +39,7 @@ func (am *authorizationMiddleware) RetrieveAll(ctx context.Context, session smqa
permission := readPermission
objectType := page.EntityType.String()
object := page.EntityID
subject := session.DomainUserID
subject := session.Subject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this was changed to Subject

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to Subject as it can be just the userID or the domainUserId. Should I revert this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DomainUserID means id of user within the domain, which is different from actual user id for platform ,
In each domain, user should have unquie id .
So just we are adding prefix domain_id to user id to get the unqiue user id for user per domain , which is called domain user id

@felixgateru felixgateru force-pushed the smq2609 branch 2 times, most recently from b0ae01d to ec39e29 Compare March 20, 2025 08:06
@felixgateru felixgateru force-pushed the smq2609 branch 2 times, most recently from d97fe33 to 6c72b27 Compare March 26, 2025 11:38
Copy link
Collaborator

@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arvindh123 Please re-review.

Copy link
Contributor

@arvindh123 arvindh123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
…ct in auth key

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
@dborovcanin dborovcanin merged commit 299cee7 into absmach:main Apr 10, 2025
8 of 9 checks passed
@felixgateru felixgateru deleted the smq2609 branch May 29, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: SuperAdmin could not perform actions over entities
3 participants