Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ Invalid answers stay at their prompt instead of ending post-setup. Earlier accep

Private `post-sign-in-progress.json` and `post-github-progress.json` files inside the installation workspace retain validated public answers, validated absolute credential paths and confirmed versioned Key Vault references. They are atomically saved with 0600 permissions and bound to the exact installation, action and saved inputs. No credential text, PEM contents, tokens, rejected input or approval is stored. On relaunch, **Resume saved answers** skips completed prompts after revalidation, except for the stored provider revision and enabled-state verification. Not-yet-uploaded credential files are read and validated again; successfully uploaded credentials are checked through their pinned Key Vault references and do not require the old local file. **Start over with the answers** requires confirmation and clears only prompt answers, never stored secrets, desired inputs or cloud resources. Each successful secret write is checkpointed before the next write. If a write's outcome is unknown, post-setup checks the current stored value first; creating another version requires an explicit choice. Resolve the pending credential before uploading a different one; provide its private file again if needed.

If sign-in setup stops after saving desired inputs but before completing its progress file, it can resume with an unchanged secret-backed origin. New progress files retain reference-only evidence to check that transition, including pinning an unversioned origin or shared authentication reference without changing an existing pinned version. They also bind normalization of the image and `deploy_hub` to the verified deployment image. Unrelated input or reference changes still stop resume and preserve the files for review. Older progress files without the relevant evidence still require review when their input fingerprint changes.

Configuration actions disclose secret writes and downtime, then save desired inputs and a private previous-input backup before applying. They correct an obsolete saved `deploy_hub=false` from bootstrap, retain unrelated runtime settings, and use the exact deployed image instead of the saved build candidate. Unrelated saved and live settings or secret references that disagree block configuration before secret writes or input persistence; reconcile them separately instead of overwriting either side. Each fresh Terraform plan is shown for approval. Only an in-place Hub runtime-environment update and intended secret-scoped `Key Vault Secrets User` grants are allowed; infrastructure drift, replacements, deletions, and image changes block the action. Every plan and replan that creates a role grant must first check Azure. A detected assignment missing from Terraform state, an unsuccessful lookup, or an incomplete, malformed, or ambiguous response blocks that plan before approval, apply, or Hub shutdown; review the reported recovery rather than deleting or automatically adopting a grant. Desired inputs or secret versions saved before planning remain available for recovery. Old Hub replicas are stopped only for an actual app update, before Azure creates the new configured revision. A grant-only or no-change plan does not stop Hub.

Readiness and protected setup availability are checked afterward; GitHub configuration also checks that GitHub appears in the provider API. Setup-only mode can legitimately leave the provider API unavailable. These checks do not prove GitHub client-secret correctness, OAuth callback registration, repository permissions or signed webhook delivery: complete the browser connection test and administrator enrollment separately.
Expand Down
7 changes: 6 additions & 1 deletion infrastructure/azure/post/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export async function configurePostSetup(
return choice
},
}
const progress = await postSetupProgress({ ...context, ui: recoveryUI }, action, inputs)
const progress = await postSetupProgress(
{ ...context, ui: recoveryUI },
action,
inputs,
deployment.image,
)
if (progress.pending || Object.keys(progress.references).length) context.onMutation?.()
let resume = false
if (progress.hasSaved) {
Expand Down
66 changes: 66 additions & 0 deletions infrastructure/azure/post/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as installationInputs from "../install/inputs/index.ts"
import { installationNames } from "../install/settings.ts"
import type { PostInputs, PostSetupTarget } from "./types.ts"
import { postSetupAzure } from "./index.ts"
import { postSetupProgress } from "./progress/index.ts"

vi.mock("ink", async (importOriginal) => {
const ink = await importOriginal<typeof import("ink")>()
Expand Down Expand Up @@ -593,6 +594,71 @@ it("uses the deployed digest despite stale deploy_hub=false and preserves settin
expect(test.leases.size).toBe(0)
})

it.each(["verified", "changed"] as const)(
"resumes a secret-backed sign-in checkpoint only with the %s deployed image",
async (image) => {
const test = await scenario()
const originReference = test.reference("hub-application-origin")
delete test.inputs.hub_application_origin
delete test.state.environment.HUB_APPLICATION_ORIGIN
test.inputs.runtime_secret_references!.HUB_APPLICATION_ORIGIN = originReference
test.secretValues.set("hub-application-origin", test.origin)
test.state.environment.AZURE_KEY_VAULT_SECRET_REFERENCES = JSON.stringify({
...JSON.parse(test.state.environment.AZURE_KEY_VAULT_SECRET_REFERENCES!),
HUB_APPLICATION_ORIGIN: originReference.secret_id,
})
const progress = await postSetupProgress(
{ config: test.target.config, directory: test.directory, ui: test.ui },
"sign-in",
test.inputs,
test.image,
)
await progress.saveAnswer("origin", test.origin)
await progress.saveAnswer("proxyHops", "2")
const savedProgress = await readFile(progress.path, "utf8")
const desired: PostInputs = {
...test.inputs,
image: image === "verified" ? test.image : `registry.azurecr.io/hub@sha256:${"c".repeat(64)}`,
deploy_hub: true,
runtime_environment_variables: {
...test.inputs.runtime_environment_variables,
HUB_TRUSTED_PROXY_HOPS: "2",
},
}
const content = JSON.stringify(desired)
const journalPath = join(test.directory, "post-desired.json")
const journal = JSON.stringify({
target: JSON.stringify(test.target.config),
hash: createHash("sha256").update(content).digest("hex"),
phase: "pending",
action: "sign-in",
previousReferences: JSON.parse(test.state.environment.AZURE_KEY_VAULT_SECRET_REFERENCES!),
})
await writeFile(test.inputsPath, content, { mode: 0o600 })
await writeFile(journalPath, journal, { mode: 0o600 })

const result = postSetupAzure(test.target, {
action: "sign-in",
run: test.run,
ui: test.ui,
request: test.request,
})
if (image === "changed") {
await expect(result).rejects.toThrow(/inputs changed/i)
expect(await readFile(test.inputsPath, "utf8")).toBe(content)
expect(await readFile(journalPath, "utf8")).toBe(journal)
expect(await readFile(progress.path, "utf8")).toBe(savedProgress)
expect(test.plans).toEqual([])
} else {
await expect(result).resolves.toContain(`${test.origin}/settings/github/setup`)
expect(JSON.parse(await readFile(test.inputsPath, "utf8"))).toEqual(desired)
expect(test.plans).toHaveLength(1)
expect(test.applies).toBe(1)
expect(test.uploads).toEqual([])
}
},
)

it("repairs a stopped Hub with saved authentication secrets but no origin only after a valid answer", async () => {
const test = await scenario()
delete test.inputs.hub_application_origin
Expand Down
Loading
Loading