Skip to content

docs: clarify component vs access roles and add custom node roles recipe - #985

Open
roonakyadav wants to merge 4 commits into
google:mainfrom
roonakyadav:docs/957-custom-access-role-guide
Open

roonakyadav wants to merge 4 commits into
google:mainfrom
roonakyadav:docs/957-custom-access-role-guide

Conversation

@roonakyadav

@roonakyadav roonakyadav commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #957

Problem

In Agent Mesh, the word "role" is used across two distinct architectural layers:

  1. Component roles (mesh:role:node, mesh:role:router), which describe infrastructure binary identities fixed at enrollment.
  2. Access roles (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-node always requests mesh: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/identity or X-Mesh-Roles), which still displays only mesh:role:node because 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

  • Step-by-step recipe: Added a practical guide (guides/custom-node-roles.md) explaining how to:
    1. Mint a bootstrap token with mesh:role:node.
    2. Enroll and run agentmesh-node.
    3. Obtain the node's PeerID (12D3KooW...) from startup logs, debug CLI (agentmesh-node debug mesh-info), or the local API (GET /debug/mesh-info).
    4. Grant a custom access role by adding {"role": "caller", "members": ["node:<peer-id>"]} to policy bindings and posting to POST /policies (merging into existing policies).
    5. Understand policy propagation (within the 0–90 second sync jitter window without restarts) and how effective permissions derive from Datalog authorizer evaluation rather than roles listed in the Biscuit.
    6. Verify allowed and denied calls via call_remote_tool and the HTTP proxy path.
  • Reference updates: Updated policy.md (concise distinction linking to guide), headless-enrollment.md, control-plane.md, agentmesh-one.md, and agentmesh-node.md to reference the component role requirements and cross-link to the new guide.
  • Concepts: Updated concepts/identity.md with component vs. access role distinctions and evaluation details.

2. Fail-Fast Bootstrap Token Role Validation

  • agentmesh-one token create --role: Validates that --role is either mesh:role:node or mesh: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 bindings
  • Control plane: HandleAdminBootstrapTokens (POST /admin/bootstrap-tokens) and HandleUserBootstrapTokens (POST /user/bootstrap-tokens) validate that role is either api.RoleNode or api.RoleRouter, returning HTTP 400 Bad Request with the same explanatory message.
  • CLI help: Updated help text on --role in agentmesh-one token create to explicitly name (mesh:role:node or mesh:role:router).
  • Egress test alignment: Updated internal/controlplane/egress_test.go to enroll nodes using mesh:role:node and 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.
  • Unit tests (go test -race ./cmd/agentmesh-one/... ./internal/controlplane/...): Passed without race conditions.
  • Integration tests (go test -p 1 -v ./tests/integration -run TestSilentEphemeralMembersAreForgotten): Passed.
  • Formatting & whitespace: Verified clean diff via git diff --check.

- 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
@roonakyadav
roonakyadav requested a review from aojea as a code owner November 28, 2026 19:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +99 to +107
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
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

@roonakyadav roonakyadav Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 0759ad4: Added an explicit step to generate ./n1/api-token before running agentmesh-node run in the foreground.

Comment on lines +155 to +159
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we need to add validation on the flags to ensure the value of role is allowed , see my original comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread site/content/docs/reference/policy.md Outdated

## Roles

Agent Mesh distinguishes between **component roles** and **access roles**:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is too verbose

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit cd1ddba: Simplified and condensed the Roles section to a concise definition linking directly to the custom node roles guide.

