Aller au contenu principal

Authorization model

Allow only, deny by default. The authz service is the single decision point; MongoDB is the source of truth and Permify evaluates relationship checks.

Building blocks​

  • Permission catalogue (pkg/catalog): every permission is declared in code as <service>.<resource>.<action>, with a scope (global or project) and flags Elevated (admin mode only) and Sensitive (passkey step-up). The Permify schema is generated from it at authz startup.
  • ARN (pkg/arn): atl:<service>:<site|*>:<type>/<id>[/<type>/<id>...][/*]. * is allowed for the site, as the last ID or as a trailing segment (resource and all sub-resources).
  • Role: global or project-scoped set of grants; grant = (permission, ARN pattern); assignment = role ↔ user or API key, source manual or keycloak.
  • A global role may map to a Keycloak role (keycloak_role); authz syncs those assignments from Keycloak.
  • An optional default role (DEFAULT_ROLE_FOR_USERS) is implicitly held by every user principal.

Grant levels​

LevelPatternPermify node
Organizationatl:<svc>:*:<type>/*organization:main
Siteatl:<svc>:<site>:<type>/*site:<site>
Projectatl:projects:<site>:project/<id>/* (project permissions only)project:<id>
Resourceatl:<svc>:<site>:<type>/<id><svc>_<type>:<id>

Project roles can only hold project-scoped permissions on their own project; projects never get global permissions. Settings and projects resource types map to the structural organization, site and project entities.

Permify schema​

Entities: user, api_key, role, project_role, organization, site, project, and one entity per catalogue resource type (inventory_item, members_member, …). Each node holds one <perm>_grant relation per permission whose subjects are role#member usersets (and project_role#member for project permissions) or API keys; permissions inherit organization → site → project → resource (generated excerpt):

entity inventory_item {
relation organization @organization
relation site @site
relation project @project
relation update_grant @role#member @project_role#member @api_key
permission update = update_grant or site.inventory_item_update or organization.inventory_item_update or project.inventory_item_update
}

Services never write resource tuples: a Check carries the resource ARN plus its parents (site, project) and authz turns them into contextual tuples. Role grants, memberships and API key grants are written by authz; a syncer applies every change incrementally and reconciles Permify from MongoDB at startup and every 5 minutes (AUTHZ_RECONCILE_INTERVAL), so Permify's memory engine can be used locally.

Decision​

  • Service principals are always allowed (background jobs).
  • API keys: effective permissions = key grants ∩ owner permissions for user-owned keys; project-owned keys are checked alone and only hold project permissions. Revoked or expired keys hold nothing.
  • Admin mode and step-up are enforced by authz after the Permify check (not as Permify attributes).
  • LookupResources and EffectivePermissions are computed from the MongoDB grants; elevated or sensitive permissions without admin mode / step-up yield an empty scope.

Denials map to HTTP 403 with codes forbidden, admin_mode_required or step_up_required (authorizer.Problem, authzclient.Check).

Using it from a service​

az := authzclient.New(cfg.AuthzURL)
// Single resource with its site parent.
err := az.Check(ctx, "members.member.update", member.ARN(id), member.SiteParents(m.SiteIDs)...)
// List filtering: which sites/projects/IDs may the caller read?
scope, err := az.Lookup(ctx, "members.member.read")

Check returns nil when allowed or a *problem.Problem to pass to httpx.Fail.