不同的组织对安全性有不同的要求 和身份验证。保险柜通过提供多个身份验证来反映这一需求 方法。Spring Vault支持多种身份验证机制。

外部化登录凭据

首次访问安全系统称为安全引入。 任何客户端都需要临时或永久凭据才能访问保险柜。外部化凭据 是保持代码高可维护性的良好模式,但存在增加披露的风险。

向任何一方披露登录凭据后,可以登录保险柜并访问以下密钥 是基础角色允许的。选择适当的客户端身份验证和 将凭据注入应用程序需要进行风险评估。

Spring 的 PropertySource 抽象是天作之合 将配置保留在应用程序代码之外。您可以使用系统属性、环境 用于存储登录凭据的变量或属性文件。每种方法都有其自己的属性。 请记住,可以使用适当的方式对命令行和环境属性进行反省 操作系统访问级别。

例 1.外部化到属性文件vault.token
@PropertySource("configuration.properties")
@Configuration
public class Config extends AbstractVaultConfiguration {

    @Override
    public ClientAuthentication clientAuthentication() {
        return new TokenAuthentication(getEnvironment().getProperty("vault.token"));
    }
}
Spring 允许多种方式获得 。使用时,注入过孔不会提供,因为环境 bean 仍在建设中,自动接线将在稍后阶段进行。您的配置类应该实现并获取 from .EnvironmentVaultPropertySource@Autowired Environment environmentEnvironmentApplicationContextAwareEnvironmentApplicationContext

有关在组件和其他属性源中引用属性的示例,请参阅SecurePropertyUsage.java

Spring 允许多种方式获得 。使用时,注入过孔不会提供,因为环境 bean 仍在建设中,自动接线将在稍后阶段进行。您的配置类应该实现并获取 from .EnvironmentVaultPropertySource@Autowired Environment environmentEnvironmentApplicationContextAwareEnvironmentApplicationContext

令牌身份验证

令牌是保险柜中身份验证的核心方法。 令牌身份验证需要提供静态令牌。

令牌身份验证是默认身份验证方法。 如果令牌被意外披露,它将获得对 Vault 的访问权限,并且 可以访问目标客户端的机密。

通常,令牌身份验证用于创建和续订令牌的方案 外部(如HashiCorp Vault服务代理)。 根据实际设置,您可能希望或可能不希望令牌续订和吊销。 有关 TTL 和令牌吊销的详细信息,请参阅 LifecycleAwareSessionManager

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {
        return new TokenAuthentication("…");
    }

    // …
}

另请参阅:

令牌身份验证是默认身份验证方法。 如果令牌被意外披露,它将获得对 Vault 的访问权限,并且 可以访问目标客户端的机密。

AppId 身份验证

Vault 已弃用 AppId 身份验证。请改用 AppRole 身份验证

保险柜支持由两个难以猜测的令牌组成的 AppId 身份验证。The AppId 默认值是静态配置的。 第二个令牌是 UserId,它是由应用程序确定的部分, 通常与运行时环境有关。IP 地址、Mac 地址或 Docker 容器名称就是一个很好的例子。Spring Vault 支持 IP 地址、Mac 地址和静态用户 ID(例如,通过系统属性提供)。 IP 和 Mac 地址表示为十六进制编码的 SHA256 哈希。spring.application.name

基于 IP 地址的 UserId 使用本地主机的 IP 地址。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {
        AppIdAuthenticationOptions options = AppIdAuthenticationOptions.builder()
                .appId("myapp")
                .userIdMechanism(new IpAddressUserId())
                .build();

        return new AppIdAuthentication(options, restOperations());
    }

    // …
}

从命令行生成 IP 地址 UserId 的相应命令为:

$ echo -n 192.168.99.1 | sha256sum
包括指向不同哈希值的导线换行符 因此,请确保包含标志。echo-n

