Authorization
ulex's authorization model: the full scope list with what each grants, tenant isolation, organization membership roles, the auth policy, per-application restrictions, how impersonation is gated and audited, and how to choose the narrowest scope that works.
ulex has four authorization layers, checked in this order. Knowing which one rejected a request is most of the debugging.
1. Authentication is there a valid credential?
2. Scope does it carry the scope this operation requires?
3. Tenant isolation is the resource in THIS tenant?
4. Application policy is the user's membership, status, and MFA level sufficient?#1. Scopes
#User-facing (OIDC)
| Scope | Grants | In the token |
|---|---|---|
openid | sub, the OIDC handshake | yes |
profile | name, nickname, locale, picture | yes |
email | email, email_verified | yes |
offline_access | a refresh token | yes |
#Control plane
| Scope | Grants |
|---|---|
read:organizations | GET /organizations*, /domains, /members |
write:organizations | POST/PATCH/PUT/DELETE on the same |
read:users | GET /users* |
write:users | POST/PATCH/DELETE /users*, suspend, unsuspend |
read:groups | GET /groups* |
write:groups | group and membership writes |
read:connections | GET /connections*, /saml/metadata, /saml/login |
write:connections | connection CRUD, /activate, /verify |
read:directories | GET /directories*, sync runs |
write:directories | directory CRUD, /sync |
read:applications | GET /applications*, /secret, /metadata |
write:applications | application CRUD, /rotate-secret |
read:webhooks | GET /webhooks*, /deliveries |
write:webhooks | webhook CRUD, /enable, /disable, /test |
read:audit_logs | GET /audit-events*, including export |
read:deployments | GET /deployments*, /environments*, /logs |
write:deployments | POST /deployments, /cancel, /rollback |
#Protocol and MCP
| Scope | Grants |
|---|---|
scim:provision | inbound /scim/v2 writes, and reading SCIM bearer tokens |
saml:consume | POST /connections/{id}/saml/acs and /saml/slo |
mcp:tools | every read-only MCP tool |
mcp:admin | destructive MCP tools: ulex_reset_tenant, ulex_delete_*, ulex_rotate_* |
sso:impersonate | impersonation_only connections |
ulex:admin | everything, including key rotation, signing-key rotation, and impersonation |
#Admin-only
ulex:admin, mcp:admin and sso:impersonate are rejected at mint time for a non-admin key, not at call time. You cannot create a key that carries a scope you are not entitled to.
#Choosing
| Workload | Scopes |
|---|---|
| An agent bootstrapping an app | mcp:tools, read:organizations, write:organizations, read:users, write:users, read:groups, write:groups, read:applications, write:applications, read:connections, write:connections, read:audit_logs |
| A CI test suite | the same, minus mcp:admin |
| A read-only dashboard | mcp:tools, read:organizations, read:users |
| A web service reading its own directory | read:organizations, read:users via client credentials |
| A customer's IdP (SCIM) | scim:provision via a SCIM bearer token |
| Key rotation in CI | ulex:admin, ip_allowlist set, 30-day expiry |
ulex:admin also grants ulex_revoke_api_key, ulex_reset_tenant, and impersonation. A key with it can log in as any user in your tenant. Always treat it as a high-privilege credential.
#Reading the rejection
{
"error": {
"type": "permission_error",
"code": "insufficient_scope",
"message": "This credential requires the write:organizations scope.",
"request_id": "req_01M3PSW9R0175NAW62NYR403R8",
"retryable": false,
"hint": "Request scope: write:organizations.",
"docs_url": "https://docs.ulexid.com/security/authorization#scopes"
}
}hint names the exact scope. insufficient_scope is retryable: false — a broader credential is required, not a retry.
#2. Tenant isolation
Every persisted record carries tenant_id, and every repository read filters on it in the query, not in application code.
| Behaviour | |
|---|---|
| A resource in another tenant | 404 not_found, not 403 |
| A resource in another tenant, deliberately | 403 cross_tenant — only for explicitly cross-tenant operations |
Cross-tenant access without ulex:admin | impossible. There is no API surface that does it |
Cross-tenant access with ulex:admin | audited as category: authorization with your request_id |
Returning 404 for another tenant's resource is deliberate. A 403 confirms the id exists, which is a tenant-enumeration oracle.
Tenants and API keys are strictly bound to their originating store: a local in-memory key cannot reach https://ulexid.com, and an API key for one tenant cannot access another — there is no header that bypasses it.
#3. Organization membership
A user is tenant-global. Their authority is per organization.
role | Can do |
|---|---|
owner | everything an admin can, plus delete the organization, transfer ownership, and change billing-relevant fields. The last owner cannot be removed |
admin | manage users, groups, connections, and settings. Cannot delete the organization |
member | use the application. Read-only on identity resources |
guest | use the application, scoped to specific groups via membership.group_ids |
organization_membership.group_ids restricts a guest to the resources those groups grant. It is enforced at the API layer, not in your application.
#Join policy and SSO
| Field | Default | State | Enforced effect |
|---|---|---|---|
allow_profiles_outside_organization | false | Enforced | a new user may join or JIT provision only if their email domain matches a verified domain on the organization |
sso_only | false | Enforced | direct password sign-in is refused; only organization.connection_id or default_connection_id may authenticate. For users in multiple orgs, the most-restrictive rule applies across all memberships |
ulex_bootstrap sets sso_only: true for enterprise SSO strategies, ensuring bootstrapped organizations require single sign-on through their configured enterprise connection. Direct password or social logins are refused with 403 access_denied.
#4. The auth policy
GET /api/v1/auth-policy and PUT /api/v1/auth-policy, or ulex_get_auth_policy / ulex_update_auth_policy.
There is one policy per tenant. GET never 404s: configured: false means nobody has called PUT yet, and the values returned are ulex's defaults. Each block also reports a set flag, so you can tell a value an operator chose from one they inherited:
{
"configured": true,
"policy": {
"id": "pol_01M3PSW6DEQ00R000000R00000",
"object": "auth_policy",
"environment": "prod",
"password": {
"min_length": 14,
"require_uppercase": true,
"require_lowercase": true,
"require_number": true,
"require_symbol": true,
"check_breached_passwords": true,
"max_age_days": 365,
"forbid_reuse_count": 5
},
"session": {
"lifetime_seconds": 43200,
"idle_timeout_seconds": 3600,
"reauthenticate_after_seconds": 3600,
"bind_to_ip": false,
"bind_to_user_agent": true,
"cross_app_sso": false
},
"mfa": {
"mode": "adaptive",
"methods": ["webauthn", "totp"],
"remember_device_days": 30
},
"blocked_ip_ranges": ["203.0.113.0/24"],
"set": { "password": true, "session": true, "mfa": false, "blocked_ip_ranges": true }
}
}set.mfa is false there: mfa.mode reads optional because that is the schema default, not because anyone decided on it. A value alone cannot tell you that, and an audit asking "did this tenant choose this" cannot answer it from the number.
PUT takes any subset of the blocks and merges onto the stored policy, so a call naming only session leaves password alone. id, tenant_id, environment and the timestamps are refused.
#What is enforced
Every field in auth_policy is enforced (password, session, mfa, and blocked_ip_ranges):
| Field | Default | Where |
|---|---|---|
password.min_length | 12 | the three places a human chooses a password: admin reset, portal signup, portal change |
password.require_uppercase / _lowercase / _number / _symbol | true | same |
password.forbid_reuse_count | 5 | checks stored password history across resets and password changes |
password.max_age_days | 365 | rejects stale password sign-ins with password_expired until rotated |
password.check_breached_passwords | true | tenant setting controls screening; ULEX_SCREEN_PASSWORDS is the default only when no tenant policy exists. A hit is a warning recorded as user.password_screened |
mfa.mode: required | optional | challenges enrolled users and enforces inline TOTP enrollment for factorless users |
mfa.mode: adaptive | optional | risk engine evaluates new device cookie (ulex_device), IP changes, failed attempt velocity, and mfa.trigger_on_* flags |
mfa.methods & remember_device_days | ["totp","webauthn"], 30 | restricts permitted enrollment/challenge factor types; remember_device_days issues signed ulex_device trust cookies |
session.lifetime_seconds | 86,400 | written as session.expires_at |
session.idle_timeout_seconds | 604,800 | written as session.idle_expires_at, clamped to lifetime_seconds |
session.reauthenticate_after_seconds | 86,400 | written as session.reauthenticate_at; drives OIDC step-up |
session.bind_to_user_agent | true | every request that reads a session; a mismatch revokes it |
session.bind_to_ip | false | same, against a pseudonym of the address |
session.cross_app_sso | true | /oauth2/authorize, on reuse from another application |
blocked_ip_ranges | [] | every authenticated request, before any credential is read |
A password that fails composition or history is refused with 400 password_policy_not_met or password_reused, and the composition message names every unmet rule at once. A password that appears in a breach corpus is warned about and stored: a corpus can be stale, and a refusal has to be right.
bind_to_ip defaults off because mobile networks change address mid-session. bind_to_user_agent defaults on because a cookie presented from a different browser is a stolen cookie far more often than it is a user with two browsers.
blocked_ip_ranges covers the whole API, not just the sign-in form: a blocklist consulted at the password page alone would leave the token endpoint, refresh rotation and every REST route reachable from the blocked network. Refusals are recorded as auth_policy.ip_blocked with the address pseudonymised, because a blocklist that refuses silently reads as a network fault to whoever is affected.
#RBAC roles and permissions
In addition to per-organization membership roles (owner, admin, member, guest), tenants can define custom RBAC roles (/api/v1/roles) with slugs and permission strings, assigned to organization memberships (PUT /api/v1/organizations/{id}/members/{userId}/roles) or groups (PATCH /api/v1/groups/{id}). Active matching-organization role slugs and permissions are emitted in deduplicated roles and permissions claims on access tokens, ID tokens, and /oauth2/userinfo, and enforced by @ulex/node (requiredRoles / requiredPermissions).
#allowed_countries was removed
It was a configurable field enforced nowhere, like the rest of this policy when it was written — and unlike blocked_ip_ranges it cannot be implemented honestly here. The only data source for a country is CloudFront-Viewer-Country, and ulex's CloudFront distribution configures no origin request policy that overwrites a viewer-supplied one. An allowlist built on that is worse than an absent one: it looks enforced, an auditor ticks the box, and one request header defeats it.
blocked_ip_ranges survives because its source is requestContext.http.sourceIp, which API Gateway populates from the connection and a client cannot set.
Restoring allowed_countries requires an origin request policy that sets the header explicitly, plus a test asserting the distribution has one. Add the field back at that point, not before.
An empty blocklist means nothing is blocked. There is no deny-by-default that surprises you on day one, and a request with no address at all — every local CLI and MCP invocation — is never refused.
#5. Per-application restrictions
Beyond scopes, an application constrains what its token can do:
| Field | Default | Restricts |
|---|---|---|
grant_types | authorization_code, refresh_token | which grants the token endpoint will honour (including jwt-bearer, token-exchange, device_code) |
response_types | ["code"] | implicit is rejected in prod |
response_mode | form_post | |
require_pkce | true | cannot be disabled |
pkce_methods | ["S256"] | plain must be added explicitly and is refused in prod |
token_endpoint_auth_method | client_secret_basic | supports client_secret_basic, client_secret_post, secretless private_key_jwt (via registered jwks / SSRF-checked jwks_uri + jti replay protection), mTLS (tls_client_auth with DN/SAN matching and self_signed_tls_client_auth via JWKS), and none |
dpop_bound_access_tokens | false | when true, /oauth2/token and /oauth2/userinfo require valid RFC 9449 DPoP proofs bound via cnf.jkt, ath, and single-use jti |
tls_client_certificate_bound_access_tokens | false | when true, binds access tokens to the mTLS peer certificate via cnf["x5t#S256"] (RFC 8705) checked at /oauth2/userinfo |
subject_type | null | null defaults to public for first_party and pairwise for third_party; explicit public or pairwise overrides per OIDC Core §8.1 |
sector_identifier_uri | null | SSRF-checked HTTPS URL grouping pairwise-subject applications; required when explicit pairwise spans multiple redirect_uris hosts |
require_pushed_authorization_requests | false | when true, /oauth2/authorize refuses raw requests without a POST /oauth2/par request_uri |
cross_app_sso_enabled | true | enforced: false means no session from another application may mint a code for this one |
cross_app_sso_redirect_urls | [] | enforced: restricts which cross-app SSO handoff redirect URLs an application accepts |
max_age on authorization | per request | enforced: the client's max_age is compared against session.auth_time |
acr_values | null | enforced: sets required assurance level / step-up floor (aal2 triggers MFA step-up when missing) |
grant_access_to_organization | true | enforced: false omits org_id/org_slug claims from issued tokens |
organization_usage | allow | enforced: deny refuses an organization param; require prompts or demands organization membership selection (account_selection_required on prompt=none) |
sign_in_with_email_enabled | true | enforced: false disables email/password & email-OTP sign-in on hosted UI and login endpoints |
sign_up_enabled | true | enforced: false blocks self-registration on the hosted login flow for that application |
branding | ulex defaults | enforced: renders custom colors and sanitized logo_url/favicon_url in the hosted login UI |
default_locale | "en" | enforced: localizes hosted UI strings with ui_locales support |
saml_allow_idp_initiated | false | enforced: GET /saml/idp/init/{appId} strictly returns 403 unless opted in |
#6. Impersonation
impersonation_only connections and POST /simulator/authenticate let a tool log in as a user with no credential.
| Gate | Value |
|---|---|
| Scope | sso:impersonate or ulex:admin |
| Tenant mode | allow_mocks: true (off by default on https://ulexid.com, forbidden when hipaa_enabled: true; true by default in local in-memory mode) |
| Audit | impersonation.started and impersonation.ended, always |
| Actor | actor_type: "agent", never user |
| Token marker | amr: ["urn:ulex:amr:impersonated"], acr: "urn:ulex:acr:simulated" |
{
"id": "aud_01M3PSW3WGDDFJFJHZ4QJNNFZD",
"action": "impersonation.started",
"category": "authorization",
"actor_type": "agent",
"actor_id": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"target": { "type": "user", "id": "usr_01M3PSV9GRT8GQGEG686AR1W9S", "display_name": "Dana Okafor" },
"metadata": { "connection_id": "con_01M3PSVAG0QFJG99R0M5DXSR5A", "reason": "e2e test" },
"outcome": "success",
"timestamp": 1790693112
}Your application must reject these tokens in production. If acr === "urn:ulex:acr:simulated" satisfies an authorization check, any test tenant with allow_mocks: true could mint an accepted login. A token minted by ulex_mint_access_token carries urn:ulex:amr:simulated for the same reason.
export function isSimulated(claims: AccessTokenClaims): boolean {
return (
claims.acr === "urn:ulex:acr:simulated" ||
(claims.amr ?? []).some((m) => m.startsWith("urn:ulex:amr:sim"))
);
}
if (isSimulated(claims)) throw new Error("simulated token rejected");#7. Auditing denials
Every denial is an audit event with outcome: "denied".
curl -sS -G "$BASE/audit-events" -H "$AUTH" \
--data-urlencode 'outcome=denied' \
--data-urlencode 'since=2026-09-29T00:00:00.000Z' \
--data-urlencode 'limit=200' | jq -r '.data[] | "\(.actor_type) \(.action) \(.error_code) \(.target.id // "-") \(.ip_hash)"'api_key mcp.tool_denied insufficient_scope ulex_delete_application sha256:9c2e4a6b…
api_key mcp.tool_denied insufficient_scope ulex_reset_tenant sha256:9c2e4a6b…
user authentication.succeeded null usr_01M3PSV9GRT8… sha256:1a3c5e7f…A sustained mcp.tool_denied from one actor is usually a mis-scoped key in a loop. A single authentication.succeeded for a user whose organization is pinned to one connection is worth a look; sso_only restricts authentication to the organization's enterprise connections.