Repository navigation
Hand App Studio's pull credential to infrastructure through a verb - #1174
Conversation
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]>
|
@mjudeikis-bot review |
mjudeikis
left a comment
There was a problem hiding this comment.
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 currentconnectionRefas 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:pullSecretMissingmatches anySecretRefNotFound, 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-portalkitfails locally under Node 20 onprovider-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) andsubresource.go(ProxiedIdentity.IsForeignProvider).- Infrastructure
controller/instance/bridge.go(bridgeSecrets,bridgeRegistryPullSecret,bridgeBYOSecret) and the Secret watch and mapper incontroller.go/watch.go. - App Studio
controller/project/controller.go(Reconcile,ensureInstance),bindings.StatusFromObjectandbindings.Desired. - The portal
types.tsanduseProductionSettings.tsplumbing ofoutputs. providers/code/tenant/registry_token.go(what the mint verb returns and which connection providers exist) andapplication.yaml: replicas haveminimum: 1, and onlywebReady/apiReady/databaseReadyreference the gated resources.
- Correctness:
ensureInstancekeeps the observedimagePullSecretRefwhile the binding names a credential and clears it otherwise. The digest annotation survives becausenextis a copy ofgot.refreshInis floored at one minute.- The status
outputsproblem 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/clusterrolesclaim. - The new
instances/image-pull-credentialclaim is a composition. The Grant-gated re-Enable is documented in the PR. - Findings: Warning 1, authorization on renewal.
- The verb writes through the Gate-returned provider client scoped to
- Provider contract:
- The verb is in
manifest.yaml,catalogentry.yamlandTestSubresourceRoutesComeFromTheManifest. - There is no bearer and no
/api/*route. - The component form is refused.
- Pacing:
RequeueAfteris used only for the token expiry clock, which §5.8 allows. Failures useRequeuewith backoff. dataplane.ConformanceTestdoes not exist anywhere in this tree, so no conformance test could be added or run.
- The verb is in
- API/codegen/storage:
- There is no field change, only comment changes on
ImagePullSecretRef. The CRD, kcp and chart copies match. - The new
ImagePullCredentialRequestkind has its CRD, APIResourceSchema, chart schema and deepcopy. make verify-codegenexits 0 and leaves the tree clean.
- There is no field change, only comment changes on
- Security:
- Errors from the verb and from
invokenever echo the credential.invalid_inputdoes not echo it either. - The credential is not logged.
IsForeignProvideris derived from the shard-stamped identity, and kcp enforces the claim before forwarding.- Findings: Warning 1 and Warning 2.
- Errors from the verb and from
- Portal: only the pure
publishingState.tshelper 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
ensureInstancekeeping 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
connectionRefdiffers from the promoted one (Warning 1), and a project-deletion test for the source Secret (Warning 2). - The
readyWhentests compile the expressions with cel-go.
- 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
- Commands run (PR head 0d8844c):
go build ./...,go vet ./...andgo test -count=1 ./...inproviders/app-studio: all pass.- The same three in
providers/infrastructure: build and vet pass for every package except the root one, andgo testpasses for every package except the root one. The root package,github.com/railgrid/provider-infrastructure, fails to set up withassets.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 withgo:embed all:portal/distreport 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) == "" { |
There was a problem hiding this comment.
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")
}There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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,
}})There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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")There was a problem hiding this comment.
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}` |
There was a problem hiding this comment.
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]>
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…credential Hand App Studio's pull credential to infrastructure through a verb
Problem
Promoting a project whose images are private finishes without a pull credential. No
<instance>-registrySecret exists, noimagePullSecretRefis set, the Instance still reportsReady=True, and authenticated requests return 502.ensureProjectRegistryPullSecretwrote the pull Secret labelledrailgrid.ai/owner: infrastructure. Since 7691b50 App Studio's Secret claim is scoped toowner: 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, theapplicationtemplate hadreadyWhenonly 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:
<prod-instance>-pull-credential, labelledapp-studio. If the project has a Connection and this fails, the promotion fails with the reason and names the connection.instances/{name}/image-pull-credentialas itself and sets the returned name as the Instance'sspec.imagePullSecretRef. It hands over again when the credential's digest changes or infrastructure reportsSecretsBridged=False/SecretRefNotFound. GitHub App tokens last about an hour, so it re-mints 15 minutes before expiry (RequeueAfterpacing an external clock).<instance>-image-pullunder its own label, owned by the Instance, and returns{secretRef: {name}}. Itssecretsclaim gainscreate/update, still scoped toowner: infrastructure. A tenant caller additionally needsupdateon the Instance; a foreign provider is authorized by its claim.outputs.imagePullCredential, and the portal shows it in place of the generic "being prepared" copy.SecretsBridged=Falseholds the Instance atReady=False, and the database, web, API and gate tiers of theapplicationtemplate declarereadyWhen(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
Rejecteduntil 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.Testing
go test ./...inproviders/infrastructureandproviders/app-studio. They cover the verb (foreign provider, tenantupdatecheck, 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'sreadyWhencompiled with cel-go. Plusnode --test src/publishingState.test.mjsandvue-tsc --noEmitin the App Studio portal.make lint-providers(infrastructure, app-studio),verify-provider-contract,verify-boilerplate,verify-design-docsandverify-ui-conformancepass.verify-portalkitfails locally on a.tsimport inprovider-sdk/portalkit/kube.tsunder Node 20, a file this PR does not touch.owner: infrastructureselector.dockerconfigjson, infra-labelled, owned by the Instance, with the expiry annotation. A second call updated it in place. Bad input returned 422invalid_input; no bearer returned 403.protected label railgrid.ai/owner must have value app-studio.applicationRGD with the newreadyWhen(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