Skip to content

fix(agent): reject deployment selectors for prebuilt images - #974

Open
herefindalex wants to merge 2 commits into
livekit:mainfrom
herefindalex:fix/971-prebuilt-deployment-validation
Open

herefindalex wants to merge 2 commits into
livekit:mainfrom
herefindalex:fix/971-prebuilt-deployment-validation

Conversation

@herefindalex

@herefindalex herefindalex commented Sep 14, 2026 •

Copy link
Copy Markdown

Problem

lk agent deploy takes an early return for --image and --image-tar, bypassing the handling of --deployment. An explicit deployment selector is therefore silently ignored, potentially updating production when the user intended to deploy to staging.

Related to #971.

Changes

Reject a nonempty --deployment when combined with --image or --image-tar. Validation runs before client initialization, secret updates, push-target requests, or image uploads.

Source deployments continue to support --deployment. Prebuilt deployments with an omitted or empty selector retain their existing behavior.

This is a guard against silently ignoring the selector; it does not implement named deployment support for prebuilt images.

Compatibility

All nonempty selectors are rejected for prebuilt images, including the literal production. The existing default path uses an empty selector, and this change does not assume that production is a supported alias.

Validation

Current regression coverage consists of four focused tests for the deploy validation hook:

  • --image with a named deployment is rejected.
  • --image-tar with a named deployment is rejected.
  • Prebuilt images without a deployment selector remain allowed (tested with --image-tar).
  • Source deployments with a named deployment remain allowed.

Rejection occurs before agent-client creation; the --image-tar rejection test explicitly asserts this. These tests exercise the registered Before hook without loading or deploying an image.

Previously performed validation and integration checks:

  • Verified that the regression tests fail on the base revision and pass with this change.
  • Full Go test suite passed with the race detector enabled.
  • golangci-lint reported no issues.
  • Local integration checks verified that rejected commands perform no HTTP requests, while default tar uploads and source deployments with a staging selector retain their existing behavior.

herefindalex and others added 2 commits September 13, 2026 22:42
Prebuilt image deploys return before reading --deployment, allowing a
requested staging deploy to upload an image and report success through
the default production workflow. Secrets may also be updated first.

Validate prebuilt deployment intent in a deploy-specific Before hook,
before client setup, secret updates, push-target acquisition, or image
loading. Explain that named deployments require deploying from source.

Preserve omitted/empty deployment selectors and source-based deployment.
Reject every nonempty prebuilt selector, including literal production:
the public client uses an empty string for the default deployment and
does not establish production as an equivalent selector alias.

Add command-boundary regression tests for both image flags, -d, secrets,
missing paths, custom/case/whitespace selectors, quiet mode, and rejection
before project validation and client creation. Accepted inputs continue
through normal client setup without changing their deployment selector.

Validation:
- New rejection tests fail on the base and pass with this change.
- Full go test -race ./... passes (438 test/subtest passes, 9 skips).
- CI-pinned golangci-lint v2.11.4 passes with Go 1.26.3 (0 issues).
- Local loopback integration verifies zero requests for rejected inputs,
  successful default tar upload, and source staging propagation.
- Binary rejection and unchanged generated fish completion verified.

Fixes livekit#971
Replace the deployment flag matrix with four explicit tests covering named
image and image-tar rejection, default prebuilt deployment, and named source
deployment. Keep one assertion that rejection precedes client creation.

Use fresh definitions for the three relevant flags and the registered
Before hook. Remove reflection, global HTTP interception, and assertions
about aliases, secrets, quiet mode, and unrelated project validation.

Production behavior is unchanged.

Validation:
- Four focused tests pass.
- Both rejection tests fail when the registered guard is bypassed.
- Complete cmd/lk package passes with the race detector on Go 1.26.3.
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