Skip to content

feat(scope): add an ENVIRONMENT scope for per-deployment grants - #54

Merged
hbrombeer merged 2 commits into
mainfrom
feat/environment-scope
Jul 24, 2026
Merged

hbrombeer merged 2 commits into
mainfrom
feat/environment-scope

Conversation

@hbrombeer

Copy link
Copy Markdown
Member

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:

  • a globally granted permission still applies inside every environment (nothing changes for existing grants);
  • an environment-scoped grant overrides the global one, but only where it is pinned;
  • a server-type or server grant still wins over both.

Details worth a second look:

  • V6__allow_environment_scope.sql widens the two scope_kind CHECKs. They were created inline in V1 and carry generated names, so the migration looks them up by definition rather than guessing.
  • The proto enum value is appended (= 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}/check takes an environment query param so the admin preview can evaluate as a given environment.

Rollout order

Deploy groundsgg/plugin-permissions#17 everywhere before the first ENVIRONMENT grant is created. Older plugin builds map unknown scope kinds to GLOBAL, 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 ENVIRONMENT grant until someone creates one.

Test

./gradlew build green. New PolicyEngineTest cases 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

hbrombeer and others added 2 commits July 24, 2026 16:03
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
@hbrombeer
hbrombeer marked this pull request as ready for review July 24, 2026 14:37
@hbrombeer
hbrombeer merged commit e4e3cbb into main Jul 24, 2026
2 checks passed
@hbrombeer
hbrombeer deleted the feat/environment-scope branch July 24, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant