Skip to content

fix(registry): warn when insecure transport is configured#3396

Open
Dashtid wants to merge 1 commit intoanchore:mainfrom
Dashtid:fix/registry-insecure-transport-warning
Open

fix(registry): warn when insecure transport is configured#3396
Dashtid wants to merge 1 commit intoanchore:mainfrom
Dashtid:fix/registry-insecure-transport-warning

Conversation

@Dashtid
Copy link
Copy Markdown

@Dashtid Dashtid commented Apr 25, 2026

Summary

  • Emit a one-time warning during config load when insecure-skip-tls-verify or insecure-use-http is set
  • These flags can be silently picked up from a config file or env var, leaving registry traffic unprotected with no indication in normal CLI output
  • The warning lists exactly which insecure flag(s) are enabled so the user can find and address them

Fixes #3101 (grype CLI half — see scope note below).

Details

The warning is emitted from the existing PostLoad() hook on the registry config struct, which is the natural single point where merged config (flag + env + YAML) is available exactly once per invocation. There is precedent for log.Warnf from inside PostLoad() in the same package (see database_search_packages.go lines 43, 62).

Implementation:

  • insecureTransportWarning() string is a pure helper that returns the message, or empty if neither flag is set. Splitting message construction from the log call lets the branching logic be unit-tested deterministically without touching the logger singleton.
  • PostLoad() calls the helper and emits log.Warn(msg) only when non-empty.
  • No behavior change beyond the new log line.

Sample output when both flags are set:

[WARN] registry communication is insecure: insecure-skip-tls-verify, insecure-use-http enabled

Scope note

#3101 outlined two changes: (1) a debug log inside stereoscope at the actual TLS/HTTP application sites, and (2) a warning at the grype CLI level. This PR addresses only (2), which @Tanish-26 indicated was the higher priority ("If I had to choose only one, I'd prioritize the grype CLI warning"). The stereoscope debug log can follow as a separate, smaller PR to anchore/stereoscope.

Test plan

  • Test_registry_insecureTransportWarning: 5 cases covering neither set, each alone, both set, and credentials-without-insecure-flags (regression guard)
  • Test_registry_PostLoad_returnsNoError: verifies all 4 flag combinations don't return an error from PostLoad (warning is observability, must never block config load)
  • Full cmd/grype/cli/options/... test suite passes — no regressions

Emit a one-time warning during config load when either
`insecure-skip-tls-verify` or `insecure-use-http` is enabled. These
flags can be set silently via a config file or environment variable
and produce no indication in normal CLI output that registry traffic
is unprotected.

The warning is built from a pure helper, `insecureTransportWarning`,
so the logic can be unit-tested without hooking the logger singleton.
PostLoad continues to return nil for any flag combination since the
warning is observability only and must not block config loading.

Fixes anchore#3101 (grype CLI half; stereoscope debug log to follow as a
separate PR per the issue's two-part scope)

Signed-off-by: David Dashti <david.dashti@hermesmedical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Runtime Warnings When TLS Verification Is Disabled or HTTP Is Enabled

1 participant