Skip to content

Commit 33beaf6

Browse files
committed
cli: require opt-in for verifying insecure deployments
This adds the same `--INSECURE` and `CONTRAST_ALLOW_INSECURE_RUNTIMES` toggles to `contrast verify` that are already present in `contrast generate`.
1 parent 6403731 commit 33beaf6

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

cli/cmd/verify.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ all policies, and the certificates of the Coordinator certificate authority.`,
4848
cmd.Flags().StringP("manifest", "m", manifestFilename, "path to manifest (.json) file")
4949
cmd.Flags().StringP("coordinator", "c", "", "endpoint the coordinator can be reached at")
5050
must(cobra.MarkFlagRequired(cmd.Flags(), "coordinator"))
51+
cmd.Flags().Bool("INSECURE", false, "allow verification of insecure (non-CC) deployments (also requires the CONTRAST_ALLOW_INSECURE_RUNTIMES environment variable to be set)")
5152

5253
return cmd
5354
}
@@ -69,6 +70,19 @@ func runVerify(cmd *cobra.Command, _ []string) error {
6970
return fmt.Errorf("failed to read manifest file: %w", err)
7071
}
7172

73+
var mnfst manifest.Manifest
74+
if err := json.Unmarshal(manifestBytes, &mnfst); err != nil {
75+
return fmt.Errorf("unmarshalling manifest: %w", err)
76+
}
77+
if mnfst.AllowInsecure() {
78+
if !flags.allowInsecureRuntimes {
79+
return fmt.Errorf("manifest contains insecure platforms but --INSECURE flag not set")
80+
}
81+
if os.Getenv("CONTRAST_ALLOW_INSECURE_RUNTIMES") == "" {
82+
return fmt.Errorf("manifest contains insecure platforms but CONTRAST_ALLOW_INSECURE_RUNTIMES environment variable not set")
83+
}
84+
}
85+
7286
kdsDir, err := cachedir("kds")
7387
if err != nil {
7488
return fmt.Errorf("getting cache dir: %w", err)
@@ -130,9 +144,10 @@ func runVerify(cmd *cobra.Command, _ []string) error {
130144
}
131145

132146
type verifyFlags struct {
133-
manifestPath string
134-
coordinator string
135-
workspaceDir string
147+
manifestPath string
148+
coordinator string
149+
workspaceDir string
150+
allowInsecureRuntimes bool
136151
}
137152

138153
func parseVerifyFlags(cmd *cobra.Command) (*verifyFlags, error) {
@@ -148,6 +163,10 @@ func parseVerifyFlags(cmd *cobra.Command) (*verifyFlags, error) {
148163
if err != nil {
149164
return nil, err
150165
}
166+
allowInsecureRuntimes, err := cmd.Flags().GetBool("INSECURE")
167+
if err != nil {
168+
return nil, err
169+
}
151170

152171
if workspaceDir != "" {
153172
// Prepend default path with workspaceDir
@@ -157,9 +176,10 @@ func parseVerifyFlags(cmd *cobra.Command) (*verifyFlags, error) {
157176
}
158177

159178
return &verifyFlags{
160-
manifestPath: manifestPath,
161-
coordinator: coordinator,
162-
workspaceDir: workspaceDir,
179+
manifestPath: manifestPath,
180+
coordinator: coordinator,
181+
workspaceDir: workspaceDir,
182+
allowInsecureRuntimes: allowInsecureRuntimes,
163183
}, nil
164184
}
165185

0 commit comments

Comments
 (0)