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

feat(access): allow more flexible access checks #873

Merged
merged 39 commits into from
Sep 12, 2024

Conversation

oyo
Copy link
Contributor

@oyo oyo commented Jun 12, 2024

Description

Enable access checks with arbitrary check functions.

Why

Currently the frontend role check is only based on role name assuming the roles names are unique across clients. This assumption can be incorrect so we implemented a more flexible access check which allows to check for client id and role name. To be future-proof the mechanism now allows arbitrary checks to be executed for decision whether access is granted or not.

In the process some redundant code has been identified and removed.

Issue

#657

Checklist

  • I have followed the contributing guidelines
  • I have performed a self-review of my own code
  • I have successfully tested my changes locally
  • I have added tests that prove my changes work
  • I have checked that new and existing tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@oyo oyo requested a review from evegufy June 12, 2024 13:20
Copy link
Contributor

@evegufy evegufy left a comment

Choose a reason for hiding this comment

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

Looks good in general but as the impact of this change could be quite huge if there was some inconsistency in which client was validated updated to now: did you check the following?:
"
The following resource needs to get checked when the user access the respective page:

URL Ressource
/registration Cl1-CX-Registration
/registration/* Cl1-CX-Registration
/?overlay=consent_osp Cl1-CX-Registration
/semantichub Cl3-CX-Semantic
/admin-credential Cl24-CX-SSI-Credential-Issuer
/usecase-participation Cl2-CX-Portal
/certificate-credential Cl2-CX-Portal
all others Cl2-CX-Portal

"

@oyo
Copy link
Contributor Author

oyo commented Jun 13, 2024

Looks good in general but as the impact of this change could be quite huge if there was some inconsistency in which client was validated updated to now:

The logic now intersects the resourceAccess attribute from the keycloak user token with a same object securing any resource. Access is granted if the intersection is not empty which means that at least one required client+role combination has been found in the user token. Tests for this logic are here:

https://github.com/eclipse-tractusx/portal-frontend/blob/feat/657/allow-clientid-for-rolecheck/src/utils/dataUtils.test.ts#L138-L181

did you check the following?: " The following resource needs to get checked when the user access the respective page:

URL Ressource
/registration/* Cl1-CX-Registration

Those URLs are from the registration app and the check must be implemented there.

/registration Cl1-CX-Registration

https://github.com/eclipse-tractusx/portal-frontend/blob/feat/657/allow-clientid-for-rolecheck/src/types/Config.tsx#L111-L112

Checked for combination of Registration client id and VIEW_REGISTRATION role - is this the correct one?

/?overlay=consent_osp Cl1-CX-Registration

Looks like this overlay is not implemented any more.
https://portal.dev.demo.catena-x.net/?overlay=consent_osp
There is a page with this name - but it's broken
https://portal.dev.demo.catena-x.net/consent_osp
@jjeroch has this logic been changed or is it broken for other reasons?

/semantichub Cl3-CX-Semantic

https://github.com/eclipse-tractusx/portal-frontend/blob/feat/657/allow-clientid-for-rolecheck/src/types/Config.tsx#L169-L175

plus two more uses of userHasSemanticHubRole in the semantic hub code

/admin-credential Cl24-CX-SSI-Credential-Issuer

https://github.com/eclipse-tractusx/portal-frontend/blob/feat/657/allow-clientid-for-rolecheck/src/types/Config.tsx#L567-L568

/usecase-participation Cl2-CX-Portal
/certificate-credential Cl2-CX-Portal
all others Cl2-CX-Portal

all other pages are using userHasPortalRole checking for that client id if correctly injected:
https://github.com/eclipse-tractusx/portal-frontend/blob/feat/657/allow-clientid-for-rolecheck/src/services/AccessService.tsx#L97-L98

src/types/Config.tsx Show resolved Hide resolved
src/types/Config.tsx Show resolved Hide resolved
src/types/Config.tsx Outdated Show resolved Hide resolved
src/types/Config.tsx Outdated Show resolved Hide resolved
src/types/Config.tsx Outdated Show resolved Hide resolved
@evegufy evegufy changed the base branch from dev to change-to-main June 21, 2024 14:00
@evegufy evegufy changed the base branch from change-to-main to main June 21, 2024 15:37
@jjeroch
Copy link
Contributor

jjeroch commented Jul 15, 2024

@oyo beside the comment added to the code; one more thing

  • Wallet UI - the revocation button should also need a {userHasSsiCredentialRole could you please check this once
  • Partner Network - for the Partner Network UI the user needs to have BPDM roles assigned; do we have this validation somewhere included? I couldnt see it

@oyo
Copy link
Contributor Author

oyo commented Jul 17, 2024

  • Wallet UI - the revocation button should also need a {userHasSsiCredentialRole could you please check this once

added userHasSsiCredentialRole(ROLES.REVOKE_CREDENTIALS_ISSUER) to the check

  • Partner Network - for the Partner Network UI the user needs to have BPDM roles assigned; do we have this validation somewhere included? I couldnt see it

it is implemented with the check allowTo: () => userHasBpdmRole(ROLES.READ_PARTNER),
src/types/Config.tsx:210 (file too large and not shown by default in diff)
https://github.com/eclipse-tractusx/portal-frontend/pull/873/files#diff-f207e98afeed11e7e08f809e36fa97a268e311ceeeebb779c00d05f3bf99ba6aR210

@jjeroch jjeroch self-requested a review July 18, 2024 19:23

This comment was marked as outdated.

@MaximilianHauer MaximilianHauer added this to the Release 24.12 milestone Aug 13, 2024
Copy link
Contributor

@evegufy evegufy left a comment

Choose a reason for hiding this comment

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

@oyo could you please resolve the conflicts? I'd approve it then.

@oyo
Copy link
Contributor Author

oyo commented Sep 10, 2024

@oyo could you please resolve the conflicts? I'd approve it then.

@evegufy conflicts resolved and PR updated

Copy link

@oyo oyo merged commit 20b6637 into main Sep 12, 2024
8 checks passed
@oyo oyo deleted the feat/657/allow-clientid-for-rolecheck branch September 12, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PR needs to prioritized at review
Projects
Status: USER READY
Development

Successfully merging this pull request may close these issues.

4 participants