Repository navigation
feat(scope): add an ENVIRONMENT scope for per-deployment grants - #54
Merged
Merged
Conversation
Permissions are administered once, centrally, and every server reads the same policy. That is right for "who is staff" and wrong for "let me try this on stage first": until now the only way to narrow a grant was by server type or by a single server id, neither of which names a deployment. ENVIRONMENT adds that axis. It sits between GLOBAL and SERVER_TYPE in specificity, so a globally granted permission still applies inside every environment — an environment-scoped grant only overrides it where it is pinned, and a server-type grant still wins over both. The enum value is appended (4) rather than inserted in specificity order: the numbers are the wire format, and renumbering would silently reinterpret grants a running server already holds. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LAkrrLYMD6xNT84FK1CBuJ
The migration finds the two CHECK constraints by definition rather than by name, because V1 created them inline. If that lookup ever misses, every environment-scoped grant is rejected at write time and nothing fails until an admin tries to create one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LAkrrLYMD6xNT84FK1CBuJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Permissions set in forge admin are global: every server reads one policy. That is right for "who is staff" and wrong for "let me try this on stage first" — the only ways to narrow a grant were server type and server id, neither of which names a deployment.
What
A fourth scope kind,
ENVIRONMENT, whose value is the deployment name (stage,prod).Specificity, least to most:
GLOBAL→ENVIRONMENT→SERVER_TYPE→SERVER. So:Details worth a second look:
V6__allow_environment_scope.sqlwidens the twoscope_kindCHECKs. They were created inline in V1 and carry generated names, so the migration looks them up by definition rather than guessing.= 4), not inserted in specificity order — the numbers are the wire format, and renumbering would silently reinterpret grants a running server already holds.GET /v1/permissions/players/{id}/checktakes anenvironmentquery param so the admin preview can evaluate as a given environment.Rollout order
Deploy groundsgg/plugin-permissions#17 everywhere before the first
ENVIRONMENTgrant is created. Older plugin builds map unknown scope kinds toGLOBAL, so such a grant would be read as unconditional on those servers; that PR fixes the mapping to drop it instead.Merging this on its own is safe — nothing produces an
ENVIRONMENTgrant until someone creates one.Test
./gradlew buildgreen. NewPolicyEngineTestcases cover environment-beats-global, environment-loses-to-server-type, no leaking into another environment, and globals still applying inside one.🤖 Generated with Claude Code
https://claude.ai/code/session_01LAkrrLYMD6xNT84FK1CBuJ