don't add user to a secret if they already can access the secret

If the user is part of a group we don't need to add them explicitly
This commit is contained in:
Jörg Thalheim
2023-08-09 10:17:11 +02:00
parent 0f32aa79e4
commit 68905fc233
7 changed files with 168 additions and 118 deletions

View File

@@ -138,9 +138,7 @@ def encrypt_file(
folder.mkdir(parents=True, exist_ok=True)
# hopefully /tmp is written to an in-memory file to avoid leaking secrets
with NamedTemporaryFile(delete=False) as dummy_manifest_file, NamedTemporaryFile(
delete=False
) as f:
with sops_manifest(keys) as manifest, NamedTemporaryFile(delete=False) as f:
try:
with open(f.name, "w") as fd:
if isinstance(content, str):
@@ -148,9 +146,7 @@ def encrypt_file(
else:
shutil.copyfileobj(content, fd)
# we pass an empty manifest to pick up existing configuration of the user
args = ["sops", "--config", dummy_manifest_file.name]
for key in keys:
args.extend(["--age", key])
args = ["sops", "--config", str(manifest)]
args.extend(["-i", "--encrypt", str(f.name)])
cmd = nix_shell(["sops"], args)
subprocess.run(cmd, check=True)