-
Notifications
You must be signed in to change notification settings - Fork 149
Add couchbase database plugin to spring-cloud-vault #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f7573ac
Start adding couchbase db to spring cloud vault
fhitchen 17d082b
Worked.
454fbc7
Initial fumblings
7e72257
Merge remote-tracking branch 'upstream/master'
fhitchen 5065b3c
Added correct couchbase-database-plugin test file.
fhitchen 4447b47
Working couchbase solution.
fhitchen 1c94f7f
added documentation.
fhitchen 511564c
Added static role test for Couchbase.
fhitchen 6d587d1
Added note.
fhitchen 7ed535e
Added couchbase.
fhitchen c1d3edd
Fixed issues from the PR review.
fhitchen 077e525
Fixed issues from the PR review.
fhitchen 2a03cbc
Fixed issues from the PR review.
fhitchen 66bdef6
Fixed issues from the PR review.
fhitchen 922b379
Fixed issues from the PR review.
fhitchen 1a35a2b
Updated dynamic role test to use new role+group creation statement fo…
fhitchen 27cde25
Fixed checkstyle import issues.
fhitchen 50fc519
Merge commit '895df4456a6d61e3f2afb3679c787c5f29fc86b7'
fhitchen 9e95a4a
Switched to use Couchbase sandbox image.
fhitchen 6f2bcab
fixed pom.xml
fhitchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. | ||
| With https://www.vaultproject.io[HashiCorp's Vault] you have a central place to manage external secret properties for applications across all environments. | ||
| Vault can manage static and dynamic secrets such as username/password for remote applications/resources and provide credentials for external services such as MySQL, PostgreSQL, Apache Cassandra, MongoDB, Consul, AWS and more. | ||
| Vault can manage static and dynamic secrets such as username/password for remote applications/resources and provide credentials for external services such as MySQL, PostgreSQL, Apache Cassandra, Couchbase, MongoDB, Consul, AWS and more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
.../main/java/org/springframework/cloud/vault/config/databases/VaultCouchbaseProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * 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.databases; | ||
|
|
||
| import javax.validation.constraints.NotEmpty; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.validation.annotation.Validated; | ||
|
|
||
| /** | ||
| * Configuration properties for Vault using the Couchbase integration. | ||
| * | ||
| * @author Francis Hitchens | ||
| */ | ||
| @ConfigurationProperties("spring.cloud.vault.couchbase") | ||
| @Validated | ||
| public class VaultCouchbaseProperties implements DatabaseSecretProperties { | ||
|
|
||
| /** | ||
| * Enable couchbase backend usage. | ||
| */ | ||
| private boolean enabled = false; | ||
|
|
||
| /** | ||
| * Role name for credentials. | ||
| */ | ||
| private String role; | ||
|
|
||
| /** | ||
| * Enable static role usage. | ||
| * | ||
| */ | ||
| private boolean staticRole = false; | ||
|
|
||
| /** | ||
| * Couchbase backend path. | ||
| */ | ||
| @NotEmpty | ||
| private String backend = "database"; | ||
|
|
||
| /** | ||
| * Target property for the obtained username. | ||
| */ | ||
| @NotEmpty | ||
| private String usernameProperty = "spring.data.couchbase.username"; | ||
|
|
||
| /** | ||
| * Target property for the obtained password. | ||
| */ | ||
| @NotEmpty | ||
| private String passwordProperty = "spring.data.couchbase.password"; | ||
|
|
||
| @Override | ||
| public boolean isEnabled() { | ||
| return this.enabled; | ||
| } | ||
|
|
||
| public void setEnabled(boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| @Override | ||
| public String getRole() { | ||
| return this.role; | ||
| } | ||
|
|
||
| public void setRole(String role) { | ||
| this.role = role; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isStaticRole() { | ||
| return this.staticRole; | ||
| } | ||
|
|
||
| public void setStaticRole(boolean staticRole) { | ||
| this.staticRole = staticRole; | ||
| } | ||
|
|
||
| @Override | ||
| public String getBackend() { | ||
| return this.backend; | ||
| } | ||
|
|
||
| public void setBackend(String backend) { | ||
| this.backend = backend; | ||
| } | ||
|
|
||
| @Override | ||
| public String getUsernameProperty() { | ||
| return this.usernameProperty; | ||
| } | ||
|
|
||
| public void setUsernameProperty(String usernameProperty) { | ||
| this.usernameProperty = usernameProperty; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPasswordProperty() { | ||
| return this.passwordProperty; | ||
| } | ||
|
|
||
| public void setPasswordProperty(String passwordProperty) { | ||
| this.passwordProperty = passwordProperty; | ||
| } | ||
|
|
||
| } |
139 changes: 139 additions & 0 deletions
139
...springframework/cloud/vault/config/databases/VaultConfigCouchbaseDatabaseStaticTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* | ||
| * Copyright 2017-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.databases; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
|
|
||
| import com.couchbase.client.java.Cluster; | ||
| import com.couchbase.client.core.error.UnambiguousTimeoutException; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.time.Duration; | ||
|
|
||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.cloud.vault.util.CanConnect; | ||
| import org.springframework.cloud.vault.util.VaultRule; | ||
| import org.springframework.cloud.vault.util.Version; | ||
| import org.springframework.test.context.junit4.SpringRunner; | ||
| import org.springframework.vault.core.VaultOperations; | ||
|
|
||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| /** | ||
| * Integration tests using the database secret backend. In case this test should fail | ||
| * because of SSL make sure you run the test within the | ||
| * spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is | ||
| * referenced with {@code ../work/keystore.jks}. | ||
| * | ||
| * Uses the existing admin user that comes with the couchbase/sandbox-server docker image | ||
| * provided by Couchbase. The test will fail if this user does not exits. | ||
| * | ||
| * @author Francis Hitchens | ||
| */ | ||
| @RunWith(SpringRunner.class) | ||
| @SpringBootTest(classes = VaultConfigCouchbaseDatabaseStaticTests.TestApplication.class, | ||
| properties = { "spring.cloud.vault.couchbase.enabled=true", | ||
| "spring.cloud.vault.couchbase.role=staticreadonly", | ||
| "spring.cloud.vault.couchbase.staticRole=true", | ||
| "spring.data.couchbase.username=foo", | ||
| "spring.data.couchbase.password=bar", | ||
| "spring.main.allow-bean-definition-overriding=true" }) | ||
| public class VaultConfigCouchbaseDatabaseStaticTests { | ||
|
|
||
| private static final int COUCHBASE_PORT = 8091; | ||
|
|
||
| private static final String COUCHBASE_HOST = "localhost"; | ||
|
|
||
| @Value("${spring.data.couchbase.username}") | ||
| String username; | ||
|
|
||
| @Value("${spring.data.couchbase.password}") | ||
| String password; | ||
|
|
||
| Cluster cluster; | ||
|
|
||
| /** | ||
| * Initialize the couchbase secret backend. | ||
| */ | ||
| @BeforeClass | ||
| public static void beforeClass() { | ||
|
|
||
| VaultRule vaultRule = new VaultRule(); | ||
| vaultRule.before(); | ||
|
|
||
| assumeTrue(CanConnect.to(new InetSocketAddress(COUCHBASE_HOST, COUCHBASE_PORT))); | ||
| assumeTrue(vaultRule.prepare().getVersion() | ||
|
fhitchen marked this conversation as resolved.
|
||
| .isGreaterThanOrEqualTo(Version.parse("0.7.1"))); | ||
|
|
||
| if (!vaultRule.prepare().hasSecretBackend("database")) { | ||
| vaultRule.prepare().mountSecret("database"); | ||
| } | ||
|
|
||
| VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations(); | ||
|
|
||
| Map<String, String> config = new HashMap<>(); | ||
| config.put("plugin_name", "couchbase-database-plugin"); | ||
| config.put("hosts", "couchbase://localhost"); | ||
| config.put("username", "Administrator"); | ||
| config.put("password", "password"); | ||
| config.put("allowed_roles", "*"); | ||
|
|
||
| vaultOperations.write("database/config/spring-cloud-vault-couchbase", config); | ||
|
|
||
| Map<String, String> body = new HashMap<>(); | ||
| body.put("db_name", "spring-cloud-vault-couchbase"); | ||
| body.put("username", "admin"); | ||
| body.put("rotation_period", "5m"); | ||
| body.put("creation_statements", "[{\"name\":\"ro_admin\"}]"); | ||
|
|
||
| vaultOperations.write("database/static-roles/staticreadonly", body); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldConnectConnection() throws UnambiguousTimeoutException { | ||
|
|
||
| this.cluster = Cluster.connect("127.0.0.1", this.username, this.password); | ||
| this.cluster.waitUntilReady(Duration.ofSeconds(5)); | ||
| this.cluster.disconnect(); | ||
| } | ||
|
|
||
| @Test(expected = UnambiguousTimeoutException.class) | ||
| public void shouldFailConnectConnection() throws UnambiguousTimeoutException { | ||
|
|
||
| this.cluster = Cluster.connect("127.0.0.1", this.username, "fake.pwd"); | ||
| this.cluster.waitUntilReady(Duration.ofSeconds(5)); | ||
| this.cluster.disconnect(); | ||
| } | ||
|
|
||
| @SpringBootApplication | ||
| public static class TestApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(TestApplication.class, args); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.