Add static role support for Vault 1.2.
Original pull request: gh-348. See gh-347.
This commit is contained in:
committed by
Mark Paluch
parent
67bddfcff6
commit
c5f5bbcf6c
@@ -47,4 +47,10 @@ public interface DatabaseSecretProperties extends VaultSecretBackendDescriptor {
|
||||
*/
|
||||
String getPasswordProperty();
|
||||
|
||||
/**
|
||||
* see https://learn.hashicorp.com/vault/secrets-management/db-creds-rotation
|
||||
* @return is vault configured to use static role or not.
|
||||
*/
|
||||
boolean isStaticRole();
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,11 @@ public class VaultCassandraProperties implements DatabaseSecretProperties {
|
||||
@NotEmpty
|
||||
private String passwordProperty = "spring.data.cassandra.password";
|
||||
|
||||
/**
|
||||
* Enable static role usage.
|
||||
*/
|
||||
private boolean staticRole = false;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
private String credPath = properties.isStaticRole() ? "static-creds"
|
||||
: "creds";
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
@@ -86,7 +89,7 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return String.format("%s/creds/%s", properties.getBackend(),
|
||||
return String.format("%s/%s/%s", properties.getBackend(), credPath,
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@@ -100,7 +103,8 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
variables.put("backend", properties.getBackend());
|
||||
variables.put("key", String.format("creds/%s", properties.getRole()));
|
||||
variables.put("key",
|
||||
String.format("%s/%s", credPath, properties.getRole()));
|
||||
return variables;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,6 +59,11 @@ public class VaultDatabaseProperties implements DatabaseSecretProperties {
|
||||
@NotEmpty
|
||||
private String passwordProperty = "spring.datasource.password";
|
||||
|
||||
/**
|
||||
* Enable static role usage.
|
||||
*/
|
||||
private boolean staticRole = false;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,11 @@ public class VaultMongoProperties implements DatabaseSecretProperties {
|
||||
@NotEmpty
|
||||
private String passwordProperty = "spring.data.mongodb.password";
|
||||
|
||||
/**
|
||||
* Enable static role usage.
|
||||
*/
|
||||
private boolean staticRole = false;
|
||||
|
||||
public VaultMongoProperties() {
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@ public class VaultMySqlProperties
|
||||
@NotEmpty
|
||||
private String passwordProperty = "spring.datasource.password";
|
||||
|
||||
/**
|
||||
* Enable static role usage.
|
||||
*/
|
||||
private boolean staticRole = false;
|
||||
|
||||
public VaultMySqlProperties() {
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ public class VaultPostgreSqlProperties implements DatabaseSecretProperties {
|
||||
@NotEmpty
|
||||
private String passwordProperty = "spring.datasource.password";
|
||||
|
||||
/**
|
||||
* Enable static role usage.
|
||||
*/
|
||||
private boolean staticRole = false;
|
||||
|
||||
public VaultPostgreSqlProperties() {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user