You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2026/09/02 06:14:45 UTC

(skywalking-horizon-ui) branch fix/malformed-verb-grants created (now 4ccbd1dd)

This is an automated email from the ASF dual-hosted git repository.

wu-sheng pushed a change to branch fix/malformed-verb-grants
in repository https://gitbox.apache.org/repos/asf/skywalking-horizon-ui.git


      at 4ccbd1dd fix(rbac): a malformed grant confers nothing, instead of the area it starts with

This branch includes the following new commits:

     new 4ccbd1dd fix(rbac): a malformed grant confers nothing, instead of the area it starts with

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(skywalking-horizon-ui) 01/01: fix(rbac): a malformed grant confers nothing, instead of the area it starts with

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wu-sheng pushed a commit to branch fix/malformed-verb-grants
in repository https://gitbox.apache.org/repos/asf/skywalking-horizon-ui.git

commit 4ccbd1dd85c65eedacb2bc892d7d8d403e69d68e
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Sep 2 14:14:35 2026 +0800

    fix(rbac): a malformed grant confers nothing, instead of the area it starts with
    
    The verb grammar is at most three segments, and `matchOne` parsed grants with
    `split(':', 3)` — which TRUNCATES rather than failing. A fourth segment was
    therefore dropped on the floor, so `rule:write:structural:extra` matched
    `rule:write:structural`. Worse, the `area:*` branch never looked at the
    sub-segment at all, so `rule:*:typo` was read as `rule:*` and handed over
    every rule permission there is: read, write, the structural sub-action and
    delete. A typo widened access rather than failing closed.
    
    Both are refused now. `isGrantRecognised` already delegates to this matcher,
    so such a grant is also named in the startup warning rather than sitting in
    a config looking effective.
    
    The same fix lands in the two UI copies of the matcher — the auth store and
    the Roles board — and the three are pinned to a shared table of cases,
    asserted on both sides. They diverged together here, which is the failure a
    per-file review cannot see: each copy was internally consistent and all
    three were wrong in the same way.
---
 apps/bff/src/rbac/verbs.test.ts                | 49 +++++++++++++++++++++++++-
 apps/bff/src/rbac/verbs.ts                     |  9 ++++-
 apps/ui/src/features/admin/roles/RolesView.vue |  5 ++-
 apps/ui/src/state/auth.test.ts                 | 37 +++++++++++++++++++
 apps/ui/src/state/auth.ts                      |  5 ++-
 docs/access-control/rbac.md                    |  2 +-
 docs/changelog/1.1.0.md                        |  2 ++
 docs/setup/rbac.md                             |  2 ++
 8 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/apps/bff/src/rbac/verbs.test.ts b/apps/bff/src/rbac/verbs.test.ts
index c0c70485..e88eafff 100644
--- a/apps/bff/src/rbac/verbs.test.ts
+++ b/apps/bff/src/rbac/verbs.test.ts
@@ -17,7 +17,12 @@
 
 import { describe, expect, it } from 'vitest';
 import { SCOPE_VERBS } from '../oauth/scopes.js';
-import { WILDCARD_EXEMPT_VERBS, hasVerb, resolveVerbsForRoles } from './verbs.js';
+import {
+  WILDCARD_EXEMPT_VERBS,
+  hasVerb,
+  isGrantRecognised,
+  resolveVerbsForRoles,
+} from './verbs.js';
 import { configSchema } from '../config/schema.js';
 import { BUILTIN_ROLES, BUILTIN_LANDING_BY_ROLE } from '../config/builtin-roles.js';
 
@@ -89,6 +94,48 @@ describe('resolveVerbsForRoles', () => {
   });
 });
 
