Commit Graph

36 Commits

Author SHA1 Message Date
Hidde Beydals e5653b2ff3 Drop SOPS LocalClient implementation
As patch has been merged upstream, and `keyservice.LocalClient` does
now accept the `KeyServiceServer` interface.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-09 22:02:05 +02:00
Hidde Beydals 36df540a5d decryptor: detect format of Secret data field
This checks the base64 decoded bytes from a Secret field for any of the
marker bytes, thereby allowing data to be encrypted into any format.
Instead of the previous behavior which assumed it to either be YAML or
JSON.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-29 15:26:36 +02:00
Hidde Beydals a7639c68d3 decryptor: detect DockerConfigJsonKey as JSON out
This ensures the Secret field gets formatted back into JSON, instead of
it being detected as binary output.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-29 11:00:44 +02:00
Steven E. Harris 7162f5e6fa
Use Secret generator keys for SOPS format hint
Rather than inspecting the source file name supplied to kustomize's
Secret generator to determine the format of the SOPS-encrypted file
content, instead inspect the Secret key (when supplied separately from
the source file name) as a more reliable heuristic.

Doing so allows kustomization authors to name their SOPS-encrypted
output files with a ".json" extension accurately reflecting the format
in which SOPS writes its encrypted output, even if the encrypted
content itself is not in JSON format.

Signed-off-by: Steven E. Harris <seh@panix.com>
2022-04-26 11:07:17 -04:00
Hidde Beydals f4528fb25d controllers: use own Kustomize FS implementation
For details, see: https://github.com/fluxcd/pkg/pull/262

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-15 15:48:23 +02:00
Hidde Beydals 105ebd9f47 controllers: improve decryptor and add tests
- Refactored recursion while iterating over Kustomization files.
  References of files that have been visited are cached, and not
  visited again. In addition, symlinks are confirmed to not traverse
  outside the working directory.
- Optimized various bits around (un)marshalling (encrypted) data, and
  YAML -> JSON -> YAML roundtrips are prevented where not required.
- Added support for decrypting INI Kustomize EnvSource references using
  the dedicated SOPS store for the format.
- Introduced support for decrypting Kustomize FileSources:
  https://pkg.go.dev/sigs.k8s.io/kustomize@v1.0.2/pkg/types#DataSources

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-14 09:17:43 +02:00
Hidde Beydals 62dafa1baf decryptor: switch Printf to Errorf
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-05 13:07:01 +02:00
Hidde Beydals bf4cefe011 decryptor: mention Secret name in import errors
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-05 12:44:35 +02:00
Hidde Beydals ffdda3f3da sops/azkv: add Token utility type
This adds a new Token type which can be used to configure an
azcore.TokenCredential on a master key. Due to this introduction, the
server only has to go through the AADConfig once.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-05 12:44:35 +02:00
Hidde Beydals dfbeae9487 sops/age: add ParsedIdentities utility type
This adds a new ParsedIdentities type which can be used to parse a set
of age identities just once, instead of parsing them for every Decrypt
request.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-05 12:44:35 +02:00
Hidde Beydals ed49f8427f sops/pgp: add GnuPGHome utility type
This adds a new GnuPGHome type which can be used to create a new
contained GnuPG home directory. The type is self-validating, ensuring
it adheres to e.g. permission rules set out by GnuPG, and allows for
importing keys from armored bytes and files.

Because of this introduction, the decryptor service no longer has to
write data from a Secret to a temporary file, but is instead able to
directly import them into the keyring from the Secret entry's bytes.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-04 23:57:46 +02:00
Hidde Beydals e5c2730342 sops/keyservice: allow config of server via opts
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-04 23:57:46 +02:00
Hidde Beydals 31bfd5a057 sops/keyservice: remove prompt capabilities
The original keyservice implementation was forked from SOPS, keeping
the prompt capabilities intact. However, since the implementations have
started to grow, it is better to remove this capability and resort to
a hardcoded `false` default for the fallback server. As the controller
is never expected to have an interactive TTY/shell.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-04 23:57:46 +02:00
Hidde Beydals 069a1065fc sops/keyservice: properly fallback to default
This solves a regression bug introduced in `v0.22.0`, which caused the
keyservice to not properly fall back to the default for Azure Key Vault
decryption requests.

A couple of nitpicks that I ran into while inspecting the code have
been adressed as well.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-25 18:03:17 +01:00
Hidde Beydals 9f768615a9 Document SOPS Azure Key Vault in spec
This includes a refactor of the other entries, to start moving guides
to the website while containing minimal technical (instructions)
in-spec.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-14 10:29:02 +01:00
Hidde Beydals 369193ee59 sops/azkv: update to SDK including azidentity
This updates to the `github.com/Azure/azure-sdk-for-go` SDK, which is
the (apparent) successor of the previous SDK, and allows for easier
configuration of credentials through the `azidentity` package.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-14 10:28:46 +01:00
Hidde Beydals a72e687607 sops/azkv: refactor initial Azure Keyvault impl
- Ensure key source follows upstream SOPS contracts as closely as
  possible (e.g. `MasterKey` interface).
