Skip to content

Offer console actions only to users whose scopes allow the call - #4135

Merged
lasanthaS merged 1 commit into
wso2:mainfrom
HiranyaKavishani:console-scope-gated-actions
Nov 9, 2026
Merged

lasanthaS merged 1 commit into
wso2:mainfrom
HiranyaKavishani:console-scope-gated-actions

Conversation

@HiranyaKavishani

@HiranyaKavishani HiranyaKavishani commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

When scope enforcement is on, the gateway checks every console call against the scopes the route accepts. The console, though, offered several actions without checking whether the signed-in user's scopes allow the call behind them. A user without the scope saw the button, clicked it, and got 401 Authentication failed, or opened a page full of actions that all failed.

These were found by signing in as each WSO2 Cloud organization role (Admin, Platform Engineer, Developer, API Publisher) and comparing every gated control in the console with the scopes of the API call it makes.

Goals

Offer an action only to a user whose scopes allow the call it makes:

  • If the user can still read the data, show it read-only, or keep the button visible but disabled with the console's standard tooltip "You don't have permission to perform this action."
  • If the action has no meaning for the user, hide it.

Approach

The console already has the permission machinery. OPERATION_SCOPES (generated from the OpenAPI spec) maps each operation to its accepted scopes, and useCan(operation) / useActionPermission(operation) answer "does this session hold one of them?". The cloud plugins do the same with permissions.canAny(scopes). This PR applies those checks where they were missing.

1. Publishing an API to a portal

Where: an API's Publish page (left menu Publish). It lists one card per API Portal, each with a Publish button (and a menu with Configure & Publish). The button opens the per-portal publish page and publishes automatically.

Control Before After
Publish button on each portal card Enabled for everyone; a user without publish rights clicked it and got 401 Disabled, with the "You don't have permission" tooltip, unless the user may publish this kind of API (publishRestApiToApiPortal / publishGraphQLApiToApiPortal)
Per-portal publish page: Save draft, Publish, Unpublish, Deprecate Shown to everyone; every click failed with 401 Shown only to users who may publish. Others see the publication read-only. Save draft also needs saveApiPublicationDraft.
Auto-publish when arriving from a card's Publish Ran for everyone Runs only for users who may publish
Publish item in the left menu, and the Publish step in the API overview's progress bar Shown and clickable for everyone Menu item hidden, and step not clickable (still shows progress), for users who cannot publish
Add Portal on the Publish page when the API has no portal yet Shown to everyone Shown only to users who may create a portal (CreateApiPortal)

2. Policies

Where: an API's Develop → Policies page.

Before After
Editing (drag a policy on, edit, remove, reorder, Save) was available to everyone, unless a gateway owned the API. Saving is an API update, so a user without update rights got 401. Without UpdateRESTAPI / UpdateGraphQLAPI the page is read-only: policies are listed, the editing controls are off. This is the same view a gateway-owned API already had, but without the "managed by the gateway" notice.

3. Test

Where: an API's Test page.

Before After
On opening, the page created a test API key (POST …/api-keys). Users without key-create rights saw an error as soon as the page loaded. The key is created only with CreateAPIKey / CreateGraphQLAPIKey.
Proxy call mode (the default) sends the request through the control plane (InvokeRESTAPIOnGateway); without that scope, Execute failed with 401. Without that scope the page uses direct mode: the browser calls the gateway itself.

4. API list

Where: a project's APIs list, the delete action on each row or card.

Before After
Deleting a GraphQL API was gated on the REST permission (DeleteRESTAPI) Gated on DeleteGraphQLAPI

5. Deploy (cloud plugin apip-cloud-ui-deploy)

Where: an API's Deploy page in WSO2 Cloud.

Control Before After
Add self-hosted / Cloud API gateway, shown when the project has no gateway yet Enabled for everyone; users without gateway-create rights got 401 Enabled only with ap:gateway:create or ap:gateway:manage; otherwise disabled with the tooltip
Deploy, Promote, Stop Required the pipeline-wide ap:deployment:deploy / undeploy / manage Also accept the API kind's own deployment scopes: ap:rest_api:deployment:create|undeploy|manage, the ap:graphql_api:… equivalents, and ap:rest_api:manage / ap:graphql_api:manage. Developers and API Publishers can deploy the APIs they build.

