Menyimpan data di secret manager eksternal

Menyimpan data di secret manager eksternal

Panduan ini menjelaskan cara menyimpan dan mengelola jenis informasi berikut di layanan penyimpanan rahasia eksternal, Hashicorp Vault, bukan di file override.yaml.

  • Garam Hash AX
  • Redis sandi
  • Kunci enkripsi

Untuk menyimpan jenis informasi lain di Vault, lihat:

Prasyarat

Prosedur

  1. Buat rahasia, kebijakan, dan peran Vault.
    1. Gunakan UI atau API Vault untuk membuat secret dan memberikan izin bagi akun layanan Kubernetes Apigee untuk membaca secret tersebut seperti yang dijelaskan di sini. Rahasia harus terdiri dari kunci dan satu atau beberapa nilai seperti yang ditunjukkan dalam tabel berikut:
      Kunci Rahasia Data Rahasia
      secret/data/apigee/axhashsalt
      {
        "ax-hash-salt": "AX_HASH_SALT_VALUE"
      }
      secret/data/apigee/redis
      {
        "redis-password": "REDIS_PASSWORD_VALUE"
      }
      secret/data/apigee/orgencryptionkeys
      {
        "kmsEncryptionKey": "KMS_ENCRYPTION_KEY_VALUE"
        "kvmEncryptionKey": "KVM_ENCRYPTION_KEY_VALUE"
        "contractEncryptionKey": "CONTRACT_ENCRYPTION_KEY_VALUE"
      }
      secret/data/apigee/envencryptionkeys
      {
        "cacheEncryptionKey": "CACHE_ENCRYPTION_KEY_VALUE"
        "kvmEncryptionKey": "KVM_ENCRYPTION_KEY_VALUE"
        "envKvmEncryptionKey": "ENV_KVM_ENCRYPTION_KEY_VALUE"
        "kmsEncryptionKey": "KMS_ENCRYPTION_KEY_VALUE"
      }
    2. Dalam Vault, buat kebijakan yang memberikan akses ke secret:
      cat axhashsalt-auth-policy.txt
      path "secret/data/apigee/axhashsalt" {
        capabilities = ["read"]
      }
      cat redis-auth-policy.txt
      path "secret/data/apigee/redis" {
        capabilities = ["read"]
      }
      cat orgencryptionkeys-auth-policy.txt
      path "secret/data/apigee/orgencryptionkeys" {
        capabilities = ["read"]
      }
      cat envencryptionkeys-auth-policy.txt
      path "secret/data/apigee/envencryptionkeys" {
        capabilities = ["read"]
      }
      
      vault policy write apigee-axhashsalt-auth axhashsalt-auth-policy.txt
      vault policy write apigee-redis-auth redis-auth-policy.txt
      vault policy write apigee-orgencryptionkeys-auth orgencryptionkeys-auth-policy.txt
      vault policy write apigee-envencryptionkeys-auth envencryptionkeys-auth-policy.txt
      
    3. Buat skrip bernama generate-encoded-sas.sh dengan konten berikut:
      # generate-encoded-sas.sh
      
      ORG=$APIGEE_ORG            # Apigee organization name
      ENVS=$APIGEE_ENV_LIST      # comma separated env names, for example: dev,prod
      
      ORG_SHORT_NAME=$(echo $ORG | head -c 15)
      ENCODE=$(echo -n $ORG | shasum -a 256 | head -c 7)
      ORG_ENCODE=$(echo "$ORG_SHORT_NAME-$ENCODE")
      NAMES="apigee-manager,apigee-redis-default,apigee-redis-envoy-default,apigee-mart-${ORG_ENCODE},apigee-mint-task-scheduler-${ORG_ENCODE}"
      
      for ENV in ${ENVS//,/ }
      do
        ENV_SHORT_NAME=$(echo $ENV | head -c 15)
        ENCODE=$(echo -n $ORG:$ENV | shasum -a 256 | head -c 7)
        ENV_ENCODE=$(echo "$ORG_SHORT_NAME-$ENV_SHORT_NAME-$ENCODE")
        NAMES+=,apigee-runtime-${ENV_ENCODE},apigee-synchronizer-${ENV_ENCODE}
      done
      
      echo $NAMES
      
    4. Jalankan skrip untuk membuat daftar nama akun layanan guna mengikat kebijakan agar:
      chmod +x ./generate-encoded-sas.sh
      ./generate-encoded-sas.sh
      

      Output harus mencantumkan nama akun layanan yang dienkode.

    5. Dengan menggunakan kebijakan tersebut, buat peran Vault yang mengikat akun layanan Apigee yang diperlukan.
      vault write auth/kubernetes/role/apigee-axhashsalt \
      	bound_service_account_names=BOUND_SA_NAMES \
      	bound_service_account_namespaces=APIGEE_NAMESPACE \
      	policies=apigee-axhashsalt-auth \
      	ttl=1m
      
      vault write auth/kubernetes/role/apigee-redis \
      	bound_service_account_names=BOUND_SA_NAMES \
      	bound_service_account_namespaces=APIGEE_NAMESPACE \
      	policies=apigee-redis-auth \
      	ttl=1m
      
      vault write auth/kubernetes/role/apigee-orgencryptionkeys \
      	bound_service_account_names=BOUND_SA_NAMES \
      	bound_service_account_namespaces=APIGEE_NAMESPACE \
      	policies=apigee-orgencryptionkeys-auth \
      	ttl=1m
      
      vault write auth/kubernetes/role/apigee-envencryptionkeys \
      	bound_service_account_names=BOUND_SA_NAMES \
      	bound_service_account_namespaces=APIGEE_NAMESPACE \
      	policies=apigee-envencryptionkeys-auth \
      	ttl=1m
      
      
  2. Membuat objek SecretProviderClass.
    1. Tambahkan secret berikut melalui resource SecretProviderClass. Resource ini memberi tahu driver CSI mengenai penyedia yang harus berkomunikasi saat meminta secret. Tabel berikut menunjukkan nama file (objectNames) yang diharapkan oleh Apigee Hybrid:
      Rahasia Nama file secret yang diharapkan
      Garam Hash Kapak
      • ax-hash-salt
      Redis
      • redis-password
      Kunci Enkripsi Org
      • kmsEncryptionKey
      • kvmEncryptionKey
      • contractEncryptionKey
      Kunci Enkripsi Env
      • kmsEncryptionKey
      • kvmEncryptionKey
      • envKvmEncryptionKey
      • cacheEncryptionKey
    2. Gunakan template SecretProviderClass berikut untuk mengonfigurasi resource ini:
      # axhashsalt-spc.yaml
      
      apiVersion: secrets-store.csi.x-k8s.io/v1
      kind: SecretProviderClass
      metadata:
        name: apigee-axhashsalt-spc
      spec:
        provider: vault
        parameters:
          roleName: apigee-axhashsalt
          vaultAddress: VAULT_ADDRESS
          # "objectName" is an alias used within the SecretProviderClass to reference
          # that specific secret. This will also be the filename containing the secret.
          # Apigee Hybrid expects these exact values so they must not be changed.
          # "secretPath" is the path in Vault where the secret should be retrieved.
          # "secretKey" is the key within the Vault secret response to extract a value from.
          objects: |
            - objectName: "ax-hash-salt"
              secretPath: ""
              secretKey: ""
      
      # redis-spc.yaml
      
      apiVersion: secrets-store.csi.x-k8s.io/v1
      kind: SecretProviderClass
      metadata:
        name: apigee-redis-spc
      spec:
        provider: vault
        parameters:
          roleName: apigee-redis
          vaultAddress: VAULT_ADDRESS
          # "objectName" is an alias used within the SecretProviderClass to reference
          # that specific secret. This will also be the filename containing the secret.
          # Apigee Hybrid expects these exact values so they must not be changed.
          # "secretPath" is the path in Vault where the secret should be retrieved.
          # "secretKey" is the key within the Vault secret response to extract a value from.
          objects: |
            - objectName: "redis-password"
              secretPath: ""
              secretKey: ""
      
      # orgencryptionkeys-spc.yaml
      
      apiVersion: secrets-store.csi.x-k8s.io/v1
      kind: SecretProviderClass
      metadata:
        name: apigee-orgencryptionkeys-spc
      spec:
        provider: vault
        parameters:
          roleName: apigee-orgencryptionkeys
          vaultAddress: VAULT_ADDRESS
          # "objectName" is an alias used within the SecretProviderClass to reference
          # that specific secret. This will also be the filename containing the secret.
          # Apigee Hybrid expects these exact values so they must not be changed.
          # "secretPath" is the path in Vault where the secret should be retrieved.
          # "secretKey" is the key within the Vault secret response to extract a value from.
          objects: |
            - objectName: "kmsEncryptionKey"
              secretPath: ""
              secretKey: ""
            - objectName: "kvmEncryptionKey"
              secretPath: ""
              secretKey: ""
            - objectName: "contractEncryptionKey"
              secretPath: ""
              secretKey: ""
      
      # envencryptionkeys-spc.yaml
      
      apiVersion: secrets-store.csi.x-k8s.io/v1
      kind: SecretProviderClass
      metadata:
        name: apigee-envencryptionkeys-spc
      spec:
        provider: vault
        parameters:
          roleName: apigee-envencryptionkeys
          vaultAddress: VAULT_ADDRESS
          # "objectName" is an alias used within the SecretProviderClass to reference
          # that specific secret. This will also be the filename containing the secret.
          # Apigee Hybrid expects these exact values so they must not be changed.
          # "secretPath" is the path in Vault where the secret should be retrieved.
          # "secretKey" is the key within the Vault secret response to extract a value from.
          objects: |
            - objectName: "cacheEncryptionKey"
              secretPath: ""
              secretKey: ""
            - objectName: "kvmEncryptionKey"
              secretPath: ""
              secretKey: ""
            - objectName: "envKvmEncryptionKey"
              secretPath: ""
              secretKey: ""
            - objectName: "kmsEncryptionKey"
              secretPath: ""
              secretKey: ""
      

      VAULT_ADDRESS adalah endpoint tempat server Vault Anda berjalan. Jika Vault berjalan di cluster dan namespace yang sama dengan Apigee, formatnya umumnya adalah http://vault.APIGEE_NAMESPACE.svc.cluster.local:VAULT_SERVICE_PORT.

    3. Terapkan SecretProviderClasses di atas ke namespace APIGEE_NAMESPACE:
      kubectl -n APIGEE_NAMESPACE apply -f axhashsalt-spc.yaml
      kubectl -n APIGEE_NAMESPACE apply -f redis-spc.yaml
      kubectl -n APIGEE_NAMESPACE apply -f orgencryptionkeys-spc.yaml
      kubectl -n APIGEE_NAMESPACE apply -f envencryptionkeys-spc.yaml
      
  3. Mengaktifkan rahasia eksternal untuk AX Hash Salt.
    1. Dalam file overrides.yaml Anda, tambahkan konfigurasi berikut untuk mengaktifkan penggunaan secret eksternal untuk AX Hash Salt:
      axHashSaltSecretProviderClass: apigee-axhashsalt-spc
    2. Terapkan perubahan dengan mengupgrade diagram Helm org:
      helm upgrade org apigee-org/ \
        --namespace APIGEE_NAMESPACE \
        -f overrides.yaml
  4. Aktifkan rahasia eksternal untuk sandi Redis.
    1. Dalam file overrides.yaml Anda, tambahkan konfigurasi berikut untuk mengaktifkan penggunaan secret eksternal untuk sandi Redis:
      redis:
        auth:
          secretProviderClass: apigee-redis-spc
    2. Kemudian terapkan perubahan dengan mengupgrade diagram operator dan redis dalam urutan berikut:
      helm upgrade operator apigee-operator/ \
        --namespace APIGEE_NAMESPACE \
        -f overrides.yaml
      helm upgrade redis apigee-redis/ \
        --namespace APIGEE_NAMESPACE \
        -f overrides.yaml
      
  5. Mengaktifkan rahasia eksternal untuk kunci enkripsi
    1. Dalam file overrides.yaml Anda, tambahkan konfigurasi berikut untuk mengaktifkan penggunaan rahasia eksternal untuk kunci enkripsi tingkat org:
      encryptionKeySecretProviderClass: apigee-orgencryptionkeys-spc
    2. Terapkan perubahan dengan mengupgrade diagram Helm org:
      helm upgrade org apigee-org/ \
        --namespace APIGEE_NAMESPACE \
        -f overrides.yaml
    3. Dalam file overrides.yaml Anda untuk setiap lingkungan, tambahkan konfigurasi berikut untuk kunci enkripsi khusus env:
      envs:
      - name: ENV_NAME
        encryptionKeySecretProviderClass: apigee-envencryptionkeys-spc
    4. Terapkan perubahan dengan mengupgrade chart Helm env satu kali untuk setiap lingkungan:
      helm upgrade ENV_NAME apigee-env/ \
        --namespace APIGEE_NAMESPACE \
        --set env=ENV_NAME \
        -f overrides.yaml
      

Rollback

Garam Hash Kapak

  1. Dalam file overrides.yaml Anda, hapus konfigurasi yang mengaktifkan penggunaan secret eksternal untuk AX Hash Salt:
    # Comment out or delete the following line:
    # axHashSaltSecretProviderClass: apigee-axhashsalt-spc
  2. Terapkan perubahan dengan mengupgrade diagram Helm org:
    helm upgrade org apigee-org/ \
      --namespace APIGEE_NAMESPACE \
      -f overrides.yaml

Sandi Redis

  1. Dalam file overrides.yaml Anda, hapus konfigurasi yang mengaktifkan penggunaan secret eksternal untuk sandi Redis:
    redis:
      auth:
      # Comment out or delete the following line:
      # secretProviderClass: apigee-redis-spc
  2. Kemudian terapkan perubahan dengan mengupgrade diagram redis dan operator dalam urutan berikut:
    helm upgrade redis apigee-redis/ \
      --namespace APIGEE_NAMESPACE \
      -f overrides.yaml
    helm upgrade operator apigee-operator/ \
      --namespace APIGEE_NAMESPACE \
      -f overrides.yaml
    

Kunci enkripsi

  1. Dalam file overrides.yaml Anda, hapus konfigurasi yang mengaktifkan penggunaan secret eksternal untuk kunci enkripsi env:
    envs:
      - name: ENV_NAME
      # Comment out or delete the following line:
      # encryptionKeySecretProviderClass: apigee-envencryptionkeys-spc
  2. Terapkan perubahan dengan mengupgrade chart Helm env satu kali untuk setiap lingkungan:
    helm upgrade ENV_NAME apigee-env/ \
      --namespace APIGEE_NAMESPACE \
      --set env=ENV_NAME \
      -f overrides.yaml
    
  3. Dalam file overrides.yaml Anda, hapus konfigurasi yang mengaktifkan penggunaan rahasia eksternal untuk kunci enkripsi org:
    # Comment out or delete the following line:
    # encryptionKeySecretProviderClass: apigee-orgencryptionkeys-spc
    
  4. Kemudian, Upgrade chart Helm org:
    helm upgrade org apigee-org/ \
      --namespace APIGEE_NAMESPACE \
      -f overrides.yaml