/

Ambitwin · source-available, not open source · © 2026 Nicolò Ghignatti

Auth Policy

Keywords on this page
WordMeaningExample
CedarA small language for access rules, with an engine that answers allow or denypermit(…) when {…};
PolicyThe rulespolicy.cedar
SchemaThe shapes the rules may readschema.cedarschema
PrincipalWho asksAccount::"caller"
ActionWhat they want to doAction::"Edit"
ResourceWhat they want to do it toResource::"acme"
EntityA principal or resource with its attributesAccount with domainsAsBusinessStaff
ContextExtra values passed with one requestrequiredWeight: 80
Tier setThe domains where the caller’s role reaches one leveldomainsAsBusinessAdmin = ["acme"]

Folder backend/libs/auth-policy. One Cedar bundle that every service evaluates inside its own process: no network call to decide access.

FileHolds
policy.cedarThe five rules
schema.cedarschemaThe Account and Resource shapes, and the five actions
fixtures/conformance.json24 cases with their expected answer, replayed by every language
policy.goEmbeds both Cedar files, parses the policy once at start-up, panics if it does not parse
authz.goGo functions CanRead, CanEdit, CanManageDomain, CanOverrideModelWeight, CanIngestDocuments

The role ladder comes from ../auth-contracts/roles.json (see Auth Contracts).


Who evaluates it

ServiceLanguage, engineHow it gets the filesEntry points used
tenancyGo, cedar-goGo module, //go:embedCanManageDomain
digital-twinRust, cedar-policyinclude_str! at build, service/authz.rsis_member_of, can_read_building, can_edit_domains, can_edit_every, filter_readable_domains_from_memberships
telemetryRust, cedar-policyinclude_str! at build, kernel/authz.rsis_member_of, can_edit_domains, filter_readable_domains_from_memberships
agentPython, cedarpyread_text() at import, app/cedar_authz.pycan_access_domain, accessible_domains, can_override_model, can_ingest_documents

No package registry spans Go, Cargo and Python. The files are plain text in one repository, so each language reads them by relative path.


The rules

ActionAllowed whenScopeUsed for
ReaddomainsAsStandardCustomer.contains(resource.domain)one domainAny member reads: twin buildings, telemetry readings, agent search
EditdomainsAsBusinessStaff.contains(resource.domain)one domainRename or re-domain a building, resync; telemetry writes on a building, through its edit helper
ManageDomaindomainsAsBusinessAdmin.contains(resource.domain)one domaintenancy: invite, remove another member, create subdomain, create invite code
ModelOverridemaxRoleWeight >= context.requiredWeightglobalagent: pick another model; the level comes from MODEL_OVERRIDE_MIN_ROLE
IngestDocumentsmaxRoleWeight >= 100globalagent POST /ingest

Why roles are expanded before Cedar

Cedar cannot look up “the weight of role X”. So each service turns the membership list into flat sets before calling Cedar, and the rules only test set membership or compare numbers.

Expansion, step by step

Go accountEntity in authz.go; Rust account_entity is the same.

  1. Read the thresholds from the ladder: business_staff = 60, business_admin = 80, admin = 100.
  2. For each membership:
    1. Role not on the ladder (or, in Rust, no role at all): skip the membership entirely.
    2. Keep the highest weight seen as maxRoleWeight.
    3. Add the domain to domainsAsStandardCustomer.
    4. Weight ≥ 60: also to domainsAsBusinessStaff.
    5. Weight ≥ 80: also to domainsAsBusinessAdmin.
    6. Weight ≥ 100: also to domainsAsAdmin.
  3. Build Account::"caller" with the four sets and maxRoleWeight.
  4. Build Resource::"<domain>" with attribute domain.
flowchart TD
    M["membership domain, role"] --> K{"role on the ladder?"}
    K -- no --> S["skip"]
    K -- yes --> W["update maxRoleWeight"]
    W --> A["add to domainsAsStandardCustomer"]
    A --> B{"weight >= 60?"}
    B -- yes --> B2["add to domainsAsBusinessStaff"]
    B2 --> C{"weight >= 80?"}
    C -- yes --> C2["add to domainsAsBusinessAdmin"]
    C2 --> D{"weight >= 100?"}
    D -- yes --> D2["add to domainsAsAdmin"]
    B -- no --> X["done"]
    C -- no --> X
    D -- no --> X
    D2 --> X

