Add ACL key expression templates bound to client identity (${cert_common_name}, ${username}) - #2662
Open
cmeng-gao wants to merge 1 commit into
Open
Add ACL key expression templates bound to client identity (${cert_common_name}, ${username})#2662cmeng-gao wants to merge 1 commit into
${cert_common_name}, ${username})#2662cmeng-gao wants to merge 1 commit into
Conversation
Allow ACL rules to define key_expr_templates with placeholders
expanded per-connection from the authenticated identity of the remote
instance: ${cert_common_name} (TLS/QUIC certificate common name) and
${username} (user/password authentication). Subjects gain
cert_common_name_prefixes for prefix-based matching. A single static
rule such as "tenant/${cert_common_name}/**" then confines every
client to its own key space, covering dynamically created tenants
without config edits or router restarts.
Templates are expanded in AclEnforcer::new_transport_unicast into
per-connection policies, evaluated as part of their subject: a
subject's effective policy is the union of its static rules and its
expanded template rules, with the usual precedence (explicit deny >
explicit allow > default permission).
Validation and failure behavior:
- substituted values must be usable as (part of) a single key
expression chunk (no '/', '*', '$', '?', '#'), otherwise the rule
is skipped for that connection;
- a template referencing an identity the connection does not have is
skipped for that connection, falling back to static rules and the
default permission;
- malformed templates, including misspelled placeholders, are
rejected at config load time via probe expansion.
Fully backward compatible: both new config fields are optional, and
configurations that do not use them behave exactly as before.
key_exprs becomes optional on a rule; at least one of key_exprs and
key_expr_templates must be provided.
Covered by unit tests and end-to-end tests over TLS, QUIC and
user/password transports (tenant isolation in both directions,
prefix-unmatched fallback to default deny, deny-template under
default allow).
Closes eclipse-zenoh#2659
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: chunmeng.gao <gaochunmeng@gmail.com>
Author
|
For the label check: this PR is a new feature (implements #2659). Could a maintainer add the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What does this PR do?
Allows ACL rules to define
key_expr_templates: plain-string key expressions containing placeholders that are expanded per connection from the authenticated identity of the remote instance, at transport establishment. Supported placeholders:${cert_common_name}— the TLS/QUIC certificate common name${username}— the user/password-authenticated usernameSubjects additionally gain
cert_common_name_prefixesfor prefix-based matching.With a single static rule, every client is confined to its own key space:
A client presenting a certificate with CN
t42can then only usetenant/t42/**.Why is this change needed?
In multi-tenant deployments (robot fleets, simulation platforms, sandboxed workloads), tenants are created and destroyed dynamically. Today each tenant requires an explicit rule/subject/policy triple (
cert_common_namesis exact-match only, andkey_exprscannot reference the connection identity), and since ACL config cannot be updated at runtime, every new tenant means editing the config and restarting the router — disrupting all connected sessions.With identity-bound templates, one static config covers an unlimited number of dynamically created tenants: no config edits, no restarts. This is in line with what MQTT brokers offer for the same problem (mosquitto's
pattern ... %u, EMQX's${username}/${clientid}).Related Issues
Closes #2659. #1432 previously proposed trust-based authorization (permissions embedded in certificates/tokens) for similar scalability reasons and was closed without implementation; this is a much lighter alternative that covers the multi-tenant isolation case within the existing ACL model.
Implementation details
AclEnforcer::new_transport_unicast, where the peer's authenticated identity is available. Templates are expanded there into per-connection policies, reusing the existingKeBoxTreemachinery.default_permission: allow; union semantics keep behavior identical to the equivalent static configuration (covered by a dedicated regression test)./,*,$,?,#), otherwise the rule is skipped for that connection;${username}on a TLS-only connection) is skipped for that connection, falling back to static rules / default permission;$is reserved in key expressions, so any unsubstituted${...}fails validation).key_exprsbecomes optional on a rule; at least one ofkey_exprs/key_expr_templatesmust be provided, and both can coexist.cert_common_name_prefixesis a separate subject field (rather than glob syntax insidecert_common_names) to avoid silently changing the semantics of existing exact-match configs.zenoh's public API is unchanged (AclConfigRuleis not re-exported). Happy to gate the new fields behindunstableif preferred.KeBoxTreeconsulted through the same cached decision path as static rules. Configurations without template rules take the exact same code path as before.DEFAULT_CONFIG.json5(with a worked example) and in thezenoh-configdoc comments.Testing
zenoh/tests/acl_template.rsover TLS, QUIC and user/password transports: tenant isolation in both directions (cross-tenant subscribe and publish blocked at the router), prefix-unmatched fallback to default deny, deny-template under default allow (regression for the union semantics).aclandauthenticationtest suites pass unchanged.🤖 Generated with Claude Code
🏷️ Label-Based Checklist
Based on the labels applied to this PR, please complete these additional requirements:
Labels:
new feature🆕 New Feature Requirements
Since this PR adds a new feature:
Consider: Can this feature be split into smaller, incremental PRs?
Instructions:
- [ ]to- [x])This checklist updates automatically when labels change, but preserves your checked boxes.