AliCloud secrets engine
The AliCloud secrets engine dynamically generates AliCloud access tokens based on RAM policies, or AliCloud STS credentials based on RAM roles. This generally makes working with AliCloud easier, since it does not involve clicking in the web UI. The AliCloud access tokens are time-based and are automatically revoked when the Vault lease expires. STS credentials are short-lived, non-renewable, and expire on their own.
Setup
Most secrets engines must be configured in advance before they can perform their functions. These steps are usually completed by an operator or configuration management tool.
Enable the AliCloud secrets engine:
By default, the secrets engine will mount at the name of the engine. To enable the secrets engine at a different path, use the
-path
argument.Create a custom policy in AliCloud that will be used for the access key you will give Vault. See "Example RAM Policy for Vault".
Create a user in AliCloud with a name like "hashicorp-vault", and directly apply the new custom policy to that user in the "User Authorization Policies" section.
Create an access key for that user in AliCloud, which is an action available in AliCloud's UI on the user's page.
Configure that access key as the credentials that Vault will use to communicate with AliCloud to generate credentials:
Alternatively, the AliCloud secrets engine can pick up credentials set as environment variables, or credentials available through instance metadata. Since it checks current credentials on every API call, changes in credentials will be picked up almost immediately without a Vault restart.
If available, we recommend using instance metadata for these credentials as they are the most secure option. To do so, simply ensure that the instance upon which Vault is running has sufficient privileges, and do not add any config.
Configure a role describing how credentials will be granted.
To generate access tokens using only policies that have already been created in AliCloud:
To generate access tokens using only policies that will be dynamically created in AliCloud by Vault:
Both
inline_policies
andremote_policies
may be used together. However, neither may be used configuring how to generate STS credentials, like so:Any
role_arn
specified must have added "trusted actors" when it was being created. These can only be added at role creation time. Trusted actors are entities that can assume the role. Since we will be assuming the role to gain credentials, theaccess_key
andsecret_key
in the config must qualify as a trusted actor.
Helpful links
Example RAM policy for Vault
While AliCloud credentials can be supplied by environment variables, an explicit
setting in the alicloud/config
, or through instance metadata, the resulting
credentials need sufficient permissions to issue secrets. The necessary permissions
vary based on the ways roles are configured.
This is an example RAM policy that would allow you to create credentials using any type of role:
However, the policy you use should only allow the actions you actually need for how your roles are configured.
If any roles are using inline_policies
, you need the following actions:
"ram:CreateAccessKey"
"ram:DeleteAccessKey"
"ram:AttachPolicyToUser"
"ram:DetachPolicyFromUser"
"ram:CreateUser"
"ram:DeleteUser"
If any roles are using remote_policies
, you need the following actions:
- All listed for
inline_policies
"ram:CreatePolicy"
"ram:DeletePolicy"
If any roles are using role_arn
, you need the following actions:
Usage
After the secrets engine is configured and a user/machine has a Vault token with the proper permission, it can generate credentials.
Generate a new access key by reading from the
/creds
endpoint with the name of the role:The
access_key
andsecret_key
returned are also known is an"AccessKeyId"
and"AccessKeySecret"
, respectively, in the Alibaba's docs.Retrieving creds for a role using a
role_arn
will carry the additional fields ofexpiration
andsecurity_token
, like so:
API
The AliCloud secrets engine has a full HTTP API. Please see the AliCloud secrets engine API for more details.