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
nixos/prometheus: Support environmentFile #97933
Conversation
If you are going to store secrets in /tmp I think |
Whoops, excellent point! Fixed. |
@benley @fpletz @globin @WilliButz @Frostman - Would someone of you mind to take a look at this? (I can't seem to add reviewers and I don't think this will review itself by waiting.) |
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.
Thank you for you contribution 👍
I have some suggestions for adding the environment file:
- as in the
codimd
module, I find it very important to make it clear to users, that the specified path forenvironmentFile
needs to be available on the same host, the corresponding service is running on (when used with Nixops for example). - instead of using
/tmp
withPrivateTmp
, I'd suggest using a service-specificRuntimeDirectory
withRuntimeDirectoryMode
set to0700
, an example of this is in themurmur
module. - to make injecting additional environment files easier for more advanced use-cases, I suggest to make
EnvironmentFile
a list of files by default (usingmkIf (cond) [ cfg.environmentFile ];
) for easier option value merging. - also when
envsubst
was new to me and I was just given the same short description about how replacement of option values works, it didn't make it clear to me how the Nix config and environmentFile actually needed to be structured for it to work together, hence the longer description in the mentionedcodimd
module with a short example for each.
(Note that I also think the mentioned points also apply to the alertmanager module, for which I should probably open a PR soon)
For the same reason Alertmanager supports environmentFile to pass secrets along, it is useful to support the same for Prometheus' configuration to store bearer tokens outside the Nix store. Use PrivateTmp on the systemd unit to safeguard potential secrets in the configuration file.
- Move away from PrivateTmp and instead use a private RuntimeDirectory for the substituted config file. - Improve documentation of environmentFile by including more descriptive text from existing packages (murmur and codimd). - Also include an example scrape config entry (from nixos) as well as the corresponding example for the environment file. - Pass the environment file to the systemd unit file generator as a list.
@WilliButz Thank you for the review, that was incredibly useful. I tried to implement your changes and it seems to have worked on my NixOS test installation. Please let me know what you think. |
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.
Looks good! 🎉
@GrahamcOfBorg test prometheus |
Test failed due to thanos, prometheus is working fine - they should probably be in separate tests. |
Motivation for this change
For the same reason Alertmanager supports environmentFile to pass secrets along, it is useful to support the same for Prometheus' configuration to store authentication/bearer tokens outside the Nix store.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)