Skip to content

fix(crafter): surface DNS-1123 validation errors instead of masking them#2983

Open
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
waveywaves:fix/dns1123-error-masking
Open

fix(crafter): surface DNS-1123 validation errors instead of masking them#2983
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
waveywaves:fix/dns1123-error-masking

Conversation

@waveywaves
Copy link
Copy Markdown
Contributor

Summary

  • Fix variable shadowing in AddMaterialContactFreeWithAutoDetectedKind: the m, err := inside the for loop created a new err that never propagated to the outer scope, so the final fallthrough error was always nil
  • Add DNS-1123 name validation at the top of AddMaterialContractFree using a regex check matching the same rule as the proto CEL constraint, returning a clear error message immediately instead of letting invalid names flow through the auto-discovery loop
  • Detect protovalidate.ValidationError in the auto-discovery loop and break early, since schema-level validation failures (like invalid names) are not kind mismatches and should not be retried across all material types

Fixes #2394

Test plan

  • Added test case non-dns-1123 name surfaces clear error (name with underscores and dots)
  • Added test case uppercase name surfaces dns-1123 error (uppercase letters)
  • All existing TestAddMaterialsAutomatic tests continue to pass (12/12)
  • Full go test ./pkg/attestation/crafter/... passes
  • go vet ./pkg/attestation/crafter/... passes
  • Verify manually with chainloop att add --value <file> --name My_Invalid.Name that a clear error is shown

🤖 Generated with Claude Code

@waveywaves waveywaves force-pushed the fix/dns1123-error-masking branch from 9241f71 to 2c1b24b Compare April 3, 2026 11:26
@javirln
Copy link
Copy Markdown
Member

javirln commented Apr 7, 2026

@waveywaves is this ready to be reviewed?

@waveywaves waveywaves force-pushed the fix/dns1123-error-masking branch from 2c1b24b to 7fb43ea Compare April 7, 2026 08:16
@waveywaves waveywaves marked this pull request as ready for review April 7, 2026 08:16
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/attestation/crafter/crafter.go">

<violation number="1" location="pkg/attestation/crafter/crafter.go:670">
P2: DNS-1123 invalid-name errors are generic errors and are not treated as terminal in auto-detect, so they are retried and wrapped by the generic auto-discovery failure instead of being surfaced immediately.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread pkg/attestation/crafter/crafter.go
@waveywaves waveywaves force-pushed the fix/dns1123-error-masking branch from 7fb43ea to a1b71af Compare April 8, 2026 10:20
@waveywaves
Copy link
Copy Markdown
Contributor Author

@jiparis Ready for review — all commits GPG-signed and rebased on main. This fixes a variable shadowing bug that silently masks DNS-1123 validation errors in AddMaterialContractFree (issue #2394).

@waveywaves
Copy link
Copy Markdown
Contributor Author

@javirln Yes, this is ready for review! All commits are GPG-signed and rebased on latest main. Sorry for the delayed reply.

@waveywaves
Copy link
Copy Markdown
Contributor Author

@migmartri Would you be able to take a look at this one? It fixes a variable shadowing bug where DNS-1123 validation errors get silently masked in AddMaterialContractFree (issue #2394). All commits GPG-signed, CI green, cubic-dev-ai's finding already addressed. Happy to answer any questions!

)
for _, kind := range schemaapi.CraftingMaterialInValidationOrder {
m, err := c.AddMaterialContractFree(ctx, attestationID, kind.String(), name, value, casBackend, runtimeAnnotations)
m, err = c.AddMaterialContractFree(ctx, attestationID, kind.String(), name, value, casBackend, runtimeAnnotations)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the actual fix that solves #2394. err was being override in the in the loop scope, making it always nil outside it.

@jiparis
Copy link
Copy Markdown
Member

jiparis commented Apr 27, 2026

Thanks @waveywaves . Check my comment for the actual fix. #2394 is not about DNS names, but just surfacing the error as you did in that line. Please check.

@waveywaves waveywaves force-pushed the fix/dns1123-error-masking branch from a1b71af to 0e8c50d Compare April 29, 2026 13:06
@waveywaves
Copy link
Copy Markdown
Contributor Author

Thanks @jiparis — you're right, the DNS-1123 regex was out of scope. Stripped the PR back to just the two relevant changes:

  1. Variable shadowing fix: m, err :=m, err = so the error propagates out of the loop
  2. protovalidate.ValidationError early break so schema-level failures aren't masked by the kind-probing loop

All the unrelated changes (gracefulGitRepoHead refactor, policyEvalMatches removal, RunCollectors optimization) are gone. One file, 13 insertions, 7 deletions.

Fix variable shadowing in AddMaterialContactFreeWithAutoDetectedKind:
m, err := (loop-scoped) → m, err = (outer-scoped) so the error from
the last failed kind probe is propagated to the caller instead of
always being nil.

Also break early on protovalidate.ValidationError during auto-discovery
so schema-level failures (e.g. invalid material name) are surfaced
immediately instead of being masked by the kind-probing loop.

Fixes: chainloop-dev#2394

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
@waveywaves waveywaves force-pushed the fix/dns1123-error-masking branch from 0e8c50d to 6d1a3bb Compare April 29, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Material type auto-discovery hides material name not being dns-1123 compliant

3 participants