Skip to content

Commit ed6422c

Browse files
author
Zsolt Horvath
committed
add support for recording creation timestamp for cosign attest
Signed-off-by: Zsolt Horvath <zsolte@gmail.com> Signed-off-by: Zsolt Horvath <zsolt.horvath@real-digital.de>
1 parent c6cdf1b commit ed6422c

File tree

4 files changed

+47
-33
lines changed

4 files changed

+47
-33
lines changed

cmd/cosign/cli/attest.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Attest() *cobra.Command {
3131
cmd := &cobra.Command{
3232
Use: "attest",
3333
Short: "Attest the supplied container image.",
34-
Example: ` cosign attest --key <key path>|<kms uri> [--predicate <path>] [--a key=value] [--no-upload=true|false] [--f] [--r] <image uri>
34+
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>
3535
3636
# attach an attestation to a container image Google sign-in
3737
cosign attest --timeout 90s --predicate <FILE> --type <TYPE> <IMAGE>
@@ -58,7 +58,10 @@ func Attest() *cobra.Command {
5858
COSIGN_DOCKER_MEDIA_TYPES=1 cosign attest --predicate <FILE> --type <TYPE> --key cosign.key legacy-registry.example.com/my/image
5959
6060
# supply attestation via stdin
61-
echo <PAYLOAD> | cosign attest --predicate - <IMAGE>`,
61+
echo <PAYLOAD> | cosign attest --predicate - <IMAGE>
62+
63+
# attach an attestation to a container image and honor the creation timestamp of the signature
64+
cosign attest --predicate <FILE> --type <TYPE> --key cosign.key --record-creation-timestamp <IMAGE>`,
6265

6366
Args: cobra.MinimumNArgs(1),
6467
PersistentPreRun: options.BindViper,
@@ -86,17 +89,18 @@ func Attest() *cobra.Command {
8689
TSAServerURL: o.TSAServerURL,
8790
}
8891
attestCommand := attest.AttestCommand{
89-
KeyOpts: ko,
90-
RegistryOptions: o.Registry,
91-
CertPath: o.Cert,
92-
CertChainPath: o.CertChain,
93-
NoUpload: o.NoUpload,
94-
PredicatePath: o.Predicate.Path,
95-
PredicateType: o.Predicate.Type,
96-
Replace: o.Replace,
97-
Timeout: ro.Timeout,
98-
TlogUpload: o.TlogUpload,
99-
RekorEntryType: o.RekorEntryType,
92+
KeyOpts: ko,
93+
RegistryOptions: o.Registry,
94+
CertPath: o.Cert,
95+
CertChainPath: o.CertChain,
96+
NoUpload: o.NoUpload,
97+
PredicatePath: o.Predicate.Path,
98+
PredicateType: o.Predicate.Type,
99+
Replace: o.Replace,
100+
Timeout: ro.Timeout,
101+
TlogUpload: o.TlogUpload,
102+
RekorEntryType: o.RekorEntryType,
103+
RecordCreationTimestamp: o.RecordCreationTimestamp,
100104
}
101105

102106
for _, img := range args {

cmd/cosign/cli/attest/attest.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ func uploadToTlog(ctx context.Context, sv *sign.SignerVerifier, rekorURL string,
7171
type AttestCommand struct {
7272
options.KeyOpts
7373
options.RegistryOptions
74-
CertPath string
75-
CertChainPath string
76-
NoUpload bool
77-
PredicatePath string
78-
PredicateType string
79-
Replace bool
80-
Timeout time.Duration
81-
TlogUpload bool
82-
TSAServerURL string
83-
RekorEntryType string
74+
CertPath string
75+
CertChainPath string
76+
NoUpload bool
77+
PredicatePath string
78+
PredicateType string
79+
Replace bool
80+
Timeout time.Duration
81+
TlogUpload bool
82+
TSAServerURL string
83+
RekorEntryType string
84+
RecordCreationTimestamp bool
8485
}
8586

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

227228
signOpts := []mutate.SignOption{
228229
mutate.WithDupeDetector(dd),
230+
mutate.WithRecordCreationTimestamp(c.RecordCreationTimestamp),
229231
}
230232

231233
if c.Replace {

cmd/cosign/cli/options/attest.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ import (
2121

2222
// AttestOptions is the top level wrapper for the attest command.
2323
type AttestOptions struct {
24-
Key string
25-
Cert string
26-
CertChain string
27-
NoUpload bool
28-
Recursive bool
29-
Replace bool
30-
SkipConfirmation bool
31-
TlogUpload bool
32-
TSAServerURL string
33-
RekorEntryType string
24+
Key string
25+
Cert string
26+
CertChain string
27+
NoUpload bool
28+
Recursive bool
29+
Replace bool
30+
SkipConfirmation bool
31+
TlogUpload bool
32+
TSAServerURL string
33+
RekorEntryType string
34+
RecordCreationTimestamp bool
3435

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

8788
cmd.Flags().StringVar(&o.TSAServerURL, "timestamp-server-url", "",
8889
"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")
90+
91+
cmd.Flags().BoolVar(&o.RecordCreationTimestamp, "record-creation-timestamp", false,
92+
"set the createdAt timestamp in the attestation artifact to the time it was created; by default, cosign sets this to the zero value")
8993
}

doc/cosign_attest.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)