Skip to content

feat(api): delete an application with a confirmation - #323

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/256-delete-application
Nov 17, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/256-delete-application

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Second part of #256 (application lifecycle): deleting an application. Stopping one is #321; the screen follows in its own pull request.

What changed

An application could not be deleted: only removing its whole environment removed it.

  • POST …/applications/{applicationId}/delete (204) deletes it. It needs environment.update on the application's environment, so who administers the environment may delete and a developer may not, and a confirmation token for application.delete on that application.
  • Refused while anything runs: 409 application_running with a placed replica, 409 deployment_in_progress with a running deployment. No container can be left on a server by a deletion: the application is stopped first (feat(api): stop an application #321). A refusal does not spend the confirmation.
  • The application's row is locked before the checks, so a deployment queued at the same moment is either seen, and refuses the deletion, or fails once the application is gone.
  • Its releases, deployments, stopped allocations and claimed domains go by cascade. The audit log stays, and so does the servers' action history, which only loses its link to the application.
  • A confirmable action can now be authorized on an environment. application.delete joins the closed catalog with environment.update. Issuance reads the application first to learn where it lives; an unknown application and one the requester may not administer both answer 404. node.remove is unchanged.
  • Audited as application.deleted with the application's name and the confirmation id.
  • openapi.json, the API client and the route and role matrix are regenerated; SPEC 3.6, 7 and 8 describe the action, who may use it and the route.

The database privilege

deploy/postgres/runtime-role.sql gave the API no DELETE on applications, on purpose: applications were removed only with their environment. This change grants DELETE on applications, and on no table that depends on it: deployments, allocations and observations still cannot be deleted by the API, only by the cascade of an application or an environment. Existing installations get the grant when the stack restarts with the new image, because the database-role service applies that file on every start.

How it was tested

  • Unit tests for the confirmation: the permission is asked where the application lives, for members and for API tokens; an unknown application, a resolver that does not say where the resource lives and a refused permission all answer a missing resource; a token for application.delete cannot remove a server.

  • Integration tests with PostgreSQL, the HTTP API, the real pipeline and the restricted runtime role:

    • refusals while the application runs and while its stop runs, without spending the confirmation;
    • a token for another application, a token of another account and a forged token are rejected;
    • after the deletion: the application answers 404, no deployment, release, allocation or domain is left, the action history and the audit events are, the name and the domain can be used again, and the other application is untouched;
    • an application whose first deployment is queued, and one that never ran;
    • a developer of an unprotected environment may deploy and stop, and is refused the confirmation and the deletion.
  • Eight mutations, each caught (one needed that last test first), including the missing database privilege, which shows as a 503.

  • On a real control plane (the rig of feat(api): stop an application #321, switched to an image built from this branch, with the runtime role provisioned by the real database-role service):

    Step Result
    Delete an application that runs 409 application_running; the application is still there
    Ask the confirmation with a wrong name 400 confirmation_name_mismatch
    Delete a stopped application 204; it answers 404; the same confirmation again answers 404
    Stop then delete the other one 204; the server has no container and no route left
    Create and deploy an application with the same name and domain succeeded
    Read the audit log two application.deleted with their confirmation ids, three confirmation.issued

Not tested

  • Two requests racing for real (a deployment queued while the deletion holds the lock): covered by the reasoning above and the row lock, not by a concurrent test.
  • An application on a server that is down or removed cannot be stopped, so it cannot be deleted either. Noted in feat(api): stop an application #321.

Security considerations

  • security-review: a destructive command with a confirmation token (rule 7), a wider database privilege for the runtime role, and the confirmation catalog extended to environment-scoped actions.
  • More secure choice where the spec was silent: deleting needs environment.update, not deploy.run. The catalog has no dedicated application.delete permission; adding one would change the role model and API token scopes, so it is left as an open question in SPEC 16.
  • The permission is checked on the route, in the command and when the confirmation is issued. The confirmation is bound to the organization, the action, the application and the account, and is spent only if the deletion commits.
  • No agent action, no shell, no secret path. Secrets belong to the environment and are not touched.

Summary by CodeRabbit

  • New Features
    • Applications can now be deleted with a confirmation and the required environment permissions. Deletion is blocked while the application has running replicas or an active deployment.
    • Deletion removes application-owned records while preserving audit and agent-action history. Application names and domains can be reused afterward.
  • Documentation
    • Updated API and permission documentation with application deletion requirements and behavior.

An application could not be deleted: only removing its whole environment
removed it.

Deleting needs environment.update on the application's environment and a
confirmation token for application.delete on that application, issued
after its name was typed and spent in the same transaction. It is refused
while a replica is placed or a deployment runs, so no container is left
on a server: stop the application first.

A confirmable action can now be authorized on an environment. The runtime
database role may delete rows of applications; their deployments,
releases, allocations and domains go by cascade only.

Refs #256

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds environment-scoped confirmations for application deletion and a POST endpoint that deletes eligible applications. The flow checks access and confirmation, locks the application, rejects active deployments or placed replicas, and publishes an application.deleted audit event.

Changes: Application deletion

Layer / File(s) Summary
Confirmation target and scope
apps/api/src/modules/apps/application/application-confirmation-target.ts, apps/api/src/modules/apps/application/ports.ts, apps/api/src/modules/apps/infrastructure/prisma-application.store.ts, apps/api/src/modules/apps/apps.module.ts, apps/api/src/modules/confirmations/application/confirmation-commands.ts, apps/api/src/modules/confirmations/application/confirmations.spec.ts, apps/api/src/modules/confirmations/application/ports.ts, apps/api/src/modules/confirmations/domain/confirmation-token.ts, docs/SPEC.md
The confirmation catalog adds application.delete with environment.update permission at environment scope. The target resolver looks up the application and returns its name and environment location. Confirmation issuance uses that location for permission checks.
Deletion endpoint and execution
apps/api/src/modules/deployments/interface/deployment.controller.ts, apps/api/src/modules/deployments/interface/deployment.dto.ts, apps/api/src/modules/deployments/application/deployment-commands.ts, apps/api/src/modules/apps/application/ports.ts, apps/api/src/modules/apps/infrastructure/prisma-application.store.ts, apps/api/src/modules/deployments/domain/release.ts, apps/api/src/modules/deployments/deployments.module.ts, deploy/postgres/runtime-role.sql, apps/api/src/audit-coverage.spec.ts
The endpoint accepts a confirmation token and calls the deletion command. The command locks the application, rejects active deployments or placed replicas, consumes the confirmation, deletes the application, and publishes application.deleted. The store adds locking and deletion operations, and the runtime role receives DELETE permission on applications.
Integration coverage and specification
apps/api/src/modules/deployments/delete-application-http.integration.spec.ts, docs/SPEC.md
Integration tests cover authorization, confirmation matching, lifecycle constraints, deleted records, retained history, and reuse of names and domains. The specification describes the endpoint, role permissions, deletion behavior, and current permission-model limitation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant DeploymentController
  participant DeploymentCommands
  participant ApplicationStore
  participant ConfirmationVerifier
  Client->>DeploymentController: POST application delete with confirmation
  DeploymentController->>DeploymentCommands: remove application
  DeploymentCommands->>ApplicationStore: lock application
  ApplicationStore-->>DeploymentCommands: return lock result
  DeploymentCommands->>ConfirmationVerifier: consume application.delete confirmation
  DeploymentCommands->>ApplicationStore: delete application
Loading

Possibly related issues

  • shipkeepdev/shipkeep#256 — The PR implements confirmed, audited application deletion and tests typed-name matching, which covers part of the issue’s requested deletion behavior.

Possibly related PRs

  • shipkeepdev/shipkeep#291 — Its agent-action foreign-key behavior supports this PR’s application deletion while retaining server action history.
  • shipkeepdev/shipkeep#321 — Both PRs use deployment-state and replica-placement checks in application lifecycle operations.

Suggested labels: track:control-plane, task

Merge Risk: Minimal · up to bc356

The new confirmed application-delete endpoint checks access against the application's environment and refuses deletion while a deployment is running or a replica is placed. The confirmation is spent only when deletion commits. No concrete merge-blocking problem was found. A real concurrent deployment-versus-delete race has not been tested, but the locking design appears sound.

Security architecture risk: Moderate · up to bc356

Authorization and confirmation checks are well scoped, but deletion can succeed before failed-deployment cleanup has actually removed running containers. This can erase application ownership while workloads remain on servers.

Retained concerns

  • Medium · security · observed: Deletion can commit before failure recovery removes running containers. For example, a first deployment can start its containers and then fail a health check. Recovery queues removal and immediately marks its allocations stopped; failed deployments are excluded from active(), and deletion checks only placed allocations. An authorized caller with a matching confirmation can then delete the application and cascade its ownership records before removal succeeds. Pending cleanup survives, but failed or expired cleanup can leave workloads without their application owner. The recovery behavior predates this PR; the new deletion path adds irreversible ownership removal while trusting that behavior.
Security review details

Security Blast Radius

  • inferred — The identified lifecycle failure is bounded to an application the caller may administer, including its replicas across nodes. It requires environment.update and that caller's matching confirmation. It does not establish cross-tenant access or increased host privileges, but workloads carrying injected environment secrets can outlive deletion if cleanup does not complete.

Security Findings and Attack Paths

  • observed — A failed deployment's cleanup is not a deletion barrier: recovery enqueues removal and marks allocations stopped without awaiting the outcome. The new deletion command neither inspects outstanding agent actions nor retains application ownership until their completion. Pending cleanup is preserved rather than cancelled, which reduces but does not eliminate the failure window.

Trust Boundaries and Controls

  • observed — The handler derives organization, project, and environment from URL parameters, and identity from the authenticated principal. The command revalidates account/API-token authority, checks live tenant permission, and finds the application within that same scope before deletion. Possession of a confirmation alone does not grant deletion authority.

Resilience and Maintainability Implications

  • observed — The normal successful stop path waits for stop and removal steps to succeed before marking allocations stopped. Failure recovery uses the same stopped state earlier, after enqueueing cleanup. This overloaded state meaning is the specific mismatch that weakens the new deletion guarantee.

Hardening Proposals

  • proposed — Make deletion eligibility depend on confirmed workload quiescence, not merely released placement reservations. Retain a durable cleanup owner or deleting state until removal succeeds and outstanding workload-starting actions are reconciled; failed or expired cleanup should remain recoverable rather than permitting ownership deletion.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(api): delete an application with a confirmation" matches the main change. The PR adds a POST endpoint that deletes an application after a confirmation token is verified. The changeset …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(api): delete an application with a confirmation" matches the main change. The PR adds a POST endpoint that deletes an application after a confirmation token is verified. The changeset includes the confirmation target, the application store delete/lock methods, the DeploymentCommands.remove flow, the DTO and controller, the runtime DB grant, and the tests. The title is specific, concise, and uses a conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fa36bf4 and bc356cc.

Files ignored due to path filters: 3

  • apps/api/openapi.json is excluded by !apps/api/openapi.json
  • docs/generated/route-role-matrix.md is excluded by !**/generated/**, !docs/generated/**
  • packages/api-client/src/gen/openapi.ts is excluded by !**/gen/**, !packages/api-client/src/gen/**
Files selected for processing: 17

  • apps/api/src/audit-coverage.spec.ts
  • apps/api/src/modules/apps/application/application-confirmation-target.ts
  • apps/api/src/modules/apps/application/ports.ts
  • apps/api/src/modules/apps/apps.module.ts
  • apps/api/src/modules/apps/infrastructure/prisma-application.store.ts
  • apps/api/src/modules/confirmations/application/confirmation-commands.ts
  • apps/api/src/modules/confirmations/application/confirmations.spec.ts
  • apps/api/src/modules/confirmations/application/ports.ts
  • apps/api/src/modules/confirmations/domain/confirmation-token.ts
  • apps/api/src/modules/deployments/application/deployment-commands.ts
  • apps/api/src/modules/deployments/delete-application-http.integration.spec.ts
  • apps/api/src/modules/deployments/deployments.module.ts
  • apps/api/src/modules/deployments/domain/release.ts
  • apps/api/src/modules/deployments/interface/deployment.controller.ts
  • apps/api/src/modules/deployments/interface/deployment.dto.ts
  • deploy/postgres/runtime-role.sql
  • docs/SPEC.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@samuelmbabhazi
samuelmbabhazi merged commit cea569d into main Nov 17, 2026
16 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/256-delete-application branch November 17, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant