Remove spring.cloud.vault.generic configuration properties.

Spring Cloud Vault uses now a single mechanism for key-value backend configuration. Properties at spring.cloud.vault.generic.* are no longer supported.

All associated functionality is now solely available by configuring the corresponding spring.cloud.vault.kv.* properties. The support classes GenericSecretBackendMetadata and VaultGenericBackendProperties were removed in favor of KeyValueSecretBackendMetadata respective VaultKeyValueBackendProperties. spring.cloud.vault.kv.enabled is now enabled by default to preserve spring.cloud.vault.generic.enabled behavior.

Closes gh-395
This commit is contained in:
Mark Paluch
2020-05-20 10:57:33 +02:00
parent ef2c83758d
commit 0f7b9ec7fc
27 changed files with 68 additions and 426 deletions

View File

@@ -587,7 +587,9 @@ All API is synchronous therefore, `GcpIamAuthentication` does not support `Authe
See also:
* https://www.vaultproject.io/docs/auth/gcp.html[Vault Documentation: Using the GCP auth backend]
* https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signJwt[GCP Documentation: projects.serviceAccounts.signJwt][[vault.authentication.gcpiam]]
* https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signJwt[GCP Documentation: projects.serviceAccounts.signJwt]
[[vault.authentication.gcpiam]]
[[vault.config.authentication.kubernetes]]
=== Kubernetes authentication
@@ -669,70 +671,14 @@ See also: https://www.vaultproject.io/docs/auth/pcf.html[Vault Documentation: Us
[[vault.config.backends.kv]]
[[vault.config.backends.generic]]
=== Generic Backend
NOTE: This backend is deprecated in favor of the Key-Value backend and will be removed with the next major version.
Spring Cloud Vault supports at the basic level the key-value secret backend.
The key-value secret backend allows storage of arbitrary values as key-value store.
A single context can store one or many key-value tuples.
Contexts can be organized hierarchically.
Spring Cloud Vault allows using the Application name and a default context name (`application`) in combination with active profiles.
----
/secret/{application}/{profile}
/secret/{application}
/secret/{default-context}/{profile}
/secret/{default-context}
----
The application name is determined by the properties:
* `spring.cloud.vault.generic.application-name`
* `spring.cloud.vault.application-name`
* `spring.application.name`
Secrets can be obtained from other contexts within the key-value backend by adding their paths to the application name, separated by commas.
For example, given the application name `usefulapp,mysql1,projectx/aws`, each of these folders will be used:
* `/secret/usefulapp`
* `/secret/mysql1`
* `/secret/projectx/aws`
Spring Cloud Vault adds all active profiles to the list of possible context paths.
No active profiles will skip accessing contexts with a profile name.
Properties are exposed like they are stored (i.e. without additional prefixes).
====
[source,yaml]
----
spring.cloud.vault:
generic:
enabled: true
backend: secret
profile-separator: '/'
default-context: application
application-name: my-app
----
====
* `enabled` setting this value to `false` disables the secret backend config usage
* `backend` sets the path of the secret mount to use
* `default-context` sets the context name used by all applications
* `application-name` overrides the application name for use in the key-value backend
* `profile-separator` separates the profile name from the context in property sources with profiles
See also: https://www.vaultproject.io/docs/secrets/kv/kv-v1.html[Vault Documentation: Using the KV Secrets Engine - Version 1 (generic secret backend)]
[[vault.config.backends.kv.versioned]]
=== Key-Value Backend
Spring Cloud Vault supports the Key-Value secret backend.
Spring Cloud Vault supports both Key-Value secret backends, the versioned (v2) and unversioned (v1).
The key-value backend allows storage of arbitrary values as key-value store.
A single context can store one or many key-value tuples.
Contexts can be organized hierarchically.
Spring Cloud Vault determines itself whether a secret is using versioning.
Spring Cloud Vault determines itself whether a secret is using versioning and maps the path to its appropriate URL.
Spring Cloud Vault allows using the Application name and a default context name (`application`) in combination with active profiles.
----

View File

@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.vault.config.GenericSecretBackendMetadata;
import org.springframework.cloud.vault.config.KeyValueSecretBackendMetadata;
import org.springframework.cloud.vault.config.SecretBackendMetadata;
import org.springframework.cloud.vault.config.aws.VaultConfigAwsBootstrapConfiguration.AwsSecretBackendMetadataFactory;
import org.springframework.cloud.vault.config.aws.VaultConfigAwsBootstrapConfigurationTests.CustomBootstrapConfiguration;
@@ -55,7 +55,7 @@ public class VaultConfigAwsBootstrapConfigurationTests extends IntegrationTestSu
SecretBackendMetadata metadata = this.factory.createMetadata(this.properties);
assertThat(metadata).isInstanceOf(GenericSecretBackendMetadata.class);
assertThat(metadata).isInstanceOf(KeyValueSecretBackendMetadata.class);
assertThat(metadata.getPath()).isEqualTo(this.properties.getRole());
}
@@ -70,7 +70,7 @@ public class VaultConfigAwsBootstrapConfigurationTests extends IntegrationTestSu
@Override
public SecretBackendMetadata createMetadata(
VaultAwsProperties backendDescriptor) {
return GenericSecretBackendMetadata
return KeyValueSecretBackendMetadata
.create(backendDescriptor.getRole());
}
};

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
import org.springframework.cloud.vault.config.GenericSecretBackendMetadata;
import org.springframework.cloud.vault.config.KeyValueSecretBackendMetadata;
import org.springframework.cloud.vault.config.SecretBackendMetadata;
import org.springframework.cloud.vault.config.consul.VaultConfigConsulBootstrapConfiguration.ConsulSecretBackendMetadataFactory;
import org.springframework.cloud.vault.config.consul.VaultConfigConsulBootstrapConfigurationTests.CustomBootstrapConfiguration;
@@ -58,7 +58,7 @@ public class VaultConfigConsulBootstrapConfigurationTests extends IntegrationTes
SecretBackendMetadata metadata = this.factory.createMetadata(this.properties);
assertThat(metadata).isInstanceOf(GenericSecretBackendMetadata.class);
assertThat(metadata).isInstanceOf(KeyValueSecretBackendMetadata.class);
assertThat(metadata.getPath()).isEqualTo(this.properties.getRole());
}
@@ -74,7 +74,7 @@ public class VaultConfigConsulBootstrapConfigurationTests extends IntegrationTes
@Override
public SecretBackendMetadata createMetadata(
VaultConsulProperties backendDescriptor) {
return GenericSecretBackendMetadata
return KeyValueSecretBackendMetadata
.create(backendDescriptor.getRole());
}
};

View File

@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.vault.config.GenericSecretBackendMetadata;
import org.springframework.cloud.vault.config.KeyValueSecretBackendMetadata;
import org.springframework.cloud.vault.config.SecretBackendMetadata;
import org.springframework.cloud.vault.config.databases.VaultConfigDatabaseBootstrapConfiguration.DatabaseSecretBackendMetadataFactory;
import org.springframework.cloud.vault.config.databases.VaultConfigDatabaseBootstrapConfigurationTests.CustomBootstrapConfiguration;
@@ -57,7 +57,7 @@ public class VaultConfigDatabaseBootstrapConfigurationTests
SecretBackendMetadata metadata = this.factory.createMetadata(this.properties);
assertThat(metadata).isInstanceOf(GenericSecretBackendMetadata.class);
assertThat(metadata).isInstanceOf(KeyValueSecretBackendMetadata.class);
assertThat(metadata.getPath()).isEqualTo(this.properties.getRole());
}
@@ -72,7 +72,7 @@ public class VaultConfigDatabaseBootstrapConfigurationTests
@Override
public SecretBackendMetadata createMetadata(
DatabaseSecretProperties backendDescriptor) {
return GenericSecretBackendMetadata
return KeyValueSecretBackendMetadata
.create(backendDescriptor.getRole());
}
};

View File

@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.vault.config.GenericSecretBackendMetadata;
import org.springframework.cloud.vault.config.KeyValueSecretBackendMetadata;
import org.springframework.cloud.vault.config.SecretBackendMetadata;
import org.springframework.cloud.vault.config.rabbitmq.VaultConfigRabbitMqBootstrapConfiguration.RabbitMqSecretBackendMetadataFactory;
import org.springframework.cloud.vault.config.rabbitmq.VaultConfigRabbitMqBootstrapConfigurationTests.CustomBootstrapConfiguration;
@@ -57,7 +57,7 @@ public class VaultConfigRabbitMqBootstrapConfigurationTests
SecretBackendMetadata metadata = this.factory.createMetadata(this.properties);
assertThat(metadata).isInstanceOf(GenericSecretBackendMetadata.class);
assertThat(metadata).isInstanceOf(KeyValueSecretBackendMetadata.class);
assertThat(metadata.getPath()).isEqualTo(this.properties.getRole());
}
@@ -72,7 +72,7 @@ public class VaultConfigRabbitMqBootstrapConfigurationTests
@Override
public SecretBackendMetadata createMetadata(
VaultRabbitMqProperties backendDescriptor) {
return GenericSecretBackendMetadata
return KeyValueSecretBackendMetadata
.create(backendDescriptor.getRole());
}
};

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config;
import java.util.List;
import org.springframework.util.Assert;
/**
* {@link SecretBackendMetadata} for the {@code generic} secret backend.
*
* @author Mark Paluch
* @deprecated since 2.2.3, will be removed with 3.0.
*/
@Deprecated
public final class GenericSecretBackendMetadata extends KeyValueSecretBackendMetadata
implements SecretBackendMetadata {
private GenericSecretBackendMetadata(String path) {
super(path);
}
/**
* Create a {@link SecretBackendMetadata} for the {@code kv} secret backend given a
* {@code secretBackendPath} and {@code key}.
* @param secretBackendPath the secret backend mount path without leading/trailing
* slashes, must not be empty or {@literal null}.
* @param key the key within the secret backend. May contain slashes but not
* leading/trailing slashes, must not be empty or {@literal null}.
* @return the {@link SecretBackendMetadata}
*/
public static SecretBackendMetadata create(String secretBackendPath, String key) {
Assert.hasText(secretBackendPath,
"Secret backend path must not be null or empty");
Assert.hasText(key, "Key must not be null or empty");
return create(String.format("%s/%s", secretBackendPath, key));
}
/**
* Create a {@link SecretBackendMetadata} for the {@code kv} secret backend given a
* {@code path}.
* @param path the relative path of the secret. slashes, must not be empty or
* {@literal null}.
* @return the {@link SecretBackendMetadata}
* @since 1.1
*/
public static SecretBackendMetadata create(String path) {
return new GenericSecretBackendMetadata(path);
}
/**
* Build a list of context paths from application name and the active profile names.
* Application name and profiles support multiple (comma-separated) values.
* @param properties the generic backend properties.
* @param profiles active application profiles.
* @return list of context paths.
*/
public static List<String> buildContexts(VaultGenericBackendProperties properties,
List<String> profiles) {
return KeyValueSecretBackendMetadata.buildContexts(properties, profiles);
}
/**
* Create a list of context names from a combination of application name and
* application name with profile name. Using an empty application name will return an
* empty list.
* @param applicationName the application name. May be empty.
* @param profiles active application profiles.
* @param profileSeparator profile separator character between application name and
* profile name.
* @return list of context names.
* @since 1.1
*/
public static List<String> buildContexts(String applicationName,
List<String> profiles, String profileSeparator) {
return KeyValueSecretBackendMetadata.buildContexts(applicationName, profiles,
profileSeparator);
}
}

View File

@@ -74,7 +74,7 @@ public class KeyValueSecretBackendMetadata extends SecretBackendMetadataSupport
"Secret backend path must not be null or empty");
Assert.hasText(key, "Key must not be null or empty");
return create(String.format("%s/data/%s", secretBackendPath, key),
return create(String.format("%s/%s", secretBackendPath, key),
UnwrappingPropertyTransformer.unwrap("data"));
}
@@ -218,6 +218,9 @@ public class KeyValueSecretBackendMetadata extends SecretBackendMetadataSupport
target.put(entry.getKey().substring(this.prefixToStrip.length() + 1),
entry.getValue());
}
else {
target.put(entry.getKey(), entry.getValue());
}
}
return target;

View File

@@ -18,8 +18,6 @@ package org.springframework.cloud.vault.config;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.env.PropertySource;
import org.springframework.util.Assert;
@@ -39,9 +37,6 @@ import org.springframework.vault.core.lease.event.LeaseErrorListener;
class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocatorSupport
implements PriorityOrdered {
private static final Log log = org.apache.commons.logging.LogFactory
.getLog(LeasingVaultPropertySourceLocator.class);
private final SecretLeaseContainer secretLeaseContainer;
private final VaultProperties properties;
@@ -98,7 +93,7 @@ class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocatorSuppor
accessor.getPath());
}
if (accessor instanceof GenericSecretBackendMetadata) {
if (accessor instanceof KeyValueSecretBackendMetadata) {
return RequestedSecret.rotating(accessor.getPath());
}

View File

@@ -82,19 +82,6 @@ public interface SecretBackendConfigurer {
SecretBackendConfigurer add(RequestedSecret requestedSecret,
PropertyTransformer propertyTransformer);
/**
* Register default generic secret backend property sources.
* @param registerDefault {@literal true} to enable default generic secret backend
* registration.
* @return {@code this} {@link SecretBackendConfigurer}.
* @deprecated since 2.2.3
*/
@Deprecated
default SecretBackendConfigurer registerDefaultGenericSecretBackends(
boolean registerDefault) {
return registerDefaultKeyValueSecretBackends(registerDefault);
}
/**
* Register default key-value secret backend property sources.
* @param registerDefault {@literal true} to enable default kv secret backend

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.vault.config;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.InitializingBean;
@@ -49,8 +50,7 @@ import org.springframework.vault.core.lease.SecretLeaseContainer;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "spring.cloud.vault.enabled", matchIfMissing = true)
@EnableConfigurationProperties({ VaultGenericBackendProperties.class,
VaultKeyValueBackendProperties.class })
@EnableConfigurationProperties(VaultKeyValueBackendProperties.class)
@Order(Ordered.LOWEST_PRECEDENCE - 10)
public class VaultBootstrapPropertySourceConfiguration implements InitializingBean {
@@ -80,14 +80,13 @@ public class VaultBootstrapPropertySourceConfiguration implements InitializingBe
public PropertySourceLocator vaultPropertySourceLocator(VaultOperations operations,
VaultProperties vaultProperties,
VaultKeyValueBackendProperties kvBackendProperties,
VaultGenericBackendProperties genericBackendProperties,
ObjectFactory<SecretLeaseContainer> secretLeaseContainerObjectFactory) {
VaultConfigTemplate vaultConfigTemplate = new VaultConfigTemplate(operations,
vaultProperties);
PropertySourceLocatorConfiguration configuration = getPropertySourceConfiguration(
Arrays.asList(kvBackendProperties, genericBackendProperties));
Collections.singletonList(kvBackendProperties));
VaultProperties.Lifecycle lifecycle = vaultProperties.getConfig().getLifecycle();
@@ -112,7 +111,7 @@ public class VaultBootstrapPropertySourceConfiguration implements InitializingBe
/**
* Apply configuration through {@link VaultConfigurer}.
* @param keyValueBackends configured backend (key-value, generic secret backend).
* @param keyValueBackends configured backend.
* @return the {@link PropertySourceLocatorConfiguration}.
*/
private PropertySourceLocatorConfiguration getPropertySourceConfiguration(
@@ -124,7 +123,7 @@ public class VaultBootstrapPropertySourceConfiguration implements InitializingBe
DefaultSecretBackendConfigurer secretBackendConfigurer = new DefaultSecretBackendConfigurer();
if (configurers.isEmpty()) {
secretBackendConfigurer.registerDefaultGenericSecretBackends(true)
secretBackendConfigurer.registerDefaultKeyValueSecretBackends(true)
.registerDefaultDiscoveredSecretBackends(true);
}
else {
@@ -147,7 +146,7 @@ public class VaultBootstrapPropertySourceConfiguration implements InitializingBe
.getEnvironment().getActiveProfiles()));
for (String context : contexts) {
secretBackendConfigurer.add(GenericSecretBackendMetadata
secretBackendConfigurer.add(KeyValueSecretBackendMetadata
.create(keyValueBackend.getBackend(), context));
}
}

View File

@@ -29,7 +29,6 @@ package org.springframework.cloud.vault.config;
* Registered bean instances of {@link VaultConfigurer} disable default secret backend
* registration for the kv and integrative (other discovered
* {@link SecretBackendMetadata}) backends. See
* {@link SecretBackendConfigurer#registerDefaultGenericSecretBackends(boolean)} and
* {@link SecretBackendConfigurer#registerDefaultDiscoveredSecretBackends(boolean)} for
* more details.
*

View File

@@ -1,160 +0,0 @@
/*
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config;
import javax.validation.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
/**
* Configuration properties for Vault using the generic backend.
*
* @author Mark Paluch
*/
@ConfigurationProperties("spring.cloud.vault.generic")
@Validated
public class VaultGenericBackendProperties
implements EnvironmentAware, VaultKeyValueBackendPropertiesSupport {
/**
* Enable the generic backend.
*/
private boolean enabled = true;
/**
* Name of the default backend.
*/
@NotEmpty
private String backend = "secret";
/**
* Name of the default context.
*/
@NotEmpty
private String defaultContext = "application";
/**
* Profile-separator to combine application name and profile.
*/
@NotEmpty
private String profileSeparator = "/";
/**
* Application name to be used for the context.
*/
private String applicationName = "application";
public VaultGenericBackendProperties() {
}
@Override
public void setEnvironment(Environment environment) {
String springCloudVaultAppName = environment
.getProperty("spring.cloud.vault.application-name");
if (StringUtils.hasText(springCloudVaultAppName)) {
this.applicationName = springCloudVaultAppName;
}
else {
String springAppName = environment.getProperty("spring.application.name");
if (StringUtils.hasText(springAppName)) {
this.applicationName = springAppName;
}
}
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "spring.cloud.vault.generic.* is deprecated in favor of spring.cloud.vault.kv",
replacement = "spring.cloud.vault.kv.enabled")
public boolean isEnabled() {
return this.enabled;
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "spring.cloud.vault.generic.* is deprecated in favor of spring.cloud.vault.kv",
replacement = "spring.cloud.vault.kv.backend")
public String getBackend() {
return this.backend;
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "spring.cloud.vault.generic.* is deprecated in favor of spring.cloud.vault.kv",
replacement = "spring.cloud.vault.kv.default-context")
public String getDefaultContext() {
return this.defaultContext;
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "spring.cloud.vault.generic.* is deprecated in favor of spring.cloud.vault.kv",
replacement = "spring.cloud.vault.kv.profile-separator")
public String getProfileSeparator() {
return this.profileSeparator;
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "spring.cloud.vault.generic.* is deprecated in favor of spring.cloud.vault.kv",
replacement = "spring.cloud.vault.kv.application-name")
public String getApplicationName() {
return this.applicationName;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void setBackend(String backend) {
this.backend = backend;
}
public void setDefaultContext(String defaultContext) {
this.defaultContext = defaultContext;
}
public void setProfileSeparator(String profileSeparator) {
this.profileSeparator = profileSeparator;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getSimpleName());
sb.append(" [enabled=").append(this.enabled);
sb.append(", backend='").append(this.backend).append('\'');
sb.append(", defaultContext='").append(this.defaultContext).append('\'');
sb.append(", profileSeparator='").append(this.profileSeparator).append('\'');
sb.append(", applicationName='").append(this.applicationName).append('\'');
sb.append(']');
return sb.toString();
}
}

View File

@@ -39,7 +39,7 @@ public class VaultKeyValueBackendProperties
/**
* Enable the kev-value backend.
*/
private boolean enabled = false;
private boolean enabled = true;
/**
* Name of the default backend.

View File

@@ -42,20 +42,6 @@ public abstract class VaultPropertySourceLocatorSupport implements PropertySourc
private final PropertySourceLocatorConfiguration propertySourceLocatorConfiguration;
/**
* Creates a new {@link VaultPropertySourceLocatorSupport}.
* @param propertySourceName must not be {@literal null} or empty.
* @param genericBackendProperties must not be {@literal null}.
* @param backendAccessors must not be {@literal null}.
*/
public VaultPropertySourceLocatorSupport(String propertySourceName,
VaultGenericBackendProperties genericBackendProperties,
Collection<SecretBackendMetadata> backendAccessors) {
this(propertySourceName,
createConfiguration(genericBackendProperties, backendAccessors));
}
/**
* Creates a new {@link VaultPropertySourceLocatorSupport} given a
* {@link PropertySourceLocatorConfiguration}.
@@ -75,29 +61,12 @@ public abstract class VaultPropertySourceLocatorSupport implements PropertySourc
}
static PropertySourceLocatorConfiguration createConfiguration(
VaultGenericBackendProperties genericBackendProperties,
Collection<SecretBackendMetadata> backendAccessors) {
VaultKeyValueBackendProperties kvBackendProperties) {
Assert.notNull(genericBackendProperties,
"VaultGenericBackendProperties must not be null");
Assert.notNull(backendAccessors, "BackendAccessors must not be null");
Assert.notNull(kvBackendProperties,
"VaultKeyValueBackendProperties must not be null");
KeyValuePropertySourceLocatorConfiguration generic = new KeyValuePropertySourceLocatorConfiguration(
genericBackendProperties);
WrappedPropertySourceLocatorConfiguration backends = new WrappedPropertySourceLocatorConfiguration(
new ArrayList<>(backendAccessors));
return new CompositePropertySourceConfiguration(generic, backends);
}
static PropertySourceLocatorConfiguration createConfiguration(
VaultGenericBackendProperties genericBackendProperties) {
Assert.notNull(genericBackendProperties,
"VaultGenericBackendProperties must not be null");
return new KeyValuePropertySourceLocatorConfiguration(genericBackendProperties);
return new KeyValuePropertySourceLocatorConfiguration(kvBackendProperties);
}
@Override
@@ -230,14 +199,14 @@ public abstract class VaultPropertySourceLocatorSupport implements PropertySourc
if (this.keyValueBackendProperties.isEnabled()) {
List<String> contexts = GenericSecretBackendMetadata.buildContexts(
List<String> contexts = KeyValueSecretBackendMetadata.buildContexts(
this.keyValueBackendProperties,
Arrays.asList(this.environment.getActiveProfiles()));
List<SecretBackendMetadata> result = new ArrayList<>(contexts.size());
for (String context : contexts) {
result.add(GenericSecretBackendMetadata.create(
result.add(KeyValueSecretBackendMetadata.create(
this.keyValueBackendProperties.getBackend(), context));
}

View File

@@ -25,18 +25,18 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link GenericSecretBackendMetadata}.
* Unit tests for {@link KeyValueSecretBackendMetadata}.
*
* @author Mark Paluch
*/
public class GenericSecretBackendMetadataUnitTests {
public class KeyValueSecretBackendMetadataUnitTests {
VaultGenericBackendProperties properties = new VaultGenericBackendProperties();
VaultKeyValueBackendProperties properties = new VaultKeyValueBackendProperties();
@Test
public void shouldCreateDefaultContexts() {
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Collections.emptyList());
assertThat(contexts).hasSize(1).contains("application");
@@ -47,7 +47,7 @@ public class GenericSecretBackendMetadataUnitTests {
this.properties.setApplicationName("my-app");
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Collections.emptyList());
assertThat(contexts).hasSize(2).containsSequence("my-app", "application");
@@ -58,7 +58,7 @@ public class GenericSecretBackendMetadataUnitTests {
this.properties.setApplicationName("my-app");
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Arrays.asList("cloud", "local"));
assertThat(contexts).hasSize(6).containsSequence("my-app/local", "my-app/cloud",
@@ -71,7 +71,7 @@ public class GenericSecretBackendMetadataUnitTests {
this.properties.setApplicationName("my-app");
this.properties.setDefaultContext("");
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Collections.emptyList());
assertThat(contexts).hasSize(1).containsSequence("my-app");
@@ -82,7 +82,7 @@ public class GenericSecretBackendMetadataUnitTests {
this.properties.setApplicationName("foo,bar");
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Collections.emptyList());
assertThat(contexts).hasSize(3).containsSequence("bar", "foo", "application");
@@ -93,7 +93,7 @@ public class GenericSecretBackendMetadataUnitTests {
this.properties.setApplicationName("foo,bar");
List<String> contexts = GenericSecretBackendMetadata
List<String> contexts = KeyValueSecretBackendMetadata
.buildContexts(this.properties, Arrays.asList("cloud", "local"));
assertThat(contexts).hasSize(9).containsSequence("bar/local", "bar/cloud", "bar",

View File

@@ -26,14 +26,13 @@ import org.springframework.cloud.vault.util.IntegrationTestSupport;
import org.springframework.cloud.vault.util.Settings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.vault.config.GenericSecretBackendMetadata.create;
/**
* Integration tests for {@link VaultConfigTemplate} using the generic secret backend.
* Integration tests for {@link VaultConfigTemplate} using the key-value secret backend.
*
* @author Mark Paluch
*/
public class GenericSecretIntegrationTests extends IntegrationTestSupport {
public class KeyValueSecretIntegrationTests extends IntegrationTestSupport {
private VaultProperties vaultProperties = Settings.createVaultProperties();
@@ -53,7 +52,8 @@ public class GenericSecretIntegrationTests extends IntegrationTestSupport {
public void shouldReturnSecretsCorrectly() {
Map<String, Object> secretProperties = this.configOperations
.read(create("secret", "app-name")).getData();
.read(KeyValueSecretBackendMetadata.create("secret", "app-name"))
.getData();
assertThat(secretProperties).containsAllEntriesOf(createExpectedMap());
}
@@ -61,7 +61,8 @@ public class GenericSecretIntegrationTests extends IntegrationTestSupport {
@Test
public void shouldReturnNullIfNotFound() {
Secrets secrets = this.configOperations.read(create("secret", "missing"));
Secrets secrets = this.configOperations
.read(KeyValueSecretBackendMetadata.create("secret", "missing"));
assertThat(secrets).isNull();
}

View File

@@ -53,7 +53,7 @@ public class LeasingVaultPropertySourceLocatorUnitTests {
this.propertySourceLocator = new LeasingVaultPropertySourceLocator(
new VaultProperties(), VaultPropertySourceLocatorSupport
.createConfiguration(new VaultGenericBackendProperties()),
.createConfiguration(new VaultKeyValueBackendProperties()),
this.secretLeaseContainer);
}
@@ -65,7 +65,7 @@ public class LeasingVaultPropertySourceLocatorUnitTests {
this.propertySourceLocator = new LeasingVaultPropertySourceLocator(
vaultProperties, VaultPropertySourceLocatorSupport.createConfiguration(
new VaultGenericBackendProperties()),
new VaultKeyValueBackendProperties()),
this.secretLeaseContainer);
assertThat(this.propertySourceLocator.getOrder()).isEqualTo(10);

View File

@@ -42,7 +42,7 @@ public class ReactiveVaultBootstrapConfigurationTests {
@Test
public void shouldConfigureWithoutAuthentication() {
this.contextRunner.withPropertyValues("spring.cloud.vault.generic.enabled=false",
this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=false",
"spring.cloud.vault.authentication=NONE").run(context -> {
assertThat(context).doesNotHaveBean(SessionManager.class);

View File

@@ -39,7 +39,7 @@ public class VaultBootstrapConfigurationTests {
@Test
public void shouldConfigureWithoutAuthentication() {
this.contextRunner.withPropertyValues("spring.cloud.vault.generic.enabled=false",
this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=false",
"spring.cloud.vault.authentication=NONE").run(context -> {
assertThat(context).doesNotHaveBean(SessionManager.class);

View File

@@ -50,7 +50,7 @@ public class VaultBootstrapPropertySourceConfigurationTests {
this.contextRunner.withUserConfiguration(MockConfiguration.class)
.withAllowBeanDefinitionOverriding(true)
.withPropertyValues("spring.cloud.vault.generic.enabled=false",
.withPropertyValues("spring.cloud.vault.kv.enabled=false",
"spring.cloud.vault.config.lifecycle.expiry-threshold=5m",
"spring.cloud.vault.config.lifecycle.min-renewal=6m",
"spring.cloud.vault.config.lifecycle.lease-endpoints=SysLeases")

View File

@@ -51,7 +51,7 @@ import static org.junit.Assume.assumeTrue;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VaultConfigCubbyholeAuthenticationTests.TestApplication.class,
properties = { "spring.cloud.vault.authentication=cubbyhole",
"spring.cloud.vault.generic.applicationName=VaultConfigCubbyholeAuthenticationTests" })
"spring.cloud.vault.kv.applicationName=VaultConfigCubbyholeAuthenticationTests" })
public class VaultConfigCubbyholeAuthenticationTests {
@Value("${vault.value}")

View File

@@ -43,9 +43,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VaultConfigGenericBackendDisabledTests.TestApplication.class,
properties = "spring.cloud.vault.generic.enabled=false")
public class VaultConfigGenericBackendDisabledTests {
@SpringBootTest(classes = VaultConfigKeyValueBackendDisabledTests.TestApplication.class,
properties = "spring.cloud.vault.kv.enabled=false")
public class VaultConfigKeyValueBackendDisabledTests {
@Autowired
Environment environment;

View File

@@ -50,7 +50,7 @@ public class VaultConfigTemplateIntegrationTests extends IntegrationTestSupport
prepare().getVaultOperations(), vaultProperties);
Secrets secrets = template
.read(GenericSecretBackendMetadata.create("secret", "myapp"));
.read(KeyValueSecretBackendMetadata.create("secret", "myapp"));
assertThat(secrets.getData()).containsEntry("key", "value");
}
@@ -71,7 +71,7 @@ public class VaultConfigTemplateIntegrationTests extends IntegrationTestSupport
prepare().getVaultOperations(), vaultProperties);
Secrets secrets = template
.read(GenericSecretBackendMetadata.create("versioned", "testVaultApp"));
.read(KeyValueSecretBackendMetadata.create("versioned", "testVaultApp"));
assertThat(secrets.getData()).containsEntry("key", "value");
}

View File

@@ -48,7 +48,7 @@ public class VaultPropertySourceIntegrationTests extends IntegrationTestSupport
VaultPropertySource propertySource = new VaultPropertySource(
new VaultConfigTemplate(prepare().getVaultOperations(), vaultProperties),
false, GenericSecretBackendMetadata.create("secret", "myapp"));
false, KeyValueSecretBackendMetadata.create("secret", "myapp"));
propertySource.init();
@@ -70,7 +70,7 @@ public class VaultPropertySourceIntegrationTests extends IntegrationTestSupport
VaultPropertySource propertySource = new VaultPropertySource(
new VaultConfigTemplate(prepare().getVaultOperations(), vaultProperties),
false, GenericSecretBackendMetadata.create("versioned", "testVaultApp"));
false, KeyValueSecretBackendMetadata.create("versioned", "testVaultApp"));
propertySource.init();

View File

@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
classes = VaultPropertySourceLocatorIntegrationTests.TestApplication.class,
properties = { "spring.application.name=wintermute",
"spring.cloud.vault.application-name=neuromancer",
"spring.cloud.vault.generic.application-name=neuromancer,icebreaker" })
"spring.cloud.vault.kv.application-name=neuromancer,icebreaker" })
@ActiveProfiles({ "integrationtest" })
public class VaultPropertySourceLocatorIntegrationTests extends IntegrationTestSupport {

View File

@@ -51,7 +51,7 @@ public class VaultPropertySourceLocatorUnitTests {
public void before() {
this.propertySourceLocator = new VaultPropertySourceLocator(this.operations,
new VaultProperties(), VaultPropertySourceLocatorSupport
.createConfiguration(new VaultGenericBackendProperties()));
.createConfiguration(new VaultKeyValueBackendProperties()));
}
@Test
@@ -62,7 +62,7 @@ public class VaultPropertySourceLocatorUnitTests {
this.propertySourceLocator = new VaultPropertySourceLocator(this.operations,
vaultProperties, VaultPropertySourceLocatorSupport
.createConfiguration(new VaultGenericBackendProperties()));
.createConfiguration(new VaultKeyValueBackendProperties()));
assertThat(this.propertySourceLocator.getOrder()).isEqualTo(42);
}
@@ -100,7 +100,7 @@ public class VaultPropertySourceLocatorUnitTests {
@Test
public void shouldLocatePropertySourcesInVaultApplicationContext() {
VaultGenericBackendProperties backendProperties = new VaultGenericBackendProperties();
VaultKeyValueBackendProperties backendProperties = new VaultKeyValueBackendProperties();
backendProperties.setApplicationName("wintermute");
this.propertySourceLocator = new VaultPropertySourceLocator(this.operations,
@@ -124,7 +124,7 @@ public class VaultPropertySourceLocatorUnitTests {
@Test
public void shouldLocatePropertySourcesInEachPathSpecifiedWhenApplicationNameContainsSeveral() {
VaultGenericBackendProperties backendProperties = new VaultGenericBackendProperties();
VaultKeyValueBackendProperties backendProperties = new VaultKeyValueBackendProperties();
backendProperties.setApplicationName("wintermute,straylight,icebreaker/armitage");
this.propertySourceLocator = new VaultPropertySourceLocator(this.operations,

View File

@@ -55,7 +55,6 @@ import static org.junit.Assume.assumeTrue;
@SpringBootTest(classes = VaultVersionedKvBackendConfigTests.TestApplication.class,
properties = { "spring.cloud.vault.host=foo", "spring.cloud.vault.port=80",
"spring.cloud.vault.uri=https://localhost:8200",
"spring.cloud.vault.generic.enabled=false",
"spring.cloud.vault.kv.enabled=true",
"spring.cloud.vault.kv.backend=versioned",
"spring.cloud.vault.application-name=testVaultApp" })