carlos / platform Public

Preserve restricted CI deployments during first-instance setup

Paul Campbell pushed by claude agent, operated by paul@keymail.dev 64d3343167b072ed92519cdf79aa4ef2b2885d46 parent 80b7fcc
7 files changed, +100 −11
  • deploy.go +7 −2
  • deploy_first_cli_test.go +18 −4
  • docs/superpowers/notes/census-proposal-first-deploy-493.md +1 −1
  • docs/superpowers/reviews/first-deploy-493-brief.md +7 −0
  • docs/superpowers/reviews/first-deploy-493-opus.md +63 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv +3 −3

CI passed — run details

diff --git a/deploy.go b/deploy.go
index 1469e5d37..63eae5ca9 100644
--- a/deploy.go
+++ b/deploy.go
@@ -412,10 +412,15 @@ func runDeploy(args []string) {
firstChannel = channels.PipelineEntry
}
rec, createErr := createDeployInstance(ctx, sess, acct, *app, firstChannel, *hostFlag, message)
- if createErr != nil {
+ var denied *enableError
+ if !createdNow && errors.As(createErr, &denied) && denied.status == http.StatusForbidden {
+ // A deploy credential can publish to an existing app without
+ // permission to enable instances. Keep that no-instance path.
+ } else if createErr != nil {
log.Fatalf("deploy: %v", createErr)
+ } else {
+ recs = []apiInstanceRecord{rec}
}
- recs = []apiInstanceRecord{rec}
}
}
channel, hosts, staticDeploy, err := deployTargets(recs, *kind, *channelFlag, *hostFlag,
diff --git a/deploy_first_cli_test.go b/deploy_first_cli_test.go
index 3e2ef5350..d0318532f 100644
--- a/deploy_first_cli_test.go
+++ b/deploy_first_cli_test.go
@@ -13,9 +13,9 @@ import (
func TestFirstDeployCLI(t *testing.T) {
bin := buildCarlos(t)
- for _, scenario := range []string{"new", "existing", "unavailable", "bad artifact", "bad env"} {
+ for _, scenario := range []string{"new", "existing", "restricted", "unavailable", "bad artifact", "bad env"} {
t.Run(scenario, func(t *testing.T) {
- exists := scenario == "existing"
+ exists := scenario == "existing" || scenario == "restricted"
handlers := map[string]func(http.ResponseWriter, []byte){}
handlers["GET /api/cli/apps/ops/hello/instances"] = func(w http.ResponseWriter, _ []byte) {
if scenario == "unavailable" {
@@ -44,6 +44,10 @@ func TestFirstDeployCLI(t *testing.T) {
w.Write([]byte(`{"channels":[],"pipeline_entry":"edge","pipeline_channels":["edge"]}`))
}
handlers["PUT /api/cli/apps/ops/hello/instances-manifest"] = func(w http.ResponseWriter, b []byte) {
+ if scenario == "restricted" {
+ w.WriteHeader(http.StatusForbidden)
+ return
+ }
w.Write([]byte(`{"domain":"bab.apps.test"}`))
}
handlers["POST /api/cli/apps/ops/hello/instances"] = func(w http.ResponseWriter, b []byte) {
@@ -98,11 +102,18 @@ func TestFirstDeployCLI(t *testing.T) {
if scenario == "bad env" {
env = "DO-NOT-PRINT"
}
- cmd := exec.Command(bin, "deploy", "--console", fc.ts.URL, "--account", "ops", "--app", "hello", "--version", "first493", "--env", env, artifact)
+ args := []string{"deploy", "--console", fc.ts.URL, "--account", "ops", "--app", "hello", "--version", "first493"}
+ if scenario == "restricted" {
+ args = append(args, "--channel", "canary/test")
+ } else {
+ args = append(args, "--env", env)
+ }
+ args = append(args, artifact)
+ cmd := exec.Command(bin, args...)
cmd.Env = carlosTestEnv(t, "CARLOS_CREDENTIALS="+credPath, "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
- if scenario == "new" || scenario == "existing" {
+ if scenario == "new" || scenario == "existing" || scenario == "restricted" {
if err != nil {
t.Fatalf("deploy: %v\n%s", err, out)
}
@@ -112,6 +123,9 @@ func TestFirstDeployCLI(t *testing.T) {
if scenario == "existing" && (fc.called("GET /api/cli/apps") || fc.called("POST /api/cli/apps/ops/new") || fc.called("PUT /api/cli/apps/ops/hello/instances-manifest")) {
t.Fatal("existing deploy attempted setup")
}
+ if scenario == "restricted" && (fc.called("POST /api/cli/apps/ops/hello/instances") || fc.called("PUT /api/cli/apps/ops/hello/config")) {
+ t.Fatal("restricted credential created an instance or changed config")
+ }
if scenario == "new" && !strings.Contains(string(out), "created instance hello.bab.apps.test") {
t.Fatalf("missing creation output: %s", out)
}
diff --git a/docs/superpowers/notes/census-proposal-first-deploy-493.md b/docs/superpowers/notes/census-proposal-first-deploy-493.md
index 44aae1fd7..e7a54c484 100644
--- a/docs/superpowers/notes/census-proposal-first-deploy-493.md
+++ b/docs/superpowers/notes/census-proposal-first-deploy-493.md
@@ -18,6 +18,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the
- new `deploy_first_preflight.go:deployArtifactPreflight`: reads +file:Open, +file:Stat; written legacy, accepted-legacy, frozen
-Seal: `43d1824141f0ce7024cc3740ab5feac3f3539322f8afb856c9ca2f10d5095e95` → `5bfa4060c9cd394dd8198cb847a80c6bdf0299360162039a330da036859ee5ee`.
+Seal: `43d1824141f0ce7024cc3740ab5feac3f3539322f8afb856c9ca2f10d5095e95` → `6b9aa3f2b21250d40b910ad1d29362687ec57ba5e895157670b785c0c3978f52`.
Overlay: `internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/reviews/first-deploy-493-brief.md b/docs/superpowers/reviews/first-deploy-493-brief.md
new file mode 100644
index 000000000..b7df8655b
--- /dev/null
+++ b/docs/superpowers/reviews/first-deploy-493-brief.md
@@ -0,0 +1,7 @@
+# Review first-deploy-493, round 2 of 3
+Repo /home/paulca/amadan.net/carlos/platform-first-deploy-493. Review working diff against origin/main plus untracked deploy_first*.go. Do not edit files, do not create a plan file, no agents, no tests/full suites, no network or production mutations. Return findings directly. Opus independent review of Codex author + Sonnet helpers.
+Prior round: design consultation at /home/paulca/.cache/first-deploy-493/design-review.txt. It identified API constraints but no ranked blocking findings. Implemented safe absence proof, existing APIs, region selection, validation and copy approval. Deliberate choices: --env uses same set semantics as env set (last duplicate wins), named bundles selected from watched hosts, existing successful instance-list deploy avoids account-list call; first binary instance for zero records, static host flow preserved. Partial writes retained and documented. Server errors and races stop with honest error, retry is user action. No blanket retries or authorization widening. Custom host goes through instanceCreate validation.
+Request: #493 first deploy creates missing app and instance and accepts --env K=V. Existing deployments should continue working.
+Read AGENTS stopping rules and docs/superpowers/reviews/REVIEW-BRIEF-TEMPLATE.md. Check real API response shapes, service token compatibility, empty/truncated list behavior, account identity/Trash/concurrency, preflight before writes, environment scope and confidentiality, channel/region/host semantics, static/temp regressions, no production operations. New strings approved by Paul in copy-review/result.json.
+Also independently rule each census unit and the root package envelope. Read docs/superpowers/notes/census-proposal-first-deploy-493.md (may be being generated; if absent use /home/paulca/.cache/first-deploy-493/census-card.txt), and changed functions reachable from them. Units runDeploy and deployArtifactPreflight. Compare authority before/after; no root path may become tenant-controlled. Return explicit verdicts with file:line for both units and envelope.
+Severity P1 unsafe/nonworking/failing test blocks. P2 wrong/missing fix without reopening review. P3 polish follow-up only. Stop at first no-P1 review, max3 rounds globally; two recurring same-invariant rounds stop fixes. Output ranked findings with verified failure scenario, file:line and concrete fix, plus census rulings, ending READY / READY AFTER FIXES / NOT READY. Read only merged specs; no pending designs.
diff --git a/docs/superpowers/reviews/first-deploy-493-opus.md b/docs/superpowers/reviews/first-deploy-493-opus.md
new file mode 100644
index 000000000..5b9f4f110
--- /dev/null
+++ b/docs/superpowers/reviews/first-deploy-493-opus.md
@@ -0,0 +1,63 @@
+**Verdict: READY AFTER FIXES.** I found no P1, one P2 and five P3s. Under the stopping rules this round ends the review. Apply the P2 without reopening it; the P3s go on the follow-up list.
+
+I reviewed the working tree as it stood at about 15:00. The author was still editing `deploy.go` while I read it: the zero-record binary block gained `truncated`/`total` guards and the `channelsErr` handling. The census overlay was regenerated at 14:59:42, after the last `deploy.go` edit, so it matches this snapshot. As briefed, I ran no tests.
+
+## Findings
+
+**P2-1: existing apps with zero instances now fail under a deploy credential, before the ship.** Invariant: existing deployments keep working and service tokens stay compatible.
+- **Where:** `deploy.go:402-419` → `deploy_first.go:121`, `:131`.
+- **Scenario:**
+ - The app already exists (`createdNow` is false) and has a pipeline (every new app gets one, `internal/console/server.go:5293`).
+ - It has no promoted channel and no instance records.
+ - CI runs `carlos deploy --channel canary/x` with a `deploy`-role credential. That is the only service role allowed both to list instances and to promote (`internal/console/authcli.go:565,673`). On a pipelined app it may move only `canary/<name>` (`internal/console/deployscope.go:118`).
+ - Before this branch: ship, promote, and "no instance follows canary/x". Now: `instancesEnable` hits `PUT instances-manifest`, which no service role may call (`authcli.go:672`, `svcrole.Set{}`). `instanceCreate` is limited to the `Instance` role (`:725`). The run dies before shipping.
+ - The window is narrow but real.
+- **Fix:** keep auto-creating the instance only when this run created the app (`createdNow`), or when the caller is a member. For an existing app, treat a 403 from the manifest or create door as "take the old no-instance path" and print a muted note. This narrows the new step; it is not a retry and widens no authorisation. Add a CLI test: existing app, zero records, `PUT instances-manifest` answers 403, and the deploy still ships and promotes.
+
+**P3-1:** `deploy.go:481`. On a truncated list, the refusal passes the app name into `{host}` and drops the `deploy:` prefix. Use `log.Fatalf("deploy: %s", …)`. Ideally name the host, or reuse FD-C10 with the app name as approved.
+
+**P3-2:** `apimode.go:3857`. `type apiInstancesMissing` was inserted between `instanceList`'s doc comment and the func, so godoc now attaches that comment to the type. Move the type above the comment and add `Unwrap() error`. No current caller needs it: `errMembershipNotFound` checks sit on other paths, `apimode.go:5113` and `instances_cli.go:1049`.
+
+**P3-3:** `deploy_first_preflight.go:51`. The NUL check can never fire, because `os.Stat` already fails on a NUL. Drop it.
+
+**P3-4:** the `--region` preflight moved from before the capabilities read and wizard to after the save offer (`deploy.go:396`). A region mismatch now refuses after the person has answered questions. Nothing has been written by then.
+
+**P3-5:** the approved docs say "creates the app and its first instance if they are missing". In fact the instance is created only when a pipeline exists and nothing has been promoted (`deploy.go:409`). A previously promoted app with no instances keeps the old path, by design. Tighten the wording at the next copy pass.
+
+## Checks that passed
+- **API shapes:**
+ - The instance list answers 404 only from the membership/app gate (`internal/console/apiinstances.go:118`). A fresh app with no manifest lists 200 and empty.
+ - `/api/cli/apps` filters an app-scoped service token down to its own app (`internal/console/apicli.go:715`).
+ - App create refuses app-scoped service tokens (`apicli.go:389`).
+ - New apps get the default `edge` pipeline, so `pipeline_entry` is present (`apicli.go:840`).
+- **Absence proof:** `ensureDeployApp` creates nothing when there is no membership, when the account name matches more than one membership, when the name appears in the live or Trash list, or when the list fails or is unsupported. Two concurrent first deploys are settled by the server's create conflict.
+- **Environment:** values never appear in errors or output. The kind is `env`, the same as `env set` (`appconfig_cli.go:396`). The bundle comes from the watched hosts, mixed bundles are refused, and so is a truncated list. All of this happens before the config write.
+- **Static and temporary flows:** unchanged apart from the minted record being appended to `recs`. That only affects the watch labels, which are empty either way.
+- **Copy:** FD-C1..C15 and FD-D1 match `copy-review/result.json` exactly. The other preflight strings are reused from `cli.go:2843,2879`.
+- **No production operations:** test fakes bind `127.0.0.1`.
+
+## Census rulings
+- **`runDeploy` (`deploy.go:133`): APPROVE.**
+ - The one local read is unchanged: `os.Stat(artifact)` at `deploy.go:329`, on a config artifact confined by `projectArtifact` (`:293`).
+ - Every new step is a console HTTP call through existing doors, or the call into `deployArtifactPreflight`.
+ - The basis items still hold: `deployAssets` refuses first (`:187`, `:351`), and `passGatedTargets` and `hostPlaces` are untouched.
+ - It is a member CLI verb (`main.go:100`), and no root path reaches it.
+- **`deployArtifactPreflight` (`deploy_first_preflight.go:20`), new, accepted-legacy: APPROVE.**
+ - It runs `Stat` and `Open`/`Close` on `fs.Args()`: command-line paths, or the confined config artifact.
+ - A binary must be a regular file before `Open`, and nothing is read.
+ - It runs as the member, its only caller is `deploy.go:376`, and there is no tenant- or box-controlled input.
+- **Envelope `.`: APPROVE.**
+ - The changed functions are:
+ - `instanceList`: error wrapping only, no new I/O.
+ - `runDeploy`, `ensureDeployApp` and `createDeployInstance`: console API calls through the server's own gates.
+ - `parseDeployEnv` and `deployEnvBundle`: pure.
+ - `deployArtifactPreflight`.
+ - None weakens a check, and no root path becomes tenant-controlled.
+
+## Author disposition
+
+Reviewed snapshot: 80b7fcc4206f69308af20f82d38c6e489eb50104. Round 1 was the design consultation; this is round 2 of the same change. No P1; review closed under AGENTS.md stopping rule 1.
+
+P2-1 applied: on an existing app only, a typed 403 from instancesEnable leaves the original instance list intact and continues to the existing ship/promote/no-instance path. A newly created app still fails on that denial. The create door's errors do not trigger fallback. No permission is expanded and no new mutation is added. TestFirstDeployCLI/restricted exercises the denial, publication, and absence of instance/config writes.
+
+P3-1 through P3-5 remain follow-ups as requested by the stopping rule. They do not reopen this review. The approved wording is unchanged.
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index da122afdb..217423782 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -46,4 +46,4 @@ plan14-root-reads-fleet-routes-followups.tsv 1379d066c8dd2335d95d5f6e9c7bce65ff5
plan14-root-reads-tunnel-websockets.tsv 949bc734a293366e6b2700244af5110dd6e84b5432023e991c09e806afd62483
plan14-root-reads-console-protection-tab.tsv eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8
plan14-root-reads-devbox-mode.tsv 43d1824141f0ce7024cc3740ab5feac3f3539322f8afb856c9ca2f10d5095e95
-plan14-root-reads-first-deploy-493.tsv 5bfa4060c9cd394dd8198cb847a80c6bdf0299360162039a330da036859ee5ee
+plan14-root-reads-first-deploy-493.tsv 6b9aa3f2b21250d40b910ad1d29362687ec57ba5e895157670b785c0c3978f52
diff --git a/internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv b/internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv
index 2050688ca..cba534f05 100644
--- a/internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv
+++ b/internal/provision/testdata/plan14-root-reads-first-deploy-493.tsv
@@ -1,8 +1,8 @@
# Census overlay first-deploy-493, written by census-propose (#369). census-ruling-first-deploy-493, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-first-deploy-493.md.
# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
-@legacy eb5668955b91bd38a21469fc936476efe500ba7eeae2daf1a2554c265106a230 deploy.go runDeploy legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets and --no-assets, refuses both together and bad folders before anything runs (deployAssets), reads the folders saved in .carlos/config for the session's console through configAssets (the config walk the CLI already makes), and saves a new list there as it saves the other deploy settings; read site unchanged (1), none added;rev3=census-ruling-gated-deploy-watch-164;basis=the static-deploy branch passes its watch targets through passGatedTargets (a console POST for a gate pass per gated host) and passes the gated-host set to watchDeployed; no new local read, read site unchanged (1), none added;rev3=census-ruling-region-labels;basis=builds a host-to-label map (hostPlaces) from the instance list it already read and passes it to the static watch targets and watchDeployed, so the watch lines say where; no read added;rev3=census-ruling-first-deploy-493;basis=Sequences existing console APIs for confirmed-missing app and first instance creation, with repeatable environment values; local artifact preflight before these new writes. Existing config artifact stat read retained. file:Stat@9052 2ff15110b7948ae62436d638496a16c0233462c76fd0abb300fed771db565fc1
+@legacy dc432cd1d82ad3c26f62b50049f7a738a07aaf9afe2dbab4d145e0d60eb67e59 deploy.go runDeploy legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets and --no-assets, refuses both together and bad folders before anything runs (deployAssets), reads the folders saved in .carlos/config for the session's console through configAssets (the config walk the CLI already makes), and saves a new list there as it saves the other deploy settings; read site unchanged (1), none added;rev3=census-ruling-gated-deploy-watch-164;basis=the static-deploy branch passes its watch targets through passGatedTargets (a console POST for a gate pass per gated host) and passes the gated-host set to watchDeployed; no new local read, read site unchanged (1), none added;rev3=census-ruling-region-labels;basis=builds a host-to-label map (hostPlaces) from the instance list it already read and passes it to the static watch targets and watchDeployed, so the watch lines say where; no read added;rev3=census-ruling-first-deploy-493;basis=Sequences existing console APIs for confirmed-missing app and first instance creation, with repeatable environment values; local artifact preflight before these new writes. Existing config artifact stat read retained. file:Stat@9052 78b4df11f549fefa38eea6581bd465255dba4d891db1bddace4c5178a56d075d
@legacy a946e716ca8becb86501be46be0f2fc2155e385b9544a8716106359832addfe3 deploy_first_preflight.go deployArtifactPreflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-first-deploy-493;basis=Checks user-supplied deploy artifact paths with Stat and Open before setup mutations. These are the same member CLI paths subsequently read by runShipAPI; no root command uses this helper, no new root input authority. file:Open@1072,file:Stat@726 77e6482e548dc54d670aa86445ed16226fafe245a0ebacbb025d8f87ab19c0d2
-deploy.go runDeploy legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets and --no-assets, refuses both together and bad folders before anything runs (deployAssets), reads the folders saved in .carlos/config for the session's console through configAssets (the config walk the CLI already makes), and saves a new list there as it saves the other deploy settings; read site unchanged (1), none added;rev3=census-ruling-gated-deploy-watch-164;basis=the static-deploy branch passes its watch targets through passGatedTargets (a console POST for a gate pass per gated host) and passes the gated-host set to watchDeployed; no new local read, read site unchanged (1), none added;rev3=census-ruling-region-labels;basis=builds a host-to-label map (hostPlaces) from the instance list it already read and passes it to the static watch targets and watchDeployed, so the watch lines say where; no read added;rev3=census-ruling-first-deploy-493;basis=Sequences existing console APIs for confirmed-missing app and first instance creation, with repeatable environment values; local artifact preflight before these new writes. Existing config artifact stat read retained. file:Stat@9052 2ff15110b7948ae62436d638496a16c0233462c76fd0abb300fed771db565fc1
+deploy.go runDeploy legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets and --no-assets, refuses both together and bad folders before anything runs (deployAssets), reads the folders saved in .carlos/config for the session's console through configAssets (the config walk the CLI already makes), and saves a new list there as it saves the other deploy settings; read site unchanged (1), none added;rev3=census-ruling-gated-deploy-watch-164;basis=the static-deploy branch passes its watch targets through passGatedTargets (a console POST for a gate pass per gated host) and passes the gated-host set to watchDeployed; no new local read, read site unchanged (1), none added;rev3=census-ruling-region-labels;basis=builds a host-to-label map (hostPlaces) from the instance list it already read and passes it to the static watch targets and watchDeployed, so the watch lines say where; no read added;rev3=census-ruling-first-deploy-493;basis=Sequences existing console APIs for confirmed-missing app and first instance creation, with repeatable environment values; local artifact preflight before these new writes. Existing config artifact stat read retained. file:Stat@9052 78b4df11f549fefa38eea6581bd465255dba4d891db1bddace4c5178a56d075d
deploy_first_preflight.go deployArtifactPreflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-first-deploy-493;basis=Checks user-supplied deploy artifact paths with Stat and Open before setup mutations. These are the same member CLI paths subsequently read by runShipAPI; no root command uses this helper, no new root input authority. file:Open@1072,file:Stat@726 77e6482e548dc54d670aa86445ed16226fafe245a0ebacbb025d8f87ab19c0d2
-@coverage . 709c469733f42774f3ead8d7fc2798e0344d8fbd85b9007aadec48cf6d40070b
+@coverage . 66e25cd79780b2c5a193def2149433a3e2cc75f47fda9d08649fc7a1f6ede1a0