基于 Mac 地址的 UserId 从 localhost绑定设备。该配置还允许指定 选择正确设备的提示。的值是可选的,可以是接口 名称或接口索引(从 0 开始)。network-interfacenetwork-interface

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        AppIdAuthenticationOptions options = AppIdAuthenticationOptions.builder()
                .appId("myapp")
                .userIdMechanism(new MacAddressUserId())
                .build();

        return new AppIdAuthentication(options, restOperations());
    }

    // …
}

从命令行生成 Mac 地址 UserId 的相应命令为:

$ echo -n 0AFEDE1234AC | sha256sum
Mac 地址指定为大写,不带冒号。 包括指向不同哈希值的导线换行符 因此,请确保包含标志。echo-n

自定义用户 ID

更高级的方法允许您实现自己的 . 此类必须位于类路径上,并且必须实现 界面 和方法。Spring Vault 将获取 UserId 通过每次使用 AppId 进行身份验证时调用 获取令牌。AppIdUserIdMechanismorg.springframework.vault.authentication.AppIdUserIdMechanismcreateUserIdcreateUserId

MyUserIdMechanism.java
public class MyUserIdMechanism implements AppIdUserIdMechanism {

  @Override
  public String createUserId() {

    String userId = …
    return userId;
  }
}
Vault 已弃用 AppId 身份验证。请改用 AppRole 身份验证
包括指向不同哈希值的导线换行符 因此,请确保包含标志。echo-n
Mac 地址指定为大写,不带冒号。 包括指向不同哈希值的导线换行符 因此,请确保包含标志。echo-n

AppRole 身份验证

AppRole 允许计算机 身份验证,类似于已弃用的(自 Vault 0.6.1 起)AppId 身份验证。 AppRole 身份验证由两个难以猜测的(机密)令牌组成:RoleId 和 SecretId。

Spring Vault 通过仅提供任一 RoleId 来支持 AppRole 身份验证 或与提供的 SecretId 一起从 Vault 获取 RoleId/SecretId (带响应展开的推拉模式)。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
                .roleId(RoleId.provided("…"))
                .secretId(SecretId.wrapped(VaultToken.of("…")))
                .build();

        return new AppRoleAuthentication(options, restOperations());
    }

    // …
}

Spring Vault 还支持完全拉取模式:如果未提供 RoleId 和 SecretId, Spring Vault 将使用角色名称和初始令牌检索它们。这 初始令牌可能与 TTL 和使用限制相关联。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        VaultToken initialToken = VaultToken.of("…");
        AppRoleAuthenticationOptions options = AppRoleAuthenticationOptions.builder()
                .appRole("…")
                .roleId(RoleId.pull(initialToken))
                .secretId(SecretId.pull(initialToken))
                .build();

        return new AppRoleAuthentication(options, restOperations());
    }

    // …
}

AWS-EC2 身份验证

aws-ec2 身份验证后端提供安全引入机制 对于 AWS EC2 实例,允许自动检索文件库 令 牌。与大多数Vault身份验证后端不同,此后端 不需要首次部署,也不需要设置对安全敏感的配置 凭据(令牌、用户名/密码、客户端证书等)。 相反,它将 AWS 视为受信任的第三方,并使用 加密签名的动态元数据信息,唯一 表示每个 EC2 实例。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {
        return new AwsEc2Authentication(restOperations());
    }

    // …
}

默认情况下,AWS-EC2 身份验证允许 nonce 遵循 首次使用信任 (TOFU) 原则。任何意外的一方 获取对 PKCS#7 标识元数据可以进行身份验证的访问权限 反对 Vault。

在第一次登录期间,Spring Vault 会生成一个随机数 它存储在实例 ID 旁边的身份验证后端。 重新身份验证需要发送相同的随机数。任何其他 party 没有随机数,可以在 Vault 中发出警报 进一步调查。

随机数保存在内存中,并在应用程序重新启动期间丢失。

AWS-EC2 身份验证角色是可选的,是 AMI 的默认角色。 您可以通过设置 它在.AwsEc2AuthenticationOptions

AWS-IAM 身份验证

aws 身份验证后端允许使用现有 AWS IAM 凭证进行文件库登录。

