Commit Graph

223 Commits

Author SHA1 Message Date
Jörg Thalheim
f3512b853a remove nix_shell_legacy 2025-04-16 21:03:58 +02:00
Jörg Thalheim
837789010e rename nix_shell_legacy to nix_shell and run_cmd to nix_shell
Than it's more obvious that we need to migrate.
2025-04-16 18:27:01 +00:00
Brian McGee
aa4fe27e51 feat(clan-cli): support multiple keys for a user 2025-04-09 09:58:58 +00:00
DavHau
ba1ad5bd43 sops: prioritize SOPS_AGE_KEY_FILE over local key
... instead of loading both keys and raise an error

This is important for testing when one wants to override SOPS_AGE_KEY_FILE

New prio: `SOPS_AGE_KEY` > `SOPS_AGE_KEY_FILE` > `~/.config/sops/age/keys.txt`
2025-04-09 08:45:34 +00:00
Jörg Thalheim
be37194b9a sops: fix compatibility with new format
The new format can have null values now.
2025-04-08 17:44:23 +02:00
Jörg Thalheim
d3a1b29c6b make gnupg a dependency of sops
if anything uses a gnupg key, we need the gnupg binary.
Sucks a bit, but at least it makes it work everywhere.
2025-03-25 18:30:18 +01:00
Louis Opter
cd248b69db clan-cli: machines delete: delete the machine's vars and secrets
When a machine is deleted with `clan machines delete`, remove its
vars and legacy secrets, and update any secrets that reference the
machine's key.

This command is a superset of `clan secrets machine delete`, and I am
wondering if we could remove the `clan secrets machine` subcommand,
unless there is an use case for having a machine defined without its
key, and any secrets/vars?

Note:

- This deletes the `ListSecretsOptions` dataclass, as it did not seem to
  bring any value, especially since `list_secrets` was receiving its
  individual members instead of the whole dataclass. We can always bring
  it back if complexity grows to demand it.
2025-03-19 10:53:38 +00:00
Jörg Thalheim
527154070c use pathlib.iterdir() everywhere 2025-03-18 15:34:06 +01:00
Jörg Thalheim
10c89fe9f9 fix only the first generator of each machine beeing re-encrypted 2025-03-11 12:09:00 +01:00
Louis Opter
0c1244ecb6 clan-cli: secrets machines remove: update secrets after removing the key
Quick follow up to PR #2781, this commit does the same kind of logic but
for machines instead of users and groups.

Note that this only affects the `clan secrets machines remove`
sub-command, and that `clan machines delete` still leaves unusable
secrets & vars behind. This can be addressed in a different change.
2025-02-13 03:53:23 +00:00
lassulus
2a8f40e91a clan_cli machines: use Flake instead of FlakeId 2025-02-07 06:26:09 +01:00
Jörg Thalheim
638710818b fix mypy 2025-02-04 04:02:42 +00:00
Louis Opter
48268f7960 clan-cli: do not skip secrets.update_secrets when a group is removed
We need to remove all keys that were in the group from affected secrets.

With this change we now take `group_name` as an argument in
`{add,remove}_member`, which is a little bit more readable than
`group_folder.parent.name`, and helps DRY the code a bit.
2025-02-04 03:13:20 +00:00
Louis Opter
ef442ef316 clan-cli: secrets users add: make sure only one key argument was passed
This is slightly better input validation FWIW.
2025-02-04 03:13:20 +00:00
Louis Opter
81cf521d8c clan-cli: secrets: properly update secrets when an user is removed
Fixes #2659.
2025-02-04 03:13:20 +00:00
Louis Opter
5fc9440a1e clan-cli: secrets: truly catch broken symlinks in collect_keys_for_type 2025-02-04 03:13:20 +00:00
Louis Opter
e2c6b7bffc clan-cli: secrets key generate: fix call to action message
So that it makes sense when an already existing PGP key is specified.
2025-02-04 03:13:20 +00:00
Louis Opter
26d07cf1f5 clan-cli: secrets: commit changes when group members are added or removed 2025-02-04 03:13:20 +00:00
Louis Opter
66a9b22d66 clan-cli: secrets/sops: fix error message in maybe_get_admin_public_key 2025-02-04 03:13:20 +00:00
Jörg Thalheim
3bcbc8fa3d reformat after update 2025-01-14 15:30:29 +01:00
Jörg Thalheim
84086b75a6 don't run sops + editor in a pipe 2025-01-07 14:12:54 +01:00
Jörg Thalheim
f2856cb773 updating groups/machines/users keys now also update vars secrets 2024-12-17 19:24:30 +01:00
Qubasa
6b784f8623 clan-cli: Rework 'clan ssh' command, improve Tor support. 2024-12-13 00:11:18 +01:00
Qubasa
b9091beff9 clan-cli: Replace log.info to machine.info if applicable 2024-12-12 15:36:17 +01:00
DavHau
4e4724f766 secrets: improve error message on wrong age key format 2024-12-04 12:04:07 +07:00
a-kenji
3d4f601c11 pkgs/cli: Fix suggestion after key generation
Fix the suggestion that is given when generating a new key.

