Skip to content

feat(environments): only the creator or an admin can destroy an API environment - #257

Merged
vigneshrajsb merged 1 commit into
mainfrom
env-destroy-creator-or-admin
Oct 9, 2026
Merged

vigneshrajsb merged 1 commit into
mainfrom
env-destroy-creator-or-admin

Conversation

@vigneshrajsb

@vigneshrajsb vigneshrajsb commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Builds on #256 (merged).

  • Who can destroy: destroying an API-created environment is now allowed only for its creator (createdByUserId) or a user with the admin role. Anyone else gets 403 forbidden_role with "Only the creator of this environment or an admin can destroy it."

  • Where it's enforced: in BuildService.requestApiEnvironmentDeletion, under the row lock, so DELETE /api/v2/environments/{uuid} and the destroy_environment MCP tool share one rule. The MCP preview phase checks the same rule, so it refuses before issuing a confirmation token.

  • Environments with no recorded creator can only be destroyed by an admin.

  • Personal API keys act as their owner. Service keys are machine identities, so they keep their existing repository-allowlist scoping.

  • Behaviour notes:

    • Admin status comes from session roles. API keys carry no roles, so an admin using a personal key can only destroy environments they created.
    • REST DELETE on environments with no recorded creator (including PR-created ones) is now admin-only.
    • A non-creator retrying a destroy on an environment that is already tearing down now gets 403 instead of 202.

Test plan

  • Unit tests for the rule: creator, admin, admin with no recorded creator, the owner's personal key and a service key are allowed; another user, a non-admin with no recorded creator, and someone else's personal key are refused. Plus an MCP test that a non-creator's preview returns forbidden_role without a token. Full Jest suite, lint, and server typecheck pass.
  • In a preview: user A creates an API environment; user B's DELETE and MCP destroy_environment preview both return forbidden_role; user A and an admin can destroy it.

@vigneshrajsb
vigneshrajsb force-pushed the env-destroy-creator-or-admin branch 2 times, most recently from 638a82f to 822edb1 Compare October 9, 2026 18:24
@vigneshrajsb
vigneshrajsb marked this pull request as ready for review October 9, 2026 19:56
@vigneshrajsb
vigneshrajsb requested a review from a team as a code owner October 9, 2026 19:56
@vigneshrajsb
vigneshrajsb force-pushed the env-destroy-creator-or-admin branch 3 times, most recently from 1961796 to c5381f3 Compare October 9, 2026 20:54
@vigneshrajsb
vigneshrajsb changed the base branch from site-soft-delete to main October 9, 2026 20:54
…nvironment

Enforced in BuildService.requestApiEnvironmentDeletion so the REST
DELETE route and the destroy_environment MCP tool share one rule. Service
keys keep their repository-allowlist scoping. The MCP preview refuses
before issuing a confirmation token.
@vigneshrajsb
vigneshrajsb force-pushed the env-destroy-creator-or-admin branch from c5381f3 to 99309d7 Compare October 9, 2026 20:55
@vigneshrajsb
vigneshrajsb merged commit 0cfc1a1 into main Oct 9, 2026
1 check passed
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.

2 participants