Skip to content

feat(attest): accept YAML for attest custom --attestation-data - #1431

Merged
dangrondahl merged 6 commits into
mainfrom
attest-custom-yaml
Dec 1, 2026
Merged

dangrondahl merged 6 commits into
mainfrom
attest-custom-yaml

Conversation

@dangrondahl

@dangrondahl dangrondahl commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

kosli attest custom --attestation-data now accepts YAML. Users who attest a
Backstage catalog-info.yaml (and later Kubernetes manifests) no longer need
yq ea -o=json '[.]' file.yaml first. The server contract is unchanged: the CLI
converts to JSON and sends what it sends today.

 attest custom
-  LoadJsonData(file)
+  LoadAttestationData(file, asList)        # cmd/kosli/cli_utils.go
+    .yaml / .yml -> utils.YAMLDocuments    # internal/utils/yaml.go
+    anything else -> LoadJsonData          # unchanged, one document
+    asList        -> JSON list, one item per document
+    otherwise     -> exactly one document, or an error naming the flag
   submit

New flag --attestation-data-as-list sends the documents of the file as a
root-level JSON list. Empty and null documents are dropped first, since
helm template output is full of them.

Scalar conversion

YAML JSON
d: 2026-12-01 "2026-12-01"
t: 2026-12-01T10:00:00Z "2026-12-01T10:00:00Z"
v: 1.10 1.1
v: "1.10" "1.10"
c: NO, e: yes, on, off strings, as written
b: true true
n: ~ null
i: 12345678901234567890 12345678901234567890
o: 0123 83
  • 0123 is octal, the way Kubernetes reads defaultMode: 0644. The flag help
    says so and tells users to quote version-like values and codes.
  • Decimal integers beyond 64 bits, .inf and .nan are errors that give the
    line. They are never sent as a rounded float. So is a leading-zero number
    that is not octal, such as 089: the error says to quote it.
  • Hex, octal and binary integers beyond 64 bits, and floats beyond float64
    such as 1e400, are sent as strings exactly as written.
  • Aliases and merge keys resolve. Duplicate keys and non-scalar keys are
    errors. Scalar keys become strings as written.

Why not a separate --attestation-data-yaml flag?

The flag names the data, not its encoding: the server still receives one JSON
value. A flag per format would mean mutual-exclusion rules here and a matching
--schema-yaml on create attestation-type, which gets YAML next and will
reuse utils.YAMLDocuments. Picking the format by extension keeps one required
flag, makes a future format one branch in the loader, and leaves every existing
invocation on the unchanged JSON path.

The cost is that YAML cannot be read from stdin or an extension-less file. If
that is needed, an optional format override can be added without breaking
anything.

JSON content in a file named .yaml keeps working, because JSON parses as
YAML. The only inputs that now fail are ones the JSON path was silently
changing: duplicate keys (last one used to win) and decimal integers beyond
64 bits (used to be rounded).

Not in this PR: the JSON path still rounds integers above 2^53. See #1430.

Evidence

  • Before: a YAML file is rejected with does not contain a valid JSON.
    After: --dry-run on the four-document Backstage fixture with
    --attestation-data-as-list prints attestation_data as a root-level list
    of the four entities in file order. Without the flag:
    contains 4 YAML documents. Use --attestation-data-as-list to send them as a list.
  • A real attestation of the fixture to app.kosli.com, read back with
    kosli get attestation -o json, equals
    testdata/backstage-catalog-info.expected.json.
  • go test ./internal/utils/ -run YAML and
    go test ./cmd/kosli/ -run 'TestLoadAttestationData|EmptyFlagAudit' pass.
    make lint reports 0 issues.
  • Not yet run locally: the six new cases in AttestCustomCommandTestSuite,
    which need the local server. CI runs them.

Merge Danger

Door: two-way until released, then one-way.

The flag name and the scalar table become a contract once customers and
published policies rely on them.

Blast Radius: narrow

Only attest custom changes. LoadJsonData is untouched, so --user-data on
other commands behaves as before. Files not ending in .yaml or .yml take
the existing path.

