The Tanzu Service Mesh API requires that requests be authenticated. You must use a combination of an API token and an access token to authenticate your calls to the Tanzu Service Mesh API.
Think of API tokens as a form of authentication similar to a username and password. Tokens are scoped within your organization for additional security. You can use an API token to interact with the Tanzu Service Mesh REST API by exchanging it for an access token.
An API token is valid for a time-to-live (TTL) period that you specify when you generate the token. The default period is 6 months. After the specified time, to continue using the Tanzu Service Mesh REST API, you must regenerate the token.
After generating an API token, save the token credentials to a safe place. You can then use the API token to obtain access tokens. You can use an access token only for a single operation and within a short period of time. After the access token expires, you can use the API token to obtain a new access token.
Scopes provide a way to control what areas in an organization your token can access, specifically which role in an organization, what services, and the level of permissions.
If you feel that the API token has been compromised, you can revoke the token to prevent any unauthorized access. When you revoke an API token, you lose the ability to perform API calls. However, access tokens obtained from the revoked API token are still valid until their expiration time (30 minutes). You generate a new API token to renew the authorization.
You can regenerate a token at any time. If you regenerate a token, you revoke all instances of the previous token. If you have used the revoked API token, for example, in one of your scripts, you must replace it with the newly generated API token.
For security reasons, after you generate the token, the API Tokens page only displays the name of the token, and not the token credentials. This means that you can no longer reuse the token by copying the credentials from this page.
Access VMware Cloud Services at https://console.cloud.vmware.com/csp/gateway/discovery.
- Generate an API token.
- In the upper-right corner of the VMware Cloud Services Console, click your user name and under User Settings, click My Account.
- On the My Account page, click the API Tokens tab and click Generate a new API token.
- Provide the following information.
- Token Name
Enter a meaningful name for the token.
- Token TTL
Specify how long the token is valid. You can set the token to never expire, but this is a security risk.
- Define Scopes
Define the scopes for the token.
Under Organization Roles, select the organization roles that the token can access.
Under Service Roles, select VMware Tanzu Service Mesh and select the user roles within Tanzu Service Mesh that the token can access.
Select Object ID.
- Click Generate.
A Token Generated dialog box displays the generated token and specifies when the token expires. You can copy, download, and print the token.
- To save the token credentials so you can retrieve them to use later on, click Copy and then paste the token into a file in a safe location.
- Click Continue.
For security reasons, after you generate the token, the API Tokens page displays only the name of the token, and not the token credentials. This prevents a user from reusing the token by copying the credentials from this page.
- To set an environment variable for the API token, run the following command.
export CSP_TOKEN $TOKEN
Where $TOKEN is the generated API token.
- To exchange the API token for an access token, submit the following request.
curl 'https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize' -H 'authority: console.cloud.vmware.com' -H 'pragma: no-cache' -H 'cache-control: no-cache' -H 'accept: application/json, text/plain, */*' --data-raw 'refresh_token=$TOKEN' --compressed'I
Where $TOKEN is the generated API token.
The value of access_token in the response contains the access token.
- Use the received access token in the csp-auth-token header in your calls to the Tanzu Service Mesh REST API.