Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve multiple aws secrete in spring boot app that have same keys

Have a spring boot app (with starter parent at 2.4.8).

The app is connecting to multiple data sources, and the automated Jenkins job being used to create secrets across company does it such a way that although secrets names are different(per app/source) but they all have same value underneath - 'username' and 'password' text.

For example:

  1. first secret would be '/secret/rds/dev/foo/foo_app_user' with value:

       username : user1 
       password: pass1
    
  2. second secret would be '/secret/snowflake/dev/hoo/hoo_app_user' with value:

        username : user2
        password: pass2
    

Trying to figure out how can they both be imported using spring config import, while still being able to be used distinctively in properties/yaml file

  spring:
     config:
        import: aws secretsmanager:/secret/rds/dev/foo/foo_app_user,/secret/snowflake/dev/hoo/hoo_app_user


...
system:
  cache:
    username: ${username}
    password: ${password}



....
snowflake:
   datasource:
        username: ${username}
        password: ${password}
like image 514
Arpit S Avatar asked Dec 11 '25 05:12

Arpit S


1 Answers

3 days ago 13th Jan, 2023 this issue has been fixed. Commit ref

With spring cloud 3.0.x (dependent on spring boot 3.0.x) you can add prefix

spring:
     config:
        import: 
          - aws-secretsmanager:/secret/rds/dev/foo/foo_app_user?prefix=foo_app.
          - aws-secretsmanager:/secret/snowflake/dev/hoo/hoo_app_user?prefix=hoo_app.

Now as a workaround for spring cloud version 2.4.x we have

  • copied the class AwsSecretsManagerPropertySource into our codebase in package io.awspring.cloud.secretsmanager. Code Ref
  • Then use similler implementation approach as version 3.0.x. Code Ref

PS: Don't change the class signature. Method name, constructor param should be same as version 2.4.x


Edit: 5th Feb, 2023

With new 2.4.3 version you can pass the same prefix. No need to do workaround.

like image 104
SnigJi Avatar answered Dec 13 '25 20:12

SnigJi