Checklist

  • Docs are autogenerated from CLI help — make sure the help text reflects your changes
  • Helm chart (charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PR
  • Terraform provider and related changes (terraform-provider-kosli, terraform-aws-kosli-reporter) updated, if needed

YAMLDocuments reads a YAML stream the way the YAML 1.2 core schema does:
dates and timestamps stay strings as written, scalar keys become strings,
and values JSON cannot carry exactly are errors.
A .yaml or .yml file is converted to JSON before it is sent, so the server
contract is unchanged. Any other extension takes the existing JSON path.
The flag sends the documents of the file as a JSON list, one item per
document, so a multi-document YAML file such as a Backstage catalog can be
attested as is. Without it, several documents is an error naming the flag.
The --attestation-data help says how the format is picked and that a
leading-zero YAML number is octal, and the examples show a multi-document
file sent with --attestation-data-as-list.
@github-actions github-actions Bot added go Pull requests that update go code feat labels Dec 1, 2026
@claude

claude Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dangrondahl's task in 1m 47s —— View job


Follow-up review complete

  • Fetch previous review comments
  • Diff BEFORE (3abe1d68)..AFTER (25fb2e61) to scope review
  • Check status of each previous finding
  • Flag any new bugs/regressions in changed lines
  • Post summary comment

Scope: the new commit (25fb2e61) only touches cmd/kosli/attestCustom_test.go (5 lines), reordering the explicit --attestation-data <file> flag to come after suite.defaultKosliArguments in 5 test cases. No production code changed.

Previous findings status:

  • internal/utils/yaml.go:122 (leading-zero error message) — resolved, already fixed in 3abe1d68 prior to this diff. Thread confirmed resolved; 089/-01890 test cases present.
  • internal/utils/yaml.go:157 (anchored timestamp/aliased key) — resolved, already fixed in 3abe1d68 prior to this diff. Thread confirmed resolved; anchored-key test cases present.

Both review threads were already marked resolved; I added a short confirmation reply to each pointing at the fix commit and tests.

New commit: no bugs or regressions. The reorder is itself a correctness fix for the test file — without it, the suite's default JSON fixture would silently win over the YAML fixture (pflag's last-occurrence-wins behavior), undermining the YAML test cases added earlier in the PR.

Full summary posted as a separate PR comment.

Comment thread internal/utils/yaml.go Resolved
Comment thread internal/utils/yaml.go Resolved
A number such as 089 was rejected as not fitting in 64 bits; it now says it
has a leading zero and is not octal. An anchored mapping key used as a value
through an alias now gets the same treatment as any other scalar, so a date
stays as written.
…n data

The suite's default arguments already set --attestation-data and came last,
so the new cases ran against the JSON file.
@claude

claude Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review: commit 25fb2e61 (after 3abe1d68)

Scope: git diff 3abe1d68..25fb2e61 touches only cmd/kosli/attestCustom_test.go (5 lines changed) — reorders the explicit --attestation-data <file> flag to come after suite.defaultKosliArguments in 5 test cases, so it overrides the suite's default --attestation-data flag instead of being silently overridden by it. No production code changed.

Previous findings:

  1. internal/utils/yaml.go:122 — leading-zero error message — resolved (already fixed in 3abe1d68, before this diff; thread marked resolved, test cases for 089/-01890 present in yaml_test.go).
  2. internal/utils/yaml.go:157 — anchored timestamp/aliased key edge case — resolved (already fixed in 3abe1d68, before this diff; thread marked resolved, test cases for anchored date/invalid-float keys present in yaml_test.go).

Neither location was touched by the new commit, so there's nothing further to re-check there.

New commit review: no bugs or regressions found in the changed lines — the reorder is a correctness fix for the tests themselves (without it, the suite's default JSON fixture would silently win over the YAML fixture due to flag-value-last-wins parsing, undermining the new YAML test cases added earlier in this PR).

0 new inline comments.

@dangrondahl
dangrondahl merged commit 76eb495 into main Dec 1, 2026
23 checks passed
@dangrondahl
dangrondahl deleted the attest-custom-yaml branch December 1, 2026 12:17
dangrondahl pushed a commit to kosli-dev/docs that referenced this pull request Dec 2, 2026
Explains that `kosli attest custom --attestation-data` now takes YAML as
well as JSON, including multi-document files and the quoting caveats.
GA: shipped in CLI v2.61.1.

Based on [feat(attest): accept YAML for attest custom
--attestation-data](kosli-dev/cli#1431).

### Upstream (does not block this merge)
- `kosli-dev/cli` → `cmd/kosli/attestCustom.go`: the
`--attestation-data` flag help names only octal as the reason to quote
`"1.10"`; it should also say decimals lose trailing zeros (`1.10`
becomes `1.1`).

---------

Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants