Skip to content

Hand App Studio's pull credential to infrastructure through a verb - #1174

Merged
railgrid-prow[bot] merged 2 commits into
mainfrom
fix/app-studio-promotion-pull-credential
Nov 16, 2026
Merged

railgrid-prow[bot] merged 2 commits into
mainfrom
fix/app-studio-promotion-pull-credential

Conversation

@cwilhit

@cwilhit cwilhit commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

Promoting a project whose images are private finishes without a pull credential. No <instance>-registry Secret exists, no imagePullSecretRef is set, the Instance still reports Ready=True, and authenticated requests return 502.

ensureProjectRegistryPullSecret wrote the pull Secret labelled railgrid.ai/owner: infrastructure. Since 7691b50 App Studio's Secret claim is scoped to owner: app-studio, and since 76b9080 the write runs as App Studio's provider identity, so kcp refuses it. Promotion logged the error and continued. Separately, the application template had readyWhen only on its HTTPRoute, so kro reported every tier ready as soon as it existed.

Fix

No provider can write under another provider's label, so the credential now crosses through each provider's published API:

  • App Studio, at promote: mints the credential from Code as before and stores it in its own Secret, <prod-instance>-pull-credential, labelled app-studio. If the project has a Connection and this fails, the promotion fails with the reason and names the connection.
  • App Studio, Project reconciler: calls the new infrastructure verb instances/{name}/image-pull-credential as itself and sets the returned name as the Instance's spec.imagePullSecretRef. It hands over again when the credential's digest changes or infrastructure reports SecretsBridged=False/SecretRefNotFound. GitHub App tokens last about an hour, so it re-mints 15 minutes before expiry (RequeueAfter pacing an external clock).
  • Infrastructure, new verb: writes <instance>-image-pull under its own label, owned by the Instance, and returns {secretRef: {name}}. Its secrets claim gains create/update, still scoped to owner: infrastructure. A tenant caller additionally needs update on the Instance; a foreign provider is authorized by its claim.
  • Visible failures: a hand-over failure goes to the production binding's outputs.imagePullCredential, and the portal shows it in place of the generic "being prepared" copy.
  • Ready means ready: SecretsBridged=False holds the Instance at Ready=False, and the database, web, API and gate tiers of the application template declare readyWhen (current generation, all replicas updated, ready and available).

Docs updated: docs/app-studio-runtime-decoupling.md, docs/infrastructure-architecture.md §12.2, providers/infrastructure/README.md.

Rollout

  1. Upgrade infrastructure before App Studio. App Studio's new claim names infrastructure's new verb.
  2. Existing workspaces must re-Enable App Studio. The new claim is a composition, so the hub's claims reconciler leaves it Rejected until the workspace consents (AGENTS.md §5.1). The setup endpoint is a no-op on an enabled binding. Until a workspace admin re-Enables App Studio, that workspace's hand-over is refused and shows as a pull-credential problem. New workspaces are unaffected: the welcome wizard and the Enable dialog pre-tick every declared composition for an admin.
  3. Projects already broken need one more promotion to get a credential.

Testing

  • Unit tests: go test ./... in providers/infrastructure and providers/app-studio. They cover the verb (foreign provider, tenant update check, rotation, invalid input without echoing the credential, component address refused), the reconciler hand-over, re-hand-over and renewal, promote failure, Ready gating, and each tier's readyWhen compiled with cel-go. Plus node --test src/publishingState.test.mjs and vue-tsc --noEmit in the App Studio portal.
  • Gates: make lint-providers (infrastructure, app-studio), verify-provider-contract, verify-boilerplate, verify-design-docs and verify-ui-conformance pass. verify-portalkit fails locally on a .ts import in provider-sdk/portalkit/kube.ts under Node 20, a file this PR does not touch.
  • Smoke test on a local Tilt stack (embedded kcp, kro kind cluster):
    • Both APIExports carry the change, and the tenant infrastructure binding keeps the owner: infrastructure selector.
    • Calling the verb as the workspace user returned 200. The Secret was dockerconfigjson, infra-labelled, owned by the Instance, with the expiry annotation. A second call updated it in place. Bad input returned 422 invalid_input; no bearer returned 403.
    • After re-Enabling App Studio in the two affected workspaces, the verb call as App Studio through its export virtual workspace returned 200. The original write, App Studio creating an infra-labelled Secret directly, is still refused: protected label railgrid.ai/owner must have value app-studio.
    • kro accepted the application RGD with the new readyWhen (revision 8, Ready).

