Skip to content
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

Support for username_file configuration in prometheus http basic auth config #12576

Open
wasim-nihal opened this issue Jul 18, 2023 · 6 comments

Comments

@wasim-nihal
Copy link
Contributor

Proposal

Feature Request

Description:
Currently, a user has to explicitly type in the sensitive data in the configuration yaml. For example, in case of basic_auth, the user needs to configure the username and password. In our organization username is also considered as sensitive data and configuring it in this way is not acceptable.

In grafana, there is an option(called as File Provider) to provide a path to a file for an value using a placeholder like $__file{<path_to_file>}. At the runtime, the content of the file is read and substituted for the variable dynamically.

Advantages

  1. In Kubernetes environment especially, the sensitive data can be made as secrets and mounted on the pod as files. And the placeholders in prometheus configuration can be dynamically updated with the contents of the respective files and then application is started.
  2. Any field in the configuration yaml can be treated as sensitive data by the organizations. Gives them better flexibility.

Example Usage in configuration

- job_name: 'health_checks'
   scrape_interval: 4m
   scrape_timeout: 25s
   static_configs:
       - targets: ['organization.com']
   metrics_path: "/api/health"
   basic_auth:
     username: $__file{/etc/secret/username}
     password: $__file{/etc/secret/password}

Contribution

I am working on the changes for this feature and if you would allow, I would be happy to contribute this back to the Prometheus community.

@roidelapluie
Copy link
Member

We already support reading passwords via file.

- job_name: 'health_checks'
   scrape_interval: 4m
   scrape_timeout: 25s
   static_configs:
       - targets: ['organization.com']
   metrics_path: "/api/health"
   basic_auth:
     username: username
     password_file: /etc/secret/password

@wasim-nihal
Copy link
Contributor Author

wasim-nihal commented Jul 25, 2023

Thanks for your response. This functionality is limited to passwords right? In some organizations, including mine, even username is treated as sensitive data and the value cannot be provided directly in the configuration yaml. So, with this feature, a user can create a Kubernetes secret for username and mount it to the pod and can further the configuration yaml placeholder($__file{username_secret_mount_file}) can be substituted with the content of the username secret.

With this, it will provide flexibility for the users/organizations on what fields they want to treat as sensitive data based on their requirements.

@roidelapluie
Copy link
Member

I am open to adding a username_file if you think it's useful.

Please note that Prometheus is not just substituting a field with the content of a file. When a file is specified, we read it on every request, enabling rolling changes of passwords without configuration reloads.

@wasim-nihal
Copy link
Contributor Author

yes, having username_file, similar to password_file would definitely be useful for some of the organizations like ours.
@roidelapluie , if this requirement (introduction of username_file) is okay, I would like to contribute here.

@wasim-nihal
Copy link
Contributor Author

@wasim-nihal wasim-nihal changed the title Support for File Provider ($__file{<path_to_file>}) in Prometheus configuration similar to Grafana Support for username_file configuration in prometheus http basic auth config Sep 5, 2023
@roypeter
Copy link

Hi @wasim-nihal, thank you for incorporating this feature; it has proven to be quite useful to us. Might you have an expected release date for it?

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

No branches or pull requests

3 participants