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/
This commit is contained in:
Louis Opter
2024-10-14 17:06:52 -07:00
committed by Mic92
parent 0bad1c79f4
commit 67c7876629
4 changed files with 255 additions and 123 deletions

View File

@@ -9,7 +9,7 @@ from clan_cli.git import commit_files
from . import sops
from .secrets import update_secrets
from .sops import (
default_admin_key_path,
default_admin_private_key_path,
generate_private_key,
maybe_get_admin_public_key,
)
@@ -23,7 +23,7 @@ def generate_key() -> sops.SopsKey:
print(f"{key.key_type.name} key {key.pubkey} is already set")
return key
path = default_admin_key_path()
path = default_admin_private_key_path()
_, pub_key = generate_private_key(out_file=path)
print(
f"Generated age private key at '{path}' for your user. Please back it up on a secure location or you will lose access to your secrets."
@@ -62,8 +62,9 @@ def register_key_parser(parser: argparse.ArgumentParser) -> None:
parser_generate = subparser.add_parser(
"generate",
description=(
"Generate an age key for the Clan, "
"to use PGP set `SOPS_PGP_FP` in your environment."
"Generate an age key for the Clan, if you already have an age "
"or PGP key, then use it to create your user, see: "
"`clan secrets users add --help'"
),
)
parser_generate.set_defaults(func=generate_command)