AWS IAM 身份验证创建一个签名的 HTTP 请求,该请求是 由 Vault 执行,以使用 AWS STS 方法获取签名者的身份。AWSv4 签名需要 IAM 凭证。GetCallerIdentity

可以从任一运行时环境中获取 IAM 凭证 或外部提供。AWS-EC2 等运行时环境, 具有分配的 IAM 委托人的 Lambda 和 ECS 不需要特定于客户端的 配置凭据,但可以从其元数据源获取这些凭据。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        AwsIamAuthenticationOptions options = AwsIamAuthenticationOptions.builder()
                .credentials(new BasicAWSCredentials(…)).build();

        return new AwsIamAuthentication(options, restOperations());
    }

    // …
}
例 2.使用 AWS-EC2 实例配置文件作为凭证源
@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        AwsIamAuthenticationOptions options = AwsIamAuthenticationOptions.builder()
                .credentialsProvider(InstanceProfileCredentialsProvider.getInstance()).build();

        return new AwsIamAuthentication(options, restOperations());
    }

    // …
}

AwsIamAuthentication需要 AWS Java 开发工具包依赖项 () 因为身份验证实施使用 AWS 开发工具包类型进行凭证和请求签名。com.amazonaws:aws-java-sdk-core

您可以通过 配置身份验证。AwsIamAuthenticationOptions

另请参阅:

Azure (MSI) 身份验证

azure auth 后端提供安全的引入机制 对于 Azure VM 实例,允许自动检索保管库 令 牌。与大多数Vault身份验证后端不同,此后端 不需要首次部署,也不需要设置对安全敏感的配置 凭据(令牌、用户名/密码、客户端证书等)。 相反,它将 Azure 视为受信任的第三方,并使用 托管服务标识和实例元数据信息可以 绑定到虚拟机实例。

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        AzureMsiAuthenticationOptions options = AzureMsiAuthenticationOptions.builder()
                    .role(…).build();

        return new AzureMsiAuthentication(options, restOperations());
    }

    // …
}

Azure 身份验证需要有关 VM 环境的详细信息(订阅 ID、 资源组名称、VM 名称)。这些详细信息可以通过 进行配置。 如果未配置,则查询 Azure 的实例元数据服务 获取这些详细信息。AzureMsiAuthenticationOptionsBuilderAzureMsiAuthentication

另请参阅:

GCP-GCE 身份验证

gcp 身份验证后端允许使用现有的 GCP (Google Cloud Platform) IAM 和 GCE 凭证登录保险柜。

GCP GCE(Google Compute Engine)身份验证以 服务帐户的 JSON Web 令牌 (JWT)。Compute Engine 实例的 JWT 使用实例标识从GCE元数据服务中获取。 此 API 创建可用于确认实例身份的 JSON Web 令牌。

与大多数Vault身份验证后端不同,此后端 不需要首次部署,也不需要设置对安全敏感的配置 凭据(令牌、用户名/密码、客户端证书等)。 相反,它将 GCP 视为受信任的第三方,并使用 加密签名的动态元数据信息,唯一 表示每个 GCP 服务帐号。

您可以通过 配置身份验证。GcpComputeAuthenticationOptions

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        GcpComputeAuthenticationOptions options = GcpComputeAuthenticationOptions.builder()
				.role(…).build();

		GcpComputeAuthentication authentication = new GcpComputeAuthentication(options,
				restOperations());
    }

    // …
}

另请参阅:

GCP-IAM 身份验证

gcp 身份验证后端允许使用现有的 GCP (Google Cloud Platform) IAM 和 GCE 凭证登录保险柜。

GCP IAM 身份验证以 JSON Web 令牌 (JWT) 的形式创建签名 对于服务帐户。服务帐户的 JWT 由下式获取 调用 GCP IAM 的 projects.serviceAccounts.signJwt API。调用方根据 GCP IAM 进行身份验证 并因此证明其身份。此保险柜后端将 GCP 视为受信任的第三方。

