When configuring a Vault storage backend for TLS and providing the parameter value for specifying a Certificate Authority (CA) certificate for validation, it is important to ensure that this certificate is of the X509 PEM encoded format.
Here is an example scenario where the certificate is provided in the incorrect format when configuring the Vault LDAP auth backend.
First, configure the backend:
$ vault write auth/ldap/config \
url="ldaps://ldaps.taco.example.com" \
userattr="samAccountName" \
userdn="OU=_USERS,OU=EXAMPLE_USERS,DC=TACO,DC=example,DC=com" \
groupdn="OU=_GROUPS,OU=EXAMPLE_WIDGETS*,DC=TACO,DC=example,DC=com" \
upndomain="TACO.example.com" \
insecure_tls=false \
starttls=true \
certificate=@ldaps_taco_example_com.crt
The certificate file provided, ldaps_taco_example_com.crt
is actually DER formatted, so when we attempt to make use of it, we will encounter an error from Vault:
$ vault auth -method=ldap username=macy
Password (will be hidden):
Error making API request.
URL: PUT https://vault.taco.example.com:8200/v1/auth/ldap/login/macy
Code: 400. Errors:
* 1 error occurred:
* error connecting to host "ldaps://ldaps.taco.example.com": could not append CA certificate
One means to verify the issue is by examining the backend configuration. If the certificate is properly formatted, its contents will appear as the value for certificate
when we read the backend configuration, like this:
$ vault read auth/ldap/config
Key Value
--- -----
binddn
bindpass
certificate -----BEGIN CERTIFICATE-----
a2VuZ2luZWVyLm5ldIIjc2UxcHBpZnNhZGMwNS5hZHBwLmFkc2tlbmdpbmVlci5u
ZXSCI2xvbnBwaWZzYWRjMDEuYWRwcC5hZHNrZW5naW5lZXIubmV0giNsb25wcGlm
c2FkYzAyLmFkcHAuYWRza2VuZ2luZWVyLm5ldIIjbG9ucHBpZnNhZGMwMy5hZHBw
LmFkc2tlbmdpbmVlci5uZXSCI2xvbnBwaWZzYWRjMDQuYWRwcC5hZHNrZW5naW5l
ZXIubmV0giNsb25wcGlmc2FkYzA1LmFkcHAuYWRza2VuZ2luZWVyLm5ldDAdBgNV
HQ4EFgQUC3zuxf16uRcu2pndccBmlcaGCpQwDQYJKoZIhvcNAQEFBQADggEBAGOw
J1CuWpWC0vCPTTuC/9Tnh3YC8DMAj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x5SIZIHwdCoZDdHjmm2HnDCc
TqDu+o7IWOG5LCQCt6E=
-----END CERTIFICATE-----
deny_null_bind true
discoverdn false
groupattr cn
groupdn OU=_GROUPS,OU=EXAMPLE_WIDGETS*,DC=TACO,DC=example,DC=com
groupfilter (|(memberUid={{.Username}})(member={{.UserDN}})(uniqueMember={{.UserDN}}))
insecure_tls false
starttls true
tls_max_version tls12
tls_min_version tls12
upndomain TACO.example.com
url ldaps://ldaps.taco.example.com
userattr samaccountname
userdn OU=_USERS,OU=EXAMPLE_USERS,DC=TACO,DC=example,DC=com
As you can can observe in the example output, our certificate is present as the value of the certificate
parameter. If you use an improperly formatted certificate, then the value of certificate
will be empty when you read the backend configuration, as in this example:
$ vault read auth/ldap/config
Key Value
--- -----
binddn
bindpass
certificate
deny_null_bind true
discoverdn false
groupattr cn
groupdn OU=_GROUPS,OU=EXAMPLE_WIDGETS*,DC=TACO,DC=example,DC=com
groupfilter (|(memberUid={{.Username}})(member={{.UserDN}})(uniqueMember={{.UserDN}}))
insecure_tls false
starttls true
tls_max_version tls12
tls_min_version tls12
upndomain TACO.example.com
url ldaps://ldaps.taco.example.com
userattr samaccountname
userdn OU=_USERS,OU=EXAMPLE_USERS,DC=TACO,DC=example,DC=com
If you encounter a could not append CA certificate
style error when attempting to authenticate with a TLS configured backend, the first step you should take in troubleshooting is to read/examine the backend configuration; make sure the certificate value is present and not empty.
If the certificate is improperly formatted, it can be either be exported in the proper format, or you can convert it with the openssl
utility. For example, here is what the command line for converting a DER formatted certificate into PEM formatted looks like:
openssl x509 \
-inform der \
-in ldaps_taco_example_com.crt \
-out ldaps_taco_example_com.pem