Skip to content

feat: add secrets management#17648

Open
hsmatulis wants to merge 1 commit intoprometheus:mainfrom
hsmatulis:hsmatulis-secrets
Open

feat: add secrets management#17648
hsmatulis wants to merge 1 commit intoprometheus:mainfrom
hsmatulis:hsmatulis-secrets

Conversation

@hsmatulis
Copy link

@hsmatulis hsmatulis commented Dec 4, 2025

secrets: Add remote secrets providers

See the proposal here. This PR is currently a work in progress, demonstrating how user's would interact with the secrets management API

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

[FEATURE] config: All secret fields e.g. `scrape[].basic_auth.password` supports now "generic" format.  This means users are able to specify in `password` either inlined secret as previously or one from certain provider. Currently only `inline` and `file` providers are supported, with more to come. Old `password_field`-like fields are still supported although discouraged. This change also removes the undocumented `password_ref`-like fields which were unused. See [documentation](TODO) and [PROM-47](https://github.com/prometheus/proposals/blob/main/proposals/0047-secret_providers.md) for details.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

This is good! Super minimal change surface.

I'd actually iterate over this PR and make this ready to be merged once common change is merged. We could double check all tests etc. 💪🏽

There are definitely some tests to fix, but it might be as trivial as adding (f *Field) Equals(other Field) bool so comparisons work correctly (they don't depend on state):

Image

NamespaceDiscovery NamespaceDiscovery `yaml:"namespaces,omitempty"`
Selectors []SelectorConfig `yaml:"selectors,omitempty"`
AttachMetadata AttachMetadataConfig `yaml:"attach_metadata,omitempty"`
ExampleSecret secrets.Field `yaml:"example_secret"`
Copy link
Member

Choose a reason for hiding this comment

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

Nice, easy use 👍🏽

Let's remove and iterate over this PR to be effectively testable and potentially mergable once common change is done, looks promising!

Copy link
Member

Choose a reason for hiding this comment

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

Although your other examples use *secrets.Field (pointer)?

Copy link
Author

Choose a reason for hiding this comment

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

Switched to not using pointers as the default way, and added a nil provider to represent when the user passes in nothing

@bwplotka
Copy link
Member

bwplotka commented Dec 8, 2025

For release log, keep in mind this is for user facing changes (e.g. user of Prometheus YAML). I would mention what user can expect (generic field and removal of ref).

I'd recommend:

[FEATURE] config: All secret fields e.g. `scrape[].basic_auth.password` supports now "generic" format.  This means users are able to specify in `password` either inlined secret as previously or one from certain provider. Currently only `inline` and `file` providers are supported, with more to come. Old `password_field`-like fields are still supported although discouraged. This change also removes the undocumented `password_ref`-like fields which were unused. See [documentation](TODO) and [PROM-47](https://github.com/prometheus/proposals/blob/main/proposals/0047-secret_providers.md) for details.

@bwplotka
Copy link
Member

Exciting feature! We even plan to mention it on KubeCon EU in March if that's ok (: cc @hsmatulis

Hopefully it's done until then 💪🏽

@bwplotka
Copy link
Member

@hsmatulis hsmatulis force-pushed the hsmatulis-secrets branch 18 times, most recently from 90d17c1 to 09ab0ec Compare January 5, 2026 13:20
@hsmatulis hsmatulis marked this pull request as ready for review January 5, 2026 15:15
Copilot AI review requested due to automatic review settings January 5, 2026 15:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds secrets management functionality to Prometheus, allowing users to specify secrets from different providers (inline and file) instead of only inline secrets. The implementation includes a secrets manager component that runs as part of the main Prometheus process and populates configuration with resolved secrets during config loading and reloading.

Key Changes

  • Added secrets manager integration that runs alongside other Prometheus components
  • Modified the configuration reload mechanism to populate secrets from configured providers
  • Replaced prometheus/common dependency with a personal fork containing secrets management implementation

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
go.mod Adds module replacement directing prometheus/common to personal fork with secrets management
go.sum Updates dependency checksums for the replaced module and adds new indirect dependencies
cmd/prometheus/main.go Integrates secrets manager lifecycle, adds context management, and modifies reload logic to populate secrets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

go.mod Outdated
google.golang.org/api v0.30.0
)

replace github.com/prometheus/common => github.com/hsmatulis/prom-common v0.0.8
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The replace directive redirects the first-party module github.com/prometheus/common to a personal fork github.com/hsmatulis/prom-common v0.0.8, introducing a supply-chain risk because all imports of github.com/prometheus/common now execute code from an external, individually controlled repository. If that fork or its release process is compromised, an attacker could inject malicious logic into Prometheus, potentially exfiltrating secrets or altering security-critical behavior without changes in this repository. To reduce this risk, depend on the official github.com/prometheus/common module (or an internal fork under the Prometheus organization or vendored code) rather than a third-party fork as a drop-in replacement for core infrastructure code.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

TODO: fix when prometheus/common#797 is merged

@hsmatulis hsmatulis force-pushed the hsmatulis-secrets branch 3 times, most recently from d77faac to 57e14f8 Compare January 14, 2026 08:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hsmatulis hsmatulis force-pushed the hsmatulis-secrets branch 2 times, most recently from e5e361e to 72cf435 Compare January 14, 2026 10:33
@hsmatulis hsmatulis requested a review from Copilot January 14, 2026 10:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hsmatulis hsmatulis force-pushed the hsmatulis-secrets branch 2 times, most recently from 5bf50e3 to f2279c4 Compare January 14, 2026 10:56
@hsmatulis hsmatulis requested a review from Copilot January 14, 2026 10:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 19 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Henrique Matulis <hmatulis@google.com>
c.EC2SDConfig.AccessKey = c.AccessKey
}
if c.SecretKey != "" {
if !c.SecretKey.IsNil() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !c.SecretKey.IsNil() {
if !c.SecretKey.IsEmpty() {

or

Suggested change
if !c.SecretKey.IsNil() {
if c.SecretKey.IsSet) {

Comment on lines +44 to +45
IdentityEndpoint: s.Mock.Endpoint(),
ApplicationCredentialSecret: secrets.MockInline(""),
Copy link
Member

Choose a reason for hiding this comment

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

I'd vote to allow empty value and IsEmpty() on nil returning true and Value() returning empty string. Because we will likely forget to set it somewhere and then it's a bit annoying to have that extra verbose thing.

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.

Generally enable reading secrets from files How to encrypt basic_auth password/password_file in prometheus.yml file?

3 participants