spring-cloud / spring-cloud/spring-cloud-vault

Token rotation in the vault does not seem to trigger Refresh Event

Open
#724 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
291
Forks
152
Avg merge
11h 24m
Merged PRs (30d)
3

Description

Describe the bug
When token in rotated in the vault, the property value is updated in the Spring Context Environment but the Refresh Event does not seem to be triggered. As the result, using @RefreshScope, @Value or @ConfigurationProperties does not work.

Sample
Given vault config:

spring:
  cloud:
    vault:
      host: vault.some.com
      port: 8200
      scheme: https
      namespace: NM
      fail-fast: false
      authentication: APPROLE
      app-role:
        role-id: ${GCS_ROLE_ID}
        secret-id: ${GCS_SECRET_ID}
      enabled: true
      reactive:
        enabled: false
      config.lifecycle:
        enabled: true
        expiry-threshold: 2m

  config:
    import: vault://${GCS_VAULT}/static-account/${GCS_VAULT_ACCOUNT}/key?prefix=app.storage.credentials.

The following code is actually working:

@Configuration
@RequiredArgsConstructor
public class CredentialConfiguration {

    private final Environment environment;

    @SneakyThrows
    @Bean
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    GoogleCredentials fromServiceKey() {

        String privateKeyData = environment.getProperty("app.storage.credentials.private_key_data");
        var decoded = Base64.getDecoder().decode(privateKeyData);
        var stream = new ByteArrayInputStream(decoded);
        return ServiceAccountCredentials.fromStream(stream);
    }

However, if property is injected with @Value or @ConfigurationProperties, the old value assigned at the application startup is used even if @RefreshScope is added to the @Bean. And none of the beans annotated with @RefreshScope are recreated.

Expected behavior: when GET /v1/gcp-non-prod/static-account/svc-dev-rebatearc-gcs/key?prefix=app.storage.credentials. is invoked and a new value is received from the vault, the Refresh Event is published so any @Bean with @RefreshScope can be refreshed.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the vault configuration import request at GET /v1/gcp-non-prod/static-account/svc-dev-rebatearc-gcs/key?prefix=app.storage.credentials. and how the updated Environment value is handled. Check whether a Refresh Event is published after the new value is received, and verify that @RefreshScope, @Value, and @ConfigurationProperties beans are recreated when the token rotates.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.