Skip to content

Commit

Permalink
Add support for recording creation timestamp for cosign attest (#3797)
Browse files Browse the repository at this point in the history
* add support for recording creation timestamp for cosign attest

Signed-off-by: Zsolt Horvath <[email protected]>
Signed-off-by: Zsolt Horvath <[email protected]>

* Fix cosign attest example in doc/cosign_attest.md

Signed-off-by: Zsolt Horvath <[email protected]>

---------

Signed-off-by: Zsolt Horvath <[email protected]>
Signed-off-by: Zsolt Horvath <[email protected]>
Co-authored-by: Zsolt Horvath <[email protected]>
  • Loading branch information
zshorvath and Zsolt Horvath authored Jul 29, 2024
1 parent 98c2cab commit 0406602
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 34 deletions.
30 changes: 17 additions & 13 deletions cmd/cosign/cli/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Attest() *cobra.Command {
cmd := &cobra.Command{
Use: "attest",
Short: "Attest the supplied container image.",
Example: ` cosign attest --key <key path>|<kms uri> [--predicate <path>] [--a key=value] [--no-upload=true|false] [--f] [--r] <image uri>
Example: ` cosign attest --key <key path>|<kms uri> [--predicate <path>] [--a key=value] [--no-upload=true|false] [--record-creation-timestamp=true|false] [--f] [--r] <image uri>
# attach an attestation to a container image Google sign-in
cosign attest --timeout 90s --predicate <FILE> --type <TYPE> <IMAGE>
Expand All @@ -58,7 +58,10 @@ func Attest() *cobra.Command {
COSIGN_DOCKER_MEDIA_TYPES=1 cosign attest --predicate <FILE> --type <TYPE> --key cosign.key legacy-registry.example.com/my/image
# supply attestation via stdin
echo <PAYLOAD> | cosign attest --predicate - <IMAGE>`,
echo <PAYLOAD> | cosign attest --predicate - <IMAGE>
# attach an attestation to a container image and honor the creation timestamp of the signature
cosign attest --predicate <FILE> --type <TYPE> --key cosign.key --record-creation-timestamp <IMAGE>`,

Args: cobra.MinimumNArgs(1),
PersistentPreRun: options.BindViper,
Expand Down Expand Up @@ -86,17 +89,18 @@ func Attest() *cobra.Command {
TSAServerURL: o.TSAServerURL,
}
attestCommand := attest.AttestCommand{
KeyOpts: ko,
RegistryOptions: o.Registry,
CertPath: o.Cert,
CertChainPath: o.CertChain,
NoUpload: o.NoUpload,
PredicatePath: o.Predicate.Path,
PredicateType: o.Predicate.Type,
Replace: o.Replace,
Timeout: ro.Timeout,
TlogUpload: o.TlogUpload,
RekorEntryType: o.RekorEntryType,
KeyOpts: ko,
RegistryOptions: o.Registry,
CertPath: o.Cert,
CertChainPath: o.CertChain,
NoUpload: o.NoUpload,
PredicatePath: o.Predicate.Path,
PredicateType: o.Predicate.Type,
Replace: o.Replace,
Timeout: ro.Timeout,
TlogUpload: o.TlogUpload,
RekorEntryType: o.RekorEntryType,
RecordCreationTimestamp: o.RecordCreationTimestamp,
}

for _, img := range args {
Expand Down
22 changes: 12 additions & 10 deletions cmd/cosign/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ func uploadToTlog(ctx context.Context, sv *sign.SignerVerifier, rekorURL string,
type AttestCommand struct {
options.KeyOpts
options.RegistryOptions
CertPath string
CertChainPath string
NoUpload bool
PredicatePath string
PredicateType string
Replace bool
Timeout time.Duration
TlogUpload bool
TSAServerURL string
RekorEntryType string
CertPath string
CertChainPath string
NoUpload bool
PredicatePath string
PredicateType string
Replace bool
Timeout time.Duration
TlogUpload bool
TSAServerURL string
RekorEntryType string
RecordCreationTimestamp bool
}

// nolint
Expand Down Expand Up @@ -226,6 +227,7 @@ func (c *AttestCommand) Exec(ctx context.Context, imageRef string) error {

signOpts := []mutate.SignOption{
mutate.WithDupeDetector(dd),
mutate.WithRecordCreationTimestamp(c.RecordCreationTimestamp),
}

if c.Replace {
Expand Down
24 changes: 14 additions & 10 deletions cmd/cosign/cli/options/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import (

// AttestOptions is the top level wrapper for the attest command.
type AttestOptions struct {
Key string
Cert string
CertChain string
NoUpload bool
Recursive bool
Replace bool
SkipConfirmation bool
TlogUpload bool
TSAServerURL string
RekorEntryType string
Key string
Cert string
CertChain string
NoUpload bool
Recursive bool
Replace bool
SkipConfirmation bool
TlogUpload bool
TSAServerURL string
RekorEntryType string
RecordCreationTimestamp bool

Rekor RekorOptions
Fulcio FulcioOptions
Expand Down Expand Up @@ -86,4 +87,7 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.TSAServerURL, "timestamp-server-url", "",
"url to the Timestamp RFC3161 server, default none. Must be the path to the API to request timestamp responses, e.g. https://freetsa.org/tsr")

cmd.Flags().BoolVar(&o.RecordCreationTimestamp, "record-creation-timestamp", false,
"set the createdAt timestamp in the attestation artifact to the time it was created; by default, cosign sets this to the zero value")
}
6 changes: 5 additions & 1 deletion doc/cosign_attest.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0406602

Please sign in to comment.