Skip to content

[6/8] cli: support insecure manifests behind opt-in - #2536

Open
msanft wants to merge 5 commits into
mainfrom
split/pr-2337-cli
Open

[6/8] cli: support insecure manifests behind opt-in#2536
msanft wants to merge 5 commits into
mainfrom
split/pr-2337-cli

Conversation

@msanft

@msanft msanft commented Jul 20, 2026

Copy link
Copy Markdown
Member

Re-roll of #2357, split from #2337 as part of a stacked review series.
Closes CON-245

This PR adds CLI support for insecure manifests behind explicit opt-in:

  • generate support
  • verify support
  • runtime class handling for insecure runtimes
  • verifier and mutator updates
  • tests

@msanft msanft added the no changelog PRs not listed in the release notes label Jul 20, 2026
@msanft
msanft marked this pull request as ready for review July 20, 2026 11:50
@linear-code

linear-code Bot commented Jul 20, 2026

Copy link
Copy Markdown

CON-245

Comment thread cli/cmd/generate.go Outdated
Comment thread cli/cmd/generate.go Outdated
Comment thread cli/cmd/generate.go Outdated
Comment thread cli/cmd/verify.go
Comment thread cli/cmd/generate.go Outdated
msanft and others added 4 commits July 23, 2026 14:17
Revert isContrastWorkload to a direct assignment; the conditional is
unnecessary since only one resource is mapped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the opt-in env var to CONTRAST_ALLOW_INSECURE, matching the
Coordinator-side env var of the same name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Parse the opt-in env var as a boolean instead of checking mere presence,
and declare the --INSECURE flag only when the env var enables it, so the
flag is neither visible in --help nor accidentally passable otherwise.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pass the already-parsed manifest to getCoordinatorState instead of
unmarshalling it a second time.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@msanft
msanft requested review from burgerdev and sespiros July 23, 2026 12:40

@burgerdev burgerdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@charludo charludo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for only getting to this now. I have a couple of comments + nits below. If any of these were already discussed, feel free to just ignore them, I do not mean to rip closed discussions open again.

  • (maybe not in this PR) we should probably add a kuberesource.IsBareContrastRuntimeClass(name) function, since the checks for contrast-cc/contrast-insecure now exist in 3 places,
  • a test for patchCoordinatorAllowInsecure would maybe be nice, I think it would have caught some of the comments

Comment thread cli/cmd/generate.go
return
}
if len(r.Spec.Template.Spec.Containers) > 0 {
r.Spec.Template.Spec.Containers[0].WithEnv(kuberesource.NewEnvVar(allowInsecureEnvVar, "1"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't idempotent (i.e. running insecure generate twice appends this twice). Since all our other mutators are this should be too.

Comment thread cli/cmd/generate.go

func patchCoordinatorAllowInsecure(resource any) {
r, ok := resource.(*applyappsv1.StatefulSetApplyConfiguration)
if !ok || !isCoordinator(resource) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isCoordinator needs to additionally check r.Spec.Template.Spec != nil

Comment thread cli/cmd/generate.go
return
}
if len(r.Spec.Template.Spec.Containers) > 0 {
r.Spec.Template.Spec.Containers[0].WithEnv(kuberesource.NewEnvVar(allowInsecureEnvVar, "1"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we really assume the coordinator is always at index 0? We should probably find the coordinator(s) at any index.

Comment thread cli/cmd/generate.go
Comment on lines +606 to +608
if flags.allowInsecureRuntimes {
patchCoordinatorAllowInsecure(res)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be overly cautious, but the flag alone should not be enough in an all-secure deployment. Maybe the if should additionally check that the usedPlatforms are all insecure.

Comment thread cli/cmd/common.go
// insecureRuntimesAllowed reports whether allowInsecureEnvVar is set to a value that parses as
// true. Commands only declare the --INSECURE flag when this returns true.
func insecureRuntimesAllowed() bool {
allowed, err := strconv.ParseBool(os.Getenv(allowInsecureEnvVar))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where the discussion around envvar presence vs value ultimately landed. However, given that in the coordinator we now have:

if os.Getenv(allowInsecureEnvVar) != "" {

one of these sites needs to be adjusted so that the semantics are the same.

Comment thread cli/cmd/verify.go
if err := json.Unmarshal(manifestBytes, &mnfst); err != nil {
return fmt.Errorf("unmarshalling manifest: %w", err)
}
if mnfst.HasInsecurePlatforms() && !flags.allowInsecureRuntimes {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need the same gate in generate, too. IIUC, currently an existing manifest with insecure platforms being re-generated works even if --INSECURE is not passed.

Comment thread cli/cmd/generate_test.go
Comment on lines +349 to +352
t.Setenv("CONTRAST_ALLOW_INSECURE", tc.value)
if !tc.set {
os.Unsetenv("CONTRAST_ALLOW_INSECURE")
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use allowInsecureEnvVar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog PRs not listed in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants