1
0
mirror of synced 2026-10-24 12:59:22 +03:00

94 Commits

Author SHA1 Message Date
Carlos Tadeu Panato Junior
f8e6ea940d Add cosign-specific user-agent to all HTTP requests (#4705)
* Add cosign-specific user-agent to all HTTP requests

This change addresses issue #4692 by ensuring that all HTTP requests
made by cosign identify with a proper user-agent that includes both
the cosign version and sigstore-go version.

Signed-off-by: Carlos Panato <ctadeu@gmail.com>

* Scope sigstore-go user-agent to sigstore-go code paths

Keep the global user-agent as cosign/<version> (os; arch) and only
send cosign/<version> sigstore-go/<version> (os; arch) on requests
made through sigstore-go. Fulcio and TSA clients built in SignData
now use a transport that overrides sigstore-go's default user-agent.

Rekor requests made via sigstore-go still use sigstore-go's
user-agent until sigstore-go exposes a way to set it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Carlos Panato <ctadeu@gmail.com>

* Set cosign user-agent on sigstore-go Fulcio, TSA and Rekor clients

Bump sigstore-go to main to pick up sigstore/sigstore-go#686, which
adds a UserAgent option and always appends sigstore-go/<version>.
Pass cosign's user-agent through it and drop the transport wrapper
and the sigstore-go version lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Carlos Panato <ctadeu@gmail.com>

---------

Signed-off-by: Carlos Panato <ctadeu@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:37:45 -07:00
Pujitha Paladugu
ff2a8f4ea2 fix(sign): pass digest hash algorithm to underlying signer in SignData
Fixes #5018

Motivation

Signing with a HashiCorp Vault Transit KMS ECDSA P-521 key fails with
"signing digest: signing bundle: error signing bundle: unexpected
length of digest for hash function specified". This is a regression
in the bundle-signing path introduced when SignerVerifierKeypair was
added: it correctly computes the digest using the key's own default
hash algorithm (SHA-512 for P-521), but never told the underlying
signer.SignMessage which hash algorithm that digest was produced with.

KMS-backed SignerVerifiers created via
pkg/signature/keys.go:SignerVerifierFromKeyRef are constructed with a
hardcoded crypto.SHA256 default (unrelated to the actual key's curve),
so sigstore-go's ComputeDigestForSigning fell back to that default,
saw a 64-byte digest against an expected 32-byte SHA-256 digest, and
rejected it with the mismatch error above.

Approach

internal/key/svkeypair.go: SignerVerifierKeypair.SignData now also
passes signatureoptions.WithCryptoSignerOpts(hashType) alongside
WithDigest(digest), so the signer is told exactly which hash algorithm
produced the digest, regardless of what hash it was constructed with
by default. This affects every SignerVerifier-backed signing path (any
KMS provider, not just Vault) whenever the key's natural hash isn't
SHA-256 (e.g. P-384/P-521 ECDSA, larger RSA keys). For keys whose
natural hash is already SHA-256 (e.g. default P-256), this is a no-op:
the newly-passed option matches the signer's existing default.

Validation

go build ./...
go test ./internal/key/... ./pkg/signature/... ./pkg/cosign/bundle/... -count=1
  ok  	github.com/sigstore/cosign/v3/internal/key
  ok  	github.com/sigstore/cosign/v3/pkg/signature
  ok  	github.com/sigstore/cosign/v3/pkg/cosign/bundle

Added TestKMSKeypair_ECDSA_P521_SignData, which reproduces the digest
length/hash mismatch reported in the issue (verified it fails without
this fix with "expected underlying signer to be given crypto.SHA512
opts matching the digest, got <nil>", and passes with it). This was
verified with a unit test against a mock SignerVerifier reproducing
the KMS signer's option-handling behavior; it was not validated
against a live HashiCorp Vault instance.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
2026-10-01 11:05:45 -07:00
Arpit Jain
b84a076464 Cap the bundle layer read in ociremote.Bundle
Bundle() decompressed the new-bundle-format attestation layer and read all of
it into memory with no size check, while every other layer read in pkg/oci
calls payloadsize.CheckSize first. A registry the user does not control could
make cosign verify-attestation --new-bundle-format allocate without bound from
a small compressed layer.

The size a registry declares is the compressed size, and this is the only one
of these reads that goes through Uncompressed(), so checking that size is
necessary but not sufficient. This does both: the declared size is checked
first so an oversized layer is rejected before anything is read, and the
decompressed stream is then bounded by the same limit.

GetBundles calls Bundle() for every manifest in a referrers index and swallows
the error with continue, since non-Sigstore referrers are expected there, so
without the second check each oversized layer in an index was read in full
before its error was reached.

MaxSize is exported from the payload size package because a caller reading a
decompressed stream needs the limit itself rather than a yes or no answer
about a size it already knows.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
2026-09-14 13:10:15 -07:00
dependabot[bot]
633e8f4303 chore(deps): bump the gomod group across 1 directory with 17 updates (#5104)
* chore(deps): bump the gomod group across 1 directory with 17 updates

Bumps the gomod group with 7 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [cuelang.org/go](https://github.com/cue-lang/cue) | `0.17.0` | `0.17.1` |
| [github.com/go-jose/go-jose/v4](https://github.com/go-jose/go-jose) | `4.1.4` | `4.1.5` |
| [github.com/go-openapi/runtime](https://github.com/go-openapi/runtime) | `0.33.0` | `0.33.2` |
| [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) | `1.20.1` | `1.20.2` |
| [github.com/secure-systems-lab/go-securesystemslib](https://github.com/secure-systems-lab/go-securesystemslib) | `0.11.0` | `0.11.1` |
| [github.com/sigstore/protobuf-specs](https://github.com/sigstore/protobuf-specs) | `0.5.1` | `0.5.2` |
| [github.com/sigstore/rekor](https://github.com/sigstore/rekor) | `1.5.3` | `1.5.4` |



Updates `cuelang.org/go` from 0.17.0 to 0.17.1
- [Release notes](https://github.com/cue-lang/cue/releases)
- [Commits](https://github.com/cue-lang/cue/compare/v0.17.0...v0.17.1)

Updates `github.com/go-jose/go-jose/v4` from 4.1.4 to 4.1.5
- [Release notes](https://github.com/go-jose/go-jose/releases)
- [Commits](https://github.com/go-jose/go-jose/compare/v4.1.4...v4.1.5)

Updates `github.com/go-openapi/runtime` from 0.33.0 to 0.33.2
- [Release notes](https://github.com/go-openapi/runtime/releases)
- [Commits](https://github.com/go-openapi/runtime/compare/v0.33.0...v0.33.2)

Updates `github.com/go-openapi/strfmt` from 0.27.0 to 0.27.1
- [Release notes](https://github.com/go-openapi/strfmt/releases)
- [Commits](https://github.com/go-openapi/strfmt/compare/v0.27.0...v0.27.1)

Updates `github.com/go-openapi/swag/conv` from 0.27.3 to 0.29.1
- [Release notes](https://github.com/go-openapi/swag/releases)
- [Commits](https://github.com/go-openapi/swag/compare/v0.27.3...v0.29.1)

Updates `github.com/open-policy-agent/opa` from 1.20.1 to 1.20.2
- [Release notes](https://github.com/open-policy-agent/opa/releases)
- [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-policy-agent/opa/compare/v1.20.1...v1.20.2)

Updates `github.com/secure-systems-lab/go-securesystemslib` from 0.11.0 to 0.11.1
- [Release notes](https://github.com/secure-systems-lab/go-securesystemslib/releases)
- [Commits](https://github.com/secure-systems-lab/go-securesystemslib/compare/v0.11.0...v0.11.1)

Updates `github.com/sigstore/protobuf-specs` from 0.5.1 to 0.5.2
- [Changelog](https://github.com/sigstore/protobuf-specs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/protobuf-specs/compare/v0.5.1...v0.5.2)

Updates `github.com/sigstore/rekor` from 1.5.3 to 1.5.4
- [Release notes](https://github.com/sigstore/rekor/releases)
- [Changelog](https://github.com/sigstore/rekor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/rekor/compare/v1.5.3...v1.5.4)

Updates `github.com/sigstore/sigstore` from 1.10.8 to 1.10.9
- [Release notes](https://github.com/sigstore/sigstore/releases)
- [Commits](https://github.com/sigstore/sigstore/compare/v1.10.8...v1.10.9)

Updates `github.com/sigstore/sigstore/pkg/signature/kms/aws` from 1.10.8 to 1.10.9
- [Release notes](https://github.com/sigstore/sigstore/releases)
- [Commits](https://github.com/sigstore/sigstore/compare/v1.10.8...v1.10.9)

Updates `github.com/sigstore/sigstore/pkg/signature/kms/azure` from 1.10.8 to 1.10.9
- [Release notes](https://github.com/sigstore/sigstore/releases)
- [Commits](https://github.com/sigstore/sigstore/compare/v1.10.8...v1.10.9)

Updates `github.com/sigstore/sigstore/pkg/signature/kms/gcp` from 1.10.8 to 1.10.9
- [Release notes](https://github.com/sigstore/sigstore/releases)
- [Commits](https://github.com/sigstore/sigstore/compare/v1.10.8...v1.10.9)

Updates `github.com/sigstore/sigstore/pkg/signature/kms/hashivault` from 1.10.8 to 1.10.9
- [Release notes](https://github.com/sigstore/sigstore/releases)
- [Commits](https://github.com/sigstore/sigstore/compare/v1.10.8...v1.10.9)

Updates `github.com/stretchr/testify` from 1.11.1 to 1.12.1
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.11.1...v1.12.1)

Updates `google.golang.org/api` from 0.284.0 to 0.290.0
- [Release notes](https://github.com/googleapis/google-api-go-client/releases)
- [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md)
- [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.284.0...v0.290.0)

Updates `google.golang.org/protobuf` from 1.36.12-0.20260120151049-f2248ac996af to 1.36.12

---
updated-dependencies:
- dependency-name: cuelang.org/go
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/go-jose/go-jose/v4
  dependency-version: 4.1.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/go-openapi/runtime
  dependency-version: 0.33.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/go-openapi/strfmt
  dependency-version: 0.27.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/go-openapi/swag/conv
  dependency-version: 0.29.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gomod
- dependency-name: github.com/open-policy-agent/opa
  dependency-version: 1.20.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/secure-systems-lab/go-securesystemslib
  dependency-version: 0.11.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/protobuf-specs
  dependency-version: 0.5.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/rekor
  dependency-version: 1.5.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/sigstore
  dependency-version: 1.10.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/sigstore/pkg/signature/kms/aws
  dependency-version: 1.10.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/sigstore/pkg/signature/kms/azure
  dependency-version: 1.10.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/sigstore/pkg/signature/kms/gcp
  dependency-version: 1.10.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/sigstore/sigstore/pkg/signature/kms/hashivault
  dependency-version: 1.10.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
- dependency-name: github.com/stretchr/testify
  dependency-version: 1.12.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gomod
- dependency-name: google.golang.org/api
  dependency-version: 0.290.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gomod
- dependency-name: google.golang.org/protobuf
  dependency-version: 1.36.12
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gomod
...

Signed-off-by: dependabot[bot] <support@github.com>

* update mock interface

Signed-off-by: Bob Callaway <bcallaway@google.com>

* fix linter errors

Signed-off-by: Bob Callaway <bcallaway@google.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Bob Callaway <bcallaway@google.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bob Callaway <bcallaway@google.com>
2026-09-08 15:36:42 -04:00
Aaron Lew
d39ab7c812 Align privacy statement prompt behavior (#5076)
* fix: evaluate tlog upload for all signers

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* refactor: extract privacy statement logic from ShouldUploadToTlog

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* refactor: generalize public good URL detection for Rekor and Fulcio

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* fix: only show privacy statement for public Sigstore services

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* refactor: rename shouldUpload to uploadToTlog

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

---------

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-09-08 15:25:10 -04:00
dependabot[bot]
b918f9d67c chore(deps): bump the all group across 1 directory with 2 updates (#5067)
* chore(deps): bump the all group across 1 directory with 2 updates

Bumps the all group with 2 updates in the / directory: golang and golangci/golangci-lint.


Updates `golang` from 1.26.5 to 1.27.0

Updates `golangci/golangci-lint` from v2.12.2 to v2.13.1

---
updated-dependencies:
- dependency-name: golang
  dependency-version: 1.27.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: golangci/golangci-lint
  dependency-version: v2.13.1
  dependency-type: direct:production
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>

* address lints

Signed-off-by: Bob Callaway <bcallaway@google.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Bob Callaway <bcallaway@google.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bob Callaway <bcallaway@google.com>
2026-09-08 13:33:49 +00:00
Aaron Lew
0fc9811059 Remove unused signing code (#4918)
* Remove unused signcommon code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused Rekor code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused Fulcio code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused tlog code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused attestation code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused bundle code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused TSA code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Replace legacy signers with static.NewSignature in verify test

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Replace tsa.GetTimestampedSignature with new helpers in verify tests

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused signer wrapper implementations

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Replace tsa.SplitPEMCertificateChain with existing helper in verify test

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused exported SplitPEMCertificateChain TSA util

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Replace bundle.MakeProtobufBundle with proto in verify_blob_* tests

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Move BundleV03MediaType constant to new constants file

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Remove unused protobundle code

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Update go.mod and go.sum

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

---------

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-06-12 07:57:20 -04:00
Aaron Lew
b1dd2e9524 Remove unused ephemeral signer (#4938)
Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-06-12 07:55:46 -04:00
Aaron Lew
9146e3fdb3 Fix Ed25519ph check to respect custom signing configs in sign-blob (#4880)
* Fix Ed25519ph check to respect custom signing configs in sign-blob

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Add Ed25519 signing test cases for sign-blob

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Add unit tests for KMSKeypair Ed25519 methods

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Fix panic on Ed25519 signing without pre-hashing

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

* Add test case for HashReader with unspecified hash algorithm

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>

---------

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-05-26 08:09:28 -07:00
Aaron Lew
1d5c7a6d34 Sign exclusively via sigstore-go (#4618)
This change refactors the signing path in all signing and attestation commands such that all signing events occur via sigstore-go, not just those in which a signing config is used.

Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-04-13 16:50:12 -07:00
Carlos Tadeu Panato Junior
8f1cd80ef8 update golangci-lint to v2.8.x (#4688) 2026-02-17 08:37:11 +01:00
Aaron Lew
934afc49e4 Add mTLS support for TSA client connections when signing with a signing config (#4620)
Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
2026-01-26 15:13:04 -08:00
Hayden
38bf9e6a99 Bump sigstore library dependencies (#4532)
Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-12-02 08:39:21 +01:00
Hayden
8e3a787545 Bump module version to v3 for Cosign v3.0 (#4427)
Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
Co-authored-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-09-26 13:31:26 -07:00
Hayden
b1acaeb92c Add a terminal spinner while signing with sigstore-go (#4402)
Recording signatures to Rekor v2 can take up to 10 seconds. We want to
avoid someone killing the process while waiting for a response from
Rekor, otherwise the user will have to re-sign the artifact.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-09-12 09:33:44 -07:00
Hayden
11163ae7d8 Bump sigstore-go, support alternative hash algorithms with keys (#4386)
* Bump sigstore-go, support alternative hash algorithms with keys

sigstore-go now handles non-ECDSA-P-256 signatures with Rekor v2. To
support verification, we also need a way to provide alternative hash
algorithms to the default SHA-256. cosign verify already had a flag for
this, so I added the flag to all verify commands. In the future, when we
are only processing bundles, we can lookup the default hash algorithm
given the key.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

* lint fmt

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

* Drop support for Fulcio with ed25519ph key

We've chosen to not support this in sigstore-go, so we'll also remove
this from Cosign. This is a niche edge case where a user provides an
ed25519 key or algorithm and requests a cert and logs it to Rekor. We'll
revisit this if there's demand or when we support the prehash variant in
Fulcio.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

---------

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
Co-authored-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-09-11 08:32:25 -07:00
Hayden
59b9930775 Support self-managed keys when signing with sigstore-go (#4368)
* Support self-managed keys when signing with sigstore-go

This creates a wrapper around the Keypair interface when a
SignerVerifier is provided for signing with KMS or any other provided
keys. This also retains support for --issue-certificate to request a
certificate for a managed key.

Fixes #4327

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

* Add issue-certificate flags to attest and attest-blob

This is for uniformity with sign/sign-blob.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

* Refactor SignerFromKeyOpts to split Fulcio signer into its own method

Now, we can generate a SignerVerifier from a provided key without
mandating that we also request a Fulcio certificate when
"issue-certificate" is provided.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

* Use default options to load key material

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>

---------

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-09-03 12:21:29 -07:00
Riccardo Schirone
b36644f793 Remove SHA256 assumption in sign-blob/verify-blob (#4050)
Use sigstore/sigstore signature.LoadSignerVerifierFromPrivateKey to load default verifiers given a private key.

Signed-off-by: Riccardo Schirone <riccardo.schirone@trailofbits.com>
2025-09-02 15:00:46 -07:00
Hayden
fd5fcfbf07 Break import cycle with e2e build tag (#4370)
When developing locally, with the e2e build tag set, there's an import
cycle. test/helpers.go imports "cmd/cosign/cli/verify", which imports
"test" in test files in the verify package. This change breaks the
import cycle by moving certificate utilities to an internal test
directory.

Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
2025-08-28 11:42:30 -07:00
Hayden
f011b93a85 Add support for SigningConfig for sign-blob/attest-blob, support Rekor v2 (#4319)
* Refactor fetching an ID token into its own package

This will allow these functions to be reused by other parts of the
codebase, and eventually we can move these into an external package for
use by other libraries.

Signed-off-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>

* Add support for SigningConfig for sign-blob/attest-blob

Signed-off-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>

* Refactor identity token retrieval into its own method

Signed-off-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>

* Disallow self-managed keys with a signing config temporarily

Signed-off-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>

---------

Signed-off-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>
Co-authored-by: Hayden B <8418760+haydentherapper@users.noreply.github.com>
2025-08-07 09:20:58 -07:00
Ville Skyttä
c03e2a8f88 More linting coverage (#4213)
* Remove explicit staticcheck and unused linter enables

They are enabled by default. For consistency, do not list them like
others that are enabled by default (for example govet) are not
explicitly listed either.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* Enable makezero and nilnesserr linters

There are no findings from either at the moment, but they serve useful
purposes.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* Ensure closing of TSA response body, enable bodyclose linter

This was flagged by bodyclose.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* Vet internal ui.Infof/Warnf uses

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* Enable usestdlibvars linter, address findings

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* test: update e2e rekor service count

https://github.com/sigstore/cosign/pull/4213#pullrequestreview-2876276830

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>

* Update e2e_test.sh to handle different healthy service totals

Rekor has healthchecks for 5 services, Fulcio currently has healthchecks for 3.

Signed-off-by: Hayden B <haydentherapper@users.noreply.github.com>

---------

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Hayden B <haydentherapper@users.noreply.github.com>
Co-authored-by: Hayden B <haydentherapper@users.noreply.github.com>
2025-05-30 10:26:07 -07:00
Cody Soyland
2e3d2960fe Remove dependency on github.com/pkg/errors (#3956)
Signed-off-by: Cody Soyland <codysoyland@github.com>
2024-12-10 12:07:43 -08:00
Hayden B
629f5f8fa6 Fixes for GHSA-88jx-383q-w4qc and GHSA-95pr-fxf5-86gv (#3661)
* Merge pull request from GHSA-95pr-fxf5-86gv

An Image may come from an untrusted source and contain an unknown number
of signatures in the .sig manifest. A common pattern in cosign is to use
the number of signatures as the capacity for a new slice. But this means
the size of the slice is based on an unvalidated external input and
could result in cosign running out of memory.

This change adds validation for certain implementations of the
oci.Signatures Get() method to limit the number of image descriptors
returned. This way, callers can rely on the returned slice of signatures
being a reasonable size to process safely.

The limit is set to 1000, which is a generous size based on the
practical restrictions that container registries set for image manifest
size and approximations of memory allocations for signature layers.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

* Merge pull request from GHSA-88jx-383q-w4qc

When downloading an attestation or SBOM from an external source, check
its size before reading it into memory. This protects the host from
potentially reading a maliciously large attachment into memory and
exhausting the system.

SBOMs can vary widely in size, and there could be legitimate SBOMs of up
to 700MB. However, reading a 700MB SBOM into memory would easily bring
down a small cloud VM. Moreover, most SBOMs are not going to be that
large. This change sets a reasonable default of 128MiB, and allows
overriding the default by setting the environment variable
`COSIGN_MAX_ATTACHMENT_SIZE`.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

---------

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
2024-04-10 14:57:21 -07:00
Carlos Tadeu Panato Junior
7a2d50b087 Update builder image, cosign image, golangci-lint (#3565)
* update cosign and builder image

Signed-off-by: cpanato <ctadeu@gmail.com>

* update golangci-lint to v1.56

Signed-off-by: cpanato <ctadeu@gmail.com>

* update go.mod in fakeoidc

Signed-off-by: cpanato <ctadeu@gmail.com>

* fix lints

Signed-off-by: cpanato <ctadeu@gmail.com>

---------

Signed-off-by: cpanato <ctadeu@gmail.com>
2024-03-03 23:33:40 +01:00
Dmitry Savintsev
f1099435db fix semgrep issues for dgryski.semgrep-go ruleset (#3541)
* fix semgrep issues dgryski.semgrep-go ruleset

Signed-off-by: Dmitry S <dsavints@gmail.com>

* golangci-lint: check error value of out.Write()

Signed-off-by: Dmitry S <dsavints@gmail.com>

---------

Signed-off-by: Dmitry S <dsavints@gmail.com>
2024-02-15 11:17:42 -08:00
Colleen Murphy
a0b02b7d7f Make E2E tests hermetic (#3499)
* Set rekor URL for online and offline tests

Some tests were setting the REKOR_URL environment variable to try to
test offline verification. This variable is no longer read so it was not
doing anything. This change removes the variable and instead sets
RekorURL in the command to either the local rekor instance (so that the
public instance is not used) or to a bad url with Offline set to true so
that offline verification is truly tested.

This change also removes the COSIGN_EXPERIMENTAL variable which is no
longer used, and replaces os.Setenv with testing.Setenv which
localizes the environment setting to the scope of the test and removes
the need for a cleanup function.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

* Fix cleanup in E2E script

Calling trap multiple times replaces the last signal handler rather than
appending to it. This change ensures that the most recent trap includes
all previous traps so that all cleanups are executed.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

* Move verify tests from shell script to Go suite

Move the `cosign dockerfile verify` and `cosign manifest verify` tests
out of the shell script and into the e2e Go test suite file with all the
other tests. This makes them consistent to manage.

The initialization of fulcio roots in other tests pollutes the trust
root in the new tests, so a reset is added to the fulcioroots package
for testing only.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

* Use local services for verify tests

Update TestDockerfileVerify and TestManifestVerify to sign ephemeral
images within the tests so that the signatures can be created with and
verified from the locally running Fulcio and Rekor instances instead of
verifying images with the public Rekor instance, so that the tests no
longer depend on external services.

The images are signed using --identity-token to avoid changing the
nature of the verification tests, which were originally written to be
keyless. A mock OIDC server is provisioned to provide the token and
enable verification.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

* Set rekor env variable in Go test suite

Move the setting of SIGSTORE_REKOR_PUBLIC_KEY from the e2e shell script
to the Go test suite, so that only the tests that need it have it set
and the shell script is doing less setup. Also remove unnecessary
instances of os.RemoveAll for temporary directories that the Go testing
framework will automatically clean up.

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>

---------

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
2024-02-07 14:34:00 -08:00
Carlos Tadeu Panato Junior
173f547a4e Set go to min 1.21 and update dependencies (#3327)
* set min go1.21

Signed-off-by: cpanato <ctadeu@gmail.com>

* update dependecies

Signed-off-by: cpanato <ctadeu@gmail.com>

* fix test TestImportPrivateKey

Signed-off-by: cpanato <ctadeu@gmail.com>

* fix lints and bump golangci-lint to 1.55.x

Signed-off-by: cpanato <ctadeu@gmail.com>

* update e2e test

Signed-off-by: cpanato <ctadeu@gmail.com>

---------

Signed-off-by: cpanato <ctadeu@gmail.com>
Signed-off-by: Bob Callaway <bobcallaway@users.noreply.github.com>
Co-authored-by: Bob Callaway <bobcallaway@users.noreply.github.com>
2023-10-29 09:14:11 -07:00
Dmitry Savintsev
f6332211b9 add 'cosign sign' command-line parameters for mTLS (#3052)
* add 'cosign sign' command-line parameters for mTLS

Add command-line parameters for key/cert/cacert used for
the connection to the TSA server.

Fixes #3006

Signed-off-by: Dmitry S <dsavints@gmail.com>

* simplify ServerName validation

Signed-off-by: Dmitry S <dsavints@gmail.com>

* add 'tsa-mtls.sh to test mTLS to TSA

Signed-off-by: Dmitry S <dsavints@gmail.com>

* add tsa mtls test to github actions

Signed-off-by: Dmitry S <dsavints@gmail.com>

* use smallstep's step to generate test certificates

Signed-off-by: Dmitry S <dsavints@gmail.com>

* in e2e_tsa_mtls.sh, build timestamp-server only if not found

Signed-off-by: Dmitry S <dsavints@gmail.com>

* add test/gencert utility, copyright

Signed-off-by: Dmitry S <dsavints@gmail.com>

---------

Signed-off-by: Dmitry S <dsavints@gmail.com>
2023-07-20 12:18:18 -04:00
Carlos Tadeu Panato Junior
84a5c8e60d use workers to limit the paralellism when verifying images (#3069)
Signed-off-by: cpanato <ctadeu@gmail.com>
2023-06-23 18:12:49 +01:00
Jon Johnson
de03ebbf72 Use SOURCE_DATE_EPOCH for OCI CreatedAt times (#2878)
Using time.Now() makes this unreproducible and causes a lot of churn
when re-running the same command.

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
2023-04-07 09:41:08 +02:00
Carlos Tadeu Panato Junior
09004f2c5d update golangci-lint to v1.52.2 (#2851)
* update golangci-lint to v1.52.2

Signed-off-by: cpanato <ctadeu@gmail.com>

* fix lints

Signed-off-by: cpanato <ctadeu@gmail.com>

---------

Signed-off-by: cpanato <ctadeu@gmail.com>
2023-04-04 15:33:55 -07:00
Hayden B
d15ed74a43 Support non-Sigstore TSA requests (#2708)
* Support non-Sigstore TSA requests

This changes the client to instead simply exchange a TSQ for a TSR given
a URL to the API. This will mean that for clients using timestamping
currently, they will need to update their Cosign calls to use the full
path (e.g. tsa.sigstore/api/v1/timestamp)

Fixes https://github.com/sigstore/cosign/issues/2704

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Address comments

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

---------

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
2023-02-16 09:00:04 -08:00
Josh Dolitsky
2b3ff73dd6 Add COSIGN_OCI_EXPERIMENTAL, push .sig/.sbom using OCI 1.1+ digest tag (#2684)
* Add COSIGN_OCI_EXPERIMENTAL, push .sig/.sbom using OCI 1.1+ digest tag

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* upgrade to latest ggcr with referrers API support

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* unexport methods whereever possible

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* Use ui logger wherever possible

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* add TODO about using created annotations

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* remove logging about unable to to find new type of attachment

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* fixes from review

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* push the config blob

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* run docgen

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

* fix for e2e tests

Signed-off-by: Josh Dolitsky <josh@dolit.ski>

---------

Signed-off-by: Josh Dolitsky <josh@dolit.ski>
2023-02-13 19:02:21 -05:00
Zack Newman
66dfb5b68c Fix prompts with Windows line endings (#2674)
Signed-off-by: Zachary Newman <zjn@chainguard.dev>
2023-01-29 08:41:17 -08:00
priyawadhwa
35bf1fe06f Add warning to use digest instead of tags to other cosign commands (#2650)
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>

Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
2023-01-24 10:28:11 -08:00
Zack Newman
fb74f73196 Fix up UI messages (#2629)
* Fix up UI messages

Signed-off-by: Zachary Newman <zjn@chainguard.dev>

* Rename Warn/Info to Warnf/Infof

Signed-off-by: Zachary Newman <zjn@chainguard.dev>

Signed-off-by: Zachary Newman <zjn@chainguard.dev>
2023-01-24 11:59:48 -05:00
Huang Huang
29360f6a33 Add oci.Signature() method to expose raw signature (#2628)
Closes #2517

Signed-off-by: mozillazg <mozillazg101@gmail.com>

Signed-off-by: mozillazg <mozillazg101@gmail.com>
2023-01-15 18:04:12 -05:00
Zack Newman
f7993d00e0 Add common UI library for confirmation prompts. (#2572)
This library:

- Is testable.
- Is consistent across the CLI.

Related to (does not fix) #2296 and #2204.

Signed-off-by: Zachary Newman <zjn@chainguard.dev>

Signed-off-by: Zachary Newman <zjn@chainguard.dev>
2023-01-02 16:32:01 +00:00
Hayden B
564a11d162 Update timestamp dependency to use updated verifier (#2539)
* Update timestamp dependency to use updated verifier

Verification now properly verifies the full certificate chain in
addition to supporting other verification, like nonce (useful for
verifying on signing).

Also updated the flag name to use "certificate" rather than "cert" to be
in line with other flag names.

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Allow no TSA certificates

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* fix v2

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Update doc comments

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
2022-12-20 15:38:02 +01:00
priyawadhwa
27bb6ad4c6 Change go module name to github.com/sigstore/cosign/v2 for Cosign 2.0 (#2544)
* Change go module name to github.com/sigstore/cosgn/v2 for Cosign 2.0

Signed-off-by: Priya Wadhwa <priya@chainguard.dev>

* Update ko paths

Signed-off-by: Priya Wadhwa <priya@chainguard.dev>

Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
2022-12-14 10:54:48 -05:00
Hayden B
b5c84865c8 Fix timestamp verification, add verify-blob tests (#2527)
* Fix timestamp verification, add verify-blob tests

While adding unit tests for verify-blob with timestamping, I found that
we try to verify with the current time if no bundle is provided, even if
we have a timestamp. I cleaned up this function to check the timestamp
time and bundle time if either are provided, and if neither is provided,
check against the current time.

I also added a mock client to clean up tests. I'll move this mock client
over to the timestamp-authority repo.

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Remove println

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
2022-12-10 13:39:58 +01:00
Hayden B
e9e9cb2c28 Updates to Timestamp signing and verification (#2499)
* Updates to Timestamp signing and verification

* Switch to using the raw signature rather than base64 signature for OCI
  and blob signing
* For blob signing, write only the timestamp to disk, not the
  LocalSignedPayload (since that's already written with the bundle)
* For blob verification, expect only a timestamp in the file. If you
  don't pass a bundle, you'll need to also pass the signature by flag
* Some nits from the previous PR

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Add testing in verify, update e2e test

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Fix test

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Add missing setting of SkipTlogVerify

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Address comments

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Fix docs

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Address nits

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Fix e2e test

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
2022-12-07 11:19:28 +01:00
Anish Shah
fa8a799784 cmd/cosign/cli: stop loading the entire blob into memory (#2500)
sign-blob always loads the entire blob into memory. This can lead to
problems when signing large blob files and increased memory usage.

Signed-off-by: Anish Shah <anishshah@google.com>

Signed-off-by: Anish Shah <anishshah@google.com>
2022-12-03 17:03:59 -05:00
Hector Fernandez
7e967e8404 Attestation/Blob signing and verification using a RFC3161 time-stamping server (#2464)
* add support for tsa signing and verification of images

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* address reviewer comments

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add support for both tsa and rekor verifications

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* signing and verification of blobs using time-stamping

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* adjust code to latest changes

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add support for attestations

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* set right annotation

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add test for blob signing/verification

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* ensure b64 signature is time-stamped

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* test: add attestation verify test

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* refactor functions and flags

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

Signed-off-by: Hector Fernandez <hector@chainguard.dev>
2022-11-23 10:17:54 -05:00
Hector Fernandez
8fc0c4674d rename tsa bundle to rfc3161timestamp (#2469)
Signed-off-by: Hector Fernandez <hector@chainguard.dev>

Signed-off-by: Hector Fernandez <hector@chainguard.dev>
2022-11-18 09:01:16 -08:00
Hector Fernandez
ba5997b878 add support for tsa signing and verification of images (#2460)
* add support for tsa signing and verification of images

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add tsa flag to cli docs

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* read tsa bundle from signatures

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* address reviewer comments

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add TODOs to the code

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

Signed-off-by: Hector Fernandez <hector@chainguard.dev>
2022-11-15 23:50:38 +01:00
Marko Mudrinić
285459e2ac feat: Implement 'env' package to handle environment variables in cosign (#2322)
* Implement 'env' package to handle environment variables

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Make 'cosign env' use the env package

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Make packages use env instead os.Getenv/LookupEnv

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Fix oci unit test

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Fix E2E tests

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Address review comments

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Update docgen

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Integrate forbidigo linter for os.Getenv/LookupEnv

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Document all environment variables used by cosign

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Address review comments - part 2

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Fix issue with tests conflicting with OS envs

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Address review comments - part 3

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Fix gocritic lint errors

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
2022-10-17 21:37:35 +00:00
asraa
5d363424c8 fix: make tlog entry lookups for online verification shard-aware (#2297)
Signed-off-by: Asra Ali <asraa@google.com>

fix tests

Signed-off-by: Asra Ali <asraa@google.com>

lint

Signed-off-by: Asra Ali <asraa@google.com>

fix online lookup

Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Asra Ali <asraa@google.com>
2022-10-01 07:12:21 -04:00
Hayden B
63fb755348 Fix BYO-root with intermediate to fetch intermediates from annotation (#2244)
This fixes a regression where intermediates, when not present in the
intermediate certificate pool, would be fetched from the OCI chain
annotation.

Ref #1554, which includes more details

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
2022-09-19 20:26:30 -04:00
asraa
80b79ed8b4 Merge pull request from GHSA-8gw7-4j42-w388
* wip

Signed-off-by: Asra Ali <asraa@google.com>

more tests

Signed-off-by: Asra Ali <asraa@google.com>

finish tests

Signed-off-by: Asra Ali <asraa@google.com>

Add explicit testcase for failure in verifytlogentry

Signed-off-by: Asra Ali <asraa@google.com>

add testing for invalid provided bundle fails

Signed-off-by: Asra Ali <asraa@google.com>

update

Signed-off-by: Asra Ali <asraa@google.com>

address hayden comments

Signed-off-by: Asra Ali <asraa@google.com>

update

Signed-off-by: Asra Ali <asraa@google.com>

* fix: verify RekorBundle payload references blob

Co-authored-by: Cody Soyland <codysoyland@github.com>
Co-authored-by: Asra Ali <asraa@google.com>

* Add test for invalid blob signature causing error

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* Add tests for checking identity flags

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>

* address bob's comment

Signed-off-by: Asra Ali <asraa@google.com>

* add comment on intoto multisig

Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Co-authored-by: Cody Soyland <codysoyland@github.com>
Co-authored-by: Hayden Blauzvern <hblauzvern@google.com>
2022-09-14 09:37:41 +01:00