可以从任一运行时环境中获取 IAM 凭证 或作为e.g. JSON外部提供。JSON 是首选形式,因为它 携带调用所需的项目 ID 和服务帐户标识符。projects.serviceAccounts.signJwt

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        GcpIamCredentialsAuthenticationOptions options = GcpIamCredentialsAuthenticationOptions.builder()
				.role(…).credential(GoogleCredentials.getApplicationDefault()).build();

		GcpIamCredentialsAuthentication authentication = new GcpIamCredentialsAuthentication(options,
				restOperations());
    }

    // …
}

GcpIamCredentialsAuthenticationOptions需要 Google Cloud Java SDK 依赖项 () 因为身份验证实现使用 Google API 进行凭据和 JWT 签名。com.google.cloud:google-cloud-iamcredentials

您可以通过 配置身份验证。GcpIamCredentialsAuthenticationOptions

Google 凭据需要 OAuth 2 令牌来维护令牌生命周期。所有 API 是同步的,因此不支持哪个是 被动使用是必需的。GcpIamCredentialsAuthenticationAuthenticationSteps
GcpIamCredentialsAuthentication使用 IAM 凭证 API,并且是使用 已弃用的 IAM API 替换已弃用的 for the deprecated API。GcpIamAuthentication

另请参阅:

Google 凭据需要 OAuth 2 令牌来维护令牌生命周期。所有 API 是同步的,因此不支持哪个是 被动使用是必需的。GcpIamCredentialsAuthenticationAuthenticationSteps
GcpIamCredentialsAuthentication使用 IAM 凭证 API,并且是使用 已弃用的 IAM API 替换已弃用的 for the deprecated API。GcpIamAuthentication

PCF 身份验证

pcf 身份验证后端允许 PCF 实例的 Vault 登录。 它利用 PCF 的应用和容器身份保证

PCF身份验证使用实例密钥和证书创建由Vault验证的签名。 如果签名匹配,并且可能绑定的组织/空间/应用程序 ID 匹配,保险柜会颁发适当范围的令牌。

实例凭证可从 和 变量 的文件中获得。CF_INSTANCE_CERTCF_INSTANCE_KEY

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        PcfAuthenticationOptions options = PcfAuthenticationOptions.builder()
                .role(…).build();

        PcfAuthentication authentication = new PcfAuthentication(options,
                restOperations());
    }

    // …
}

PcfAuthenticationOptions需要 BouncyCastle 库来创建 RSA-PSS 签名。

您可以通过 配置身份验证。PcfAuthenticationOptions

另请参阅:

TLS 证书身份验证

身份验证后端允许使用 SSL/TLS 客户端进行身份验证 由 CA 签名或自签名的证书。cert

若要启用身份验证,需要:cert

  1. 使用 SSL,请参阅 [vault.client-ssl]

  2. 配置包含客户机的 Java 证书和私钥Keystore

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        ClientCertificateAuthenticationOptions options = ClientCertificateAuthenticationOptions.builder()
                .path(…).build();

        return new ClientCertificateAuthentication(options, restOperations());
    }

    // …
}

Cubbyhole 身份验证

Cubbyhole 身份验证使用 Vault 基元提供安全身份验证 工作流。Cubbyhole 身份验证使用令牌作为主要登录方法。 临时令牌用于从 Vault 的 Cubbyhole 秘密后端。登录令牌的生存期通常较长,并且用于 与 Vault 交互。可以从包装的登录令牌中检索 响应或来自该部分。data

创建包装的令牌

用于创建令牌的响应包装需要 Vault 0.6.0 或更高版本。
例 3.装箱和存储令牌
$ vault token-create -wrap-ttl="10m"
Key                            Value
---                            -----
wrapping_token:                397ccb93-ff6c-b17b-9389-380b01ca2645
wrapping_token_ttl:            0h10m0s
wrapping_token_creation_time:  2016-09-18 20:29:48.652957077 +0200 CEST
wrapped_accessor:              46b6aebb-187f-932a-26d7-4f3d86a68319
例 4.包装的令牌响应用法
@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions
                .builder()
                .initialToken(VaultToken.of("…"))
                .wrapped()
                .build();

        return new CubbyholeAuthentication(options, restOperations());
    }

    // …
}

