-
Notifications
You must be signed in to change notification settings - Fork 14
proposal: Support secret providers #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hsmatulis
wants to merge
9
commits into
prometheus:main
Choose a base branch
from
hsmatulis:secret-providers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
45d10a3
Initial draft of proposal
hsmatulis 55e0f18
New draft
hsmatulis d344204
Fix spacing
hsmatulis 296a135
Add changes from discussionn
hsmatulis ca962cc
Reply to comments
hsmatulis a8b43ab
Reply to comments
hsmatulis 0864090
Add section on secret rotation
hsmatulis ec70387
Reply to comments
hsmatulis fb37c95
Add Secret Refresh and Caching section
hsmatulis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
## Remote Secrets (Secret Providers) | ||
|
||
* **Owners:** | ||
* Henrique Matulis (@hsmatulisgoogle) | ||
|
||
* **Implementation Status:** Not implemented | ||
|
||
* **Related Issues and PRs:** | ||
* https://github.com/prometheus/prometheus/issues/8551 | ||
* https://github.com/prometheus/prometheus/issues/11477 | ||
* https://github.com/prometheus/alertmanager/issues/3108 | ||
* https://github.com/prometheus/prometheus/pull/13955 | ||
* https://github.com/prometheus/exporter-toolkit/pull/141 | ||
* https://github.com/prometheus/prometheus/issues/5795 | ||
|
||
|
||
|
||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* **Other docs or links:** | ||
* [Prometheus Remote Secrets Doc](https://docs.google.com/document/d/1EqHd2EwQxf9SYD8-gl3sgkwaU6A10GhiN7aw-2kx7NU/edit?tab=t.0) | ||
* Previous proposal by @TheSpiritXIII | ||
* https://stackoverflow.com/questions/43609144/can-prometheus-store-basic-auth-passwords-in-any-format-other-then-plain-text | ||
* https://groups.google.com/g/prometheus-users/c/yWLE9qoG5GU/m/ke8ewxjIAQAJ | ||
|
||
|
||
> TL;DR: This document proposes adding a new way for Prometheus to discover and use secrets from various secret providers, similar to how service discovery works. It introduces a new configuration section where users can specify different secret providers and their configurations. It also defines interfaces and methods for secret providers to implement, allowing for flexibility in how secrets are fetched and managed. | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Why | ||
|
||
The motivation behind this design document is to enhance the security and flexibility of secret management in Prometheus. Currently, Prometheus only supports reading secrets from the filesystem or directly from the configuration file, which can lead to security vulnerabilities and limitations when working with certain service providers. | ||
|
||
This proposal introduces secret discovery, similar to service discovery, where different secret providers can contribute code to read secrets from their respective APIs. This would allow for more secure and dynamic secret retrieval, eliminating the need to store secrets in the filesystem and reducing the potential for unauthorized access. | ||
|
||
### Pitfalls of the current solution | ||
|
||
Storing secrets in the filesystem poses risks, especially in environments like Kubernetes, where any pod on a node can access files mounted on that node. This could expose secrets to attackers. Additionally, configuring secrets through the filesystem often requires extra setup steps in some enviroments, which can be cumbersome for users. | ||
|
||
Storing secrets inline can also pose risks, as the configuration file may still be accessible through the filesystem. Additionally it can lead to configuration files becoming cluttered and difficult to manage. | ||
|
||
## Goals | ||
|
||
Goals and use cases for the solution as proposed in [How](#how): | ||
|
||
* Allow Prometheus to read secrets remotely from secret providers. | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Introduce secret discovery, similar to service discovery, where different secret providers can contribute code to read secrets from their respective API. | ||
|
||
### Audience | ||
|
||
* Prometheus maintainers | ||
* Alertmanager maintainers | ||
* Secret providers interested in contributing code | ||
* Users looking to use secret providers | ||
|
||
## Non-Goals | ||
|
||
* Implement a variety of secret providers. | ||
|
||
## How | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
### Interfaces | ||
|
||
Secret providers will be created from their configurations through the following interface: | ||
|
||
``` | ||
type SecretProviderConfiguration interface { | ||
// Returns the secret provider for the given configuration. | ||
Load() (SecretProvider, error) | ||
} | ||
``` | ||
|
||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Secret providers will have to satisfy the following interface. Secret providers will be expected to be long lived to allow for caching. However they will be re-instantiated in case of a configuration change. The Fetch method will be called before each http request done through `prometheus/common/config` | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
type SecretProvider interface { | ||
// Returns the secret value for the given configuration. | ||
Fetch(ctx context.Context, secretRef string) (string, error) | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
``` | ||
|
||
### Configuration | ||
|
||
Globally there will be a section to configure secrete providers to be used throught the config file. Here is an example: | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
global: | ||
secret_providers: | ||
- name: my_secret_provider | ||
kubernetes_sp_config: | ||
namespace: ns1 | ||
``` | ||
|
||
|
||
For secret related fields under http_config, a new `ref` variant will be added that can reference these secret providers. For instance, basic_auth will have the following form | ||
|
||
``` | ||
basic_auth: | ||
... | ||
password: <secret> | ||
password_file: <string> | ||
password_ref: | ||
<string>: <string> | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
and could be instantiated as follows: | ||
|
||
``` | ||
basic_auth: | ||
password_ref: | ||
my_secret_provider: 'my-secret-key' | ||
``` | ||
|
||
#### Full configuration example | ||
``` | ||
global: | ||
secret_providers: | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: kube1 | ||
kubernetes_sp_config: | ||
namespace: ns1 | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: kube2 | ||
kubernetes_sp_config: | ||
namespace: ns2 | ||
... | ||
scrape_configs: | ||
- job_name: 'http-basic-auth-endpoint' | ||
http_config: | ||
basic_auth: | ||
username: 'myuser' | ||
password_ref: | ||
kube1: 'myuser-pass' | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static_configs: | ||
- targets: ['www.endpoint.com/basic-auth'] | ||
scrape_configs: | ||
- job_name: 'http-authorization-auth-endpoint' | ||
http_config: | ||
authorization: | ||
credentials_ref: | ||
kube2: 'header-credentials' | ||
static_configs: | ||
- targets: ['www.endpoint.com/authorization-auth'] | ||
scrape_configs: | ||
- job_name: 'tls-certificate-endpoint' | ||
http_config: | ||
tls_config: | ||
key_ref: | ||
kube2: 'header-credentials' | ||
static_configs: | ||
- targets: ['www.endpoint.com/tls-certificate'] | ||
``` | ||
|
||
|
||
## Alternatives | ||
|
||
### Modify Secret type | ||
|
||
Currently most secrets in the config use the prometheus.common.config.Secret alias. We could modify this type such that if only a string is passed it behaves the same as before, and if a map is passed in it assumes it to be a reference to be fetched from the associated secret provider. | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This would mean the config would look like this instead: | ||
``` | ||
basic_auth: | ||
password: 'my-secret-value' | ||
... | ||
basic_auth: | ||
password: | ||
my_secret_provider: 'my-secret-key' | ||
``` | ||
|
||
Pros: | ||
* Simpler, more unified config | ||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Defines a clear way to use secrets outside of the `http_config` component | ||
|
||
Cons: | ||
* Can be more confusing | ||
* Requires more careful documentation | ||
* Unclear how to refresh the configs for arbitrary components that could now change dynamically | ||
|
||
|
||
hsmatulis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Action Plan | ||
|
||
* [x] Add a secret manager to `prometheus.common.config` | ||
* [ ] Add secret providers to prometheus | ||
* [ ] Add docs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: username doesn't match (anymore? I think it was changed)