Skip to content
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

fix(auth-admin): Allow delegation-admin into domains controller #17125

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

GunnlaugurG
Copy link
Member

@GunnlaugurG GunnlaugurG commented Dec 4, 2024

What

When fetching delegations for delegation lookups, those who did not have @admin.island.is/delegations scope could not look it up since that was required to get the domain name for the delegation.

Why

So all users with delegation system access can lookup delegations.

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features
    • Enhanced authorization for the domain retrieval process with new access scopes.
  • Bug Fixes
    • Improved security model by refining access control mechanisms.

@GunnlaugurG GunnlaugurG requested review from a team as code owners December 4, 2024 13:20
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request focus on the DomainsController class within the domains.controller.ts file. The modifications include the addition of the AdminPortalScope import and an update to the @Scopes decorator for the findAll method. This update introduces two new authorization scopes, enhancing the access control for retrieving domain information. The overall structure and existing method signatures of the controller remain unchanged, and documentation annotations are preserved.

Changes

File Change Summary
apps/services/auth/delegation-api/src/app/domains/domains.controller.ts Added AdminPortalScope import; updated @Scopes decorator in findAll method to include new scopes.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • saevarma

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ee57f3b and 12be4ea.

📒 Files selected for processing (1)
  • apps/services/auth/delegation-api/src/app/domains/domains.controller.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/services/auth/delegation-api/src/app/domains/domains.controller.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
apps/services/auth/delegation-api/src/app/domains/domains.controller.ts (3)

95-98: Consider security implications of scope changes

The changes appropriately enhance access control by:

  1. Maintaining authentication through IdsUserGuard
  2. Providing alternative access paths via delegationSystem scope
  3. Preserving admin access via delegationSystemAdmin scope

However, please ensure that:

  1. The delegationSystem scope provides appropriate access level for non-admin users
  2. The change doesn't unintentionally expose sensitive domain information

Line range hint 63-94: Update method documentation to reflect new access patterns