6. Gateway details (cloud plugin apip-cloud-ui-gateways)

Where: API Gateways → open a gateway.

Control Before After
Registration token Opening a gateway created a registration token automatically; users without token rights got a 401 error message Created (and Reconfigure enabled) only with the token scopes (ap:gateway:token:create|manage, ap:gateway:manage)
Edit button Shown to everyone; it bounced back for users who could not update Shown only with UpdateManagedGateway

7. "Deploy to Gateway" button

Where: the API overview header.

Before After
Gated on the built-in DeployAPI operation, even in WSO2 Cloud, where the Deploy page is replaced by a cloud plugin that deploys under different scopes. A user could see an enabled Deploy to Gateway and land on a page where every action was disabled. New optional extension field actionScopes: a page override declares the scopes its main action needs. The cloud declares its deploy scopes. A user without them sees View deployments instead.

8. New feature key project-delete

Before After
Delete project was always offered. The WSO2 Cloud gateway serves no DELETE /projects/{id} (projects are deleted from the Cloud Console), so it failed with 404. project-delete joins the disable_features list. A deployment that deletes projects elsewhere hides the action. Nothing changes unless a deployment sets it.

Result per WSO2 Cloud role

Action Admin Platform Engineer Developer API Publisher
Publish (menu, card buttons, page actions) ✓ hidden or disabled hidden or disabled ✓
Edit policies ✓ read-only ✓ ✓
Test page key and proxy mode ✓ no (direct mode) ✓ ✓
Deploy to Gateway, Deploy, Stop ✓ ✓ ✓ ✓
Add gateway (Deploy page) ✓ ✓ disabled disabled
Gateway registration token, Edit ✓ ✓ no no
Add Portal (empty Publish page) ✓ ✓ hidden ✓ (with wso2cloud-deployment #6467)

User stories

  • As a Developer, I'm not shown publishing or portal creation, and I can deploy the APIs I build.
  • As a Platform Engineer, I see APIs and policies read-only, and the Test page does not fail on load.
  • As an API Publisher, I can publish, and I'm not offered gateway creation.

Documentation

N/A: behaviour follows the existing scopes. project-delete is listed with the other disable_features names in src/config/features.ts.

Automation tests

  • Unit tests: new PortalPublicationCard.test.tsx (Publish enabled with the right, disabled without it). Typecheck and lint are clean. In the suites for portals, overview, navigation, permissions and config, 572 of 577 pass; the 5 failures (PortalPublishPage thumbnail and banner timing) also fail on unmodified main in the same environment (6 there). Cloud-plugin deploy suite: 66 of 66.
  • Integration tests: a headless-Chrome run against a local WSO2 Cloud stack with gateway scope enforcement on, signed in as each of the four roles: 60 of 60 control checks match each role's scopes, with no 401 on any page load. The per-portal publish page and the gateway details page were not exercised live, because the test organization had no portal or gateway to open.

Security checks

  • Followed secure coding standards? yes
  • Ran FindSecurityBugs plugin and verified report? N/A (TypeScript; eslint clean)
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes

Related PRs

  • wso2-enterprise/wso2cloud-deployment#6466 and wso2-enterprise/apim-saas#3464: the gateway routes and cloud spec accept the API kind's deployment scopes for deploy and stop. Merge together with this PR, or the Deploy button is offered to roles the gateway still refuses.
  • wso2-enterprise/wso2cloud-deployment#6467: API Publisher may create portals.
  • jwt-auth v1.6.0: answer a valid token without the required scope with 403 gateway-controllers#393: jwt-auth answers a missing scope with 403 instead of 401 (independent).

Test environment

macOS, Node 22, local WSO2 Cloud (OpenChoreo k3d), Chrome (headless).

🤖 Generated with Claude Code

With scopes enforced at the gateway, several console actions were offered
to roles whose token cannot make the call behind them, so the user clicked
and got 401 ("Authentication failed"), or reached a page they could only
read:

- Publish page and portal cards: publish, unpublish, deprecate and save
  draft need the API kind's publication / draft scopes; without them the
  page is read-only and the card's Publish is disabled with the reason.
- Publish sidebar item and the overview's Publish step: shown / linked only
  for users who may publish. The empty-state Add Portal needs CreateApiPortal.
- Policies: editing needs UpdateRESTAPI / UpdateGraphQLAPI (saving is an
  API update); otherwise the panel is read-only.
- Test page: the test API key is minted only with CreateAPIKey /
  CreateGraphQLAPIKey, and the proxy call mode needs InvokeRESTAPIOnGateway
  (else the request goes direct).
- API list: GraphQL rows are deleted under DeleteGraphQLAPI, not DeleteRESTAPI.
- Cloud Deploy page: adding a gateway needs ap:gateway:create|manage; deploy
  and stop also accept the API kind's deployment scopes
  (ap:{rest,graphql}_api:deployment:create|undeploy|manage, *_api:manage).
- Cloud gateway overview: minting / reconfiguring registration tokens needs
  the token scopes; Edit follows UpdateManagedGateway.
- Deploy to Gateway: a host that overrides the Deploy page declares
  actionScopes (the cloud: its deploy scopes); a user without them gets
  "View deployments".
- New feature key project-delete, for deployments whose projects are deleted
  elsewhere (the cloud gateway serves no DELETE /projects/{id}).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 39ff60c and cff2520.

Files selected for processing: 29

  • portals/api-control-plane/src/config/features.ts
  • portals/api-control-plane/src/extensions.tsx
  • portals/api-control-plane/src/navigation/navigationRegistry.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/apis/listing/ApiListView.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/apis/listing/components/ApiCard.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/apis/overview/ApiDetailPage.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/apis/overview/ApiOverviewHeader.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/apis/overview/ProgressBanner.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/develop/policies/PolicyPanel.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/graphqlApis/develop/GraphqlPolicyPanel.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/graphqlApis/overview/GraphqlApiDetailPage.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/graphqlApis/overview/GraphqlProgressBanner.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/organizations/OrganizationHomePage.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/portals/ApiPortalPublicationsList.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/portals/PortalPublishPage.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/portals/components/PortalPublicationCard.test.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/portals/components/PortalPublicationCard.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/projects/ProjectsList.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/projects/components/ProjectCard.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/test/TestPage.tsx
  • portals/api-control-plane/src/pages/appShell/appShellPages/test/utils/useTestApiKey.ts
  • portals/cloud-plugins/apip-cloud-ui-deploy/src/DeployFeature.tsx
  • portals/cloud-plugins/apip-cloud-ui-deploy/src/DeployPage.tsx
  • portals/cloud-plugins/apip-cloud-ui-deploy/src/components/NoGatewayState.tsx
  • portals/cloud-plugins/apip-cloud-ui-deploy/src/permissions.ts
  • portals/cloud-plugins/apip-cloud-ui-gateways/src/GatewaysFeature.tsx
  • portals/cloud-plugins/apip-cloud-ui-gateways/src/components/GatewayOverview.tsx
  • portals/cloud-plugins/apip-cloud-ui-gateways/src/permissions.ts
  • portals/cloud-plugins/apip-cloud-ui/src/hosts/api-control-plane.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

@codecov-commenter

codecov-commenter commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.17%. Comparing base (4bdddde) to head (cff2520).
⚠️ Report is 47 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4135      +/-   ##
==========================================
- Coverage   64.13%   62.17%   -1.96%     
==========================================
  Files        1279     1308      +29     
  Lines      197785   200840    +3055     
  Branches     6239     6265      +26     
==========================================
- Hits       126847   124871    -1976     
- Misses      62072    67338    +5266     
+ Partials     8866     8631     -235     
Flag Coverage Δ
ai-workspace-bff-integration 11.90% <ø> (ø)
ai-workspace-bff-unit 82.44% <ø> (ø)
ai-workspace-ui-integration 28.68% <ø> (+0.23%) ⬆️
ai-workspace-ui-unit 84.22% <ø> (-0.02%) ⬇️
api-portal-server-integration 66.83% <ø> (+1.90%) ⬆️
api-portal-ui-integration 51.52% <ø> (+4.47%) ⬆️
api-portal-unit 75.02% <ø> (+2.45%) ⬆️
gateway-controller-integration 29.25% <ø> (-24.53%) ⬇️
platform-api-integration 30.68% <ø> (-20.22%) ⬇️
policy-engine-integration 27.74% <ø> (-8.98%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@lasanthaS
lasanthaS merged commit 6ccf5fa into wso2:main Nov 9, 2026
8 checks passed
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.

3 participants