使用存储的令牌

例 5.装箱和存储令牌
$ vault token create
Key                    Value
---                    -----
token                  f9e30681-d46a-cdaf-aaa0-2ae0a9ad0819
token_accessor         4eee9bd9-81bb-06d6-af01-723c54a72148
token_duration         0s
token_renewable        false
token_policies         [root]

$ vault token create -use-limit=2 -orphan -no-default-policy -policy=none
Key                    Value
---                    -----
token                  895cb88b-aef4-0e33-ba65-d50007290780
token_accessor         e84b661c-8aa8-2286-b788-f258f30c8325
token_duration         0s
token_renewable        false
token_policies         [none]

$ export VAULT_TOKEN=895cb88b-aef4-0e33-ba65-d50007290780
$ vault write cubbyhole/token token=f9e30681-d46a-cdaf-aaa0-2ae0a9ad0819
例 6.存储的令牌响应使用情况
@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions
                .builder()
                .initialToken(VaultToken.of("…"))
                .path("cubbyhole/token")
                .build();

        return new CubbyholeAuthentication(options, restOperations());
    }

    // …
}

剩余TTL/可续订性

从与非零 TTL 关联的 Cubbyhole 检索到的令牌在 令牌创建时间。该时间不一定与应用程序相同 启动。为了补偿初始延迟,Cubbyhole 身份验证执行 自行查找与非零 TTL 关联的令牌,以检索剩余的 TTL。 Cubbyhole 身份验证不会在没有 TTL 的情况下自行查找包装的令牌,因为 零 TTL 表示没有关联的 TTL。

未包装的代币不会提供有关可续订性和 TTL 的详细信息,只需 检索令牌。自我查找将查找可续订性和剩余的 TTL。

另请参阅:

用于创建令牌的响应包装需要 Vault 0.6.0 或更高版本。

JWT 身份验证

配置 JWT 身份验证需要令牌或 JWT 供应商。 您可以通过 配置身份验证。JwtAuthenticationOptions

在Vault端,您可以通过启用JWT身份验证后端并创建角色来配置JWT后端。 您可以使用 ,也可以配置 JWT 后端。oidc_discovery_urljwks_urljwt_validation_pubkeys

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        JwtAuthenticationOptions options = JwtAuthenticationOptions.builder()
                .role(…).jwt(…).path(…).build();

        return new JwtAuthentication(options, restOperations());
    }

    // …
}

另请参阅:

Kubernetes 身份验证

Vault 支持自 0.8.3 起使用 Kubernetes 令牌的基于 kubernetes 的身份验证。

使用 Kubernetes 身份验证需要 Kubernetes 服务帐户令牌, 通常安装在 . 该文件包含读取并发送到 Vault 的令牌。 Vault 在登录期间使用 Kubernetes 的 API 验证其有效性。/var/run/secrets/kubernetes.io/serviceaccount/token

配置 Kubernetes 身份验证至少需要提供角色名称:

@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        KubernetesAuthenticationOptions options = KubernetesAuthenticationOptions.builder()
                .role(…).jwtSupplier(…).build();

        return new KubernetesAuthentication(options, restOperations());
    }

    // …
}

您可以通过 配置身份验证。KubernetesAuthenticationOptions

另请参阅:

用户名/密码身份验证

用户名/密码通常是最终用户身份验证方案。 多个保险柜身份验证后端支持使用用户名和密码:

  • 用户名和密码 (userpass)

  • LDAP (ldap)

  • Okta(,支持额外的基于时间的一次性令牌)okta

  • 半径 (radius)

UserPasswordAuthenticationOptions可以与上述所有身份验证后端一起使用,因为登录 API 在所有机制中都是相似的。 请确保在配置时使用适当的身份验证挂载路径。UserPasswordAuthenticationOptions

例 7.配置UserPasswordAuthentication
@Configuration
class AppConfig extends AbstractVaultConfiguration {

    // …

    @Override
    public ClientAuthentication clientAuthentication() {

        UserPasswordAuthenticationOptions options = UserPasswordAuthenticationOptions.builder()
                .username(…).password(…).build();

        return new UserPasswordAuthentication(options, restOperations());
    }

