Aller au contenu principal

Internal RPC (authz)

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​

RPCPurposePrincipal tokenErrors
CheckMay the principal use a permission on a resource?requiredunauthenticated (bad token), unavailable (store / Permify error)
CheckManySeveral checks for the same principal, evaluated in orderrequiredas Check; invalid_argument above 100 items
LookupResourcesScopes on which the principal holds a permission, to filter list queriesrequiredas Check
EffectivePermissionsPermission names granted anywhere, and whether admin mode is availablerequiredas Check
SubjectRolesGlobal and project roles the principal belongs to (event invitations)requiredas Check
LookupSubjectsUsers holding a permission on a resource (notification recipients)service principalas Check; permission_denied (not a service), invalid_argument (unknown permission, bad target)
AuthenticateAPIKeyValidate a raw API keynoneunauthenticated (unknown, revoked, expired or malformed key), unavailable

A denial is not an error: Check answers allowed=false with a reason.

Messages​

Resource​

FieldTypeDescription
arnstringResource ARN, or a site / organization / collection pattern for collection-level actions
parentsrepeated stringAncestor ARNs (site atl:settings:<site>:site/<site>, project atl:projects:<site>:project/<id>) turned into contextual tuples

Check / CheckMany​

MessageFieldTypeDescription
CheckRequestprincipal_tokenstringSigned principal token
permissionstringCatalogue name, e.g. members.member.read
resourceResourceTarget
CheckResponseallowedboolTrue only for REASON_ALLOWED
reasonReasonSee below
CheckManyRequestprincipal_tokenstring
itemsrepeated CheckItem (permission, resource)At most 100
CheckManyResponseresultsrepeated CheckResponseSame order as items
ReasonMeaning
REASON_UNSPECIFIEDnot returned
REASON_ALLOWEDallowed
REASON_DENIEDno grant, anonymous principal, unusable API key or target that does not match the permission
REASON_STEP_UP_REQUIREDsensitive permission without a recent passkey validation
REASON_ADMIN_MODE_REQUIREDelevated permission without admin mode
REASON_UNKNOWN_PERMISSIONpermission absent from pkg/catalog

LookupResources​

MessageFieldTypeDescription
LookupResourcesRequestprincipal_tokenstring
permissionstringCatalogue name
LookupResourcesResponseallboolGranted on the whole organization; the other fields are then empty
sitesrepeated stringSite IDs where every resource is granted
projectsrepeated stringProject IDs where every project resource is granted
idsrepeated stringIndividually 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​

MessageFieldTypeDescription
EffectivePermissionsRequestprincipal_tokenstring
EffectivePermissionsResponsepermissionsrepeated stringSorted catalogue names granted anywhere (default role included)
can_admin_modeboolTrue when one of them is elevated

SubjectRoles​

MessageFieldTypeDescription
SubjectRolesRequestprincipal_tokenstring
SubjectRolesResponserole_idsrepeated stringSorted global role IDs: active assignments (manual and Keycloak-synced) plus the default user role
project_role_idsrepeated stringSorted 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​

MessageFieldTypeDescription
LookupSubjectsRequestprincipal_tokenstringToken of a service principal (kind=service)
permissionstringCatalogue name
resourceResourceTarget node (resource with parents, project, site or organization)
LookupSubjectsResponseuser_idsrepeated stringSorted Keycloak IDs of the explicit holders
default_roleboolThe 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​

MessageFieldTypeDescription
AuthenticateAPIKeyRequestkeystringRaw key atl_<prefix>_<secret>
AuthenticateAPIKeyResponsekey_idstringKey ULID (becomes the principal ID)
owner_kindstringuser or project
owner_idstringOwner ID
allowed_cidrsrepeated stringAllowed networks; empty means any
expires_atint64Unix 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​

CallerRPCsThrough
gatewayAuthenticateAPIKey (results cached in Valkey), EffectivePermissions (/v1/auth/me)raw client authzclient.New(AUTHZ_URL).RPC()
members, audit, files, eventsCheck, LookupResourcesauthzclient.Client
notificationsLookupSubjects (recipient resolution, service token)authzclient.Client.Subjects
inventoryCheck, LookupResources (handler interfaces)authzclient.Scope; not wired in a main yet

CheckMany has no caller yet.

pkg/authzclient​

FunctionBehaviour
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​

ItemLocation
Protoproto/authz/v1/authz.proto (package authz.v1)
buf configbuf.yaml, buf.gen.yaml (managed mode, go_package_prefix github.com/Atelier-Epita/intranet/pkg/gen)
Pluginsprotoc-gen-go, protoc-gen-connect-go (run with go tool, paths=source_relative)
Messagespkg/gen/authz/v1/authz.pb.go
Connect client / handlerpkg/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.