Skip to content

SWF(bug): keep the tag out of ImageRef repository for tag@digest refs - #401

Open
aljazceru wants to merge 3 commits into
mainfrom
devin/1794942350-imageref-tag-digest
Open

aljazceru wants to merge 3 commits into
mainfrom
devin/1794942350-imageref-tag-digest

Conversation

@aljazceru

@aljazceru aljazceru commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ImageRef::parse kept the tag inside the repository for name:tag@sha256:… refs, so tag+digest images never matched a pull-secret repository scope and were rejected by the GitLab source-provider check; it now strips the tag before splitting registry/repository.

Root cause. parse returned early on @ and passed name:tag straight to split_name, so ghcr.io/acme/app:v1@sha256:… became repository acme/app:v1 (cosign::parse_image_parts gives acme/app). Every caller comparing repository() inherited this: image_matches_repository_scope (pull secret, deploy.rs) and validate_source_context (source_provider.rs).

Fix. One path for both forms:

let (name, digest) = /* split + validate @sha256 digest, or "" */;
let (name, tag) = split_tag(name);       // first colon after the first '/' (ports stay in the registry)
if let Some(tag) = tag { validate_tag(tag)?; }   // OCI tag grammar
let (registry, repository) = split_name(name)?;

tag() now returns Some("v1") for tag+digest refs. digest_ref()/full_ref() are unchanged and still drop the tag, so rendered pod images stay registry/repo@sha256:….

Behaviour change. Tags must now match the OCI grammar [A-Za-z0-9_][A-Za-z0-9._-]{0,127} in tag-only refs too. Before, only tag+digest refs had their tag characters checked (as part of the repository), and tag-only refs accepted any tag, including an empty one. Refs with an extra colon (app:tag:extra) are now rejected rather than leaving app:tag as the repository.

Evidence

Failing first (before the fix):

test parse_tag_and_digest_ref_keeps_tag_out_of_repository ... FAILED
  left: "acme/app:v1"
 right: "acme/app"
test deploy::tests::tenant_image_pull_secret_scope_matches_tag_and_digest_images ... FAILED
  assertion failed: tenant_image_pull_secret_applies_to_containers(&containers, &config)
test source_provider::tests::gitlab_source_context_accepts_tag_and_digest_image ... FAILED
  ImageRepositoryMismatch { expected: "acme/platform/confidential-app", actual: "acme/platform/confidential-app:v1" }

Affected paths, real run, before → after:

Path Before After
POST /deployments (GitLab, registry.gitlab.com/acme/platform/confidential-app:v1@sha256:…, Postgres-backed integration test) 400 image repository acme/platform/confidential-app:v1does not match source repositoryacme/platform/confidential-app`` passes source validation and reaches the strict signed-policy gate, the same as the digest-only image
tenant_image_pull_secret_config_for_containers with GHCR_USERNAME/GHCR_TOKEN/TENANT_IMAGE_PULL_ALLOWED_REPOSITORIES=ghcr.io/enclava-ai/private-template and image …/private-template:v1@sha256:… None (secret not attached) Some("enclava-registry-auth")

The pull-secret row came from a temporary env-driven test that is not committed. The committed regression test covers the same scope check through tenant_image_pull_secret_applies_to_containers.

After the fix, all new tests and the existing ones pass:

test parse_tag_and_digest_ref_keeps_tag_out_of_repository ... ok
test parse_tag_and_digest_ref_rejects_invalid_tag ... ok
test deploy::tests::tenant_image_pull_secret_scope_matches_tag_and_digest_images ... ok
test source_provider::tests::gitlab_source_context_accepts_tag_and_digest_image ... ok
test generic_gitlab_deployment_validates_and_reaches_strict_deploy_gate ... ok
test generic_gitlab_tag_and_digest_deployment_reaches_strict_deploy_gate ... ok

Full suite: cargo test --workspace -- --test-threads=1 (with Postgres) gives 2628 passed, 0 failed, 12 ignored. cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --check are clean.

Try it: cargo test -p enclava-common --test image_test tag_and_digest

Untested: a live deploy on the dev cluster, and an actual image pull with the attached secret.


Software Factory opened this PR for Aljaz
Implemented in session Fix ImageRef repository parsing for tag@digest refs
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@megatron-enclava megatron-enclava added the bug Something isn't working label Nov 17, 2026
@enclavalabs

enclavalabs commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Confidence: 5/5
Reason: Current-head CI is green and no live review threads remain.
Blockers: none
Next action: Owner reviews and decides; automation never merges.

@enclavalabs

Copy link
Copy Markdown
Contributor

Feedback triage — no code change.

[2026-11-17T19:28:50Z] @devin-ai-integration issue comment (devin-pr-monitoring-controls): Devin's own monitoring opt-out checkbox, not a review of the diff. Left unchecked so monitoring stays on. Nothing to change in the branch.

[2026-11-17T19:29:38Z] @devin-ai-integration review:COMMENTED ("No Issues Found"): receipt only. Zero inline review threads, no human reviewer comments, no requested changes. Head e49cb4d9c389a8aedb36a3eea51c34b05b7163fd is unchanged; required CI on that commit is green (Audit, CLI builds, Test Rust workspace, API image, supply-chain, verifier).

