Commit Graph

81 Commits

Author SHA1 Message Date
Jonathan Thiessen
ea7cfc350a Add dependent vars generator dynamic validation test 2025-03-30 04:33:30 +00:00
Louis Opter
546ed03a90 clan-cli: tests: call SopsSetup.init while setting up fixtures
We do this by introducing `flake_with_sops` fixture, that calls the
init method ahead of the test. We did not want to do this in the `flake`
fixture since not all tests using the `flake` fixture need to have sops
setup.
2025-03-19 10:53:38 +00:00
Louis Opter
b52ec05497 clan-cli: don't try to delete a dir that doesn't exist in the pass vars backend
Do not crash in `delete_store`, if the machine has no vars, or the store
has been deleted already.
2025-03-19 10:53:38 +00:00
Jörg Thalheim
10c89fe9f9 fix only the first generator of each machine beeing re-encrypted 2025-03-11 12:09:00 +01:00
lassulus
2a8f40e91a clan_cli machines: use Flake instead of FlakeId 2025-02-07 06:26:09 +01:00
a-kenji
cf1a4f805c pkgs/cli: Rename create_file -> persist 2025-02-06 14:59:59 +00:00
a-kenji
da0f792d9e vars/interface: Change prompt.persist default to false
Change `prompt.persist` default to false.
We want a consistent default that is not conditionally dependent on
other values.
This makes communication on how the functionality is used more
consistent and easier understood.
2025-02-04 07:47:22 +00:00
Johannes Kirschbauer
f0d5cad992 Vars/tests: secrets dont raise backend error depending on the previous backend 2025-01-22 09:02:55 +00:00
DavHau
4a9ae3a45f vars: rename createFile -> persist 2025-01-11 04:19:46 +00:00
Johannes Kirschbauer
06869a4d27 API/vars: use string based interfaces to get and set vars to avoid state mutations 2025-01-10 12:06:01 +00:00
Johannes Kirschbauer
ecf37e02f8 API/vars: simplify get/set prompts 2025-01-07 11:09:58 +01:00
Jörg Thalheim
f2856cb773 updating groups/machines/users keys now also update vars secrets 2024-12-17 19:24:30 +01:00
Jörg Thalheim
e978bfdf9a vars/tests: merge test_build_scripts_for_correct_system into test_generate_secret_for_multiple_machines 2024-12-17 17:39:27 +01:00
Jörg Thalheim
792aa8033b merge three prompt type tests into one 2024-12-17 17:39:19 +01:00
Jörg Thalheim
33aa638338 vars: remove duplicate test 2024-12-17 17:21:10 +01:00
Jörg Thalheim
e6addcc879 var: merge migration tests into one 2024-12-17 17:21:10 +01:00
Jörg Thalheim
4f7bd8e485 vars: delete duplicate shared flag test 2024-12-17 17:21:01 +01:00
Jörg Thalheim
047a6722eb clan_cli: merge four var tests into one 2024-12-17 17:21:01 +01:00
DavHau
b64422679e vars: commit files for clan vars set
fixes #2601
2024-12-17 15:56:08 +07:00
DavHau
1cbba05055 build-clan: fix bug where vars generator scripts are built for target system instead of local system 2024-12-16 19:20:17 +07:00
lassulus
f184128433 cli test_vars: make output check less sensible to nix output 2024-12-14 13:42:31 +01:00
Jörg Thalheim
9ad4e4d041 fix clan vars for public vars 2024-12-11 16:39:54 +01:00
DavHau
a5148ede1d vars: add test to ensure shared secrets access after --regenerate
Ensure that a shared secret can still be accessed by all machines that share it, after a 'clan vars generate --regenerate' has been issued
2024-12-11 15:44:30 +07:00
DavHau
9ae5e27c33 vars: add test for shared secret not being regenerated
see https://git.clan.lol/clan/clan-core/issues/2393
2024-12-11 15:14:44 +07:00
lassulus
9129790e5c vars: move ensure_consistent_state into health_check, move into store classes 2024-12-10 11:54:52 +00:00
Jörg Thalheim
621fbd0f83 test_vars: set hostPlatform 2024-12-04 17:25:20 +01:00
DavHau
439cde691f vars: print() -> log.info() 2024-12-04 14:08:50 +07:00
DavHau
a11820b1d6 vars: Improve logging for migration 2024-12-04 12:42:03 +07:00
DavHau
5c5a87d416 vars: rename: invalidation -> validation 2024-11-29 17:23:31 +07:00
DavHau
44e6fe803f vars: make all python tests work in nix sandbox
- generate a flake.lock file for each template by copying the clan-core flake.lock and modifying it

