bank-vaults / vault-helm-chart

A Helm chart for installing Hashicorp Vault
Apache License 2.0
8 stars 3 forks source link

vault-config.yml contents is converted to JSON and doesn't affect application #15

Closed kirillplis closed 12 months ago

kirillplis commented 12 months ago

Describe the bug: In vault-config Secret, vault-config.yml contents is converted into a JSON format before being encrypted, and being ignored by the application.

vault-config.yml:
  {{ .Values.vault.externalConfig | toPrettyJson | b64enc }}

Expected behaviour: vault-config.yml is kept in YAML format before encription.

vault-config.yml:
  {{ .Values.vault.externalConfig | toYaml | b64enc }}

Steps to reproduce the bug:

  1. Try to change policy name or add another auth method to the externalConfig block:

    #   value: /etc/gcp/service-account.json
    externalConfig:
    # Allows creating policies in Vault which can be used later on in roles
    # for the Kubernetes based authentication.
    # See https://www.vaultproject.io/docs/concepts/policies.html for more information.
    policies:
      - name: test_allow_secrets
        rules: path "secret/*" {
          capabilities = ["create", "read", "update", "delete", "list"]
          }
    auth:
      - type: kubernetes
        # Allows creating roles in Vault which can be used later on for the Kubernetes based
        # authentication.
        # See https://www.vaultproject.io/docs/auth/kubernetes.html#creating-a-role for
        # more information.
        roles:
          # Allow every pod in the default namespace to use the secret kv store
          - name: default
            bound_service_account_names: default
            bound_service_account_namespaces: default
            policies: allow_secrets
            ttl: 1h
    secrets:
      - path: test-secret
        type: kv
        description: General secrets.
        options:
          version: 2

    This step should produce no changes to the policies/secrets/auth configuration.

  2. Put same contents directly into the vault-config.yml file and observe the changes

    kubectl exec -it vault-0 -n vault -c vault -- sh
    echo YAML_CONFIG > vault/config/vault-config.yml
    cat vault/config/vault-config.yml

    This step should produce desired changes to the policies/secrets/auth configuration.

Environment details:

/kind bug

kirillplis commented 12 months ago

PR https://github.com/bank-vaults/vault-helm-chart/pull/16

akijakya commented 12 months ago

Hi @kirillplis, thank you for using Bank-Vaults!

I agree that vault-config.yml should not be a json based on the file extension 🙂

I don't quite understand step 1. though, as changing the config values in the Helm chart and then upgrading it (which should be a safe thing to do if you use consul or a bucket for storage backend) should result in changing the config just as fine (I tried it with an S3 bucket as storage).

If you'd like to get an even better experience configuring Vault, I would recommend using the vault-operator, which has a reconciliation loop to apply the changes in configuration to Vault provided in a custom resource!

kirillplis commented 12 months ago

Hi @akijakya, thank you for looking into this. I ran another test right now and you are totally correct, it works in json format too. Apparently, my config was off then I tested it, and I made a false conclusion that json format was the issue. I probably fixed the config during my investigation so at the moment I replaced vault-config.yml contents inside the pod with yaml version - it all worked.

Since it's resolved, and PR was merged - I'm closing this issue.