Skip to content
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

control-service: remove default vault token #2475

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.lang.Nullable;
import org.springframework.vault.authentication.*;
import org.springframework.vault.client.VaultEndpoint;
import org.springframework.vault.config.AbstractVaultConfiguration;
Expand All @@ -27,6 +27,7 @@

@Slf4j
@Configuration
@ConditionalOnProperty(value = "featureflag.vault.integration.enabled")
public class VaultConfiguration extends AbstractVaultConfiguration {

@Value("${vdk.vault.uri:}")
Expand All @@ -39,7 +40,6 @@ public class VaultConfiguration extends AbstractVaultConfiguration {
String secretId;

@Value("${vdk.vault.token:}")
@Nullable
String vaultToken;

@Bean
Expand All @@ -65,23 +65,23 @@ public VaultEndpoint vaultEndpoint() {
@Override
@Bean
public ClientAuthentication clientAuthentication() {
// Token authentication should only be used for development purposes. If the token expires, the
// secrets
// functionality will stop working
if (StringUtils.isNotBlank(vaultToken)) {
log.warn("Initializing vault integration with Token Authentication.");
return new TokenAuthentication(vaultToken);
} else {
if (StringUtils.isNotBlank(this.roleId) && StringUtils.isNotBlank(this.secretId)) {
log.info("Initializing vault integration with AppRole Authentication.");
AppRoleAuthenticationOptions.AppRoleAuthenticationOptionsBuilder builder =
AppRoleAuthenticationOptions.builder()
.roleId(AppRoleAuthenticationOptions.RoleId.provided(this.roleId))
.secretId(AppRoleAuthenticationOptions.SecretId.provided(this.secretId));

RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(vaultUri));
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(this.vaultUri));

return new AppRoleAuthentication(builder.build(), restTemplate);
}
// Token authentication should only be used for development purposes. If the token expires, the
// secrets functionality will stop working
else {
log.warn("Initializing vault integration with Token Authentication.");
return new TokenAuthentication(this.vaultToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,5 @@ featureflag.vault.integration.enabled=false
vdk.vault.uri=http://localhost:8200/v1/
vdk.vault.approle.roleid=
vdk.vault.approle.secretid=
vdk.vault.token=root
vdk.vault.token=
datajobs.vault.size.limit.bytes=1048576