spring-cloud/spring-cloud-config

S3 Backend Behaves Differently With Multiple Application Names

dmarmugi opened this issue · 1 comments

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 (#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

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: