Skip to content

Commit

Permalink
fix: store secrets on disk when partial arn is used (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
saranyailla authored Dec 5, 2024
1 parent a21b165 commit 89c4aa0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ private void save(List<SecretConfiguration> secretConfiguration) {
secretConfiguration.forEach((secretConfig) -> {
secretConfig.getLabels().forEach((label) -> {
String arn = secretConfig.getArn();
if (secrets.containsKey(arn) && secrets.get(arn).responseMap.containsKey(label)) {
responses.add(secrets.get(arn).responseMap.get(label));
}
secrets.entrySet().stream().filter(entry -> entry.getKey().contains(arn))
.filter(entry -> entry.getValue().responseMap.containsKey(label))
.forEach(entry -> responses.add(entry.getValue().responseMap.get(label)));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ private void mockSecretResponse() throws SecretManagerException, IOException {
.name(secretName).arn(secretArn).secretString("secretValue2").versionId("id2")
.versionStages("new").createdDate(Instant.now().minusSeconds(1000000)).build())
.when(secretClient).getSecret(GetSecretValueRequest.builder().secretId(secretArn).versionStage("new").build());

lenient().doReturn(
software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse.builder().name("partialarn")
.arn("arn:aws:secretsmanager:us-east-1:999936977227:secret:partialarn" + "-43lYMk")
.secretString("secretValue").versionId("partialarnid").versionStages(CURRENT_LABEL)
.createdDate(Instant.now().minusSeconds(1000000)).build()).when(secretClient).getSecret(
GetSecretValueRequest.builder()
.secretId("arn:aws:secretsmanager:us" + "-east-1:999936977227:secret:partialarn")
.versionStage(CURRENT_LABEL).build());
}

@AfterEach
Expand Down Expand Up @@ -219,6 +228,22 @@ void GIVEN_secret_service_WHEN_ipc_handler_called_THEN_correct_response_returned
assertEquals("secretValue", response.getSecretValue().getSecretString());
}

@Test
void GIVEN_secret_service_WHEN_ipc_request_partialarn_THEN_correct_response_returned() throws Exception {
startKernelWithConfig("config.yaml", State.RUNNING);
software.amazon.awssdk.aws.greengrass.model.GetSecretValueRequest secretWithPartialArn =
new software.amazon.awssdk.aws.greengrass.model.GetSecretValueRequest();
secretWithPartialArn.setSecretId("partialarn");


GreengrassCoreIPCClientV2 clientV2 = IPCTestUtils.connectV2Client(kernel, "ComponentRequestingSecrets");
GetSecretValueResponse response = clientV2.getSecretValue(secretWithPartialArn);
assertEquals("arn:aws:secretsmanager:us-east-1:999936977227:secret:partialarn-43lYMk", response.getSecretId());
assertEquals("partialarnid", response.getVersionId());
assertTrue(response.getVersionStage().contains(CURRENT_LABEL));
assertEquals("secretValue", response.getSecretValue().getSecretString());
}

@Test
void GIVEN_secret_service_WHEN_periodic_refresh_THEN_secret_updated() throws Exception {
startKernelWithConfig("config_refresh.yaml", State.RUNNING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- arn: "arn:aws:secretsmanager:us-east-1:999936977227:secret:randomSecret-74lYJh"
labels:
- "new"

- arn: "arn:aws:secretsmanager:us-east-1:999936977227:secret:partialarn"
ComponentRequestingSecrets:
dependencies:
- aws.greengrass.SecretManager
Expand Down

0 comments on commit 89c4aa0

Please sign in to comment.