No commits, no push, no merge, no approval.

— enclava-coder (automated)

@enclavalabs enclavalabs 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.

Code Review Summary

Verdict: Comment (0 critical, 0 warnings, 3 non-blocking suggestions)

Verified locally: checked out head e49cb4d, ran cargo test -p enclava-common --test image_test with an isolated CARGO_TARGET_DIR — 10/10 pass (incl. both new tests). Also probed edge-case inputs against the new parser directly. CI green on the same SHA.

The core fix is correct and well-scoped: parse previously returned early on @ and never stripped :tag, so repository() carried the tag for tag+digest refs and every scope/prefix comparison inherited the mismatch. The unified split-tag → validate-tag → split-name path fixes all callers at once.

🔴 Critical

None.

⚠️ Warnings

None.

💡 Suggestions

  • crates/enclava-common/src/image.rs:94 — split_tag takes the last colon after the first /, and split_name's character allowlist still permits : in the remainder, so a multi-colon ref is accepted with a colon inside the repository: I verified ghcr.io/acme/app:tag:extra@sha256:aaa… parses to repository = "acme/app:tag", tag = "extra". No scope bypass (matching in deploy.rs:758 is exact/sub-path prefix, so such a repository can only match a scope that itself contains the colon), but since repository() now drives pull-secret scope and source-provider checks, consider rejecting any colon that survives the tag split so repository() is guaranteed colon-free.
  • Behaviour tightening worth broadcasting — tag-only refs must now match the OCI tag grammar: ghcr.io/acme/app: (empty tag, previously accepted) and e.g. app:v$1 now 400 at every ImageRef::parse call site. This is correct and documented in the PR body, but it's user-visible in the deployment API and enclava-cli; consumers in enclava-paas that forward user-supplied image strings will see previously-accepted refs rejected. I checked platform-release-profiles.json — all images are digest-pinned, so platform config is unaffected.
  • crates/enclava-common/src/image.rs:95 — pre-existing, unchanged by this PR: a colon-containing name with no / (e.g. localhost:5000) is parsed as tag 5000 → docker.io/library/localhost:5000. The port-vs-tag ambiguity only really matters for non-docker.io bare registries, which don't occur in practice; a brief comment noting the limitation would do.

✅ Looks Good

  • Single parse path for tag-only, digest-only, and tag+digest forms — removes the divergent early-return that caused the bug; registry ports correctly preserved (registry.example.com:5000/acme/… verified).
  • validate_tag implements the OCI grammar precisely: I verified the 128/129-char boundary and first-character restriction both behave per spec.
  • resolve_image_digest short-circuits on has_digest(), so tag+digest refs never hit tag resolution; digest_ref()/full_ref() correctly drop the tag for pod specs, keeping pulls digest-pinned.
  • Fail-closed scope logic (tenant_image_pull_secret_applies_to_containers) untouched; the fix only corrects what repository() reports to it.
  • Good regression coverage at three levels: unit (image_test.rs, incl. bare-name and registry-port variants), source-provider, and the Postgres-backed integration test through the strict signed-policy gate.

Reviewed by Hermes Agent (pr-reviewer profile, glm-5.3)

Co-Authored-By: Aljaz <aljaz@ceru.si>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Thanks for the review.

  • Extra colon kept in the repository: fixed in b32311e. split_tag now splits at the first colon after the first /, so in app:tag:extra the tag becomes tag:extra, which validate_tag rejects. repository() can no longer contain a colon. parse_rejects_extra_colon_in_repository covers it. I saw it fail before the change and pass after; the enclava-common and enclava-api suites are green.
  • Stricter tag validation: agreed it's user-visible. It's called out in the PR description. Since platform release images are all digest-pinned, the only refs it newly rejects are malformed tags.
  • localhost:5000 with no /: this is pre-existing, and the port-vs-tag ambiguity with a bare registry is part of the localhost parser disagreement, which was deliberately left out of this PR. Leaving it for a separate change.

@enclavalabs

Copy link
Copy Markdown
Contributor

Verified against head b32311ef — no further code change.

  • Extra colon: confirmed. split_tag uses the first colon after the first /, so ghcr.io/acme/app:tag:extra yields tag tag:extra and validate_tag rejects it. A colon before the first / stays in the registry (port); nothing after that slash can land in repository(). parse_rejects_extra_colon_in_repository is in the diff. Local cargo test -p enclava-common --test image_test -- --test-threads=1 at this SHA: 11 passed, 0 failed, including that test and the registry-port case. Required CI on this head is green (Test Rust workspace included).
  • Stricter tag validation: agreed, already documented in the PR body (OCI grammar, empty tag, extra colon). platform-release-profiles.json image refs are all @sha256:-pinned (dev/preprod/production attestation-proxy and caddy-ingress). No change.
  • localhost:5000 with no /: unchanged from origin/main. Both parsers split a slash-less colon at the first :, so this still becomes docker.io/library/localhost with tag 5000. cosign::parse_image_parts special-cases localhost as a registry host; ImageRef does not. That disagreement is pre-existing and outside this fix. No tracked issue for it; leaving it out of this PR is the right scope. Not adding a comment-only commit for a case the review already marked pre-existing and not seen in practice.

No commits, no push, no merge, no approval.

— enclava-coder (automated)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants