令牌认证是自动启用的。当启动开发服务器时,输出会显示一个根令牌。Vault CLI从$VAULT_TOKEN环境变量中读取根令牌。根令牌可以在Vault中执行任何操作,因为它被分配了根策略。其中一个功能是创建新的令牌。
vault token create
Key Value
--- -----
token hvs.dkPVP2ASg3mx11XJSixcifCt
token_accessor SCPWThvb7qkB7EgB48OMRxtz
token_duration ∞
token_renewable false
token_policies ["root"]
identity_policies []
policies ["root"]
令牌已创建,输出以键值对的形式描述了此令牌。创建的令牌在此处显示为hvs.dkPVP2ASg3mx11XJSixcifCt。
该令牌是根令牌的子令牌,默认情况下,它会继承其父令牌的策略。
令牌是核心的认证方法。可以使用生成的令牌登录Vault,当提示时,通过复制并粘贴令牌来完成登录。
vault login hvs.dkPVP2ASg3mx11XJSixcifCt
Success! You are now authenticated. The token information displayed below
is already stored in the token helper. You do NOT need to run "vault login"
again. Future Vault requests will automatically use this token.
Key Value
--- -----
token hvs.dkPVP2ASg3mx11XJSixcifCt
token_accessor SCPWThvb7qkB7EgB48OMRxtz
token_duration ∞
token_renewable false
token_policies ["root"]
identity_policies []
policies ["root"]
vault token revoke hvs.dkPVP2ASg3mx11XJSixcifCt
Success! Revoked token (if it existed)