Example

Memberships acme: business_admin, unibo: standard_customer, lab: some_future_role.

AttributeValue
domainsAsStandardCustomeracme, unibo (lab skipped)
domainsAsBusinessStaffacme
domainsAsBusinessAdminacme
domainsAsAdmin—
maxRoleWeight80
QuestionAnswerWhy
Read on uniboallowIn domainsAsStandardCustomer
Read on labdenyUnknown role grants nothing
Edit on unibodenyNot in domainsAsBusinessStaff
ManageDomain on acmeallowIn domainsAsBusinessAdmin
ModelOverride, required 60allow80 ≥ 60
IngestDocumentsdeny80 < 100

A decision end to end

tenancy removing a member, leaveDomain in internal/api/handler.go:

sequenceDiagram
    autonumber
    participant B as Browser
    participant M as tenancy<br/>RequireMeshClaims
    participant H as tenancy<br/>leaveDomain
    participant P as auth-policy<br/>CanManageDomain
    participant C as cedar-go
    B->>M: DELETE /tenancy/domains/acme/members/acc-2
    M->>H: claims in context
    H->>H: target == claims.Sub? self-removal, skip Cedar
    H->>P: CanManageDomain(claims.Memberships, "acme")
    P->>P: authorize(memberships, "ManageDomain", "acme", nil)
    P->>P: accountEntity(memberships), resourceEntity("acme")
    P->>C: policySet.IsAuthorized(entities, request)
    C->>C: rule ManageDomain: domainsAsBusinessAdmin.contains("acme")
    C-->>P: Allow or Deny
    P-->>H: true or false
    H-->>B: false gives 403, true goes on to remove

Data at each step

Caller acc-1 with acme: business_admin removes acc-2.

StepData
1Path domain acme, target acc-2
3acc-2 ≠ acc-1: not self-removal, Cedar decides
6Account::"caller" with domainsAsBusinessAdmin = ["acme"], maxRoleWeight = 80; Resource::"acme" with domain = "acme"
7Principal Account::"caller", action Action::"ManageDomain", resource Resource::"acme", empty context
8["acme"].contains("acme") = true
9Allow
10true

Removing oneself never reaches Cedar: it is a comparison of two ids, not a rule. Any member may leave.

Global actions

ModelOverride and IngestDocuments are not tied to one domain. authorize is called with domain "", so the resource is Resource::"" (Python: Resource::"global"). The rules never read resource.domain for these two.

Example. agent with MODEL_OVERRIDE_MIN_ROLE=business_staff: can_override_model sends requiredWeight: 60. A caller whose best role is business_staff anywhere passes. A required role that is not on the ladder becomes 101, which nobody reaches.


Conformance

fixtures/conformance.json holds 24 cases: memberships, action, domain, optional context, expected allow or deny.

GroupCasesExample
Read4A platform admin of other reading eng: deny
Edit6An editing role in an unrelated domain: deny
ManageDomain4business_staff: deny, below the tier
ModelOverride5Global: the resource’s domain does not matter
Unknown role1some_future_role_not_in_roles_json reading its own domain: deny
IngestDocuments4Admin in an unrelated domain: still allowed, it is global
RunnerCalls
conformance_test.goThe real CanRead, CanEdit, …
digital-twin/tests/cedar_conformance.rsThe real authorize_any
telemetry/tests/cedar_conformance.rsThe real Rust entry point
agent/tests/unit/test_cedar_conformance.pyIts own copy of the expansion, not app/cedar_authz.py
mise exec -- go test ./...                 # backend/libs/auth-policy
mise exec -- cargo test cedar              # backend/digital-twin, backend/telemetry
just test agent

Changing a rule

  1. Edit policy.cedar and, when needed, schema.cedarschema.
  2. Add the case to fixtures/conformance.json.
  3. Run the four replays above.
  4. A new action is a contract too: every language’s binding must learn it.

Gaps