- call nix build with --store for tests inside the sandbox
2024-11-27 14:32:02 +07:00
Jörg Thalheim
c9e80f38ca vars: make interface more type-safe 2024-11-26 17:08:26 +01:00
Jörg Thalheim
39db147e48 test_vars: mock ask function instead of sys.stdin 2024-11-26 11:56:38 +00:00
DavHau
1881d7f0a5 vars: fix migration - secrets end up in public store 2024-11-26 17:02:11 +07:00
DavHau
d4c8b2e4ed vars: implement invalidation mechanism
This adds options `invalidationData` to generators.

`invalidationData` can be used by an author of a generator to signal if a re-generation is required after updating the logic.

Whenever a generator with invalidation data is executed, a hash of that data is stored by the respective public and/or secret backends.

The stored hashes will be checked on future deployments, and a re-generation is triggered whenever a hash doesn't match what's defined in nix.
2024-11-20 16:27:22 +07:00
DavHau
2127c7f5cb vars: add test for 'clan vars get' 2024-11-19 13:32:27 +07:00
DavHau
1d66d32163 tests: improve performance, keep flake.lock between tests
- deprecate fixture generate_flake in favor of class ClanFlake
- allow creating flake templates that can be copied, including their state, like git and lock files, in order to avoid expensive re-initialization
2024-11-18 17:01:58 +07: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
DavHau
33d049915c vars: fix shared dependency was not resolved correctly 2024-10-23 20:43:33 +07:00
DavHau
29f70640ef vars,facts: add sops.defaultGroups to new machines
Prior to this, when initializing new machines, only the current user had access to it's key which prevents other admin users to deploy this machine later
2024-10-10 19:31:03 +07:00
Jörg Thalheim
4655199028 tests: set git author name + email via environment variables 2024-10-09 12:07:58 +02:00
Jörg Thalheim
d2d72e28e8 re-use gpg key across tests 2024-10-09 11:56:41 +02:00
Jörg Thalheim
cfb8df33a1 fix missing hostPlatform in test_vars 2024-10-09 11:56:36 +02:00
DavHau
11c37ebeba vars/keygen: fix + cleanup tests
- generate keys in ./sops instead of ./sops/vars for now
- don't initialize all flakes with sops keys, only generate when needed
- use the new 'clan vars keygen' in tests
2024-10-04 17:25:17 +02:00
DavHau
2a9ced1e26 vars: add 'clan vars keygen' 2024-10-04 16:13:49 +02:00
Jörg Thalheim
27b1aeb827 add temp_dir fixture 2024-10-01 20:54:19 +02:00
DavHau
e49d1f0127 vars/sops: improve shared secrets, switching backend
When a second machine checks for a shared secret, now the exists() call returns negative and only when updating the secrets for that machine, the machine is added to the sops receivers.

Also throw proper errors when the user switches backends without cleaning the files first.
2024-09-20 15:06:54 +02:00
DavHau
0a8b7f38a8 vars: implement migration
Migrating generated files from the facts subsystem to the vars subsystem is now possible.

HowTo:
1. declare `clan.core.vars.generators.<generator>.migrateFact = my_service` where `my_service` refers to a service from `clan.core.facts.services`
2. run `clan vers generate your_machine` or `clan machines update your_machine`

Vars will only be migrated for a generator if:
1. The facts service specified via `migrateFact` does exist
2. None of the vars to generate exist yet
3. All public var names exist in the public facts store
4. All secret var names exist in the secret fact store

If the migration is deemed possible, the generator script will not be executed. Instead the files from the public or secret facts store are read and stored into the corresponding vars store
2024-09-19 17:57:03 +02:00
DavHau
01c833f2bc vars/generate: improve output when vars are updated
fixes #2076

- print old and new value if possible
- also inform the user if something hasn't changed
2024-09-18 16:57:01 +02:00
DavHau
6fc27d402b vars: allow setting a default for values 2024-09-17 21:11:38 +02:00
DavHau
bd79e6aef6 vars: generate proper commit messages
fixes #2126
2024-09-17 20:22:18 +02:00