-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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/utils: introduce genJqStructuredSecretsReplacementSnippet, deprecate genJqSecretsReplacementSnippet #324955
Conversation
01b0e08
to
0df5d65
Compare
@ofborg test gitlab sing-box lemmy engelsystem artalk discourse filebeat does not have a NixOS test. netbird's NixOS test does not use secrets. |
We usually add a new function in this case and guide users to use this function in the documentation. Changing the current behavior seems less ideal. |
EDIT: the old implementation can be viewed here:
Could you provide some precedents?
Providing two slightly different functions is also not good. To be clear, there is no implicit behavior change. Out-of-tree usage of genJqSecretsReplacementSnippet will fail to eval without damaging running systems. With a post in https://discourse.nixos.org/t/breaking-changes-announcement-for-unstable/17574 , I consider the situation good enough. The current somewhat mysterious error message "error: cannot coerce a function to a string" can be improved at the cost of worse interface of genJqSecretsReplacementSnippet: we decrease the number of parameters by move some parameters into the newly added attribute set like this genJqSecretsReplacementSnippet' = attr: { set, output, quote ? false }: Then the error message becomes more clear error: function 'genJqSecretsReplacementSnippet'' called without required argument 'set'
at /path/to/nixpkgs/nixos/lib/utils.nix:215:43:
214| # attr which identifies the secret to be changed.
215| genJqSecretsReplacementSnippet' = attr: { set, output, quote ? false }:
| ^
216| let |
Maybe #287364 |
…ecate genJqSecretsReplacementSnippet genJqReplacementSnippet quotes the content of the secret file in the output json file, which prevents structured secret, such as a list or an object, from being used. This patch is a breaking change for genJqSecretsReplacementSnippet'. Since the function is somewhat internal, it should be fine.
0df5d65
to
edad32d
Compare
Switched to a non-breaking approach. Please re-review. |
I think this is not an ideal solution since end users can not choose between string or JSON secrets. A better user interface should allow users to choose whether the secret is JSON or string for every single secret. For example, genJqSecretsReplacementSnippet {
example = [
{
irrelevant = "not interesting";
}
{
ignored = "ignored attr";
relevant = {
secretString1 = {
_secret = "/path/to/secret";
};
secretString2 = {
_secret = "/path/to/secret";
quote = true; # or some other attribute name
};
secretJson = {
_secret = "/path/to/secret";
quote = false; # or some other attribute name
};
};
}
];
} "/path/to/output.json" And, another advantage of this user interface is that it keeps backward compatibility. |
Perhaps we could use a shorter name for your new function, and keep the initially compatible behavior? |
A demo: master...linyinfeng:nixpkgs:json-secrets. # demo.nix
let
demoNixpkgs = fetchTarball "https://github.com/linyinfeng/nixpkgs/archive/refs/heads/json-secrets.zip";
pkgs = import demoNixpkgs {};
inherit (pkgs) lib;
utils = import "${demoNixpkgs}/nixos/lib/utils.nix" {
inherit lib pkgs;
config = null;
};
in
utils.genJqSecretsReplacementSnippet {
example = [
{
irrelevant = "not interesting";
}
{
ignored = "ignored attr";
relevant = {
secretString1 = {
_secret = "/path/to/secret-quote-1";
};
secretString2 = {
_secret = "/path/to/secret-quote-2";
quote = true; # or some other attribute name
};
secretJson = {
_secret = "/path/to/secret-json";
quote = false; # or some other attribute name
};
};
}
];
} "/path/to/output.json" $ nix eval --file ./demo.nix --impure --raw
if [[ -h '/path/to/output.json' ]]; then
rm '/path/to/output.json'
fi
inherit_errexit_enabled=0
shopt -pq inherit_errexit && inherit_errexit_enabled=1
shopt -s inherit_errexit
secret1=$(<'/path/to/secret-json')
export secret1
secret2=$(<'/path/to/secret-quote-1')
export secret2
secret3=$(<'/path/to/secret-quote-2')
export secret3
/nix/store/axpqa3f5l63mc38h11x1gc5cykw8bn5i-jq-1.7.1-bin/bin/jq >'/path/to/output.json' '."example"[1]."relevant"."secretJson" = ($ENV.secret1 | fromjson) | ."example"[1]."relevant"."secretString1" = ($ENV.secret2) | ."example"[1]."relevant"."secretString2" = ($ENV.secret3)' <<'EOF'
{"example":[{"irrelevant":"not interesting"},{"ignored":"ignored attr","relevant":{"secretJson":{"_secret":"/path/to/secret-json","quote":false},"secretString1":{"_secret":"/path/to/secret-quote-1"},"secretString2":{"_secret":"/path/to/secret-quote-2","quote":true}}}]}
EOF
(( ! $inherit_errexit_enabled )) && shopt -u inherit_errexit |
Even though I do not like the idea that users are able to choose between string and JSON secrets, especially with string as the default, I think it is the only backward compatible way. I also realize that my current implementation is actually a breaking change due to lack of a notification mechanism to tell users @linyinfeng Would you like to create a PR? |
I believe that string should be a reasonable default.
I created #325217. |
Closing in favor of #325217 |
Description of changes
genJqReplacementSnippet quotes the content of the secret file in the
output json file, which prevents structured secret, such as a list or
an object, from being used.
This patch is a breaking change for genJqSecretsReplacementSnippet'.
Since the function is somewhat internal, it should be fine.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.