Repository navigation
Conversation
992e961 to
44810f7
Compare
|
@ofborg test utils scrutiny glance discourse actual artalk immich-kiosk engelsystem lemmy ente immich nginx-sso perses gitlab recyclarr sing-box filebeat netbird
|
|
ambroisie
left a comment
There was a problem hiding this comment.
I'd like to see tests with strings that need escaping, both in JSON and the key-value generator.
| setWithSecretsReplaced = mapAttrsRecursiveCond' (as: !(isAttrs as && hasAttr attr as)) ( | ||
| path: item: | ||
| if (isAttrs item && hasAttr attr item) then | ||
| sanitizePath "@.${concatMapStringsSep "." (n: ''"${n}"'') path}@" |
There was a problem hiding this comment.
Question: should this use some form of lib.escape rather than `''"${n}"''?
There was a problem hiding this comment.
That will surely be better indeed. I will test with some strings that include quotes and all.
There was a problem hiding this comment.
I added tests for that and sanitizePath takes care of correctly escaping what is needed.
That's exactly why I introduced the regression tests in a previous PR. The idea was that the regression tests on Thinking about long term maintenance, would you want instead for me to move all those tests to be applied on |
No I think it's fine to test I'm asking to test the escapes because I don't see any in your key-value tests, and haven't seen any in the JSON ones either. There's no real test stress-testing correct handling of escapes (e.g: |
|
@ambroisie so I managed to get something working. It's pretty much a WIP commit but I would like you to validate this implementation makes sense already. So now the The best would've been to be able to serialize the generator but that does not exist. The closest I found was to do: fn=lib.toJSON nix eval --impure --expr 'let nixpkgs = import ./. {}; fs = nixpkgs.lib.splitString "." (builtins.getEnv "fn"); f = nixpkgs.lib.foldl (base: name: builtins.getAttr name base) nixpkgs fs; in f "abcd"'
"\"abcd\""But that is frown upon, rightfully so. So I resorted to have the |
|
Seems fine to me as an approach. |
|
@ofborg test utils scrutiny glance discourse actual artalk immich-kiosk engelsystem lemmy ente immich nginx-sso perses gitlab recyclarr sing-box filebeat netbird |
|
@ambroisie I made a small change In the implementation with far reaching implications. The generator is now a function that produces a file in the nix store. This makes the |
|
@ofborg test utils scrutiny glance discourse actual artalk immich-kiosk engelsystem lemmy ente immich nginx-sso perses gitlab recyclarr sing-box filebeat netbird |
|
@ibizaman This looks very cool! So if I understand things correctly, the helper will replace (possibly nested) attrsets containing a A few dumb questions (I skimmed the code, so I'm sure they'd be answerable is I paid more attention):
|
|
@prescientmoon Thanks for the kind words.
Exactly.
Yes the secrets remain in place forever. The replacement script will delete and re-create the config file on each invocation, even if the secrets did not change.
It is created, as well as parent directory tree.
That's a great idea. I'll have to think about how to implement this. But currently the config stays forever. Note that all the answers I gave on the behavior existed before this PR. That is what the previous Not changing the behavior was intentional, to avoid scope creeping the PR and increasing the chances of merging it. |
maybe an alternative there seems like openbao agent templates. that could be at the same level as (i.e. competing with) rather than complementing the approach here, but if so, i would argue say contracts could allow people to plug in whichever solution they would deem better suited to their use-case. but yeah, i agree if that was pre-existing then this PR shouldn't have to solve that. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
82280ea to
200b5d0
Compare
|
I really would like to merge this. How can I help move this forward? There are some work I could upstream from my SelfHostBlocks project but it's blocked by not having this function. (There are always ways around it, I could copy this function in other places, but I don't think there's a good reason for doing this). |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
This PR creates a new function
genSecretsReplacement. It'sgenJqSecretsReplacementfor any config file format. It achieves that by taking a generator following thepkgs.formats.*. This new function can become the underlying function that all other secret generation function uses. Now,genJqSecretsReplacementis simply defined in terms ofgenSecretsReplacement.This made it possible to integrate free form module with secrets in configuration. It doesn't require any specific wiring, just using the functions in the correct location. This is reflected in the manual.
The previous implementation of
genJqSecretsReplacementcould not be salvaged as it was very specific to JSON. Instead, it uses the python replace-secrets package which had to be updated to add a--quoteand--quote-charoption.The previous PR added regression tests which ensure this function does not break any use case.
From https://secretspec.dev/blog/secrets-dont-belong-in-config/
Potentially 152 modules could benefit from this.
Identified downstream modules are - those using
genJqSecretsReplacement:pnpm-9.15.9is unsafepnpm-9.15.9is unsafeThings done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.