Skip to content

Commit 81e920f

Browse files
Address review comments
--signing-config and --use-signing-config are now mutually exclusive. TrustedMaterial and SigningConfig are set in the same line as fetching the trusted root and signing config. Signed-off-by: Hayden <8418760+haydentherapper@users.noreply.github.com>
1 parent 134a928 commit 81e920f

File tree

8 files changed

+20
-24
lines changed

8 files changed

+20
-24
lines changed

cmd/cosign/cli/attest.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,26 @@ func Attest() *cobra.Command {
113113
return fmt.Errorf("loading trusted root: %w", err)
114114
}
115115
} else {
116-
trustedMaterial, err := cosign.TrustedRoot()
116+
ko.TrustedMaterial, err = cosign.TrustedRoot()
117117
if err != nil {
118118
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)
119119
}
120-
ko.TrustedMaterial = trustedMaterial
121120
}
122121
}
123122

124123
if (o.UseSigningConfig || o.SigningConfigPath != "") && !o.NewBundleFormat {
125124
return fmt.Errorf("must provide --new-bundle-format with --signing-config or --use-signing-config")
126125
}
127126
if o.UseSigningConfig {
128-
signingConfig, err := cosign.SigningConfig()
127+
ko.SigningConfig, err = cosign.SigningConfig()
129128
if err != nil {
130129
return fmt.Errorf("error getting signing config from TUF: %w", err)
131130
}
132-
ko.SigningConfig = signingConfig
133131
} else if o.SigningConfigPath != "" {
134-
signingConfig, err := root.NewSigningConfigFromPath(o.SigningConfigPath)
132+
ko.SigningConfig, err = root.NewSigningConfigFromPath(o.SigningConfigPath)
135133
if err != nil {
136134
return fmt.Errorf("error reading signing config from file: %w", err)
137135
}
138-
ko.SigningConfig = signingConfig
139136
}
140137

141138
attestCommand := attest.AttestCommand{

cmd/cosign/cli/attest_blob.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,25 @@ func AttestBlob() *cobra.Command {
101101
return fmt.Errorf("loading trusted root: %w", err)
102102
}
103103
} else {
104-
trustedMaterial, err := cosign.TrustedRoot()
104+
ko.TrustedMaterial, err = cosign.TrustedRoot()
105105
if err != nil {
106106
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)
107107
}
108-
ko.TrustedMaterial = trustedMaterial
109108
}
110109
}
111110
if (o.UseSigningConfig || o.SigningConfigPath != "") && o.BundlePath == "" {
112111
return fmt.Errorf("must provide --bundle with --signing-config or --use-signing-config")
113112
}
114113
if o.UseSigningConfig {
115-
signingConfig, err := cosign.SigningConfig()
114+
ko.SigningConfig, err = cosign.SigningConfig()
116115
if err != nil {
117116
return fmt.Errorf("error getting signing config from TUF: %w", err)
118117
}
119-
ko.SigningConfig = signingConfig
120118
} else if o.SigningConfigPath != "" {
121-
signingConfig, err := root.NewSigningConfigFromPath(o.SigningConfigPath)
119+
ko.SigningConfig, err = root.NewSigningConfigFromPath(o.SigningConfigPath)
122120
if err != nil {
123121
return fmt.Errorf("error reading signing config from file: %w", err)
124122
}
125-
ko.SigningConfig = signingConfig
126123
}
127124

