Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOPS: Decrypt dotenv files used in kustomize secret generator #463

Merged
merged 1 commit into from
Oct 18, 2021

Conversation

somtochiama
Copy link
Member

@somtochiama somtochiama commented Oct 14, 2021

This PR adds support for decrypting dotenv files (encrypted with SOPS) that are used with kustomize secret generator.

Example

Create an env file:

ROUTER_PASSWORD=admin
DB_PASSWORD=admin

Encrypt it with SOPS:

sops --encrypt --in-place podinfo.env

Create a kustomization.yaml that generates an env secret:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: default
secretGenerator:
  - name: env-secret
    envs:
      - podinfo.env

Configure Flux to decrypt the secret before apply:

apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: secrets
  namespace: flux-system
spec:
  decryption:
    provider: sops
    secretRef:
      name: sops-age
  interval: 1m0s
  path: ./secrets
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system

Ref: fluxcd/flux2#779

@stefanprodan stefanprodan added area/sops SOPS related issues and pull requests enhancement New feature or request labels Oct 14, 2021
@stefanprodan stefanprodan changed the title Decrypt dotenv files SOPS: Decrypt dotenv files generated with kustomize Oct 15, 2021
@stefanprodan stefanprodan changed the title SOPS: Decrypt dotenv files generated with kustomize SOPS: Decrypt dotenv files used in kustomize secret generator Oct 15, 2021
@somtochiama somtochiama marked this pull request as ready for review October 15, 2021 14:29
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @somtochiama 🌹

PS. I'll do a followup PR to the API docs and website and add examples for dotenv files.

controllers/kustomization_decryptor.go Outdated Show resolved Hide resolved
controllers/kustomization_decryptor.go Outdated Show resolved Hide resolved
controllers/kustomization_controller.go Outdated Show resolved Hide resolved
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@stefanprodan stefanprodan merged commit e0be92e into fluxcd:main Oct 18, 2021
@danufr
Copy link

danufr commented Dec 20, 2021

Guys, is this functionality works only with secretGenerator or with configMapGenerator too?

@kingdonb
Copy link
Member

kingdonb commented Dec 20, 2021

@danufr I have not tried it, but from reading:

https://github.com/fluxcd/kustomize-controller/pull/463/files#diff-efcb6cc0bdb62e54699cd11dfb9fbbab9f2ae76ada019846e853667ab29c86b0R216-R218

I would say it looks to me like this feature only works with secretGenerator. The decryptDotEnvFiles function does not go and decrypt every .env.enc with a wildcard everywhere in the Kustomization path, it only decrypts those that are in the path of an actual secretGenerator (and then, only if the file contains a string that matches the format of an encrypted data file.)

I think there's a principled stance that it should not work for configmap generators either, as it would be improper to take secret data that was stored as encrypted and store it in a non-secret "configmap" which is not handled as a secret, then provide access to folks who are not authorized to read secrets... this is a way for privilege to escalate and information to leak out from those securely encrypted sources. Anyway, at present the code paths are such that I think it will definitely not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sops SOPS related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants