Skip to content

feat(rest): new readOnly user role.#3242

Open
rudra-superrr wants to merge 1 commit intoeclipse-sw360:mainfrom
siemens:feat/readOnlyUserRestEndpoints
Open

feat(rest): new readOnly user role.#3242
rudra-superrr wants to merge 1 commit intoeclipse-sw360:mainfrom
siemens:feat/readOnlyUserRestEndpoints

Conversation

@rudra-superrr
Copy link
Copy Markdown
Contributor

@rudra-superrr rudra-superrr commented Jun 26, 2025

Issue: #3241

This will restrict the endpoints for the new readOnly user role.

@rudra-superrr rudra-superrr linked an issue Jun 26, 2025 that may be closed by this pull request
@rudra-superrr rudra-superrr added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for labels Jun 26, 2025
Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

A question.

@rudra-superrr rudra-superrr force-pushed the feat/readOnlyUserRestEndpoints branch from c2046ed to d7ef8ad Compare July 2, 2025 06:25
@rudra-superrr
Copy link
Copy Markdown
Contributor Author

Made the changes.

GMishx
GMishx previously approved these changes Jul 2, 2025
Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

Changes looks good.

@keerthi-bl
Copy link
Copy Markdown
Contributor

@rudra-superrr

Resolve the conflicts and can you please add steps to test this PR in the description.

Copy link
Copy Markdown
Contributor

@bibhuti230185 bibhuti230185 left a comment

Choose a reason for hiding this comment

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

Few more areas to look for

  1. ProjectPermissions.java — isVisible() needs VIEWER awareness
  2. ProjectController.java — VIEWER sees full project objects ,needs field stripping
  3. ProjectController.java — Missing VIEWER guards on multiple project endpoints
Endpoint Line What's missing
GET /projects/{id}/licenseClearing L457 default should be blocked — add throwIfReadOnlyUser with a // TODO: revisit after License Clearing decision comment
GET /projects/{id}/linkedProjects L580 VIEWER must not see linked projects — add throwIfReadOnlyUser
GET /projects/{id}/linkedProjects/releases L629 Same — add throwIfReadOnlyUser

  1. SW360ReportController.java L122 — Report exports need per-module VIEWER guard

    Requirement: "Exports of Excel Sheet are allowed, ReadMeOSS are allowed (from License Clearing Tab), Product Clearing not allowed (from Obligations Tab)."

    GET /reports dispatches to different report types based on a module parameter. The requirement says:

    • ✅ Allowed: projects, components, licenses (Excel sheets), licenseInfo (ReadMeOSS)
    • ❌ Blocked: exportCreateProjectClearingReport (Product Clearing), licenseResourceBundle, projectReleaseSpreadsheetWithEccInfo (ECC)
    • ⚠️ SBOM: needs discussion

    Currently there's no VIEWER check at all — every module is accessible.

  2. SearchController.java L98 — Search must respect VIEWER restrictions

    Requirement: "Search should follow the same restrictions like normal view, Projects with 'Everyone' visibility, all Components & Releases."

    GET /search passes all typeMasks to the search service without filtering.

    For VIEWER this means: components ✅, releases ✅, licenses ✅, projects (EVERYONE only) ⚠️, vulnerabilities ❌, users ❌.

  3. "UserController.java" : POST /users/tokens creates API tokens. Currently the EndpointsFilter blocks all POST requests for VIEWER . This means VIEWER cannot create any token — including READ tokens, which the requirement explicitly allows.
    Additionally, even if the POST were allowed, there's no check preventing VIEWER from requesting WRITE authorities in the token body. The authorities field in the request is user-supplied.

  4. In PermissionUtils.java, DEFAULT_USER_GROUP = UserGroup.USER. Per R8, new org-wide users should default to VIEWER. This needs to change to UserGroup.VIEWER

  5. Keycloak integration — not present
    VIEWER group in Keycloak realm
    Sw360UserStorageProviderFactory update to assign VIEWER by default
    Department-based USER promotion (configurable via orgmapping.properties from PR #3594)

@bibhuti230185 bibhuti230185 force-pushed the feat/readOnlyUserRestEndpoints branch 3 times, most recently from 01a6f72 to 7b66ca9 Compare March 2, 2026 09:08
Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

I guess only one miss-understanding happened here. Rest looks good.

@GMishx
Copy link
Copy Markdown
Member

GMishx commented Mar 10, 2026

A quick question, you'd be implementing the changes for KeyCloak in this branch or in a separate PR? I'd prefer a separate PR to keep it logically separated as well.

@bibhuti230185 bibhuti230185 force-pushed the feat/readOnlyUserRestEndpoints branch from 7b66ca9 to 0009780 Compare March 17, 2026 10:48
Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

Final few changes still needed

) throws TException, URISyntaxException, PaginationParameterException, ResourceClassNotFoundException {

User sw360User = restControllerHelper.getSw360UserFromAuthentication();
restControllerHelper.throwIfViewerUser(sw360User); // VIEWER must not see linked projects
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would still have to be removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please block following endpoints for viewer role as well:

  • /vulnerabilitySummary
  • /vulnerabilities

@bibhuti230185 bibhuti230185 force-pushed the feat/readOnlyUserRestEndpoints branch 2 times, most recently from f3f0a6a to c6065ea Compare March 30, 2026 11:13
Implement read-only VIEWER role (UserGroup.VIEWER) with restricted access across REST API endpoints:
- Block VIEWER from vulnerabilities, obligations, ECC, reports, clearing/moderation requests, and Fossology operations
- Restrict project visibility to EVERYONE for VIEWER users
- Block mutation operations (POST/PATCH/PUT/DELETE) in EndpointsFilter
- Allow VIEWER to create READ-only API tokens
- Strip non-permitted fields from project responses for VIEWER
- Return empty project sets for component/release usedBy queries
- Restrict search to allowed types (no vulnerabilities, obligations)
- Add PermissionUtils.isViewer() and VIEWER case in role hierarchy
- Add VIEWER visibility guard in ProjectPermissions.isVisible()
- Add throwIfViewerUser() helper in RestControllerHelper
- Add unit and REST integration tests for VIEWER restrictions

Signed-off-by: Bibhuti Bhusan Dash <bibhuti230185@gmail.com>
@bibhuti230185 bibhuti230185 force-pushed the feat/readOnlyUserRestEndpoints branch from c6065ea to 8c2ed6e Compare March 31, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs general test This is general testing, meaning that there is no org specific issue to check for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a new Read Only user role

4 participants