fluxcd / flux2

Open and extensible continuous delivery solution for Kubernetes. Powered by GitOps Toolkit.
https://fluxcd.io
Apache License 2.0
6.3k stars 588 forks source link

SOPS in-cluster decryption with GCP-KMS from a non-GKE Kubernetes cluster (without workload identity) #1232

Open anthony-pastor opened 3 years ago

anthony-pastor commented 3 years ago

Hi, We wanted to use SOPS in-cluster decryption with GCP-KMS from a non-GKE Kubernetes cluster (without workload identity). Unfortunately the documentation currently doesn't provide guides to implement this very specific setup.

As GCP-KMS uses Application Default Credentials we found a way to have a GCP-KMS encrypted file beeing in-cluster decrypted with these steps:

        - mountPath: /tmp/flux/fluxcd_gsa_keyfile.json
          name: fluxcd-leo-google-sa-secret
          subPath: fluxcd_gsa_keyfile.json
      - name: fluxcd-leo-google-sa-secret
        secret:
          secretName: fluxcd-leo-google-sa-secret

It would be helpful to add all these informations in the documentation. Thanks.

DARK-art108 commented 3 years ago

Can I work on this issue?

DARK-art108 commented 3 years ago

I want to know more in which place in documentation these all Information need to be added!

stefanprodan commented 3 years ago

@DARK-art108 here is the SOPS doc: https://github.com/fluxcd/website/blob/main/content/en/docs/guides/mozilla-sops.md#google-cloud

PS. Users shouldn't edit the kustomize-controller deployment manifest, instead they should create a kustomize patch before bootstrap, here are the docs for that: https://fluxcd.io/docs/installation/#customize-flux-manifests

DARK-art108 commented 3 years ago

Under what header I should start adding these details in SOPS docs! Please Explain!

tvories commented 1 year ago

Has anyone had any updated success with this? I am still unable to get this working, and I have followed @anthony-pastor guide.

Namely, how can I edit the kustomize-controller in a git-ops way, rather than editing the current deployment?

tvories commented 1 year ago

OK, I was able to get this working in my deployment. First, you have to update the flux Kustomization to patch the credential. This assumes you have already created a service account with the proper permissions:

---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: manage-flux
  namespace: flux-system
spec:
  interval: 10m0s
  path: ./manifests/install
  prune: true
  wait: true
  sourceRef:
    kind: GitRepository
    name: flux

  patches:
    # GCP KMS: https://github.com/fluxcd/kustomize-controller/blob/5056fbf6ac5c48de434680042c5979fa79a5de04/docs/spec/v1beta2/kustomization.md#gcp-kms
    - target:
        kind: Deployment
        name: kustomize-controller
      patch: |
        - op: add
          path: /spec/template/spec/containers/0/env/-
          value:
            name: GOOGLE_APPLICATION_CREDENTIALS
            value: /var/gcp/gcp-flux-sa-credential.json
        - op: add
          path: /spec/template/spec/containers/0/volumeMounts/-
          value:
            mountPath: /var/gcp/gcp-flux-sa-credential.json
            name: fluxcd-google-sa-secret
            subPath: gcp-flux-sa-credential.json
            readOnly: true
        - op: add
          path: /spec/template/spec/volumes/-
          value:
            name: fluxcd-google-sa-secret
            secret:
              secretName: fluxcd-google-sa-secret

That will patch the kustomization-controller deployment to mount the gcp credential to /var/gcp/gcp-flux-sa-credential.json and set the environment variable.