Creating Vault secrets for LDAP bind credentials
Create Vault secrets for Lightweight Directory Access Protocol (LDAP) bind credentials.
About this task
To use LDAP bind credentials from Vault, create Vault secrets for the LDAP bind distinguished name (DN) and password.
Procedure
-
Create secrets in Vault for LDAP bind credentials as shown in the following example.
vault kv put secret/im-ldap-bind-creds msad-ldap-bind-password="<msad_ldap_bind_password>" msad-ldap-bind-dn="<msad_ldap_bind_dn>"If you need to use multiple LDAP bind credentials from Vault, create a multiple key value pair as shown in the following example:
vault kv put secret/im-ldap-bind-creds msad-ldap-bind-password="<msad_ldap_bind_password>" msad-ldap-bind-dn="<msad_ldap_bind_dn>" openldap-ldap-bind-password="<openldap_ldap_bind_password>" openldap-ldap-bind-dn="<openldap_ldap_bind_dn>" -
Configure Vault to use Kubernetes authentication:
vault auth enable kubernetes -
Configure the Kubernetes authentication method.
If Vault is running in the same Kubernetes cluster, run the following command:
vault write auth/kubernetes/config \ issuer="https://kubernetes.default.svc.cluster.local" \ token_reviewer_jwt="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443" \ kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crtIf Vault is running outside of the Kubernetes cluster, run the following commands to gather the token and theca.crtcertificate from one of the pods, update it in Vault, and help ensure thatvault-csi-provideris running in the cluster.oc exec -n <CSNamespace> -it <some-pod> -- shcat /var/run/secrets/kubernetes.io/serviceaccount/token cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crtvault write auth/kubernetes/config \ issuer="https://kubernetes.default.svc.cluster.local" \ token_reviewer_jwt="<token_content>" \ kubernetes_host="<kuberentes_external_host>" \ kubernetes_ca_cert=<ca_crt_content>` -
Create a policy for IBM Cloud Pak foundational services Identity Management (IM) LDAP.
vault policy write cs-im-ldap-policy - <<EOF # Read-only access to bind credentials path "secret/data/im-ldap-bind-creds" { capabilities = ["read"] } EOF -
Create an
authrole to access the policy. Replace the<CSNamespace>value with a namespace where IBM Cloud Pak foundational services is deployed.Starting with version 4.17.0, use the following command:
vault write auth/kubernetes/role/cs-im-ldap-role \ bound_service_account_names="ibm-iam-operand-restricted,platform-identity-management,platform-identity-provider" \ bound_service_account_namespaces="<CSNamespace>" \ audience="https://kubernetes.default.svc" \ policies="cs-im-ldap-policy" \ ttl=20mFor versions 4.16.0 and earlier, use the following command:
vault write auth/kubernetes/role/cs-im-ldap-role \ bound_service_account_names=ibm-iam-operand-restricted \ bound_service_account_namespaces=<CSNamespace> \ policies=cs-im-ldap-policy \ ttl=20m -
Create a
SecretProviderClassobject for LDAP bind credentials.- Run the following command to create a
SecretProviderClassobject that contains IM LDAP bind credentials information in the foundational services namespace with theauthentication.operator.ibm.com/as-volume: "ldap-bind-cred-vol"andapp.kubernetes.io/part-of: "im"labels. - Replace the
<CSNamespace>value with a namespace where foundational services is deployed. - For the
objectNamevalues, replace<ldap_connection_name>with the LDAP connection name that is created when you configure an LDAP connection with IM.cat << EOF | oc apply -f - apiVersion: secrets-store.csi.x-k8s.io/v1 kind: SecretProviderClass metadata: name: im-ldap-bind-creds-spc namespace: <CSNamespace> labels: authentication.operator.ibm.com/as-volume: "ldap-bind-cred-vol" app.kubernetes.io/part-of: "im" spec: parameters: objects: | - objectName: "<ldap_connection_name>_ldap_bind_pwd" secretPath: "secret/data/im-ldap-bind-creds" secretKey: "msad-ldap-bind-password" - objectName: "<ldap_connection_name>_ldap_bind_dn" secretPath: "secret/data/im-ldap-bind-creds" secretKey: "msad-ldap-bind-dn" roleName: cs-im-ldap-role vaultAddress: 'http://vault.hashicorp-vault:8200' provider: vault EOF - After the secret provider classes are created, update the IM authentication custom resource (CR) by setting the
useSecretsStoreCSIvalue totrue. Then, the IM operator picks theSecretProviderClassobjects, mounts them into IM operand pods, and uses LDAP bind credentials from Vault. After theSecretProviderClassobjects are present in the cluster, updated volume and volume mounts appear.- This example shows the volume after the
SecretProviderClassobjects are present in the cluster.- name: ldap-bind-cred-vol csi: driver: secrets-store.csi.k8s.io readOnly: true volumeAttributes: secretProviderClass: im-ldap-bind-creds-spc - This example shows volume mounts after the
SecretProviderClassobjects are present in the cluster.- name: ldap-bind-cred-vol mountPath: /opt/ibm/vault/ldap-bind-cred
- This example shows the volume after the
- When an LDAP connection is created with an API, and you want to use bind DN and a password from Vault, omit the
"ldap_binddn"and"ldap_bindpassword"parameters from theidp_configconfiguration and include"ldap_bindfromvault": truein theidp_configconfiguration. - When an LDAP connection is created with the UI, and the
useSecretsStoreCSIvalue is set totrueon the Authentication CR, from Connection details, you can select Use vault for bind DN and password.
- Run the following command to create a