hcp iam workload-identity-providers create-cred-file
Command: hcp iam workload-identity-providers create-cred-file
The hcp iam workload-identity-providers create-cred-file
command creates a
credential file that allow access authenticating to HCP from a variety of
external accounts.
The generated credential file contains details on how to obtain the credential from the external identity provider and how to exchange them for an HCP access token.
After creating the credential file, the HCP CLI can be authenticated by the
workload by running hcp auth login --cred-file=PATH
where PATH is the path to
the generated credential file.
Usage
Examples
Create a credential file for an AWS workload:
Create a credential file for a GCP workload:
Create a credential file for an Azure workload using a User Managed Identity:
Create a credential file for an Azure workload that has multiple User Managed Identities:
Create a credential file for an Azure workload that is using a Managed Identity to authenticate as a Entra ID Application:
Create a credential file that sources the token from a file:
Create a credential file that sources the token from a file:
Create a credential file that sources the token from an URL:
Create a credential file that sources the token from an URL:
Create a credential file that sources the token from an URL:
Create a credential file that sources the token from an environment variable:
Create a credential file that sources the token from an environment variable:
Positional arguments
WORKLOAD_IDENTITY_PROVIDER_NAME
- The resource name of the provider for which the external identity will be exchanged against using the credential file.
Required flags
--output-file=PATH
- The path to output the credential file.
Optional flags
--aws
- Set if exchanging an AWS workload identity.--azure
- Set if exchanging an Azure workload identity.--azure-client-id=ID
- In the case that the workload has multiple User Assigned Managed Identities, this flag specifies which Client ID should be used to retrieve the Azure identity token.If the workload only has one User Assigned Managed Identity, this flag is not required.
--azure-resource=URI
- The Azure Instance Metadata Service (IMDS) allows retrieving an access token for a specific resource. The audience (aud) claim in the returned token is set to the value of the resource parameter. As such, the azure-resource flag must be set to one of the allowed audiences for the Workload Identity Provider.The typical values for this flag are:
- The Client ID of the User Assigned Managed Identity (UUID)
- The Application ID URI of the Microsoft Entra ID Application
(
api://123-456-678-901
).
For more details on the resource parameter, see the Azure documentation.
--gcp
- Set if exchanging an GCP workload identity.It is assumed the workload identity provider was created with the issuer URI set to
https://accounts.google.com
and the default allowed audiences.--imdsv1
- Set if the AWS instance metadata service is using version 1.--source-env=VAR
- The environment variable name that contains the credential to exchange.--source-file=PATH
- Path to file that contains the credential to exchange.--source-header=KEY=VALUE [Repeatable]
- Headers to send to the URL when obtaining the credential.--source-json-pointer=/PATH/TO/CREDENTIAL
- A JSON pointer that indicates how to access the credential from a JSON. If used with thesource-url
flag, the pointer is used to extract the credential from the JSON response from calling the URL. If used with thesource-file
flag, the pointer is used to extract the credential read from the JSON file. Similarly, if used with thesource-env
flag, the pointer is used to extract the credential from the environment variable whose value is a JSON object.As an example, if the JSON payload containing the credential file is:
You can access the top level access token using the pointer
/access_token
and the nested access token can be accessed using the pointer/nested/access_token
.--source-url=URL
- URL to obtain the credential from.