- Prevent unnecesary FS operations by allowing token creation and
  and authorizer configuration to be factored from file bytes.
- Ensure a limited number of configuration option is taken into
  account, excluding e.g. file path references.
- Ensure server maintains backwards compatibility with previously
  supported "global" Azure configuration, _without_ relying on file
  assumptions and/or inspections (but rather, server configurations).

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-03-14 10:28:46 +01:00
David Quagebeur 343f937e59 sops/azkv: support for credentials via SecretRef
Signed-off-by: David Quagebeur <david.quagebeur@worldline.com>
2022-03-14 10:27:55 +01:00
Soule BA c579e71430
add native support for sops decryption/encryption with Vault
If implemented, the kustomize controller will be able to retrieve a
secret containing a VAULT TOKEN and use it to decrypt the sops encrypted
master key. It will then use it to decrypt the data key and finally use the data
key to decrypt the final data.

Signed-off-by: Soule BA <bah.soule@gmail.com>
2022-01-19 21:59:10 +01:00
Stefan Prodan 4958b9c8ce
Warn when secrets are not decrypted before apply
If decryption is not enabled, SOPS encrypted secrets will fail to apply with a validation error that doesn't give any hints. It's better to exit early and throw an error that tells users to enable decryption.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-11-08 15:58:27 +02:00
Rishabh Bohra b8cebd3838
chore: remove deprecated io/ioutil
Signed-off-by: Rishabh Bohra <rishabhbohra01@gmail.com>
2021-10-29 20:28:25 +05:30
Stefan Prodan c610944139
SOPS: Fix dotenv decryption error reporting
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-10-19 11:10:10 +03:00
Somtochi Onyekwere 84a88d5878 Decrypt dotenv files
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2021-10-17 15:27:04 +01:00
Stefan Prodan 1e01d800c5
Implement reconciliation using server-side apply
Reconciler behaviour:
- Creates an inventory of objects to be applied (persisted in-cluster under `.status.inventory`).
- Applies first custom resource definitions (CRDs) and namespaces, waits for them to register and only then applies the custom resources.
- Validates all resources with server-side dry-run apply (namespaced objects must contain `metadata.namespace`, defaulting to the `default` namespace is no longer supported).
- Reconciles only the resources that drifted.
- Prunes the objects that were previously applied but are missing from the current inventory.
- Emits events for only the resources that where created, configured or deleted.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-09-30 18:34:40 +03:00
Gorka Maiztegi 56739d387b Support decrypting any file format in secret generator
Signed-off-by: Gorka Maiztegi <gmaiztegi@reviewpro.com>
2021-05-31 16:06:05 +02:00
bob.rohan a77ea03ec6 Decrypt base64 encoded SOPS encrypted secrets
Signed-off-by: Bob Rohan <bob.rohan@hodge.co.uk>
2021-04-28 11:54:25 +01:00
Hidde Beydals 8688fd6159 Look for `.agekey` to prevent future collisions
The previous `.txt` is very generic and could have resulted in
collisions when a new encryption format would be introduced in the
future.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-04-01 13:20:17 +02:00
Hidde Beydals b8bdc0c999 Support decrypting using age keys
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-03-31 11:55:44 +02:00
Hidde Beydals c3e1252665 Only GPG import keys with `.asc` extension
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-03-30 13:20:13 +02:00
David J. M. Karlsen 750a45a34b
Avoid promts on import by adding batch flag to gpg
Signed-off-by: David J. M. Karlsen <david@davidkarlsen.com>
2021-02-20 23:36:31 +01:00
Nicolas Lamirault 460eae2a2d
Add: Sops user error
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
2020-12-17 19:07:31 +01:00
Hidde Beydals 6a4bf74cf3 Add safe guards for relative paths
This commit ensures that relative (user configurable) paths never
traverse outside their working directory.

It does _not_ provide protection against path traversal within
`kustomization.yaml` files.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-12-16 12:44:13 +01:00
Stefan Prodan dde74d9ea5
Change copyright to Flux authors
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-27 18:49:02 +02:00
stefanprodan 50104826ae Promote API to v1beta1 2020-09-30 19:10:27 +03:00
Hidde Beydals 07f13e56eb GPG decryption in contained environment 2020-09-02 15:42:02 +02:00
stefanprodan c605ccf6d2 Implement Mozilla SOPS decryption 2020-09-01 15:51:22 +03:00