128125
v := attest.AttestBlobCommand{

cmd/cosign/cli/options/attest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {
124124
cmd.Flags().StringVar(&o.SigningConfigPath, "signing-config", "",
125125
"path to a signing config file. Must provide --new-bundle-format, which will store verification material in the new format")
126126

127+
cmd.MarkFlagsMutuallyExclusive("use-signing-config", "signing-config")
128+
127129
cmd.Flags().StringVar(&o.TrustedRootPath, "trusted-root", "",
128130
"optional path to a TrustedRoot JSON file to verify a signature after signing")
129131
}

cmd/cosign/cli/options/attest_blob.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func (o *AttestBlobOptions) AddFlags(cmd *cobra.Command) {
109109
cmd.Flags().StringVar(&o.SigningConfigPath, "signing-config", "",
110110
"path to a signing config file. Must provide --bundle, which will output verification material in the new format")
111111

112+
cmd.MarkFlagsMutuallyExclusive("use-signing-config", "signing-config")
113+
112114
cmd.Flags().StringVar(&o.TrustedRootPath, "trusted-root", "",
113115
"optional path to a TrustedRoot JSON file to verify a signature after signing")
114116

cmd/cosign/cli/options/sign.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func (o *SignOptions) AddFlags(cmd *cobra.Command) {
152152
cmd.Flags().StringVar(&o.SigningConfigPath, "signing-config", "",
153153
"path to a signing config file. Must provide --new-bundle-format, which will store verification material in the new format")
154154

155+
cmd.MarkFlagsMutuallyExclusive("use-signing-config", "signing-config")
156+
155157
cmd.Flags().StringVar(&o.TrustedRootPath, "trusted-root", "",
156158
"optional path to a TrustedRoot JSON file to verify a signature after signing")
157159
}

cmd/cosign/cli/options/signblob.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ func (o *SignBlobOptions) AddFlags(cmd *cobra.Command) {
9292
cmd.Flags().StringVar(&o.SigningConfigPath, "signing-config", "",
9393
"path to a signing config file. Must provide --bundle, which will output verification material in the new format")
9494

95+
cmd.MarkFlagsMutuallyExclusive("use-signing-config", "signing-config")
96+
9597
cmd.Flags().StringVar(&o.TrustedRootPath, "trusted-root", "",
9698
"optional path to a TrustedRoot JSON file to verify a signature after signing")
9799

cmd/cosign/cli/sign.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,26 @@ race conditions or (worse) malicious tampering.
143143
return fmt.Errorf("loading trusted root: %w", err)
144144
}
145145
} else {
146-
trustedMaterial, err := cosign.TrustedRoot()
146+
ko.TrustedMaterial, err = cosign.TrustedRoot()
147147
if err != nil {
148148
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)
149149
}
150-
ko.TrustedMaterial = trustedMaterial
151150
}
152151
}
153152

154153
if (o.UseSigningConfig || o.SigningConfigPath != "") && !o.NewBundleFormat {
155154
return fmt.Errorf("must provide --new-bundle-format with --signing-config or --use-signing-config")
156155
}
157156
if o.UseSigningConfig {
158-
signingConfig, err := cosign.SigningConfig()
157+
ko.SigningConfig, err = cosign.SigningConfig()
159158
if err != nil {
160159
return fmt.Errorf("error getting signing config from TUF: %w", err)
161160
}
162-
ko.SigningConfig = signingConfig
163161
} else if o.SigningConfigPath != "" {
164-
signingConfig, err := root.NewSigningConfigFromPath(o.SigningConfigPath)
162+
ko.SigningConfig, err = root.NewSigningConfigFromPath(o.SigningConfigPath)
165163
if err != nil {
166164
return fmt.Errorf("error reading signing config from file: %w", err)
167165
}
168-
ko.SigningConfig = signingConfig
169166
}
170167

171168
if err := sign.SignCmd(ro, ko, *o, args); err != nil {

cmd/cosign/cli/signblob.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,25 @@ func SignBlob() *cobra.Command {
111111
return fmt.Errorf("loading trusted root: %w", err)
112112
}
113113
} else {
114-
trustedMaterial, err := cosign.TrustedRoot()
114+
ko.TrustedMaterial, err = cosign.TrustedRoot()
115115
if err != nil {
116116
ui.Warnf(context.Background(), "Could not fetch trusted_root.json from the TUF repository. Continuing with individual targets. Error from TUF: %v", err)
117117
}
118-
ko.TrustedMaterial = trustedMaterial
119118
}
120119
}
121120
if (o.UseSigningConfig || o.SigningConfigPath != "") && o.BundlePath == "" {
122121
return fmt.Errorf("must provide --bundle with --signing-config or --use-signing-config")
123122
}
124123
if o.UseSigningConfig {
125-
signingConfig, err := cosign.SigningConfig()
124+
ko.SigningConfig, err = cosign.SigningConfig()
126125
if err != nil {
127126
return fmt.Errorf("error getting signing config from TUF: %w", err)
128127
}
129-
ko.SigningConfig = signingConfig
130128
} else if o.SigningConfigPath != "" {
131-
signingConfig, err := root.NewSigningConfigFromPath(o.SigningConfigPath)
129+
ko.SigningConfig, err = root.NewSigningConfigFromPath(o.SigningConfigPath)
132130
if err != nil {
133131
return fmt.Errorf("error reading signing config from file: %w", err)
134132
}
135-
ko.SigningConfig = signingConfig
136133
}
137134

138135
for _, blob := range args {

0 commit comments

Comments
 (0)