    // …
}

另请参阅:

身份验证步骤

ClientAuthentication对象描述身份验证流程并执行实际的身份验证 身份验证步骤。预先组合的身份验证易于使用和配置 与同步执行的紧密绑定。

身份验证方法的组成和重用常见步骤,例如发布登录 不打算将有效负载加载到 Vault 或从 HTTP 源检索身份验证输入 与对象。ClientAuthentication

身份验证步骤提供常见身份验证活动的可重用性。 通过以下方式创建的步骤描述了功能中的身份验证流 样式将实际的身份验证执行留给特定的执行程序。AuthenticationSteps

例 8.存储的令牌身份验证流。
AuthenticationSteps.just(VaultToken.of(…));                              (1)
1 仅从 .AuthenticationStepsVaultToken

可以从单个输入创建单步身份验证流。流声明 多个身份验证步骤以 或 开头,提供 身份验证状态对象,可用于映射或发布到 Vault 进行登录。SupplierHttpRequest

例 9.AppRole 身份验证流程
AuthenticationSteps.fromSupplier(                                       (1)

    () -> getAppRoleLogin(options.getRoleId(), options.getSecretId()))  (2)

    .login("auth/{mount}/login", options.getPath());                    (3)
1 开始声明接受 . 状态对象类型取决于响应类型,该响应类型可在后续步骤中映射。AuthenticationStepsSupplier<T>Supplier
2 实际实现。 在本例中创建一个。SupplierMap
3 通过将状态对象 () 发布到 Vault 端点以创建 Vault 令牌来执行 Vault 登录。 请注意,模板变量受 URL 转义的影响。Map

身份验证流程需要执行程序来执行实际登录。我们提供两个执行人 对于不同的执行模型:

  • AuthenticationStepsExecutor作为 synchronous 的直接替代品。ClientAuthentication

  • AuthenticationStepsOperator用于反应式执行。

许多都带有静态工厂方法,用于为其特定于身份验证的选项创建:ClientAuthenticationAuthenticationSteps

例 10.同步执行AuthenticationSteps
CubbyholeAuthenticationOptions options = …
RestOperations restOperations = …

AuthenticationSteps steps = CubbyholeAuthentication.createAuthenticationSteps(options);

AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(steps, restOperations);

VaultToken token = executor.login();
1 仅从 .AuthenticationStepsVaultToken
1 开始声明接受 . 状态对象类型取决于响应类型,该响应类型可在后续步骤中映射。AuthenticationStepsSupplier<T>Supplier
2 实际实现。 在本例中创建一个。SupplierMap
3 通过将状态对象 () 发布到 Vault 端点以创建 Vault 令牌来执行 Vault 登录。 请注意,模板变量受 URL 转义的影响。Map

代币生命周期

Vault 的代币可以与生存时间相关联。通过身份验证方法获取的令牌 只要会话处于活动状态,就应使用,并且在应用程序处于活动状态时不应过期。

Spring Vault 为 LifecycleAwareSessionManager 提供了一个会话管理器,该管理器可以续订令牌,直到它到达其终端 TTL,然后执行另一次登录以获取与会话关联的下一个令牌。

根据身份验证方法,登录名可以创建两种令牌:

  • VaultToken:封装实际令牌的通用令牌。

  • LoginToken:与可续订性/TTL 关联的令牌。

身份验证方法(如 TokenAuthentication)只是创建一个不带有任何可续订性/TTL 详细信息的方法。 将对令牌运行自我查找,以从 Vault 中检索可续订性和 TTL。 如果启用了自查找,则会定期续订。请注意,永远不会被撤销,只会被撤销。VaultTokenLifecycleAwareSessionManagerVaultTokenVaultTokenLoginToken

直接创建的身份验证方法(所有基于登录的身份验证方法)已提供设置令牌续订所需的所有详细信息。如果会话管理器关闭,则从登录名获取的令牌将被撤销。LoginTokenLifecycleAwareSessionManager