The @Documentation decorator should be updated to reflect that the endpoint is now accessible via multiple scope combinations. This will help API consumers understand the various access paths.

   @Documentation({
     description: `Get all domains. Provides query parameters to filter domains
-      delegation support and/or specific delegation direction.`,
+      delegation support and/or specific delegation direction. Accessible with
+      either delegation system access or delegation admin access.`,
     request: {

Controller scopes are indeed too restrictive for read-only operations

The current controller uses delegationScopes which includes @island.is/auth/delegations:write scope. This is overly restrictive for endpoints that only perform read operations. The scope should be adjusted to match the actual requirements of the endpoints.

  • Consider creating separate read-only scopes for delegation lookups
  • Update the controller to use appropriate read scopes instead of write scopes
  • If write operations exist in the controller, consider splitting the endpoints into separate controllers with different scope requirements
🔗 Analysis chain

Line range hint 43-44: Verify if base controller scopes are too restrictive

The controller-level @Scopes(...delegationScopes) might be too restrictive given the PR objective to allow broader access to delegation lookups.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the contents of delegationScopes to ensure it's not overly restrictive
rg -A 5 "export const delegationScopes.*=" 

Length of output: 411


Script:

#!/bin/bash
# Check the definition of AuthScope.delegations and AdminPortalScope.delegations
rg -A 2 "export (enum|const) (AuthScope|AdminPortalScope)" libs/auth/scopes/src/lib/auth.scope.ts

Length of output: 234

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4a229a4 and ee57f3b.

📒 Files selected for processing (1)
  • apps/services/auth/delegation-api/src/app/domains/domains.controller.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/services/auth/delegation-api/src/app/domains/domains.controller.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/services/auth/delegation-api/src/app/domains/domains.controller.ts (2)

18-18: LGTM: Import addition is appropriate

The addition of AdminPortalScope import aligns with the PR objective to enhance delegation access control.


95-98: Verify scope hierarchy and implications

While the addition of both scopes (delegationSystemAdmin and delegationSystem) aligns with the PR objective, we should verify:

  1. The scope hierarchy - is delegationSystemAdmin a superset of delegationSystem?
  2. The interaction with controller-level delegationScopes
✅ Verification successful

Scopes are correctly layered and not redundant

Based on the findings:

  1. The scopes are distinct and hierarchical:
    • delegationSystem = '@admin.island.is/delegation-system'
    • delegationSystemAdmin = '@admin.island.is/delegation-system:admin'
  2. The controller has class-level @Scopes(...delegationScopes) and method-level scopes working together
  3. The :admin suffix in delegationSystemAdmin indicates a higher privilege level, following standard naming convention

The implementation follows secure authorization patterns by:

  • Using both IdsUserGuard and ScopesGuard
  • Properly layering scopes at both class and method levels
  • Following the established scope naming convention
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check scope definitions and hierarchy
rg -A 10 "export enum AdminPortalScope"

# Check for any scope documentation or tests
fd -e ts -e md . | xargs rg -l "delegationSystemAdmin.*delegationSystem|scope.*hierarchy"

Length of output: 1280


Script:

#!/bin/bash
# Let's search for the specific scopes in the enum and their usage
rg "delegationSystem(Admin)?" libs/auth/scopes/src/lib/admin-portal.scope.ts

# Let's also check for any documentation about these scopes
fd "README|CONTRIBUTING" -e md | xargs rg -l "delegation.*scope"

# Let's check for any tests that might reveal the scope hierarchy
fd "(test|spec)" -e ts | xargs rg -l "delegationSystem"

# Let's check the controller class for any class-level scopes
rg -B 5 "class DomainsController" apps/services/auth/delegation-api/src/app/domains/domains.controller.ts

Length of output: 583


Script:

#!/bin/bash
# Let's check for any class-level scopes on the controller
rg -B 10 "@UseGuards|@Scopes" apps/services/auth/delegation-api/src/app/domains/domains.controller.ts

# Let's also check the findAll method implementation to understand the context
ast-grep --pattern $'findAll($$$) {
  $$$
}'  apps/services/auth/delegation-api/src/app/domains/domains.controller.ts

# Let's check if there are any other methods using these scopes
rg "delegationSystem|delegationSystemAdmin" apps/services/auth/delegation-api/src/app/domains/domains.controller.ts

Length of output: 977

@datadog-island-is
Copy link

Datadog Report

All test runs f001821 🔗

8 Total Test Services: 1 Failed, 7 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.2%), 15 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
services-auth-delegation-api 19 3 0 251 0 4m 7.75s 1 decreased (-0.2%) Link
api 0 0 0 4 0 3.5s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.35s 1 no change Link
application-system-api 0 0 0 46 0 2m 25s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 37.51s 1 no change Link
services-auth-ids-api 0 0 0 254 0 1m 38s 1 no change Link
services-user-notification 0 0 0 51 0 1m 30.21s 1 no change Link
services-user-profile 0 0 0 99 0 26.26s 1 no change Link

❌ Failed Tests (19)

This report shows up to 5 failed tests.

  • DomainsController withAuth with outgoing access test case: accessControlledCompanyScopes GET /domains returns expected domains - apps/services/auth/delegation-api/src/app/domains/test/domains.controller.spec.ts - Details

    Expand for error
     expect(received).toEqual(expected) // deep equality
     
     Expected: 200
     Received: 403
    
  • DomainsController withAuth with outgoing access test case: customDelegationScopes GET /domains returns expected domains - apps/services/auth/delegation-api/src/app/domains/test/domains.controller.spec.ts - Details

    Expand for error
     expect(received).toEqual(expected) // deep equality
     
     Expected: 200
     Received: 403
    
  • DomainsController withAuth with outgoing access test case: customScopeRulesExcluded GET /domains returns expected domains - apps/services/auth/delegation-api/src/app/domains/test/domains.controller.spec.ts - Details

    Expand for error
     expect(received).toEqual(expected) // deep equality
     
     Expected: 200
     Received: 403
    
  • DomainsController withAuth with outgoing access test case: customScopeRulesIncluded GET /domains returns expected domains - apps/services/auth/delegation-api/src/app/domains/test/domains.controller.spec.ts - Details

    Expand for error
     expect(received).toEqual(expected) // deep equality
     
     Expected: 200
     Received: 403
    
  • DomainsController withAuth with outgoing access test case: happyCase GET /domains returns expected domains - apps/services/auth/delegation-api/src/app/domains/test/domains.controller.spec.ts - Details

    Expand for error
     expect(received).toEqual(expected) // deep equality
     
     Expected: 200
     Received: 403
    

🔻 Code Coverage Decreases vs Default Branch (1)

  • services-auth-delegation-api - jest 50.25% (-0.2%) - Details

@GunnlaugurG GunnlaugurG added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 4, 2024
@kodiakhq kodiakhq bot merged commit 0b31a03 into main Dec 4, 2024
41 checks passed
@kodiakhq kodiakhq bot deleted the fix/allow-domain-for-delegation-admin branch December 4, 2024 14:22
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.72%. Comparing base (be2291a) to head (cfedf2a).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17125   +/-   ##
=======================================
  Coverage   35.71%   35.72%           
=======================================
  Files        6920     6920           
  Lines      147498   147498           
  Branches    42001    42001           
=======================================
+ Hits        52686    52689    +3     
+ Misses      94812    94809    -3     
Flag Coverage Δ
api 3.34% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
application-system-api 38.74% <ø> (-0.01%) ⬇️
application-template-api-modules 27.77% <ø> (+<0.01%) ⬆️
application-ui-shell 22.48% <ø> (ø)
services-auth-delegation-api 58.50% <100.00%> (-0.09%) ⬇️
services-auth-ids-api 52.32% <ø> (+0.03%) ⬆️
services-user-notification 46.53% <ø> (-0.01%) ⬇️
services-user-profile 56.84% <ø> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...legation-api/src/app/domains/domains.controller.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be2291a...cfedf2a. Read the comment docs.

GunnlaugurG added a commit that referenced this pull request Dec 4, 2024
* allow delegation admin into domain controller

* fix scopes for find all

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Dec 4, 2024
…) (#17130)

* allow delegation admin into domain controller

* fix scopes for find all

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants