Skip to content

Commit b126109

Browse files
committed
Do not load trusted root when CT env key is set
In 32a2d62 the ability to use TUF to read and refresh trusted_root.json was added. Prior, there was already a --trusted-root flag for verify* commands, to read trusted_root.json directly without using a TUF client. This did not exist for the sign* commands, which still need key material to verifyi the CT key. The workaround for the sign commands was to use the SIGSTORE_CT_LOG_PUBLIC_KEY_FILE environment variable, but when the TUF client was updated, this workaround regressed. This change makes it so that this flag will still work and that the machine's cached trusted root is not used if it's not intended to be used. The permanent fix going forward should be to add the --trusted-root flags to the sign* commands. Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
1 parent 19ef59d commit b126109

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

cmd/cosign/cli/attest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
2525
"github.com/sigstore/cosign/v2/internal/ui"
2626
"github.com/sigstore/cosign/v2/pkg/cosign"
27+
"github.com/sigstore/cosign/v2/pkg/cosign/env"
2728
"github.com/spf13/cobra"
2829
)
2930

@@ -99,7 +100,7 @@ func Attest() *cobra.Command {
99100
TSAServerURL: o.TSAServerURL,
100101
NewBundleFormat: o.NewBundleFormat,
101102
}
102-
if o.Key == "" { // Get the trusted root if using fulcio for signing
103+
if o.Key == "" && env.Getenv(env.VariableSigstoreCTLogPublicKeyFile) == "" { // Get the trusted root if using fulcio for signing
103104
trustedMaterial, err := cosign.TrustedRoot()
104105
if err != nil {
105106
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)

cmd/cosign/cli/attest_blob.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
2323
"github.com/sigstore/cosign/v2/internal/ui"
2424
"github.com/sigstore/cosign/v2/pkg/cosign"
25+
"github.com/sigstore/cosign/v2/pkg/cosign/env"
2526
"github.com/spf13/cobra"
2627
)
2728

@@ -84,7 +85,7 @@ func AttestBlob() *cobra.Command {
8485
BundlePath: o.BundlePath,
8586
NewBundleFormat: o.NewBundleFormat,
8687
}
87-
if o.Key == "" { // Get the trusted root if using fulcio for signing
88+
if o.Key == "" && env.Getenv(env.VariableSigstoreCTLogPublicKeyFile) == "" { // Get the trusted root if using fulcio for signing
8889
trustedMaterial, err := cosign.TrustedRoot()
8990
if err != nil {
9091
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)

cmd/cosign/cli/sign.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
2626
"github.com/sigstore/cosign/v2/internal/ui"
2727
"github.com/sigstore/cosign/v2/pkg/cosign"
28+
"github.com/sigstore/cosign/v2/pkg/cosign/env"
2829
"github.com/spf13/cobra"
2930
)
3031

@@ -130,7 +131,7 @@ race conditions or (worse) malicious tampering.
130131
TSAServerURL: o.TSAServerURL,
131132
IssueCertificateForExistingKey: o.IssueCertificate,
132133
}
133-
if o.Key == "" || o.IssueCertificate {
134+
if (o.Key == "" || o.IssueCertificate) && env.Getenv(env.VariableSigstoreCTLogPublicKeyFile) == "" {
134135
trustedMaterial, err := cosign.TrustedRoot()
135136
if err != nil {
136137
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)

cmd/cosign/cli/signblob.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
2626
"github.com/sigstore/cosign/v2/internal/ui"
2727
"github.com/sigstore/cosign/v2/pkg/cosign"
28+
"github.com/sigstore/cosign/v2/pkg/cosign/env"
2829
"github.com/spf13/cobra"
2930
"github.com/spf13/viper"
3031
)
@@ -98,7 +99,7 @@ func SignBlob() *cobra.Command {
9899
RFC3161TimestampPath: o.RFC3161TimestampPath,
99100
IssueCertificateForExistingKey: o.IssueCertificate,
100101
}
101-
if o.Key == "" || o.IssueCertificate {
102+
if (o.Key == "" || o.IssueCertificate) && env.Getenv(env.VariableSigstoreCTLogPublicKeyFile) == "" {
102103
trustedMaterial, err := cosign.TrustedRoot()
103104
if err != nil {
104105
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)

0 commit comments

Comments
 (0)