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

S3 Backend Behaves Differently With Multiple Application Names #2642

Closed
dmarmugi opened this issue Nov 19, 2024 · 1 comment · Fixed by #2652
Closed

S3 Backend Behaves Differently With Multiple Application Names #2642

dmarmugi opened this issue Nov 19, 2024 · 1 comment · Fixed by #2652
Labels
Milestone

Comments

@dmarmugi
Copy link

dmarmugi commented Nov 19, 2024

Describe the bug
Given

  • Spring Cloud Config Server Version 4.1.3
  • spring.application.name: appA,appB
  • spring.profiles.active: dummy

When

  • Resulting Request: http://<config server>/appA,appB/dummy (the profile name doesn't matter here, just the app names)

Then

  • Against Git and Vault backends (Multiple spring application name for Vault #1356), this will return appB as propertySources[0] and appA as propertySources[1]
  • Against the S3 backend, this will return appA as propertySources[0] and appB as propertySources[1]

This is a problem because:
This affects the override behavior in cases where the same value exists in both appA and appB's responses

@dmarmugi
Copy link
Author

Searching with regex for \.findOne\("\w+,\w+ turned up these tests:
Vault and Spring Vault have tests asserting precedence:

  • public void findOneWithDefaultKeyAndMultipleApplicationNames() {
    stubRestTemplate("secret/myapp", toEntityResponse("myapp-foo", "myapp-bar"));
    stubRestTemplate("secret/yourapp", toEntityResponse("yourapp-foo", "yourapp-bar"));
    stubRestTemplate("secret/mydefaultkey", toEntityResponse("def-foo", "def-bar"));
    var properties = new VaultEnvironmentProperties();
    properties.setDefaultKey("mydefaultkey");
    var e = vaultEnvironmentRepository(properties).findOne("myapp,yourapp", null, null);
    assertThat(e.getName()).isEqualTo("myapp,yourapp");
    assertThat(e.getPropertySources().size()).isEqualTo(3);
    assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("yourapp-foo", "yourapp-bar"));
    assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:yourapp");
    assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("myapp-foo", "myapp-bar"));
    assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:myapp");
    assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
    assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:mydefaultkey");
    }
  • public void findOneWithDefaultKeyAndMultipleApplicationNames() {
    when(keyValueTemplate.get("myapp")).thenReturn(withVaultResponse("myapp-foo", "myapp-bar"));
    when(keyValueTemplate.get("yourapp")).thenReturn(withVaultResponse("yourapp-foo", "yourapp-bar"));
    when(keyValueTemplate.get("mydefaultkey")).thenReturn(withVaultResponse("def-foo", "def-bar"));
    var properties = new VaultEnvironmentProperties();
    properties.setDefaultKey("mydefaultkey");
    var e = springVaultEnvironmentRepository(properties).findOne("myapp,yourapp", null, "lbl");
    assertThat(e.getName()).isEqualTo("myapp,yourapp");
    assertThat(e.getPropertySources()).hasSize(3);
    assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:yourapp");
    assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("yourapp-foo", "yourapp-bar"));
    assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:myapp");
    assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("myapp-foo", "myapp-bar"));
    assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:mydefaultkey");
    assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
    }

So, too, CredHub:

  • public void shouldRetrieveGivenMultipleApplicationNames() {
    stubCredentials("/app1/default/myLabel", credential("c1", "k1", "v1"));
    stubCredentials("/app2/default/myLabel", credential("c2", "k2", "v2"));
    Environment environment = this.credhubEnvironmentRepository.findOne("app1,app2", null, "myLabel");
    assertThat(environment.getName()).isEqualTo("app1,app2");
    assertThat(environment.getProfiles()).containsExactly("default");
    assertThat(environment.getLabel()).isEqualTo("myLabel");
    assertThat(environment.getPropertySources()).hasSize(2);
    assertThat(environment.getPropertySources().get(0).getName()).isEqualTo("credhub-app2-default-myLabel");
    assertThat(environment.getPropertySources().get(0).getSource()).isEqualTo(Map.of("k2", "v2"));
    assertThat(environment.getPropertySources().get(1).getName()).isEqualTo("credhub-app1-default-myLabel");
    assertThat(environment.getPropertySources().get(1).getSource()).isEqualTo(Map.of("k1", "v1"));
    }

Unfortunately, AWSS3 and Git seem to just assert on size of response:

@ryanjbaxter ryanjbaxter added this to the 4.2.0 milestone Nov 25, 2024
ryanjbaxter added a commit to ryanjbaxter/spring-cloud-config that referenced this issue Nov 25, 2024
This matches the behavior of other EnvironmentRepositories like Git.

#Fixes spring-cloud#2642
@github-project-automation github-project-automation bot moved this to Done in 2024.0.0 Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants