Commit graph

182 commits

Author SHA1 Message Date
Jörg Thalheim
563411a342 unit-test: pass in sops-install-secrets via callPackage 2024-11-24 18:29:59 +01:00
Jörg Thalheim
a2b11a4b86 ingore recvcheck lint for FormatType 2024-11-24 18:29:59 +01:00
Jörg Thalheim
c4a672fdec importAgeSSHKeys never returnss an error 2024-11-24 18:29:59 +01:00
Jörg Thalheim
035bd53bb7 avoid various type conversions i.e. int -> uint32 2024-11-24 18:29:59 +01:00
Jörg Thalheim
17bc7838d8 use switch case where possible 2024-11-24 16:55:22 +01:00
Jörg Thalheim
fa1c48a0c0 check for is dry activation in one place 2024-11-24 16:55:22 +01:00
Jörg Thalheim
35a86416aa always check for errors on type casting 2024-11-24 16:55:22 +01:00
Jörg Thalheim
1f66022025 don't use named returns 2024-11-24 16:55:22 +01:00
Jörg Thalheim
fc20a8fdf9 add newlines before return 2024-11-24 16:55:22 +01:00
Jörg Thalheim
1b8016259b don't capatalize errors 2024-11-24 16:55:22 +01:00
Jörg Thalheim
3e7cba9a38 wrap all external errors 2024-11-24 16:55:22 +01:00
Jörg Thalheim
d1b8b2a00a fix wsl lints 2024-11-24 15:39:10 +01:00
Jörg Thalheim
4bc1bfdec2 tests: avoid type shadowing 2024-11-24 15:39:10 +01:00
Jörg Thalheim
14753257fb tests: avoid sprint for simple string concatination 2024-11-24 15:39:10 +01:00
Jörg Thalheim
f57a556af4 apply golangci-lints 2024-11-24 15:39:10 +01:00
Jörg Thalheim
d5e0983eb9 tests: move NOBODY/NOGROUP into a constant 2024-11-24 15:39:10 +01:00
Jörg Thalheim
582b2a8300 remove space before nolint 2024-11-24 15:39:10 +01:00
Jörg Thalheim
4d5d1b7559 fix wsl lints 2024-11-24 15:39:10 +01:00
Jörg Thalheim
975c685308 unittest: set t.Helper() and t.Parallel() 2024-11-24 15:39:10 +01:00
Jörg Thalheim
ae893d14fb hook_test: fix linter errors 2024-11-24 15:39:10 +01:00
Jörg Thalheim
3ba597a5e6 remove sops-pgp-hook 2024-11-24 15:39:10 +01:00
Jörg Thalheim
9190dee408 sops-pgp-hook: set parallel and helper 2024-11-24 15:39:10 +01:00
Jörg Thalheim
887d4b7322 enable gofumpt 2024-11-24 15:39:10 +01:00
Jörg Thalheim
a33e8cc43f enable shellcheck 2024-11-24 15:39:10 +01:00
Jörg Thalheim
76aa784427 delete duplicate shell.nix 2024-11-24 15:39:10 +01:00
Jared Baur
e39947d0ee allow for missing switch-to-configuration directory
NixOS' switch-to-configuration program creates the /run/nixos directory,
which may not be present if `system.switch.enable` is `false`.
2024-11-18 18:23:53 +00:00
Jörg Thalheim
799b572ef1 move checks out of pkgs 2024-11-17 15:33:42 +01:00
Jörg Thalheim
dfcebb55c8 only export nixos tests on Linux 2024-11-17 13:20:58 +01:00
Jörg Thalheim
6b85086bcc reformat code base with nixfmt 2024-11-17 12:22:59 +01:00
Jeremy Fleischman
eee831aadb Do not render templates when decrypting neededForUsers secrets
This fixes https://github.com/Mic92/sops-nix/issues/659

In https://github.com/Mic92/sops-nix/pull/649, we started rendering
templates twice:

1. When rendering `neededForUsers` secrets (if there are any
   `neededForUsers` secrets).
2. When decrypting "regular" secrets.

This alone was weird and wrong, but didn't cause issues
for people until https://github.com/Mic92/sops-nix/pull/655, which
triggered https://github.com/Mic92/sops-nix/issues/659. The cause is not
super obvious:

1. When rendering `neededForUsers` secrets, we'd generate templates in
   `/run/secrets-for-users/rendered`.
2. However, the `path` for these templates is in
   `/run/secrets/rendered`, which is not inside of the
   `/run/secrets-for-users` directory we're dealing with, so we'd
   generate a symlink from `/run/secrets/rendered/<foo>` to
   `/run/secrets-for-users/rendered/<foo>`, which required making
   the parent directory of the symlink (`/run/secrets/rendered/`).
