proto/authz/v1/authz.proto defines authz.v1.AuthzService, served by the authz service
with ConnectRPC on the same port as its REST API (:8081 locally). Methods are POST /authz.v1.AuthzService/<Method>.
The gateway only routes /v1/* prefixes, so these paths are not reachable from outside.
Methods
| RPC | Purpose | Principal token | Errors |
|---|
Check | May the principal use a permission on a resource? | required | unauthenticated (bad token), unavailable (store / Permify error) |
CheckMany | Several checks for the same principal, evaluated in order | required | as Check; invalid_argument above 100 items |
LookupResources | Scopes on which the principal holds a permission, to filter list queries | required | as Check |
EffectivePermissions | Permission names granted anywhere, and whether admin mode is available | required | as Check |
SubjectRoles | Global and project roles the principal belongs to (event invitations) | required | as Check |
LookupSubjects | Users holding a permission on a resource (notification recipients) | service principal | as Check; permission_denied (not a service), invalid_argument (unknown permission, bad target) |
AuthenticateAPIKey | Validate a raw API key | none | unauthenticated (unknown, revoked, expired or malformed key), unavailable |
A denial is not an error: Check answers allowed=false with a reason.
Messages
Resource
| Field | Type | Description |
|---|
arn | string | Resource ARN, or a site / organization / collection pattern for collection-level actions |
parents | repeated string | Ancestor ARNs (site atl:settings:<site>:site/<site>, project atl:projects:<site>:project/<id>) turned into contextual tuples |
Check / CheckMany
| Message | Field | Type | Description |
|---|
CheckRequest | principal_token | string | Signed principal token |
| permission | string | Catalogue name, e.g. members.member.read |
| resource | Resource | Target |
CheckResponse | allowed | bool | True only for REASON_ALLOWED |
| reason | Reason | See below |
CheckManyRequest | principal_token | string | |
| items | repeated CheckItem (permission, resource) | At most 100 |
CheckManyResponse | results | repeated CheckResponse | Same order as items |
Reason | Meaning |
|---|
REASON_UNSPECIFIED | not returned |
REASON_ALLOWED | allowed |
REASON_DENIED | no grant, anonymous principal, unusable API key or target that does not match the permission |
REASON_STEP_UP_REQUIRED | sensitive permission without a recent passkey validation |
REASON_ADMIN_MODE_REQUIRED | elevated permission without admin mode |
REASON_UNKNOWN_PERMISSION | permission absent from pkg/catalog |
LookupResources
| Message | Field | Type | Description |
|---|
LookupResourcesRequest | principal_token | string | |
| permission | string | Catalogue name |
LookupResourcesResponse | all | bool | Granted on the whole organization; the other fields are then empty |
| sites | repeated string | Site IDs where every resource is granted |
| projects | repeated string | Project IDs where every project resource is granted |
| ids | repeated string | Individually granted resource IDs |
Lists are sorted. Unknown permissions, and elevated / sensitive ones without admin mode / step-up, give an empty
scope. For API keys the scope is the intersection of the key and owner scopes.
EffectivePermissions
| Message | Field | Type | Description |
|---|
EffectivePermissionsRequest | principal_token | string | |
EffectivePermissionsResponse | permissions | repeated string | Sorted catalogue names granted anywhere (default role included) |
| can_admin_mode | bool | True when one of them is elevated |
SubjectRoles
| Message | Field | Type | Description |
|---|
SubjectRolesRequest | principal_token | string | |
SubjectRolesResponse | role_ids | repeated string | Sorted global role IDs: active assignments (manual and Keycloak-synced) plus the default user role |
| project_role_ids | repeated string | Sorted project role IDs |
API keys only report the roles assigned to the key itself (not their owner's); revoked, expired or unknown keys,
anonymous and service principals have none. authzclient.Client.Roles wraps it.
LookupSubjects
| Message | Field | Type | Description |
|---|
LookupSubjectsRequest | principal_token | string | Token of a service principal (kind=service) |
| permission | string | Catalogue name |
| resource | Resource | Target node (resource with parents, project, site or organization) |
LookupSubjectsResponse | user_ids | repeated string | Sorted Keycloak IDs of the explicit holders |
| default_role | bool | The default user role grants the permission: every user holds it |
Holders are users actively assigned (manually or through Keycloak sync) to a non-deleted global or project role
with a grant of the permission whose node covers the target (organization ⊃ site ⊃ project ⊃ resource). API keys
and service principals are never returned. The default role cannot be enumerated: it is reported with
default_role and its members are not listed. Admin mode and step-up are ignored (they gate the use of a
permission, not its possession). Computed from the MongoDB grants. authzclient.Client.Subjects wraps it.
AuthenticateAPIKey
| Message | Field | Type | Description |
|---|
AuthenticateAPIKeyRequest | key | string | Raw key atl_<prefix>_<secret> |
AuthenticateAPIKeyResponse | key_id | string | Key ULID (becomes the principal ID) |
| owner_kind | string | user or project |
| owner_id | string | Owner ID |
| allowed_cidrs | repeated string | Allowed networks; empty means any |
| expires_at | int64 | Unix seconds, 0 when the key never expires |
A successful call also updates the key last_used_at (at most once a minute). Expiry and CIDR checks on the
response are enforced by the gateway.
Authentication of internal calls
- There is no transport-level caller authentication. Each decision RPC carries the principal token in the
message: the token the gateway signed for the current request (
X-Atl-Principal), read back with
principal.TokenFromContext. authz verifies it like any service: EdDSA, issuer atl-gateway, audience
atl-internal, expiry required (2 min TTL, 5 s leeway). See identity.
- A token with
kind=service and a non-empty subject is allowed everything.
- Services holding
PRINCIPAL_SIGNING_KEY may sign their own tokens: events does so to evaluate tokenised
calendar feeds as the feed owner.
AuthenticateAPIKey takes no principal token; it relies on authz not being publicly routed.
Callers
| Caller | RPCs | Through |
|---|
| gateway | AuthenticateAPIKey (results cached in Valkey), EffectivePermissions (/v1/auth/me) | raw client authzclient.New(AUTHZ_URL).RPC() |
| members, audit, files, events | Check, LookupResources | authzclient.Client |
| notifications | LookupSubjects (recipient resolution, service token) | authzclient.Client.Subjects |
| inventory | Check, LookupResources (handler interfaces) | authzclient.Scope; not wired in a main yet |
CheckMany has no caller yet.
pkg/authzclient
| Function | Behaviour |
|---|
New(baseURL) | Connect client over HTTP, 5 s timeout |
Check(ctx, permission, target, parents...) | nil when allowed; anonymous → 401 problem without calling authz; RPC error → 503 authorization service unavailable; step-up → 403 code step_up_required; admin mode → 403 code admin_mode_required; otherwise 403 permission denied |
Allowed(...) | Check as a boolean; 401 / 403 → false, other errors returned |
Lookup(ctx, permission) | Scope (All, Sites, Projects, IDs); anonymous → empty scope; RPC error → 503 |
Subjects(ctx, permission, target, parents...) | Holders (UserIDs, DefaultRole); non-service principal → 403 without calling authz; RPC error → 503 |
NewWithRPC, RPC() | wrap or expose the raw generated client |
Inside authz, REST handlers call the authorizer in process instead of the RPC.
Code generation
| Item | Location |
|---|
| Proto | proto/authz/v1/authz.proto (package authz.v1) |
| buf config | buf.yaml, buf.gen.yaml (managed mode, go_package_prefix github.com/Atelier-Epita/intranet/pkg/gen) |
| Plugins | protoc-gen-go, protoc-gen-connect-go (run with go tool, paths=source_relative) |
| Messages | pkg/gen/authz/v1/authz.pb.go |
| Connect client / handler | pkg/gen/authz/v1/authzv1connect/authz.connect.go |
Run make generate (go tool buf lint && go tool buf generate) after changing the proto, and commit the
generated files.