Skip to content

add support for basic auth web config - #4652

Closed
Hades32 wants to merge 1 commit into
prometheus-operator:mainfrom
Hades32:basic-auth-users
Closed

Hades32 wants to merge 1 commit into
prometheus-operator:mainfrom
Hades32:basic-auth-users

Conversation

@Hades32

@Hades32 Hades32 commented Mar 17, 2022 •

Copy link
Copy Markdown

Description

Extends WebSpec with basic-auth user information to secure the Prometheus API

This fixes #4200

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Changelog entry

Add support for configuring HTTP basic auth. See Prometheus docs for details.

Draft: Open Points

  • refactor to use secrets to store basic auth users
  • add internal user for health-check and config reloader

@Hades32
Hades32 requested a review from a team as a code owner March 17, 2022 15:41

@simonpasquier simonpasquier left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your PR!

We shouldn't expose credentials directly in the custom resource for security reasons. One approach would be to have a list of references to secret keys like for other sensitive fields. Lets reuse the existing BasicAuth struct:

type Prometheus struct {
	...
	BasicAuthUsers []BasicAuth `json:"basicAuthUsers,omitempty"`
	...
}

Another point to keep in mind is that the config reloader uses the Prometheus web service so it needs to be configured with valid authn credentials.

@simonpasquier

Copy link
Copy Markdown
Contributor

I see that @fpetkovski commented on the issue that we could reuse the existing basicAuth type which makes sense indeed.

@Hades32

Hades32 commented Mar 17, 2022

Copy link
Copy Markdown
Author

Thanks for your comments! Yes, I realized just now, that also the health check is actually affected by this...
But I'll continue working on this over the next few days

@Hades32
Hades32 marked this pull request as draft March 18, 2022 08:06
@Hades32

Hades32 commented Mar 18, 2022

Copy link
Copy Markdown
Author

@simonpasquier OK, so changing to the existing BasicAuth type was straightforward, but fixing health-checks and config reloader will be trickier. My idea would be like this:

  • always create a basic auth user secret for each Prometheus object (something like internal-operator-user, with a UUID as password)
  • if the list of basic auth users exists and has entries, add this user
  • somehow add this user to the health-check and config reloader
    • here your input would be appreciated

WDYT?

@simonpasquier

Copy link
Copy Markdown
Contributor

My instinct would be to generate a user/password for the config reloader and append it to the list provided by the user (if not empty). It sounds better than reusing an existing user/password (cleaner separation).

Liveness/readiness probes are another issue indeed... In this case, we could use an exec probe (already the case when Prometheus listens on localhost) and inject the credentials via environment variables. Ideally Prometheus shouldn't require authentication for the /-/ready and /-/healthy endpoints.

@RomainPhil

Copy link
Copy Markdown

Hi any news concerning this feature ?

@Hades32

Hades32 commented Jun 16, 2022

Copy link
Copy Markdown
Author

Unfortunately, I didn't have time to finish this and solved it by simply running an Nginx sidecar container that only does basic-auth

@shenxuxie

Copy link
Copy Markdown

Thanks for your PR!

We shouldn't expose credentials directly in the custom resource for security reasons. One approach would be to have a list of references to secret keys like for other sensitive fields. Lets reuse the existing BasicAuth struct:

type Prometheus struct {
	...
	BasicAuthUsers []BasicAuth `json:"basicAuthUsers,omitempty"`
	...
}

Another point to keep in mind is that the config reloader uses the Prometheus web service so it needs to be configured with valid authn credentials.

how to configur the config reloader with authncredentials

@ArthurSens

Copy link
Copy Markdown
Member

Hey @Hades32, I'm closing this one since you've communicated that you won't be able to continue. Thanks for the effort and feel free to re-open if you feel like continuing in the future :)

@ArthurSens ArthurSens closed this Nov 17, 2023
bicknell-effodio added a commit to bicknell-effodio/prometheus-operator that referenced this pull request May 20, 2026
Apply the review feedback from prometheus-operator#8577.

Design changes:

- Drop operator-managed internal user. The operator no longer generates
  credentials or owns a Secret with a stable name. Replaced with a
  user-supplied `web.internalUser` field referencing a Secret with three
  keys: username, password (plaintext), and an optional passwordBcrypt.
- When passwordBcrypt is absent, the operator bcrypts the plaintext at
  reconcile and caches the result keyed on a hash of the plaintext, so
  reconciles where the plaintext is unchanged reuse the cached bcrypt and
  produce byte-identical web-config Secrets.
- When passwordBcrypt is set, the operator verifies it matches the
  plaintext and writes it verbatim. On mismatch the operator falls back to
  default-mode bcrypting with a Warning event; the system stays functional.
- In-pod callers (probes, reloader, sidecar) read credentials from a
  mounted Secret volume so rotation propagates without pod restarts.
  Reloader uses --reload-basic-auth-password-file rather than an env var.
- Add Thanos version gate (>= 0.24.0) for the http-client-file flag.
- basicAuthUsers without internalUser is now a reconcile error.

Text changes:

- Workarounds list rewritten: drop the unsupported spec.secrets bullet,
  add the reverse-proxy sidecar pattern with a reference to Hades32's
  comment in prometheus-operator#4652, drop the "most popular" framing for which we have no
  data.
- Rename the "Ingress-level auth is no longer a defensible answer"
  subsection to "Proxy-based workarounds share a structural limitation".
  Treat the proxy-in-front pattern generically; trim the ingress-nginx
  retirement discussion to a single soft sentence with one citation; add
  an explicit acknowledgment that basic auth is not a complete security
  solution and layered defenses (NetworkPolicies, TLS) are encouraged.
- Validation section expanded with the new internal user rules and the
  reconcile-time bcrypt format heuristics. CEL enforces only the
  structural rule (basicAuthUsers requires internalUser); content-based
  checks are runtime events since CEL cannot read Secret values.
- Open questions trimmed to one item (exporter-toolkit prometheus-operator#151 follow-up).
  Status-condition/metric and CEL-on-Secret-values questions dropped.
- Add a new Alternatives entry documenting Secret-as-user-list as
  considered and rejected for v1, with rationale and forward-compat note.
- Take the suggested addition to the operator-side-bcrypt rejection
  bullet ("exposes the operator to potential security issues which
  maintainers don't want to deal with") and clarify that the bullet
  addresses the general case; the internal user's bounded operator-side
  bcrypt is a different question handled in "Internal user" above.

cspell:

- Add bcrypting, bcrypts, htpasswd to the dictionary for the new wording.

Signed-off-by: Leo Bicknell <[email protected]>
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.

Support basic_auth_users in web configuration for Prometheus and Alertmanager

5 participants