3. This breaks sops-nix's assumption that `/run/secrets` either doesn't
   exist, or is a symlink, and you get the symptoms described in
   <https://github.com/Mic92/sops-nix/issues/659>.

Reproducing this in a test was straightforward: just expand our existing
template test to also have a `neededForUsers` secret.

Fixing this was also straightforward: don't render templates during the
`neededForUsers` phase (if we want to add support for `neededForUsers`
templates in the future, that would be straightforward to do, but I
opted not do that here).
2024-11-17 06:19:41 +00:00
Ian
d2bd7f433b Implement darwin module for sops-nix 2024-11-16 09:09:49 +00:00
Jeremy Fleischman
60e1bce199 Add support for restartUnits and reloadUnits for templates
This fixes https://github.com/Mic92/sops-nix/issues/634
2024-11-08 06:34:20 +00:00
Jeremy Fleischman
c9f6b151cc fix: create template.path symlink
This fixes https://github.com/Mic92/sops-nix/issues/653.

Note: `main.go` has been slowly accumulating shared logic between vanilla
"secrets" and "templates". It feels to me like we could DRY up some of
the logic in here by creating some shared "interface" that they both
implement. I opted not to try to tackle that here, though.
2024-11-08 06:07:13 +00:00
Jeremy Fleischman
fe63071416 Improve activation messages about rendered templates
This fixes https://github.com/Mic92/sops-nix/issues/652
2024-11-07 19:49:39 +00:00
Jeremy Fleischman
33f18b404e Rework restart-and-reload to assert more strictly on the activation output
I've reworked the test to assert on the entire output. This allows us to
detect unexpected output without having to write weird "i expect this
random string to *not* show up assertions", which aren't great at
preventing regressions.

I did have to change the code under test a little bit to make it
behavior deterministically (by sorting the files it outputs).

tl;dr: this demonstrates <https://github.com/Mic92/sops-nix/issues/652>
but does not fix it. I will fix it in a subsequent commit.
2024-11-07 19:49:39 +00:00
thomaslepoix
f21c31dadf Emit plain file when key is empty
Co-Authored-By: Slaier <slaier@users.noreply.github.com>
2024-11-06 05:57:58 +00:00
Jeremy Fleischman
aa5caa129b rebase, complete implementation 2024-11-06 04:55:41 +00:00
Jörg Thalheim
bb7d636211 template refactoring 2024-11-06 04:55:41 +00:00
Martijn de Munnik
a4c33bfecb Allow to set uid and gid instead of owner and group. No checks will be performed when uid and gid are set.
```
sops.secrets = {
  sslCertificate = {
    sopsFile = ./secrets.yaml;
    owner = "";
    group = "";
    uid = config.containers."nginx".config.users.users."nginx".uid;
    gid = config.containers."nginx".config.users.groups."nginx".gid;
  };
  sslCertificateKey = {
    sopsFile = ./secrets.yaml;
    owner = "";
    group = "";
    uid = config.containers."nginx".config.users.users."nginx".uid;
    gid = config.containers."nginx".config.users.groups."nginx".gid;
  };
};
```

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2024-10-23 07:38:42 +00:00
Jörg Thalheim
2750ed784e nixos-tests: enable system switch again 2024-10-06 16:02:18 +00:00
r-vdp
d9d781523a Support userborn 2024-09-05 12:42:46 +00:00
Ramses
5db5921e40
Reuse the existing nixpkgs instance for the tests instead of re-importing it (#611)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2024-09-01 14:30:42 +00:00
Janne Heß
b549832718 darwin: Mount hfs+ case-sensitive
sops-nix assumes this is the case since it's the default on linux
2024-05-22 17:51:40 +00:00
Kaede Akino
0cd7cac744 sops-install-secrets: add mount options for darwin 2024-05-22 17:51:40 +00:00
Jörg Thalheim
b94c6edbb8 fix symlink directory not existing 2024-04-18 18:17:04 +02:00
Jörg Thalheim
6b259336bd
Lint fixes (#539)
* fix various additional linter errors

* extend golangci checks
2024-04-18 16:19:26 +02:00
the-furry-hubofeverything
74f03c1a51 Refuse age keyfile paths that are in the nix store 2024-04-18 08:17:46 +00:00
Jörg Thalheim
85d13d5aa4 sops-install-secrets: also write out pubring to make gnupg happy 2024-03-14 15:47:03 +01:00
Jörg Thalheim
a2d9145e98 fix build with new ssh-to-age library 2024-03-14 15:47:03 +01:00
Janik H.
eb7e7f0842 sops-install-secrets: change sops url
downgrade go-crypto again
2024-03-14 15:47:03 +01:00