@aojea aojea left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

  1. Update development/examples/sandboxed-agent/ (and its use-case doc): Stricter validation breaks development/examples/sandboxed-agent/Makefile (which passes --role agent) and agent.py (which enrolls as agent), plus site/content/docs/use-cases/sandboxed-agent.md. That example isn't run in CI, and it only happened to work because the Python SDK bypassed agentmesh-node's mesh:role:node check and never acted as a provider — it was leaning on the exact unvalidated loophole we're closing. Let's update sandboxed-agent to enroll as mesh:role:node and grant the agent role via a node:<peer-id> policy binding so the demo stays working and matches our API.

  2. Keep bootstrap role validation in one place in api/: Right now role != api.RoleNode && role != api.RoleRouter and its error message are duplicated in cmd/agentmesh-one/admin.go and both handlers in internal/controlplane/server.go. Please put a single helper (e.g. api.ValidateBootstrapTokenRole) right next to the role constants in api/datalog.go so the CLI and control plane stay in sync with the defined roles. It's also worth adding a short comment explaining why api.RoleControlPlane (mesh:role:control-plane) is intentionally excluded, along with a unit test confirming it is rejected.

  3. Check order in HandleUserBootstrapTokens (internal/controlplane/server.go): Validate the role before the user.Role != "admin" check. As written, a non-admin user sending {"role": "caller"} gets 403 Forbidden: Standard users can only generate tokens for node role — which makes it sound like an admin could mint "caller" — instead of 400 Bad Request. Please add unit test coverage for POST /user/bootstrap-tokens too.

  4. 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 caller generates a token that fails later during agentmesh-node join. With this PR, token creation itself fails right away.
    • In Step 1, agentmesh-one token create ... > node-token writes three lines (Token:, Role:, and Expires:) into the file, so agentmesh-node join --bootstrap-token-path ./node-token will fail. Pipe it through awk '/^Token:/ {print $2}' > node-token (and include --server / --data-dir).
    • In Step 2, please drop (or clarify) the note about keeping --bootstrap-token-path for autonomous re-enrollment — the default single-use token from Step 1 doesn't have --autonomous-recovery set.
    • 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:router should match the real default ("allowed_services": ["*"], "allowed_targets": ["*"]) instead of "allowed_publish".
    • In Step 6, a raw curl POST to http://localhost/mcp needs -H "Accept: application/json, text/event-stream" (otherwise the MCP HTTP handler returns 406), or we can show mcp-client like in quickstart.md.

…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.
@roonakyadav

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and actionable feedback @aojea! All points have been addressed in the latest commit:

  1. sandboxed-agent example and documentation:

    • Updated agent.py to enroll with role mesh:role:node and added an id subcommand to enroll and output the node's PeerID.
    • Updated Makefile to mint single-use tokens for mesh:role:node and added a make bind URL=... PEER=... target that appends the agent role binding to the active mesh policy.
    • Initialized "bindings": [] in policy.json.
    • Updated SCRIPT.md and record.sh captions and command sequences.
    • Updated site/content/docs/use-cases/sandboxed-agent.md with the updated workflow.
  2. Single validation helper in api/:

    • Added api.ValidateBootstrapTokenRole(role string) error next to the role constants in api/datalog.go, with a comment explaining why RoleControlPlane is excluded.
    • Reused api.ValidateBootstrapTokenRole across cmd/agentmesh-one/admin.go, HandleAdminBootstrapTokens, and HandleUserBootstrapTokens.
    • Added TestValidateBootstrapTokenRole in api/datalog_test.go verifying acceptance of RoleNode and RoleRouter, and rejection of RoleControlPlane, custom access roles, and empty strings.
  3. Validation order in HandleUserBootstrapTokens:

    • Reordered HandleUserBootstrapTokens to validate api.ValidateBootstrapTokenRole before the non-admin check, so custom roles return 400 Bad Request for both admin and standard users.
    • Added unit test TestUserBootstrapTokenRoleValidation in internal/controlplane/identity_lifecycle_test.go covering standard users and admins across valid and invalid roles.
  4. Guide fixes (site/content/docs/guides/custom-node-roles.md & reference/policy.md):

    • Updated explanation of why bootstrap tokens only enroll component identities to show that creation fails immediately with 400 Bad Request.
    • Step 1: Piped agentmesh-one token create through awk '/^Token:/ {print $2}' > node-token and added --server / --data-dir.
    • Step 2: Clarified single-use token lifecycle and that autonomous re-enrollment requires --autonomous-recovery.
    • Replaced $\rightarrow$ with plain-text -> for Hugo compatibility.
    • Step 4: Aligned mesh:role:router in policy-updated.json with the default ("allowed_services": ["*"], "allowed_targets": ["*"]).
    • Step 6: Added -H "Accept: application/json, text/event-stream" to MCP curl calls.

All tests (make build, golangci-lint, deadcode, and make test) pass cleanly.

This branch has not been deployed

No deployments
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.

Docs: step-by-step recipe for giving a node a custom role

2 participants