Cloud Foundry (CF) auth method
Note: This engine can use external X.509 certificates as part of TLS or signature validation. Verifying signatures against X.509 certificates that use SHA-1 is deprecated and will no longer be usable without a workaround starting in Vault 1.12. See the deprecation FAQ for more information.
The cf
auth method provides an automated mechanism to retrieve a Vault token
for CF instances. It leverages CF's App and Container Identity Assurance.
At a high level, this works as follows:
- You construct a request to Vault including your
CF_INSTANCE_CERT
, signed by yourCF_INSTANCE_KEY
. - Vault validates that the signature is no more than 300 seconds old, or 60 seconds in the future.
- Vault validates that the cert was issued by the CA certificate you've pre-configured.
- Vault validates that the request was signed by the private key for the
CF_INSTANCE_CERT
. - Vault validates that the
CF_INSTANCE_CERT
application ID, space ID, and org ID presently exist. - If all checks pass, Vault issues an appropriately-scoped token.
Known risks
This authentication engine uses CF's instance identity service to authenticate users to Vault. Because CF makes its CA certificate and private key available to certain users at any time, it's possible for someone with access to them to self-issue identity certificates that meet the criteria for a Vault role, allowing them to gain unintended access to Vault.
For this reason, we recommend that if you enable this auth method, you carefully guard access to the
private key for your instance identity CA certificate. In CredHub, it can be obtained through the
following call: $ credhub get -n /cf/diego-instance-identity-root-ca
.
Take extra steps to limit access to that path in CredHub, whether it be through use of CredHub's ACL system, or through carefully limiting the users who can access CredHub.
Usage
Preparing to configure the plugin
To configure this plugin, you'll need to gather the CA certificate that CF uses to issue each CF_INSTANCE_CERT
,
and you'll need to configure it to access the CF API.
To gain your instance identity CA certificate, in the cf dev environment it can be found using:
In environments containing Ops Manager, it can be found in CredHub. To gain access to CredHub, first install
the PCF command-line utility and authenticate to it
using the metadata
file it describes. These instructions also use jq for
ease of drilling into the particular part of the response you'll need.
Once those steps are complete, get the credentials you'll use for CredHub:
SSH into your Ops Manager VM:
Please note that the above OPS_MGR_URL shouldn't be prepended with https://
.
Log into CredHub with the credentials you obtained earlier:
And view the root certificate CF uses to issue instance identity certificates:
The output to that call will include two certificates and one RSA key. You will need to copy the certificate
under ca: |
and place it into a file on your local machine that's properly formatted. Here's an example of
a properly formatted CA certificate:
An easy way to verify that your CA certificate is properly formatted is using OpenSSL like so:
You will also need to configure access to the CF API. To prepare for this, we will now use the cf command-line tool.
First, while in the directory containing the metadata
file you used earlier to authenticate
to CF, run $ pcf target
. This points the cf
tool at the same place as the pcf
tool. Next,
run $ cf api
to view the API endpoint that Vault will use.
Next, configure a user for Vault to use. This plugin was tested with Org Manager level permissions, but lower level permissions may be usable.
Specifically, the vault
user created here will need to be able to perform the following API calls:
- Method: "GET", endpoint: "/v2/info"
- Method: "POST", endpoint: "/oauth/token"
- Method: "GET", endpoint: "/v2/apps/\$APP_ID"
- Method: "GET", endpoint: "/v2/organizations/\$ORG_ID"
- Method: "GET", endpoint: "/v2/spaces/\$SPACE_ID"
Next, PCF often uses a self-signed certificate for TLS, which can be rejected at first with an error like:
If you encounter this error, you will need to first gain a copy of the certificate that CF is using for the API via:
Here is an example of a real call:
Part of the response will contain a certificate, which you'll need to copy and paste to
a well-formatted local file. Please see ca.crt
above for an example of how the certificate
should look, and how to verify it can be parsed using openssl
. The walkthrough below presumes
you name this file cfapi.crt
.
Walkthrough
After obtaining the information described above, a Vault operator will configure the CF auth method like so:
Once configured, from a CF instance containing real values for the CF_INSTANCE_CERT
and
CF_INSTANCE_KEY
, login can be performed using:
For CF, we do also offer an agent that, once configured, can be used to obtain a Vault token on your behalf.
Enabling mutual TLS with the CF API
The CF API can be configured to require mutual TLS with clients. This plugin supports mutual TLS by setting the
cf_api_mutual_tls_certificate
and cf_api_mutual_tls_key
configuration properties.
The provided certificate must be signed by a certificate authority trusted by the CF API. Obtaining such a certificate depends on the specifics of your deployment of Cloud Foundry.
Maintenance
In testing we found that CF instance identity CA certificates were set to expire in 3 years. Some CF docs indicate they expire every 4 years. However long they last, at some point you may need to add another CA certificate - one that's soon to expire, and one that is currently or soon-to-be valid.
If Vault receives a CF_INSTANCE_CERT
matching any of the identity_ca_certificates
,
the instance cert will be considered valid.
A similar approach can be taken to update the cf_api_trusted_certificates
.
Troubleshooting At-A-Glance
If you receive an error containing x509: certificate signed by unknown authority
, set
cf_api_trusted_certificates
as described above.
If you're unable to authenticate using the CF_INSTANCE_CERT
, first obtain a current copy
of your CF_INSTANCE_CERT
and copy it to your local environment. Then divide it into two
files, each being a distinct certificate. The first certificate tends to be the actual
identity.crt
, and the second one tends to be the intermediate.crt
. Verify each are
properly named and formatted using a command like:
Then, verify that the certificates are properly chained to the ca.crt
you've configured:
This should show a success response. If it doesn't, try to identify the root cause, be it
an expired certificate, an incorrect ca.crt
, or a Vault configuration that doesn't
match the certificates you're checking.
API
The CF auth method has a full HTTP API. Please see the CF Auth API for more details.