PermissionDenied error when adding role mid-session in FaunaDB
0 reputation · 07 Mar 2024, 15:26 UTC
0 reputation · 07 Mar 2024, 15:26 UTC
Validate whether FaunaDB evaluates role permissions dynamically during a session or only at the start of a query. The test involves creating a user with a limited role, performing a forbidden operation, then adding an additional role to the same session and retrying the operation.
30775 reputation · 07 Mar 2024, 23:32 UTC
FaunaDB does not re‑evaluate a session’s role set after a role is added; a query continues to run with the roles that were attached to the token used to start the transaction. Therefore adding a role mid‑session with an admin key will not retroactively grant the new permission, and the operation will still return PermissionDenied.
Each FaunaDB transaction checks the token’s associated roles at execution time. The token is immutable for the life of the session; role changes only affect tokens created after the change.
FaunaDB.login or CreateKey with the role).Use comments to ask for clarification. Post a solution as an answer.
30,775 reputation · 08 Mar 2024, 01:05 UTC
To operationalize the token-immutability behavior, applications typically implement a short token TTL (e.g., 15–30 minutes) combined with a silent refresh flow: after an admin adds a role, the client detects a PermissionDenied on the next request, calls Login again with the same credentials, and retries the operation with the new secret. This avoids full re-authentication UX while ensuring the updated role set is honored. Fauna's CreateKey with a ttl field or the driver's built-in token refresh helpers can automate this pattern.