Not covered: an end-to-end promotion of private images followed by an authenticated request to the app. The local stack had no promoted project or validated GitHub connection, and no App Studio e2e suite exists yet.

🤖 Generated with Claude Code

Promoting a project with private images finished without a pull credential:
ensureProjectRegistryPullSecret wrote the Secret labelled
railgrid.ai/owner: infrastructure, but since the write moved to App Studio's
provider identity kcp refuses any App Studio write outside its own
owner: app-studio label. Promotion logged the refusal and carried on, the
Instance reported Ready, and authenticated requests got 502.

No provider can write under another's label, so the credential now crosses
through each provider's published API:

- App Studio keeps the minted credential in its own app-studio-labelled
  Secret (<prod-instance>-pull-credential). A failure to mint or store it
  fails the promotion with the reason.
- The Project reconciler hands it to the new infrastructure verb
  instances/{name}/image-pull-credential, as App Studio, and sets the
  returned name as the Instance's imagePullSecretRef. It re-hands over when
  the credential changes or infrastructure reports the Secret missing, and
  re-mints a GitHub App token 15 minutes before it expires.
- Infrastructure writes <instance>-image-pull under its own label, owned by
  the Instance. Its secrets claim gains create/update, still scoped to that
  label.
- A hand-over failure is reported on the production binding
  (outputs.imagePullCredential) and shown by the portal.

Ready now means ready: an Instance with SecretsBridged=False is held at
Ready=False, and the application template's database, web, API and gate
tiers declare readyWhen, so kro no longer reports them ready on creation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit

cwilhit commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

@mjudeikis-bot review

@mjudeikis mjudeikis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two Warnings and two Notes; no Critical found. The hand-over design holds up: each provider writes only under its own owner label, the verb is served behind sdk.Gate, the manifest, chart and generated copies agree, and the provider and codegen verifiers pass. The Warnings are a missing authorization re-check on renewal and a credential that outlives its project.

Findings

  • Warning providers/app-studio/controller/project/pull_credential.go:129: renewal mints from the Project's current connectionRef as the provider, with no caller check.
  • Warning providers/app-studio/api/project_promote.go:95: the App Studio source Secret is never deleted with the project.
  • Note providers/app-studio/controller/project/pull_credential.go:155: pullSecretMissing matches any SecretRefNotFound, including the BYO OIDC one.
  • Note providers/app-studio/portal/src/publishingState.ts:111: a visible copy and tone change with no rendered evidence.

Not anchored

  • The PR body says verify-portalkit fails locally under Node 20 on provider-sdk/portalkit/kube.ts. I did not run it, since this diff touches no portalkit or agentkit file.

