org.springframework.vault.authentication.KubernetesServiceAccountTokenFile Java Examples

The following examples show how to use org.springframework.vault.authentication.KubernetesServiceAccountTokenFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnvironmentVaultConfiguration.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
protected ClientAuthentication kubeAuthentication() {

		String role = getProperty("vault.kubernetes.role");
		String tokenFile = getProperty("vault.kubernetes.service-account-token-file",
				KubernetesServiceAccountTokenFile.DEFAULT_KUBERNETES_SERVICE_ACCOUNT_TOKEN_FILE);
		String path = getProperty("vault.kubernetes.kubernetes-path",
				KubernetesAuthenticationOptions.DEFAULT_KUBERNETES_AUTHENTICATION_PATH);

		Assert.hasText(role, "Vault Kubernetes authentication: role must not be empty");

		KubernetesJwtSupplier jwtSupplier = new KubernetesServiceAccountTokenFile(tokenFile);

		KubernetesAuthenticationOptionsBuilder builder = KubernetesAuthenticationOptions.builder().role(role)
				.jwtSupplier(jwtSupplier).path(path);

		return new KubernetesAuthentication(builder.build(), restOperations());
	}
 
Example #2
Source File: ClientAuthenticationFactory.java    From spring-cloud-vault with Apache License 2.0 6 votes vote down vote up
private ClientAuthentication kubernetesAuthentication(
		VaultProperties vaultProperties) {

	VaultProperties.KubernetesProperties kubernetes = vaultProperties.getKubernetes();

	Assert.hasText(kubernetes.getRole(),
			"Role (spring.cloud.vault.kubernetes.role) must not be empty");
	Assert.hasText(kubernetes.getServiceAccountTokenFile(),
			"Service account token file (spring.cloud.vault.kubernetes.service-account-token-file) must not be empty");

	KubernetesAuthenticationOptions options = KubernetesAuthenticationOptions
			.builder().path(kubernetes.getKubernetesPath()).role(kubernetes.getRole())
			.jwtSupplier(new KubernetesServiceAccountTokenFile(
					kubernetes.getServiceAccountTokenFile()))
			.build();

	return new KubernetesAuthentication(options, this.restOperations);
}
 
Example #3
Source File: KubernetesClientAuthenticationProvider.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Override
public ClientAuthentication getClientAuthentication(
		VaultEnvironmentProperties vaultProperties,
		RestOperations vaultRestOperations, RestOperations externalRestOperations) {

	VaultEnvironmentProperties.KubernetesProperties kubernetes = vaultProperties
			.getKubernetes();

	Assert.hasText(kubernetes.getRole(), missingPropertyForAuthMethod(
			"kubernetes.role", AuthenticationMethod.KUBERNETES));
	Assert.hasText(kubernetes.getServiceAccountTokenFile(),
			missingPropertyForAuthMethod("kubernetes.service-account-token-file",
					AuthenticationMethod.KUBERNETES));

	KubernetesAuthenticationOptions options = KubernetesAuthenticationOptions
			.builder().path(kubernetes.getKubernetesPath()).role(kubernetes.getRole())
			.jwtSupplier(new KubernetesServiceAccountTokenFile(
					kubernetes.getServiceAccountTokenFile()))
			.build();

	return new KubernetesAuthentication(options, vaultRestOperations);
}