Closes: #2537
2024-12-03 10:01:55 +01:00
lassulus
3ae82f3efc *: nix fmt 2024-12-02 15:14:40 +01:00
Qubasa
1f98df96e3 clan-cli: cmd.run now has its options extracted to a dataclass 2024-11-28 15:26:37 +01:00
Louis Opter
93fa2af239 clan-cli: secrets: sops: SOPS_NIX_SECRET is not a sops variable
It's a variable internal to us, and it does not need to be allowed.
2024-11-27 06:27:53 +00:00
Louis Opter
ffe7b9057d clan-cli: secrets: address CR feedback for sops encryption and key handling
- Move public keys collection to a class method on `SopsKey`, and
  implement collection for each key type in `KeyType`, this helps make
  the code more generic ;
- Replace `Operation.__call__` by `run` (`sops.run` if you import the
  entire module), that allows us to dedent the code so that's cool ;
- Fix exception handling when trying to get a in-memory temporary file ;
- Make Executor cuter 😵🪦.
2024-11-27 06:27:53 +00:00
Louis Opter
07cd22393a clan-cli: rebase sops changes on top of vars changes
vars changes in question are from commit: 8b94bc71bc

With this changeset the age specific sops logic that was added is now
generic.

To keep things simple, this changeset modifies `SopsKey` so that
`username` is ignored when comparing different keys. I don't really see
us relying on `username` and this makes `SopsKey` hashable, and usable
in a `set`, which is nice when you check that you have a particular key.
2024-11-27 06:27:53 +00:00
Louis Opter
c266ffce6f clan-cli: secrets: treemft 2024-11-27 06:27:53 +00:00
Louis Opter
f4e621af88 clan-cli: secrets.sops: improve age keys detection
This change allows you to e.g. directly pass `$(age-keygen)` on the
command line.
2024-11-27 06:27:53 +00:00
Louis Opter
775be88a9c clan-cli: filter any sops recipients set in the environment for encryption
This forces sops to use our config file, otherwise if any of the
environment variables set to specify recipients is present then
`--config` will be ignored (see [env_check]).

That's simple enough, still I ended up refactoring how we call sops for
correctness, and to align with its behavior. The code now distinguishes
between public and private keys explicitly. `secrets.decrypt_secret`
does not try to lookup for public and private keys anymore.

With this changeset, some people might have to adjust their environment
as public age and PGP keys will be discovered like sops would do. In
particular if multiple public keys are discovered, then the user will
have to specify which one to use for the clan.

This also makes the following changes:

- try to use `/dev/shm` when swapping a secret (it's what [pass] does
  fwiw);
- alias immediate values for readability;
- remove some float comparison that could never succeed, and use sops'
  exit status instead;
- remove unused function `maybe_get_sops_key`.

