Skip to content

Commit

Permalink
Add TSA certificate flag/fields for cosign attest-blob
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Savintsev <dsavints@gmail.com>
  • Loading branch information
dmitris committed Feb 21, 2025
1 parent 442e0e8 commit b060021
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/cosign/cli/attest/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
"github.com/sigstore/cosign/v2/internal/pkg/cosign/tsa"
"github.com/sigstore/cosign/v2/internal/pkg/cosign/tsa/client"
tsaclient "github.com/sigstore/cosign/v2/internal/pkg/cosign/tsa/client"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/cosign/v2/pkg/cosign/attestation"
cbundle "github.com/sigstore/cosign/v2/pkg/cosign/bundle"
Expand Down Expand Up @@ -165,7 +165,16 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
var timestampBytes []byte
var rekorEntry *models.LogEntryAnon

if c.TSAServerURL != "" {
if c.KeyOpts.TSAServerURL != "" {
tc := tsaclient.NewTSAClient(c.KeyOpts.TSAServerURL)
if c.TSAClientCert != "" {
tc = tsaclient.NewTSAClientMTLS(c.KeyOpts.TSAServerURL,
c.KeyOpts.TSAClientCACert,
c.KeyOpts.TSAClientCert,
c.KeyOpts.TSAClientKey,
c.KeyOpts.TSAServerName,
)
}
// We need to decide what signature to send to the timestamp authority.
//
// Historically, cosign sent `sig`, which is the entire JSON DSSE
Expand All @@ -186,12 +195,12 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
return err
}

timestampBytes, err = tsa.GetTimestampedSignature(envelopeSigBytes, client.NewTSAClient(c.TSAServerURL))
timestampBytes, err = tsa.GetTimestampedSignature(envelopeSigBytes, tc)
if err != nil {
return err
}
} else {
timestampBytes, err = tsa.GetTimestampedSignature(sig, client.NewTSAClient(c.TSAServerURL))
timestampBytes, err = tsa.GetTimestampedSignature(sig, tc)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/cosign/cli/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func AttestBlob() *cobra.Command {
OIDCRedirectURL: o.OIDC.RedirectURL,
OIDCProvider: o.OIDC.Provider,
SkipConfirmation: o.SkipConfirmation,
TSAClientCACert: o.TSAClientCACert,
TSAClientKey: o.TSAClientKey,
TSAClientCert: o.TSAClientCert,
TSAServerName: o.TSAServerName,
TSAServerURL: o.TSAServerURL,
RFC3161TimestampPath: o.RFC3161TimestampPath,
BundlePath: o.BundlePath,
Expand Down
16 changes: 16 additions & 0 deletions cmd/cosign/cli/options/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type AttestBlobOptions struct {

SkipConfirmation bool
TlogUpload bool
TSAClientCACert string
TSAClientCert string
TSAClientKey string
TSAServerName string
TSAServerURL string
RFC3161TimestampPath string

Expand Down Expand Up @@ -103,6 +107,18 @@ func (o *AttestBlobOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.RekorEntryType, "rekor-entry-type", "dsse",
"specifies the type to be used for a rekor entry upload. Options are intoto or dsse (default). ")

cmd.Flags().StringVar(&o.TSAClientCACert, "timestamp-client-cacert", "",
"path to the X.509 CA certificate file in PEM format to be used for the connection to the TSA Server")

cmd.Flags().StringVar(&o.TSAClientCert, "timestamp-client-cert", "",
"path to the X.509 certificate file in PEM format to be used for the connection to the TSA Server")

cmd.Flags().StringVar(&o.TSAClientKey, "timestamp-client-key", "",
"path to the X.509 private key file in PEM format to be used, together with the 'timestamp-client-cert' value, for the connection to the TSA Server")

cmd.Flags().StringVar(&o.TSAServerName, "timestamp-server-name", "",
"SAN name to use as the 'ServerName' tls.Config field to verify the mTLS connection to the TSA Server")

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")

Expand Down
4 changes: 4 additions & 0 deletions doc/cosign_attest-blob.md

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

4 changes: 4 additions & 0 deletions 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 b060021

Please sign in to comment.