Skip to main content

Connect an External Secrets Manager

Starting with v7.6.0, HAP Private Deployment can read sensitive settings, such as database passwords, from HashiCorp Vault, Tencent Cloud Secrets Manager (SSM), or Azure Key Vault.

Prerequisites​

  • Before enabling the integration, check the images used in your deployment and apply any required upgrades together.
    The minimum versions are HAP: v7.6.0+, HDP: v1.3.0+, SC: v3.3.0+, and RAG: v1.1.0+.
  • Store sensitive values such as database passwords in the external secrets manager. Set the credentials needed to connect to it as container environment variables. Keep other environment variables in the existing deployment configuration.
  • Verify that the container that reads secrets can reach the selected secrets manager.

Map Secrets to Environment Variables​

Name Conversion​

Secret names from HashiCorp Vault, Tencent Cloud SSM, and Azure Key Vault are converted to uppercase, with hyphens - replaced by underscores _.

  1. The converted name must match ENV_[A-Z0-9_]+ and be a supported environment variable. If the same variable is set in the deployment configuration, the value from the external secrets manager takes precedence.
  2. Tencent Cloud SSM filters credentials by ENV_SSM_SECRET_PREFIX. HAP removes the prefix before converting the name. For example, removing hap-dev- from hap-dev-env-redis-password leaves env-redis-password.
  3. env-redis-password becomes ENV_REDIS_PASSWORD.

HashiCorp Vault​

HAP reads secrets from Vault KV v2 using AppRole or token authentication.

Preparation​

  1. Create a secret in KV v2. For example, add a field named env-redis-password at the hap path under the secret mount. Field values can be strings, numbers, or booleans.

  2. Grant the chosen AppRole or token read access to the target path. Use the following Vault policy for this example.

    path "secret/data/hap" {
    capabilities = ["read"]
    }

Configure HAP​

Add the environment variables for your chosen authentication method to the HAP deployment configuration. The policy uses the API path secret/data/hap. Set ENV_VAULT_KV_PATH to hap, the path relative to the mount.

AppRole Authentication (Recommended)

ENV_SECRET_BACKEND: 'vault'
ENV_VAULT_ADDR: 'https://vault.example.com:8200'
ENV_VAULT_AUTH: 'approle'
ENV_VAULT_ROLE_ID: '<RoleID>'
ENV_VAULT_SECRET_ID: '<SecretID>'
ENV_VAULT_KV_PATH: 'hap'

Each time HAP loads secrets, it logs in with the RoleID and SecretID. After reading the secrets, it attempts to revoke the token issued for that login. Update the deployment configuration before the SecretID expires or reaches its usage limit.

Token Authentication

ENV_SECRET_BACKEND: 'vault'
ENV_VAULT_ADDR: 'https://vault.example.com:8200'
ENV_VAULT_AUTH: 'token'
ENV_VAULT_TOKEN: '<Vault Token>'
ENV_VAULT_KV_PATH: 'hap'

HAP attempts to renew the configured Vault token.

Optional Configuration​

Add the settings you need to the deployment environment variables and replace the example values.

ENV_VAULT_KV_MOUNT: 'kv-hap'
ENV_VAULT_APPROLE_MOUNT: 'hap-approle'
ENV_VAULT_NAMESPACE: 'platform/hap'
ENV_VAULT_CACERT: |
-----BEGIN CERTIFICATE-----
<CA 证书正文>
-----END CERTIFICATE-----
  • The default KV v2 mount is secret. If you use the example mount kv-hap, update the path in the Vault read policy to kv-hap/data/hap.
  • The default AppRole authentication mount is approle. Set ENV_VAULT_APPROLE_MOUNT if you use a different mount.
  • If you use a Vault Enterprise namespace, set ENV_VAULT_NAMESPACE.
  • If you use a private CA, set ENV_VAULT_CACERT to the full PEM certificate. Use | in YAML to preserve the line breaks.

Azure Key Vault​

Preparation​

  1. Use a dedicated vault for each application and environment. Create one secret per setting, with a name such as env-redis-password and the raw value as its contents.
  2. Create an app registration in Microsoft Entra ID. Obtain the directory (tenant) ID, application (client) ID, and client secret Value.
  3. Assign the Key Vault Secrets User role for the target vault to the application's service principal. If you use a legacy access policy, grant the List and Get permissions for secrets. If you use a private endpoint, verify that the container can access the private network and resolve the vault hostname.

Configure HAP​

Add the following environment variables to the deployment configuration.

ENV_SECRET_BACKEND: 'azure-keyvault'
ENV_AZURE_VAULT_URL: 'https://<vault-name>.vault.azure.net'
ENV_AZURE_TENANT_ID: '<tenant-id>'
ENV_AZURE_CLIENT_ID: '<client-id>'
ENV_AZURE_CLIENT_SECRET: '<客户端密钥 Value>'

HAP reads the latest value of each secret whose converted name begins with ENV_. This integration supports Azure public cloud and service principal authentication with a client secret. Before the client secret expires, create a new credential, update the deployment configuration, and recreate the containers. Remove the old credential after verification.

Tencent Cloud SSM​

Preparation​

  1. Create custom text credentials in the target region. Store one raw value per credential. For example, store the Redis password in hap-dev-env-redis-password.
  2. In Cloud Access Management (CAM), grant the identity the ssm:ListSecrets action with Resource set to *. Limit ssm:ListSecretVersionIds and ssm:GetSecretValue to the target credentials. The prefix and tags filter the credentials.

Configure HAP​

Use the API keys of a CAM sub-user with the permissions above. Add the following environment variables to the deployment configuration.

ENV_SECRET_BACKEND: 'tencent-ssm'
ENV_SSM_REGION: 'ap-guangzhou'
ENV_SSM_SECRET_PREFIX: 'hap-dev-'
ENV_SSM_SECRET_ID: '<SecretId>'
ENV_SSM_SECRET_KEY: '<SecretKey>'
# ENV_SSM_TAGS: 'product=hap,env=dev'

Set ENV_SSM_SECRET_PREFIX to match your credential names. The prefix is required and case-sensitive. Tags are optional and use the key=value,key=value format. Keys and values must be nonempty and contain no commas. Each key must be unique.

HAP selects the latest version of each credential by creation time. Startup fails if a matching credential is disabled, has no usable version, or has more than one version with the latest creation time. To restore a previous value, publish it as a new version and recreate the containers.