[env_check]: 8c567aa8a7/cmd/sops/main.go (L2229)
[pass]: http://passwordstore.org/
2024-11-27 06:27:53 +00:00
Qubasa
1063ac661a clan-cli: Remove tty.py 2024-11-25 20:32:36 +01:00
DavHau
8b94bc71bc vars: allow re-encrypting secrets when recipient keys were added.
When the users of a secret change, when for example a new admin user is added, an error will be thrown when generating vars, prompting the user to pass --fix to re-encrypt the secrets
2024-11-13 18:49:30 +07:00
Louis Opter
4effc0c50e vars: add the user and group options on files
This changeset forwards the ownership control options from sops-nix.
2024-10-23 09:05:53 +00:00
Jörg Thalheim
1666513e91 Revert "Merge pull request 'Revert "Merge pull request 'clan-cli: secrets: Add support for PGP keys with sops-nix' (#2186) from lopter/clan-core:lo-sops-nix-pgp-support into main"' (#2202) from revert into main"
This reverts commit a5496e8db0, reversing
changes made to 9bb1aef245.
2024-10-04 16:36:35 +00:00
Jörg Thalheim
084ebf9edc Revert "Merge pull request 'clan-cli: secrets: Add support for PGP keys with sops-nix' (#2186) from lopter/clan-core:lo-sops-nix-pgp-support into main"
This reverts commit 5668fd05a0, reversing
changes made to dd17fbdc6d.

Reverting for now as Dave's recent change conflicts with this change.
2024-10-04 17:54:29 +02:00
Louis Opter
ab46e3c1e2 Improvements for clan secrets key generate.
I am not sure to understand what `extract_public_key` was for. It seems
like `age-keygen -y` will just work fine for a file like
`extract_public_key` is looking for. Unless someone intentionally made a
file with a comment like that without the private key in it.

Messages are moved to stdout rather being logged. It feels like the
output is meaningful in the first step users are going to take. Also
makes testing easier, as log messages are captured differently than
stdout. The call to add an user is changed to be easier to copy paste
and work whether PGP or age is in use.

A description for the command is added instead of help which does not
seem to be displayed.
2024-10-04 15:36:30 +00:00
Louis Opter
611d8b40f3 Make clan_cli.secrets.sops.SopsKey immutable and remove its __eq__ method
Immutability seems sensible for this type.

There is some ambiguity on how to compare keys, in particular when `user.name == ""`, but the rest matches.
2024-10-04 15:36:30 +00:00
Louis Opter
69b9f1ae23 fix: clan secrets user get dump the user identity correctly 2024-10-04 15:36:30 +00:00
Louis Opter
cf492b15aa Fix key dump in clan secrets key show
```
In [4]: str(Type.AGE)
Out[4]: Type.AGE

In [5]: Type.AGE.name.lower()
Out[5]: age
```
2024-10-04 15:36:30 +00:00
Jörg Thalheim
5d87bc2435 secrets/show: pretty print json 2024-10-04 15:36:30 +00:00
Jörg Thalheim
105e6bd86a secrets: replace Key, key type tuple with SopsKey class 2024-10-04 15:36:30 +00:00
Jörg Thalheim
160fe82576 fix serialisation of SopsKey type 2024-10-04 15:36:30 +00:00
Jörg Thalheim
ca4ff0611c default key type to age and rename to age-key/pgp-key 2024-10-04 15:36:30 +00:00
Jörg Thalheim
4cd4334b1c secrets: do not shadow python builtins 2024-10-04 15:36:30 +00:00
Louis Opter
b2e796145a Fix: use new sops api in clan secrets machines 2024-10-04 15:36:30 +00:00
Louis Opter
7a673ea95f Draft: clan-cli: secrets: Add support for PGP keys with sops-nix
To use a PGP key instead of an age key you can set `SOPS_PGP_FP`. (You
can use `gpg -k --fingerprint --fingerprint` to get your PGP encryption
key fingerprint, remove spaces from it).

The internal manifest file already supported a type field, and so I built
from there.

With those changes, I was able to add my PGP key, and update all my
secrets with it, instead of the age key originally generated:

```
% clan secrets key show | jq
{
  "key": "ADB6276965590A096004F6D1E114CBAE8FA29165",
  "type": "pgp"
}
% clan secrets key update
% for s in $(clan secrets list) ; do clan secrets users add-secret kal-pgp-from-2022-12-to-2024-12 "$s"; done
% for s in $(clan secrets list) ; do clan secrets users remove-secret --debug kal "$s" ; done
```
2024-10-04 15:36:30 +00:00