mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 02:24:21 +01:00
Explain complete RBAC role replacement without losing saved restrictions (#4026)
Use the current tenant-store semantics to explain preserving effects, conditions and role metadata. Keep private and uncertain-outcome guidance, with all example fields still visible. Contract-Neutral: Existing RBAC documentation and recipe checks only. No route, grant, persistence or runtime policy changes. --- Fleet candidate `20261106T140016Z-product-intelligence` from the `product-intelligence` lane. Reviewed tip `407e80c3adb461f8c07bf6501a33f593d2b74445` on `main`. [How Pulse handles triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
77
docs/RBAC.md
77
docs/RBAC.md
@@ -118,43 +118,43 @@ permission exports, tokens, cookies and full responses private.
|
||||
|
||||
### Before Using the API
|
||||
|
||||
Prefer **Settings → Security → Roles** and **Settings → Security → Users** for one-off administration.
|
||||
The API examples require the licensed `rbac` capability and permission to
|
||||
administer users. With RBAC enabled, role and user administration requires a
|
||||
full-access (`*`) API token bound to an authorised administrator; a monitoring
|
||||
token is not enough. Do not widen an agent's token for this job.
|
||||
Prefer **Settings → Security → Roles** and **Settings → Security → Users** for
|
||||
one-off changes. API calls need licensed `rbac`, permission to administer users and a
|
||||
full-access (`*`) token bound to an authorised administrator. A monitoring token
|
||||
is not enough. Do not widen an agent's token.
|
||||
|
||||
If you already use an administration token, prepare its private header file
|
||||
and define `pulse_api` **in the same Bash session** using
|
||||
[API authentication](API.md#-authentication). The helper is local example code,
|
||||
not an installed Pulse command. Never paste the token or a session cookie into
|
||||
a command, URL or report, or use browser **Copy as cURL**.
|
||||
Use [API authentication](API.md#-authentication) to prepare a private header
|
||||
file and define `pulse_api` **in the same Bash session**. It is example code,
|
||||
not an installed Pulse command. Never paste tokens or session cookies into
|
||||
commands, URLs or reports, or use **Copy as cURL**. Use loopback on the Pulse
|
||||
host. Remotely, use that guide's HTTPS origin with certificate verification enabled.
|
||||
|
||||
On the Pulse host, the helper uses loopback; for remote use, follow that guide's
|
||||
HTTPS-origin instructions and keep certificate verification enabled. It makes
|
||||
one request with a five-second connection limit and a twenty-second total limit,
|
||||
prints only the HTTP status and saves each response in a new owner-only file.
|
||||
Inspect the file privately, including on failure: role lists, user identities
|
||||
and errors can contain private information. Share only a relevant redacted
|
||||
excerpt, not full responses, header files or tokens. HTTP 401/402/403, redirects
|
||||
and transport errors are not an empty role or user list.
|
||||
The helper sends one request with five-second connection and twenty-second
|
||||
total limits. It prints only HTTP status and saves each response in a new
|
||||
owner-only file. Inspect errors and results privately. Share only a relevant
|
||||
redacted excerpt, not full responses, header files or tokens.
|
||||
HTTP 401/402/403, redirects and transport errors are not an empty role or user list.
|
||||
|
||||
**These are separate operations, not a script to run from top to bottom.**
|
||||
Choose the intended target and change before making a request; preserve an
|
||||
existing administrator recovery path. Deleting a role or user and sending an
|
||||
empty role list remove access. After a change, check that target's saved roles
|
||||
and intended access through the normal UI or a separate read-only request.
|
||||
The helper does not follow redirects or retry. A timeout or partial response
|
||||
can occur **after the change was applied**; inspect the current state before
|
||||
deciding what to do, rather than repeating the mutation blindly. HTTP success
|
||||
alone does not establish the intended access or disable an upstream IdP account.
|
||||
**Choose each operation separately, not as a top-to-bottom script.** Keep an
|
||||
administrator recovery path. Deleting a role or user, or sending an empty role
|
||||
list, removes access. The helper does not follow redirects or retry. A partial
|
||||
response or timeout can follow an applied change. Check saved roles and intended
|
||||
access in the UI or a separate read before writing again. HTTP success does not
|
||||
prove access or disable an upstream IdP account.
|
||||
|
||||
**Role PUT replaces the complete policy.** Read the existing role from
|
||||
`GET /api/admin/roles`. Preserve its exact ID, `parentId`, `priority`, and each
|
||||
permission's `effect` and `conditions`, except for intended changes. Missing
|
||||
`effect` means `allow`, not “keep deny”. Use lowercase `allow` or `deny`. Stop
|
||||
on failed reads or missing/null `permissions`. Coordinate writers.
|
||||
Re-read the list after saving, not just the write response.
|
||||
|
||||
### Creating a Role
|
||||
|
||||
**UI:** Settings → Security → Roles → New Role
|
||||
|
||||
Use a new custom role ID. Built-in roles (`admin`, `operator`, `viewer`,
|
||||
`auditor`) cannot be modified or deleted. These examples use `alert-manager`.
|
||||
Use a new role ID. Built-in roles (`admin`, `operator`, `viewer`,
|
||||
`auditor`) cannot be modified or deleted. These examples use the new `alert-manager`.
|
||||
|
||||
**API:**
|
||||
```bash
|
||||
@@ -180,18 +180,17 @@ pulse_api GET /api/admin/roles
|
||||
|
||||
### Updating a Role
|
||||
|
||||
**Full replacement.** [Preserve saved fields](#before-using-the-api).
|
||||
|
||||
```bash
|
||||
pulse_api PUT /api/admin/roles/alert-manager <<'JSON'
|
||||
{
|
||||
"name": "Alert Manager",
|
||||
"description": "Updated description",
|
||||
"permissions": [
|
||||
{"action": "read", "resource": "alerts"},
|
||||
{"action": "write", "resource": "alerts"},
|
||||
{"action": "read", "resource": "nodes"},
|
||||
{"action": "read", "resource": "ai"}
|
||||
]
|
||||
}
|
||||
{ "permissions": [
|
||||
{"action": "read", "resource": "alerts"},
|
||||
{"action": "write", "resource": "alerts"},
|
||||
{"action": "read", "resource": "nodes"},
|
||||
{"action": "read", "resource": "ai"}
|
||||
], "name": "Alert Manager",
|
||||
"description": "Updated description" }
|
||||
JSON
|
||||
```
|
||||
|
||||
|
||||
@@ -118,43 +118,43 @@ permission exports, tokens, cookies and full responses private.
|
||||
|
||||
### Before Using the API
|
||||
|
||||
Prefer **Settings → Security → Roles** and **Settings → Security → Users** for one-off administration.
|
||||
The API examples require the licensed `rbac` capability and permission to
|
||||
administer users. With RBAC enabled, role and user administration requires a
|
||||
full-access (`*`) API token bound to an authorised administrator; a monitoring
|
||||
token is not enough. Do not widen an agent's token for this job.
|
||||
Prefer **Settings → Security → Roles** and **Settings → Security → Users** for
|
||||
one-off changes. API calls need licensed `rbac`, permission to administer users and a
|
||||
full-access (`*`) token bound to an authorised administrator. A monitoring token
|
||||
is not enough. Do not widen an agent's token.
|
||||
|
||||
If you already use an administration token, prepare its private header file
|
||||
and define `pulse_api` **in the same Bash session** using
|
||||
[API authentication](API.md#-authentication). The helper is local example code,
|
||||
not an installed Pulse command. Never paste the token or a session cookie into
|
||||
a command, URL or report, or use browser **Copy as cURL**.
|
||||
Use [API authentication](API.md#-authentication) to prepare a private header
|
||||
file and define `pulse_api` **in the same Bash session**. It is example code,
|
||||
not an installed Pulse command. Never paste tokens or session cookies into
|
||||
commands, URLs or reports, or use **Copy as cURL**. Use loopback on the Pulse
|
||||
host. Remotely, use that guide's HTTPS origin with certificate verification enabled.
|
||||
|
||||
On the Pulse host, the helper uses loopback; for remote use, follow that guide's
|
||||
HTTPS-origin instructions and keep certificate verification enabled. It makes
|
||||
one request with a five-second connection limit and a twenty-second total limit,
|
||||
prints only the HTTP status and saves each response in a new owner-only file.
|
||||
Inspect the file privately, including on failure: role lists, user identities
|
||||
and errors can contain private information. Share only a relevant redacted
|
||||
excerpt, not full responses, header files or tokens. HTTP 401/402/403, redirects
|
||||
and transport errors are not an empty role or user list.
|
||||
The helper sends one request with five-second connection and twenty-second
|
||||
total limits. It prints only HTTP status and saves each response in a new
|
||||
owner-only file. Inspect errors and results privately. Share only a relevant
|
||||
redacted excerpt, not full responses, header files or tokens.
|
||||
HTTP 401/402/403, redirects and transport errors are not an empty role or user list.
|
||||
|
||||
**These are separate operations, not a script to run from top to bottom.**
|
||||
Choose the intended target and change before making a request; preserve an
|
||||
existing administrator recovery path. Deleting a role or user and sending an
|
||||
empty role list remove access. After a change, check that target's saved roles
|
||||
and intended access through the normal UI or a separate read-only request.
|
||||
The helper does not follow redirects or retry. A timeout or partial response
|
||||
can occur **after the change was applied**; inspect the current state before
|
||||
deciding what to do, rather than repeating the mutation blindly. HTTP success
|
||||
alone does not establish the intended access or disable an upstream IdP account.
|
||||
**Choose each operation separately, not as a top-to-bottom script.** Keep an
|
||||
administrator recovery path. Deleting a role or user, or sending an empty role
|
||||
list, removes access. The helper does not follow redirects or retry. A partial
|
||||
response or timeout can follow an applied change. Check saved roles and intended
|
||||
access in the UI or a separate read before writing again. HTTP success does not
|
||||
prove access or disable an upstream IdP account.
|
||||
|
||||
**Role PUT replaces the complete policy.** Read the existing role from
|
||||
`GET /api/admin/roles`. Preserve its exact ID, `parentId`, `priority`, and each
|
||||
permission's `effect` and `conditions`, except for intended changes. Missing
|
||||
`effect` means `allow`, not “keep deny”. Use lowercase `allow` or `deny`. Stop
|
||||
on failed reads or missing/null `permissions`. Coordinate writers.
|
||||
Re-read the list after saving, not just the write response.
|
||||
|
||||
### Creating a Role
|
||||
|
||||
**UI:** Settings → Security → Roles → New Role
|
||||
|
||||
Use a new custom role ID. Built-in roles (`admin`, `operator`, `viewer`,
|
||||
`auditor`) cannot be modified or deleted. These examples use `alert-manager`.
|
||||
Use a new role ID. Built-in roles (`admin`, `operator`, `viewer`,
|
||||
`auditor`) cannot be modified or deleted. These examples use the new `alert-manager`.
|
||||
|
||||
**API:**
|
||||
```bash
|
||||
@@ -180,18 +180,17 @@ pulse_api GET /api/admin/roles
|
||||
|
||||
### Updating a Role
|
||||
|
||||
**Full replacement.** [Preserve saved fields](#before-using-the-api).
|
||||
|
||||
```bash
|
||||
pulse_api PUT /api/admin/roles/alert-manager <<'JSON'
|
||||
{
|
||||
"name": "Alert Manager",
|
||||
"description": "Updated description",
|
||||
"permissions": [
|
||||
{"action": "read", "resource": "alerts"},
|
||||
{"action": "write", "resource": "alerts"},
|
||||
{"action": "read", "resource": "nodes"},
|
||||
{"action": "read", "resource": "ai"}
|
||||
]
|
||||
}
|
||||
{ "permissions": [
|
||||
{"action": "read", "resource": "alerts"},
|
||||
{"action": "write", "resource": "alerts"},
|
||||
{"action": "read", "resource": "nodes"},
|
||||
{"action": "read", "resource": "ai"}
|
||||
], "name": "Alert Manager",
|
||||
"description": "Updated description" }
|
||||
JSON
|
||||
```
|
||||
|
||||
|
||||
@@ -276,13 +276,54 @@ class AdminDocsTest(unittest.TestCase):
|
||||
|
||||
def test_rbac_guidance_preserves_private_and_uncertain_change_boundaries(self):
|
||||
guide = (DOCS / "RBAC.md").read_text()
|
||||
readable = " ".join(guide.replace("**", "").split())
|
||||
for boundary in ("in the same Bash session", "not an installed Pulse command",
|
||||
"owner-only file", "redacted", "five-second", "twenty-second",
|
||||
"not a script to run from top to bottom", "administrator recovery path",
|
||||
"empty role list remove access", "does not follow redirects or retry",
|
||||
"after the change was applied", "inspect the current state",
|
||||
"not as a top-to-bottom script", "administrator recovery path",
|
||||
"empty role list, removes access", "does not follow redirects or retry",
|
||||
"timeout can follow an applied change", "read before writing again",
|
||||
"HTTP success", "upstream IdP account"):
|
||||
self.assertIn(boundary, guide)
|
||||
self.assertIn(boundary, readable)
|
||||
|
||||
def test_role_replacement_guidance_preserves_the_current_policy(self):
|
||||
guide = (DOCS / "RBAC.md").read_text()
|
||||
readable = " ".join(guide.replace("**", "").split())
|
||||
for boundary in (
|
||||
"Role PUT replaces the complete policy",
|
||||
"existing role from `GET /api/admin/roles`",
|
||||
"exact ID, `parentId`, `priority`",
|
||||
"each permission's `effect` and `conditions`",
|
||||
"Missing `effect` means `allow`, not “keep deny”",
|
||||
"lowercase `allow` or `deny`",
|
||||
"Stop on failed reads or missing/null `permissions`",
|
||||
"Coordinate writers",
|
||||
"Re-read the list after saving, not just the write response",
|
||||
"examples use the new `alert-manager`",
|
||||
):
|
||||
with self.subTest(boundary=boundary):
|
||||
self.assertIn(boundary, readable)
|
||||
update = guide.split("### Updating a Role\n", 1)[1].split("### Deleting a Role\n", 1)[0]
|
||||
self.assertIn("**Full replacement.** [Preserve saved fields](#before-using-the-api).", update)
|
||||
|
||||
# The live tenant store, not the legacy file manager, owns this policy.
|
||||
provider = (ROOT / "internal/api/access_tenant_provider.go").read_text()
|
||||
self.assertIn("auth.NewSQLiteManager(auth.SQLiteManagerConfig{", provider)
|
||||
handler = (ROOT / "internal/api/access_control_handlers.go").read_text()
|
||||
put = handler.split("case http.MethodPut:", 1)[1].split("case http.MethodDelete:", 1)[0]
|
||||
self.assertIn("var role auth.Role", put)
|
||||
self.assertIn("role.ID = roleID", put)
|
||||
self.assertIn("manager.SaveRole(role)", put)
|
||||
store = (ROOT / "pkg/auth/sqlite_manager.go").read_text()
|
||||
save = store.split("func (m *SQLiteManager) SaveRoleWithContext(", 1)[1].split("func (m *SQLiteManager) getRoleUnsafe(", 1)[0]
|
||||
for field in ("name", "description", "parent_id", "priority"):
|
||||
self.assertIn(f"{field} = excluded.{field}", save)
|
||||
self.assertIn('DELETE FROM rbac_permissions WHERE role_id = ?', save)
|
||||
self.assertIn("effect := perm.GetEffect()", save)
|
||||
self.assertIn("json.Marshal(perm.Conditions)", save)
|
||||
role = (ROOT / "pkg/auth/rbac.go").read_text()
|
||||
self.assertIn('if p.Effect == "" {\n\t\treturn EffectAllow', role)
|
||||
evaluator = (ROOT / "pkg/auth/policy_evaluator.go").read_text()
|
||||
self.assertIn("if len(perm.Conditions) == 0 {\n\t\treturn true", evaluator)
|
||||
|
||||
def test_rbac_operations_keep_private_success_bodies_in_new_owner_only_files(self):
|
||||
steps = recipes("RBAC")
|
||||
|
||||
Reference in New Issue
Block a user