Checked

  • Read beyond the diff:
    • provider-sdk/dataplane/gate.go (Gate, Authorize) and subresource.go (ProxiedIdentity.IsForeignProvider).
    • Infrastructure controller/instance/bridge.go (bridgeSecrets, bridgeRegistryPullSecret, bridgeBYOSecret) and the Secret watch and mapper in controller.go/watch.go.
    • App Studio controller/project/controller.go (Reconcile, ensureInstance), bindings.StatusFromObject and bindings.Desired.
    • The portal types.ts and useProductionSettings.ts plumbing of outputs.
    • providers/code/tenant/registry_token.go (what the mint verb returns and which connection providers exist) and application.yaml: replicas have minimum: 1, and only webReady/apiReady/databaseReady reference the gated resources.
  • Correctness:
    • ensureInstance keeps the observed imagePullSecretRef while the binding names a credential and clears it otherwise. The digest annotation survives because next is a copy of got.
    • refreshIn is floored at one minute.
    • The status outputs problem is recomputed on every pass, so it clears itself.
    • Findings: the OIDC reason collision (Note 3).
  • Concurrency: no new shared state or goroutines. Source Secret writes from promote and the reconciler are guarded by resourceVersion. The Instance update retries on conflict.
  • Tenancy/kcp:
    • The verb writes through the Gate-returned provider client scoped to req.ClusterID.
    • The claim stays selector-scoped to owner: infrastructure.
    • No new serviceaccounts/clusterroles claim.
    • The new instances/image-pull-credential claim is a composition. The Grant-gated re-Enable is documented in the PR.
    • Findings: Warning 1, authorization on renewal.
  • Provider contract:
    • The verb is in manifest.yaml, catalogentry.yaml and TestSubresourceRoutesComeFromTheManifest.
    • There is no bearer and no /api/* route.
    • The component form is refused.
    • Pacing: RequeueAfter is used only for the token expiry clock, which §5.8 allows. Failures use Requeue with backoff.
    • dataplane.ConformanceTest does not exist anywhere in this tree, so no conformance test could be added or run.
  • API/codegen/storage:
    • There is no field change, only comment changes on ImagePullSecretRef. The CRD, kcp and chart copies match.
    • The new ImagePullCredentialRequest kind has its CRD, APIResourceSchema, chart schema and deepcopy.
    • make verify-codegen exits 0 and leaves the tree clean.
  • Security:
    • Errors from the verb and from invoke never echo the credential. invalid_input does not echo it either.
    • The credential is not logged.
    • IsForeignProvider is derived from the shard-stamped identity, and kcp enforces the claim before forwarding.
    • Findings: Warning 1 and Warning 2.
  • Portal: only the pure publishingState.ts helper changed, with no vendored portalkit/agentkit edits. Finding: Note 4.
  • Tests:
    • The new tests cover the verb's foreign and tenant paths, bad input and the component refusal. They cover the reconciler's one-shot hand-over, renewal, problems and ensureInstance keeping the ref. They also cover promote failing without a credential, and promote writing the source Secret under the app-studio label.
    • Missing: a renewal test where the Project's connectionRef differs from the promoted one (Warning 1), and a project-deletion test for the source Secret (Warning 2).
    • The readyWhen tests compile the expressions with cel-go.
  • Commands run (PR head 0d8844c):
    • go build ./..., go vet ./... and go test -count=1 ./... in providers/app-studio: all pass.
    • The same three in providers/infrastructure: build and vet pass for every package except the root one, and go test passes for every package except the root one. The root package, github.com/railgrid/provider-infrastructure, fails to set up with assets.go:23: pattern all:portal/dist: no matching files found. That is the unbuilt portal embed in this checkout, not the diff.
    • make lint-providers: app-studio reports 0 issues. infrastructure and the other providers with go:embed all:portal/dist report only that same missing-embed typecheck error.
    • make verify-provider-contract: passes (21 node tests, 0 permission-claim violations).
    • make verify-codegen: passes (exit 0, clean tree). It includes the boilerplate check.
  • E2E: none run. This area needs the Tilt/kind/kro stack, and the PR notes that no App Studio e2e suite exists. The end-to-end promotion of private images stays unverified, as the PR says.

// renewPullCredential mints a fresh credential from the project's Connection
// and rewrites the source Secret with it.
func (r *Reconciler) renewPullCredential(ctx context.Context, reader client.Reader, c client.Client, clusterName string, p *aiv1alpha1.Project, source *unstructured.Unstructured) (*unstructured.Unstructured, error) {
if p.Spec.Repository == nil || strings.TrimSpace(p.Spec.Repository.ConnectionRef) == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Renewal mints from the Project's current connectionRef, as the provider, with no check that the user may use that Connection
Promote authorizes the Connection by reading it as the caller (project_promote.go:75). Renewal re-reads p.Spec.Repository.ConnectionRef and mints for it as App Studio. Spec.Repository.ConnectionRef has no immutability marker, and the mint verb's Gate skips the SubjectAccessReview for a foreign provider. A user who can update the Project but cannot get Connection B can change connectionRef to B after promoting with A. About 45 minutes later, when A's token enters the 15-minute window, the reconciler mints B's installation token (packages:read across B's installation) and hands it to the production instance. I traced this through the code and did not run it end to end. Renewal should stay on the Connection the credential was minted for. Record that name on the source Secret at promote and use it here.

// promote: SourceSecret annotation ConnectionAnnotation = connectionRef
// renew:
connectionRef := strings.TrimSpace(source.GetAnnotations()[pullcredential.ConnectionAnnotation])
if connectionRef == "" {
	return nil, fmt.Errorf("the pull credential records no connection to renew from; promote again")
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 91a3d9c. Promote, which reads the Connection as the caller, now records its name and UID on the source Secret (ai.railgrid.ai/pull-credential-connection[-uid]). Renewal mints only from that Connection and never reads the Project's connectionRef. A Connection recreated under the same name (new UID) stops renewal and reports "promote again", so a new promotion authorizes again. Tests: TestEnsurePullCredentialRenewsFromThePromotedConnection (connectionRef edited after promote) and TestEnsurePullCredentialRefusesAReplacedConnection.

res := c.Resource(secretResource, pullcredential.Namespace)
existing, err := res.Get(ctx, name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
if _, err = res.Create(ctx, desired, metav1.CreateOptions{}); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: The <prod-instance>-pull-credential Secret is never deleted, so a registry credential outlives its project
The infrastructure copy is owned by the Instance and is garbage-collected. App Studio's source Secret has no ownerReferences, and finalize in controller/project/teardown.go does not delete it (grep for SourceSecretName finds only the promote path). For a PAT or OAuth connection the minted token is the Connection's own long-lived token, which the Code provider documents as Scoped: false and with no expiry. After the Project is deleted, that token stays in the tenant workspace under default/<instance>-pull-credential indefinitely. Set an owner reference to the Project when writing it, or delete it in finalize.

desired.SetOwnerReferences([]metav1.OwnerReference{{
	APIVersion: aiv1alpha1.SchemeGroupVersion.String(), Kind: "Project",
	Name: p.Name, UID: p.UID,
}})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 91a3d9c. The source Secret now carries an ownerReference to the Project (bindings.OwnerRef, the same one the coding-sandbox cache Instance relies on for kcp GC), and renewal keeps it. TestPromoteRecordsPullCredentialUnderOwnLabel and the renewal test assert it. I relied on that existing GC precedent and did not delete a Project on the live stack to watch the collection.


// pullSecretMissing reports whether infrastructure says the Secret the
// Instance names is gone, in which case it is handed over again.
func pullSecretMissing(inst *unstructured.Unstructured) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: pullSecretMissing fires on any SecretsBridged=False/SecretRefNotFound, including the BYO OIDC reference
bridgeSecrets also reports ReasonSecretRefNotFound when spec.oidcBridgeSecretRef names a missing Secret (bridge.go:219). The pull Secret has already been bridged by then, but pullSecretMissing matches on the reason alone. Every Project reconcile therefore skips the digest short-circuit at line 112 and runs the hand-over verb and an Instance update again until the tenant creates the OIDC Secret. The loop is bounded, because nothing changes status, but it is a wasted call and Secret write per pass. Match the message, or have infrastructure give the pull case its own reason.

return cond["status"] == "False" && cond["reason"] == "SecretRefNotFound" &&
	strings.Contains(fmt.Sprint(cond["message"]), "spec.imagePullSecretRef")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 91a3d9c, as you suggested: pullSecretMissing now also requires the message to start with spec.imagePullSecretRef . I kept the shared reason, since docs and the railgrid skill document SecretRefNotFound. To keep the prefix from drifting, bridge.go has a comment saying App Studio depends on it, and the new infrastructure test TestMissingSecretMessagesNameTheirReference pins both messages. The App Studio test checks that a missing OIDC Secret no longer triggers a hand-over. (Small correction: bridge.go:219 is the pull case; the OIDC one is at :122.)

if (!deployment.ready) {
const problem = productionPullCredentialProblem(binding)
if (problem) {
return `Production can't pull its container images, so it isn't serving traffic. ${problem}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: A user-visible state, copy and danger tone change ships with no rendered evidence
productionDeploymentDescription and productionDeploymentState now show a new message and the danger tone when outputs.imagePullCredential is set. The PR's tests are unit tests on the helper only. There are no screenshots of the production card in html.dark and html.light, and none at a narrow viewport. The hand-over message can be long, for example the HTTP error plus the verb error. Please attach renders showing that it wraps correctly.

Review follow-ups on the pull-credential hand-over:

- Renewal no longer reads the Project's connectionRef. Promote, which reads
  the Connection as the caller, records its name and UID on App Studio's
  Secret, and the reconciler (which mints as the provider, with no caller
  to check) mints only from that Connection. A connectionRef edited after
  promote could otherwise mint from a Connection the editor cannot read. A
  Connection recreated under the same name (new UID) stops renewal and asks
  for a promotion.
- App Studio's Secret carries an ownerReference to the Project, kept across
  renewals, so a long-lived PAT or OAuth token does not outlive the project.
- A missing BYO OIDC Secret shares SecretRefNotFound with a missing pull
  Secret. The hand-over is repeated only when the message names
  spec.imagePullSecretRef, and an infrastructure test pins both messages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit

cwilhit commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

/approve

@railgrid-prow

railgrid-prow Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cwilhit

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@railgrid-prow
railgrid-prow Bot merged commit 4961680 into main Nov 16, 2026
17 checks passed
mjudeikis pushed a commit that referenced this pull request Nov 16, 2026
…credential

Hand App Studio's pull credential to infrastructure through a verb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants