Repository navigation
docs: clarify component vs access roles and add custom node roles recipe - #985
roonakyadav wants to merge 4 commits into
Conversation
- Distinguish component roles (mesh:role:node, mesh:role:router) from custom access roles (caller, developer, analyst). - Clarify that bootstrap tokens only enroll component identities and cannot enroll arbitrary access roles. - Add practical step-by-step guide under guides/custom-node-roles.md demonstrating token creation, enrollment, PeerID lookup, policy binding via node:<peer-id>, and call verification. - Document policy propagation timing within the sync jitter window (0-90s by default). - Clarify that effective permissions come from policy evaluation rather than the roles printed in a node's Biscuit credential. - Update policy, headless enrollment, control-plane, agentmesh-one, and agentmesh-node references. Closes google#957
There was a problem hiding this comment.
Code Review
This pull request introduces a new guide on granting custom access roles to a node and updates existing documentation to clarify the distinction between component roles and access roles. The review feedback points out two important improvements for the new guide: first, adding a step to pre-create the API token file to prevent startup failures, and second, adding a warning to ensure users merge policy changes rather than overwriting their entire mesh policy.
| Once joined, start the node: | ||
|
|
||
| ```bash | ||
| agentmesh-node run \ | ||
| --control-plane https://mesh.example.com \ | ||
| --data-dir ./n1 \ | ||
| --bind-addr 127.0.0.1:8080 \ | ||
| --api-token-path ./n1/api-token | ||
| ``` |
There was a problem hiding this comment.
Since agentmesh-node run is executed in the foreground (without --daemonize), it expects the file specified by --api-token-path to already exist and contain a valid token. If ./n1/api-token does not exist, the command will fail to start.\n\nPlease add a step to generate or create this token file before running the node, for example:\nbash\necho "some-secure-token" > ./n1/api-token\n\nor use openssl rand -hex 16 > ./n1/api-token.
There was a problem hiding this comment.
Fixed in commit 0759ad4: Added an explicit step to generate ./n1/api-token before running agentmesh-node run in the foreground.
| Add your custom access role under `roles` and bind it to the node's PeerID | ||
| under `bindings`. For example, to grant a role named `caller` that allows | ||
| invoking `mcp://calculator` and any inference model: | ||
|
|
||
| ```json |
There was a problem hiding this comment.
Since POST /policies replaces the entire mesh policy rather than patching it, posting this example JSON directly will overwrite and remove any other existing roles (such as mesh:role:router) and bindings, which can break router enrollment and other mesh functions.\n\nPlease add a warning note advising the user to merge these new roles and bindings into their existing policy.json fetched in the previous step, rather than replacing the file entirely with this example.
There was a problem hiding this comment.
Fixed in commit 0759ad4: Added a warning note explaining that POST /policies replaces the full document and provided a jq example showing how to merge new roles and bindings into the existing policy.json.
- Pre-create ./n1/api-token before running agentmesh-node in foreground. - Add warning note that POST /policies replaces the whole policy and provide jq merge example to prevent dropping existing roles.
| | Command | Flags | Effect | | ||
| |---|---|---| | ||
| | `token create` | `--role` (`mesh:role:node`), `--ttl-hours` (24), `--max-usages` (1), `--description`, `--autonomous-recovery` | Mint a token. Prints it once on stdout. | | ||
| | `token create` | `--role` (`mesh:role:node`), `--ttl-hours` (24), `--max-usages` (1), `--description`, `--autonomous-recovery` | Mint a component enrollment token (`mesh:role:node` or `mesh:role:router`). Prints it once on stdout. | |
There was a problem hiding this comment.
we need to add validation on the flags to ensure the value of role is allowed , see my original comment
There was a problem hiding this comment.
Added in commit cd1ddba: Added flag validation in agentmesh-one token create --role and request validation in POST /admin/bootstrap-tokens / POST /user/bootstrap-tokens to ensure only mesh:role:node or mesh:role:router are accepted. If an access role is passed, it fails fast with a clear error pointing to policy bindings. Also updated CLI help text and added unit tests.
|
|
||
| ## Roles | ||
|
|
||
| Agent Mesh distinguishes between **component roles** and **access roles**: |
There was a problem hiding this comment.
Addressed in commit cd1ddba: Simplified and condensed the Roles section to a concise definition linking directly to the custom node roles guide.
… simplify policy roles doc
aojea
left a comment
There was a problem hiding this comment.
Thanks for adding the fail-fast validation and tightening up policy.md — this is heading in the right direction. Before we merge, there is one real regression outside CI, a couple of small cleanups in the validation code, and a few doc details to fix:
-
Update
development/examples/sandboxed-agent/(and its use-case doc): Stricter validation breaksdevelopment/examples/sandboxed-agent/Makefile(which passes--role agent) andagent.py(which enrolls asagent), plussite/content/docs/use-cases/sandboxed-agent.md. That example isn't run in CI, and it only happened to work because the Python SDK bypassedagentmesh-node'smesh:role:nodecheck and never acted as a provider — it was leaning on the exact unvalidated loophole we're closing. Let's updatesandboxed-agentto enroll asmesh:role:nodeand grant theagentrole via anode:<peer-id>policy binding so the demo stays working and matches our API. -
Keep bootstrap role validation in one place in
api/: Right nowrole != api.RoleNode && role != api.RoleRouterand its error message are duplicated incmd/agentmesh-one/admin.goand both handlers ininternal/controlplane/server.go. Please put a single helper (e.g.api.ValidateBootstrapTokenRole) right next to the role constants inapi/datalog.goso the CLI and control plane stay in sync with the defined roles. It's also worth adding a short comment explaining whyapi.RoleControlPlane(mesh:role:control-plane) is intentionally excluded, along with a unit test confirming it is rejected. -
Check order in
HandleUserBootstrapTokens(internal/controlplane/server.go): Validate the role before theuser.Role != "admin"check. As written, a non-admin user sending{"role": "caller"}gets403 Forbidden: Standard users can only generate tokens for node role— which makes it sound like an admin could mint"caller"— instead of400 Bad Request. Please add unit test coverage forPOST /user/bootstrap-tokenstoo. -
A few small fixes in
site/content/docs/guides/custom-node-roles.md:- The section explaining why bootstrap tokens only enroll component identities still says
agentmesh-one token create --role callergenerates a token that fails later duringagentmesh-node join. With this PR, token creation itself fails right away. - In Step 1,
agentmesh-one token create ... > node-tokenwrites three lines (Token:,Role:, andExpires:) into the file, soagentmesh-node join --bootstrap-token-path ./node-tokenwill fail. Pipe it throughawk '/^Token:/ {print $2}' > node-token(and include--server/--data-dir). - In Step 2, please drop (or clarify) the note about keeping
--bootstrap-token-pathfor autonomous re-enrollment — the default single-use token from Step 1 doesn't have--autonomous-recoveryset. - Replace
$\rightarrow$on line 308 with→(the Hugo site doesn't render LaTeX math there, so it shows up literally). - In Step 4's example
policy-updated.json,mesh:role:routershould match the real default ("allowed_services": ["*"],"allowed_targets": ["*"]) instead of"allowed_publish". - In Step 6, a raw
curlPOST tohttp://localhost/mcpneeds-H "Accept: application/json, text/event-stream"(otherwise the MCP HTTP handler returns406), or we can showmcp-clientlike inquickstart.md.
- The section explaining why bootstrap tokens only enroll component identities still says
…d-agent and guide - Centralize bootstrap token role validation in api.ValidateBootstrapTokenRole in api/datalog.go with unit tests covering valid and rejected roles. - In HandleUserBootstrapTokens, validate role before user role authorization so custom roles return HTTP 400 Bad Request, and add unit test coverage in identity_lifecycle_test.go. - Update development/examples/sandboxed-agent/ (Makefile, agent.py, policy.json, record.sh, SCRIPT.md) and site/content/docs/use-cases/sandboxed-agent.md to enroll as mesh:role:node and grant the agent role via policy binding (node:<peer-id>). - Fix custom-node-roles.md to reflect immediate validation at creation time, pipe token extraction through awk, clarify single-use vs autonomous recovery tokens, fix Hugo arrow syntax, align default router role, and add Accept header for MCP calls.
|
Thanks for the thorough review and actionable feedback @aojea! All points have been addressed in the latest commit:
All tests ( |
Closes #957
Problem
In Agent Mesh, the word "role" is used across two distinct architectural layers:
mesh:role:node,mesh:role:router), which describe infrastructure binary identities fixed at enrollment.caller,developer,analyst), which describe what services a member may call or publish.Because both concepts are named "role", users attempting to create a node bootstrap token with an access role (e.g.
agentmesh-one token create --role caller) hit unexpected failures during enrollment:agentmesh-nodealways requestsmesh:role:node(RequiredRole: api.RoleNode), and the control plane requires the requested role to match the bootstrap token's role. Furthermore, users who switch to policy bindings are often surprised when inspecting the enrolled node's Biscuit credential (/mesh/identityorX-Mesh-Roles), which still displays onlymesh:role:nodebecause custom roles are evaluated dynamically via distributed Datalog rules rather than baked into the Biscuit.Changes
This PR implements the recipe and fail-fast validation requested in #957:
1. Documentation & Recipe
guides/custom-node-roles.md) explaining how to:mesh:role:node.agentmesh-node.12D3KooW...) from startup logs, debug CLI (agentmesh-node debug mesh-info), or the local API (GET /debug/mesh-info).{"role": "caller", "members": ["node:<peer-id>"]}to policy bindings and posting toPOST /policies(merging into existing policies).call_remote_tooland the HTTP proxy path.policy.md(concise distinction linking to guide),headless-enrollment.md,control-plane.md,agentmesh-one.md, andagentmesh-node.mdto reference the component role requirements and cross-link to the new guide.concepts/identity.mdwith component vs. access role distinctions and evaluation details.2. Fail-Fast Bootstrap Token Role Validation
agentmesh-one token create --role: Validates that--roleis eithermesh:role:nodeormesh:role:router. If an arbitrary role is passed (e.g.,caller), it immediately returns a descriptive error:invalid role "caller": bootstrap tokens only enroll component types (mesh:role:node or mesh:role:router); custom access roles must be granted via policy bindingsHandleAdminBootstrapTokens(POST /admin/bootstrap-tokens) andHandleUserBootstrapTokens(POST /user/bootstrap-tokens) validate thatroleis eitherapi.RoleNodeorapi.RoleRouter, returning HTTP 400 Bad Request with the same explanatory message.--roleinagentmesh-one token createto explicitly name(mesh:role:node or mesh:role:router).internal/controlplane/egress_test.goto enroll nodes usingmesh:role:nodeand grant custom roles through policy bindings (node:<peer-id>).Files Changed
site/content/docs/guides/custom-node-roles.md(new step-by-step recipe)site/content/docs/guides/_index.md(guides directory index)site/content/docs/guides/headless-enrollment.md(bootstrap token minting role clarification)site/content/docs/reference/policy.md(concise role definition and guide link)site/content/docs/reference/control-plane.md(bootstrap tokens endpoint description)site/content/docs/reference/agentmesh-one.md(token create command description)site/content/docs/reference/agentmesh-node.md(bootstrap-token-path flag description)site/content/docs/concepts/identity.md(bootstrap token role and policy binding clarification)cmd/agentmesh-one/admin.go(role validation and updated CLI flag help text)cmd/agentmesh-one/admin_test.go(unit tests for role flag validation)internal/controlplane/server.go(role validation in bootstrap token creation handlers)internal/controlplane/server_test.go(unit tests for bootstrap token role validation)internal/controlplane/egress_test.go(alignment with component role enrollment and policy bindings)Validation Performed
make build: All binaries built cleanly.golangci-lint: 0 issues found.deadcode: 0 dead code detected across the repository.go test -race ./cmd/agentmesh-one/... ./internal/controlplane/...): Passed without race conditions.go test -p 1 -v ./tests/integration -run TestSilentEphemeralMembersAreForgotten): Passed.git diff --check.