add caib image token command for internal registry builds#177
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds a new Changes
Sequence DiagramsequenceDiagram
actor User
participant CLI as caib image token
participant Handler as Token Handler
participant Client as Build API Client
participant Server as API Server
participant TokenSvc as Token Minting Service
User->>CLI: run `caib image token <build>`
CLI->>Handler: RunToken(cmd,args)
Handler->>Handler: validate ServerURL, token, TLS
Handler->>Client: CreateBuildToken(ctx, build)
Client->>Server: POST /v1/builds/{name}/token
Server->>Server: fetch ImageBuild & resolve requester
Server->>Server: verify ownership, build phase, service-account auth, internal image
Server->>TokenSvc: mintRegistryToken(...)
TokenSvc-->>Server: token + expiresAt
Server-->>Client: 200 TokenResponse (registry, username, token, expiresAt, image)
Client-->>Handler: TokenResponse
Handler->>User: print credentials and `podman login` command
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/caib/tokencmd/token.go`:
- Around line 76-78: Replace the insecure podman login examples that print the
token with the password-in-stdin pattern: change the fmt.Println/fmt.Printf
block that currently prints "To authenticate:" and the line using "-p %s"
(referencing tok.Registry, tok.Username, tok.Token) to instead instruct piping
the token via echo and using "--password-stdin" (e.g., echo <token> | podman
login <registry> -u <username> --password-stdin); likewise update the
help/example text in the image command's help block (the podman login example in
the image.go help example) to show the same echo | podman login ...
--password-stdin pattern so tokens are not exposed on the command line.
In `@internal/buildapi/server.go`:
- Around line 678-683: The token minting in getBuild is bypassing the ownership
check performed in handleCreateBuildToken, allowing any authenticated caller of
getBuild to receive a RegistryToken; fix by enforcing the same requester vs
owner check (compare
build.Annotations["automotive.sdv.cloud.redhat.com/requested-by"] to
a.resolveRequester(c)) before minting or returning a RegistryToken inside
getBuild, or alternatively remove RegistryToken creation from getBuild and
centralize token issuance inside handleCreateBuildToken after the existing
ownership check; update getBuild (or relocate RegistryToken logic) so only the
owner can obtain tokens.
- Around line 686-719: Move the imageRef resolution (using
build.Spec.GetExportOCI() / GetContainerPush()) above the mintRegistryToken call
and change the eligibility check: only call a.mintRegistryToken when
build.Status.Phase == phaseCompleted (remove phaseFailed) AND the build actually
has an internal-registry artifact — enforce either
build.Spec.GetBuildDiskImage() == true OR the resolved imageRef points to an
internal-registry image. Replace the current GetUseServiceAccountAuth() gate
with this composite guard (use GetUseServiceAccountAuth() as a prerequisite if
you want, but do not rely on it alone), and keep mintRegistryToken,
GetExportOCI/GetContainerPush, GetBuildDiskImage, and build.Status.Phase as the
referenced symbols to locate the change.
- Around line 696-729: mintRegistryToken currently returns only the token and
the handler computes a hardcoded 4-hour expiry; change mintRegistryToken to
return (string, metav1.Time, error) and have it capture and return
tokenResp.Status.ExpirationTimestamp (the real expiry from the Kubernetes
TokenRequest API). Update the caller in server.go (the mintRegistryToken(...)
call and its error branch) to accept the new metav1.Time value, format it with
time.RFC3339 (handling zero/empty timestamps safely) and set
TokenResponse.ExpiresAt to that formatted value instead of computing expSeconds;
ensure any other call sites of mintRegistryToken are updated to the new
signature and error handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d2ed9400-6d87-4e49-975c-6ce7027512c3
📒 Files selected for processing (6)
cmd/caib/image/image.gocmd/caib/runtime_wiring.gocmd/caib/tokencmd/token.gointernal/buildapi/client/client.gointernal/buildapi/server.gointernal/buildapi/types.go
Allow users to request a fresh 4-hour registry token for completed builds that used --internal-registry. The token can be used with podman, skopeo, or any OCI tool to pull images externally. The endpoint verifies build ownership before minting a token. Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-opus-4.6
3b50576 to
4b88172
Compare
Allow users to request a fresh 4-hour registry token for completed builds that used --internal-registry
Summary by CodeRabbit
New Features
caib image tokensubcommand to request short-lived registry credentials for builds; supports--serverand--token.podman logincommand.Behavior Changes