+/** Grant → required → expected. Shared with `apps/ui/src/state/auth.test.ts`,
+ *  which runs the SAME table through the UI's copy of this matcher: three
+ *  copies exist (BFF, auth store, Roles board) and they diverged together
+ *  once, so they are pinned to one answer rather than to one another. */
+export const MATCHER_CASES: ReadonlyArray<[string, string, boolean]> = [
+  // A malformed grant confers nothing — it must never be read as a shorter
+  // one it happens to start with.
+  ['rule:*:typo', 'rule:delete', false],
+  ['rule:*:typo', 'rule:write:structural', false],
+  ['rule:write:structural:extra', 'rule:write:structural', false],
+  ['metrics:read:typo', 'metrics:read', false],
+  ['*:read:typo', 'metrics:read', false],
+  // The documented grammar, unchanged.
+  ['rule:*', 'rule:delete', true],
+  ['rule:*', 'rule:write:structural', true],
+  ['rule:write:structural', 'rule:write:structural', true],
+  ['rule:write:structural', 'rule:write', false],
+  ['*:read', 'metrics:read', true],
+  ['metrics:*', 'metrics:read', true],
+  ['metrics:read', 'metrics:read', true],
+  // Wildcard-exempt: only a bare `*`, `admin`, or the verb itself.
+  ['*:read', 'audit:read', false],
+  ['audit:*', 'audit:read', false],
+  ['audit:read', 'audit:read', true],
+  ['*', 'audit:read', true],
+  ['admin', 'audit:read', true],
+];
+
+describe('the verb grammar, including what is NOT it', () => {
+  it.each(MATCHER_CASES)('%s grants %s → %s', (grant, required, expected) => {
+    expect(hasVerb([grant], required)).toBe(expected);
+  });
+
+  it('a malformed grant is reported at startup rather than quietly granting', () => {
+    // `split(':', 3)` truncates instead of failing, so `rule:*:typo` used to
+    // read as `rule:*` and hand over the whole area.
+    for (const g of ['rule:*:typo', 'rule:write:structural:extra', 'metrics:read:typo']) {
+      expect(isGrantRecognised(g), g).toBe(false);
+    }
+  });
+});
+
 describe('retired verbs still granted by an upgraded horizon.yaml', () => {
   const R = (grants: string[]): string[] =>
     resolveVerbsForRoles({ r: grants }, ['r'], true).sort();
diff --git a/apps/bff/src/rbac/verbs.ts b/apps/bff/src/rbac/verbs.ts
index 61fbed1e..3b220cea 100644
--- a/apps/bff/src/rbac/verbs.ts
+++ b/apps/bff/src/rbac/verbs.ts
@@ -209,10 +209,17 @@ function matchOne(grant: Verb, required: Verb): boolean {
   if (grant === '*' || grant === 'admin') return true;
   if (grant === required) return true;
   if (WILDCARD_EXEMPT_VERBS.has(required)) return false;
+  // The grammar is at most three segments. `split(':', 3)` TRUNCATES rather
+  // than failing, so without this a fourth segment is silently dropped and
+  // `rule:write:structural:typo` grants `rule:write:structural` — a typo that
+  // confers authority instead of none.
+  if (grant.split(':').length > 3) return false;
   // `area:*` matches any verb in that area (and any sub-action — `rule:*` covers `rule:write:structural`)
   const [grantArea, grantAction, grantSub] = grant.split(':', 3);
   const [reqArea, reqAction, reqSub] = required.split(':', 3);
-  if (grantArea === reqArea && grantAction === '*') return true;
+  // `grantSub` must be absent: `rule:*:typo` is not a narrower `rule:*`, it is
+  // malformed, and reading it as the area wildcard grants the whole area.
+  if (grantArea === reqArea && grantAction === '*' && grantSub === undefined) return true;
   // `*:action` matches that action in any area
   if (grantArea === '*' && grantAction === reqAction && (grantSub ?? '') === (reqSub ?? '')) return true;
   // Sub-action exact match (e.g. grant `rule:write:structural` only matches itself)
diff --git a/apps/ui/src/features/admin/roles/RolesView.vue b/apps/ui/src/features/admin/roles/RolesView.vue
index 02904e5b..c7c95a0d 100644
--- a/apps/ui/src/features/admin/roles/RolesView.vue
+++ b/apps/ui/src/features/admin/roles/RolesView.vue
@@ -58,9 +58,12 @@ function hasVerb(grants: readonly string[], required: string): boolean {
     // this board draws a check mark for a grant the server denies, on the row
     // whose own hint says a wildcard does not include it.
     if (WILDCARD_EXEMPT_VERBS.has(required)) continue;
+    // Both as the BFF: a fourth segment is malformed rather than truncated,
+    // and `area:*` carries no sub-segment.
+    if (g.split(':').length > 3) continue;
     const gp = g.split(':', 3);
     const rp = required.split(':', 3);
-    if (gp[0] === rp[0] && gp[1] === '*') return true;
+    if (gp[0] === rp[0] && gp[1] === '*' && gp[2] === undefined) return true;
     if (gp[0] === '*' && gp[1] === rp[1] && (gp[2] ?? '') === (rp[2] ?? '')) return true;
     if (gp[0] === rp[0] && gp[1] === rp[1] && (gp[2] ?? '') === (rp[2] ?? '')) return true;
   }
diff --git a/apps/ui/src/state/auth.test.ts b/apps/ui/src/state/auth.test.ts
index 0b916d0e..da2e706f 100644
--- a/apps/ui/src/state/auth.test.ts
+++ b/apps/ui/src/state/auth.test.ts
@@ -103,3 +103,40 @@ describe('auth store — no cached data survives an identity change', () => {
     expect(queryClient.getQueryCache().getAll()).toHaveLength(0);
   });
 });
+
+/**
+ * The same table `apps/bff/src/rbac/verbs.test.ts` asserts, run through the
+ * UI's copy of the matcher. Three copies of it exist — this store, the Roles
+ * board, and the BFF — and they diverged together once: a malformed grant
+ * (`rule:*:typo`) read as the area wildcard on all three, so the sidebar
+ * offered pages the server would have allowed too. Pin them to one answer.
+ */
+const MATCHER_CASES: ReadonlyArray<[string, string, boolean]> = [
+  ['rule:*:typo', 'rule:delete', false],
+  ['rule:*:typo', 'rule:write:structural', false],
+  ['rule:write:structural:extra', 'rule:write:structural', false],
+  ['metrics:read:typo', 'metrics:read', false],
+  ['*:read:typo', 'metrics:read', false],
+  ['rule:*', 'rule:delete', true],
+  ['rule:*', 'rule:write:structural', true],
+  ['rule:write:structural', 'rule:write:structural', true],
+  ['rule:write:structural', 'rule:write', false],
+  ['*:read', 'metrics:read', true],
+  ['metrics:*', 'metrics:read', true],
+  ['metrics:read', 'metrics:read', true],
+  ['*:read', 'audit:read', false],
+  ['audit:*', 'audit:read', false],
+  ['audit:read', 'audit:read', true],
+  ['*', 'audit:read', true],
+  ['admin', 'audit:read', true],
+];
+
+describe('the auth store answers the verb grammar exactly as the BFF does', () => {
+  beforeEach(() => setActivePinia(createPinia()));
+
+  it.each(MATCHER_CASES)('%s grants %s → %s', (grant, required, expected) => {
+    const auth = useAuthStore();
+    auth.user = { username: 'u', roles: ['r'], verbs: [grant] } as MeResponse;
+    expect(auth.hasVerb(required)).toBe(expected);
+  });
+});
diff --git a/apps/ui/src/state/auth.ts b/apps/ui/src/state/auth.ts
index c94a8e43..1371a25f 100644
--- a/apps/ui/src/state/auth.ts
+++ b/apps/ui/src/state/auth.ts
@@ -108,9 +108,12 @@ export const useAuthStore = defineStore('auth', () => {
       // BEFORE both wildcard branches, so `*:read` and `audit:*` are equally
       // denied.
       if (WILDCARD_EXEMPT_VERBS.has(verb)) continue;
+      // Both as the BFF: a fourth segment is malformed rather than truncated,
+      // and `area:*` carries no sub-segment.
+      if (g.split(':').length > 3) continue;
       const [ga, gact, gsub] = g.split(':', 3);
       const [ra, ract, rsub] = verb.split(':', 3);
-      if (ga === ra && gact === '*') return true;
+      if (ga === ra && gact === '*' && gsub === undefined) return true;
       if (ga === '*' && gact === ract && (gsub ?? '') === (rsub ?? '')) return true;
       if (ga === ra && gact === ract && (gsub ?? '') === (rsub ?? '')) return true;
     }
diff --git a/docs/access-control/rbac.md b/docs/access-control/rbac.md
index 09fb2f89..0f39020f 100644
--- a/docs/access-control/rbac.md
+++ b/docs/access-control/rbac.md
@@ -102,7 +102,7 @@ A user's grant string is matched against a required verb using these rules:
 |---|---|
 | `*` or `admin` | Any verb. |
 | `area:verb` (exact) | The exact required verb (case-sensitive). |
-| `area:*` | Any verb in that area, including sub-actions: `rule:*` matches `rule:read`, `rule:write`, `rule:write:structural`, `rule:delete`. |
+| `area:*` | Any verb in that area, including sub-actions: `rule:*` matches `rule:read`, `rule:write`, `rule:write:structural`, `rule:delete`. The `*` is the whole second segment — `rule:*:anything` is not a narrower form of this, it is malformed, and grants nothing. |
 | `*:read` | The `read` action in any area: matches `metrics:read`, `alarms:read`, `cluster:read`, etc. Does **not** match `rule:write:structural` (the action is not `read`), and does **not** match `audit:read` — see below. |
 
 Effective verbs for a session are the **union** of all grants from all roles.
diff --git a/docs/changelog/1.1.0.md b/docs/changelog/1.1.0.md
index 2f0417e6..fbdfd322 100644
--- a/docs/changelog/1.1.0.md
+++ b/docs/changelog/1.1.0.md
@@ -19,6 +19,8 @@
 
 ### Fixes
 
+**A malformed permission no longer grants more than it says.** A grant is at most three segments, but a longer one used to be silently truncated to its first three — so `rule:*:typo` was read as `rule:*` and handed over every rule permission, and `rule:write:structural:extra` matched `rule:write:structural`. Anything outside the documented forms now matches nothing and is named in the startup warning alongside other unrecognised grants.
+
 **The BanyanDB audit configuration is only what a deployment actually differs on** — where the server is, how to authenticate to it, a namespace prefix, and how long to keep records. The groups' layout is bundled rather than exposed: one shard, which a sign-in rate never outgrows. That is also the safe default, because BanyanDB fixes a group's shard count at creation and does not move data when it changes — a shard count edited after records exist would route new ones away from the old o [...]
 
 **The login audit list pages the way every other SkyWalking list does.** It asks for a page number rather than carrying a position between requests, which is the arrangement OAP uses for traces, logs, alarms and events alike. The page still shows 50 rows at a time and still reports only whether more exist; paging is bounded at 500 pages deep, and a request past that is refused rather than quietly answered with something else.
diff --git a/docs/setup/rbac.md b/docs/setup/rbac.md
index 2a2832f4..fe3fdd77 100644
--- a/docs/setup/rbac.md
+++ b/docs/setup/rbac.md
@@ -96,6 +96,8 @@ Grants are dot-namespaced strings. Four matching modes:
 | `area:*` | Matches any verb in that area: `rule:*` grants `rule:read`, `rule:write`, `rule:write:structural`, `rule:delete`. |
 | `*:read` | Matches the `read` action across any area. |
 
+Nothing else is a grant. A string outside these forms — a typo like `rule:*:typo`, or a fourth segment — matches no verb and confers nothing; Horizon names it in a startup warning so it does not sit in your config looking effective.
+
 A user's effective verbs are the **union** of all grants from all their roles.
 
 ## `landingByRole`