Changes for 5.0.0 release
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config</artifactId>
|
||||
<version>4.3.1-SNAPSHOT</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -137,6 +137,11 @@
|
||||
<artifactId>google-cloud-secretmanager</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>google-cloud-iamcredentials</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-cloudresourcemanager</artifactId>
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
package org.springframework.cloud.config.server.environment.vault.authentication;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
|
||||
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties;
|
||||
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties.AuthenticationMethod;
|
||||
@@ -27,9 +28,8 @@ import org.springframework.cloud.config.server.environment.vault.SpringVaultClie
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.vault.authentication.ClientAuthentication;
|
||||
import org.springframework.vault.authentication.GcpCredentialSupplier;
|
||||
import org.springframework.vault.authentication.GcpIamAuthentication;
|
||||
import org.springframework.vault.authentication.GcpIamAuthenticationOptions;
|
||||
import org.springframework.vault.authentication.GcpIamCredentialsAuthentication;
|
||||
import org.springframework.vault.authentication.GcpIamCredentialsAuthenticationOptions;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
|
||||
public class GcpIamClientAuthenticationProvider extends SpringVaultClientAuthenticationProvider {
|
||||
@@ -49,45 +49,48 @@ public class GcpIamClientAuthenticationProvider extends SpringVaultClientAuthent
|
||||
|
||||
Assert.hasText(gcp.getRole(), missingPropertyForAuthMethod("gcp-iam.role", AuthenticationMethod.GCP_IAM));
|
||||
|
||||
GcpIamAuthenticationOptions.GcpIamAuthenticationOptionsBuilder builder = GcpIamAuthenticationOptions.builder()
|
||||
GcpIamCredentialsAuthenticationOptions.GcpIamCredentialsAuthenticationOptionsBuilder builder = GcpIamCredentialsAuthenticationOptions
|
||||
.builder()
|
||||
.path(gcp.getGcpPath())
|
||||
.role(gcp.getRole())
|
||||
.jwtValidity(gcp.getJwtValidity());
|
||||
|
||||
if (StringUtils.hasText(gcp.getProjectId())) {
|
||||
builder.projectId(gcp.getProjectId());
|
||||
builder.serviceAccountId(gcp.getProjectId());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(gcp.getServiceAccountId())) {
|
||||
builder.serviceAccountId(gcp.getServiceAccountId());
|
||||
}
|
||||
|
||||
GcpCredentialSupplier supplier = GcpCredentialProvider.getGoogleCredential(gcp);
|
||||
builder.credential(supplier.get());
|
||||
builder.credentials(GcpCredentialProvider.getGoogleCredential(gcp));
|
||||
|
||||
GcpIamAuthenticationOptions options = builder.build();
|
||||
GcpIamCredentialsAuthenticationOptions options = builder.build();
|
||||
|
||||
return new GcpIamAuthentication(options, vaultRestOperations);
|
||||
return new GcpIamCredentialsAuthentication(options, vaultRestOperations);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static class GcpCredentialProvider {
|
||||
|
||||
public static GcpCredentialSupplier getGoogleCredential(VaultEnvironmentProperties.GcpIamProperties gcp) {
|
||||
return () -> {
|
||||
|
||||
public static GoogleCredentials getGoogleCredential(VaultEnvironmentProperties.GcpIamProperties gcp) {
|
||||
try {
|
||||
VaultEnvironmentProperties.GcpCredentials credentialProperties = gcp.getCredentials();
|
||||
if (credentialProperties.getLocation() != null) {
|
||||
return GoogleCredential.fromStream(credentialProperties.getLocation().getInputStream());
|
||||
return GoogleCredentials.fromStream(credentialProperties.getLocation().getInputStream());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(credentialProperties.getEncodedKey())) {
|
||||
return GoogleCredential.fromStream(
|
||||
return GoogleCredentials.fromStream(
|
||||
new ByteArrayInputStream(Base64.getDecoder().decode(credentialProperties.getEncodedKey())));
|
||||
}
|
||||
|
||||
return GoogleCredential.getApplicationDefault();
|
||||
};
|
||||
return GoogleCredentials.getApplicationDefault();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// TODO log
|
||||
return GoogleCredentials.newBuilder().build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class VanillaConfigServerIntegrationTests {
|
||||
ResponseEntity<Environment> response = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/invalid/default", HttpMethod.GET, getV2AcceptEntity(),
|
||||
Environment.class);
|
||||
assertThat(response.getStatusCodeValue()).isEqualTo(500);
|
||||
assertThat(response.getStatusCode().value()).isEqualTo(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ public class VaultEnvironmentRepositoryTests {
|
||||
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application");
|
||||
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
|
||||
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders()).containsEntry("X-Vault-Token", List.of("token"));
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().containsHeader("X-Vault-Token")).isTrue();
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().get("X-Vault-Token")).isEqualTo(List.of("token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,7 +245,8 @@ public class VaultEnvironmentRepositoryTests {
|
||||
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application");
|
||||
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
|
||||
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders()).containsEntry("X-Vault-Token", List.of("token"));
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().containsHeader("X-Vault-Token")).isTrue();
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().get("X-Vault-Token")).isEqualTo(List.of("token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,9 +279,11 @@ public class VaultEnvironmentRepositoryTests {
|
||||
|
||||
vaultEnvironmentRepository(properties).findOne("myapp", null, "lbl");
|
||||
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders()).containsEntry("X-Vault-Namespace",
|
||||
List.of("mynamespace"));
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders()).containsEntry("X-Vault-Token", List.of("token"));
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().containsHeader("X-Vault-Namespace")).isTrue();
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().get("X-Vault-Namespace"))
|
||||
.isEqualTo(List.of("mynamespace"));
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().containsHeader("X-Vault-Token")).isTrue();
|
||||
assertThat(requestHeaderCaptor.getValue().getHeaders().get("X-Vault-Token")).isEqualTo(List.of("token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -63,7 +63,7 @@ import org.springframework.vault.authentication.ClientAuthentication;
|
||||
import org.springframework.vault.authentication.ClientCertificateAuthentication;
|
||||
import org.springframework.vault.authentication.CubbyholeAuthentication;
|
||||
import org.springframework.vault.authentication.GcpComputeAuthentication;
|
||||
import org.springframework.vault.authentication.GcpIamAuthentication;
|
||||
import org.springframework.vault.authentication.GcpIamCredentialsAuthentication;
|
||||
import org.springframework.vault.authentication.KubernetesAuthentication;
|
||||
import org.springframework.vault.authentication.PcfAuthentication;
|
||||
import org.springframework.vault.authentication.TokenAuthentication;
|
||||
@@ -231,7 +231,7 @@ class SpringVaultClientConfigurationTests {
|
||||
properties.getGcpIam().setServiceAccountId("service-account");
|
||||
properties.getGcpIam().getCredentials().setEncodedKey(base64(GCE_JSON));
|
||||
|
||||
assertClientAuthenticationOfType(properties, GcpIamAuthentication.class);
|
||||
assertClientAuthenticationOfType(properties, GcpIamCredentialsAuthentication.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user