繁体   English   中英

在应用程序属性中集成 AWS Secrets,Spring 启动应用程序

[英]Integrate AWS Secrets in application Properties, Spring Boot application

我在 AWS 秘密管理器中创建了秘密作为 OAuth2 clientId 和秘密的键值对。 如何将其嵌入到应用程序属性中? 预先感谢您的任何帮助。

有许多可能的方法来进行集成。 我几乎没有接触过 AWS 基础设施,因此无法对此发表评论。 我找到了这个页面: 亚马逊官方文档但是它并没有真正解释从 spring 引导的角度集成调用的最佳方法,它只是展示了如何从秘密管理器中检索数据。

像这样进行集成的一种方法是在 spring 启动应用程序启动之前调用 AWS 密钥管理器(在 main 方法中):

示意图如下所示:

@SpringBootApplication
public class MySpringBootApp {

   public static void main(String [] args) {
     // Call SecurityManager here and obtain all the required credential
     // then define system properties so that they'll be able to override the defaults:
     System.setProperty("whateverSecret", <I've_got_the_value_from_AWS_Security_Manager>");
     System.setProperty(...) // other properties
     SprintApplication.run(MySpringBootApp.class);
   }
}

如果您的设置更高级并且您使用的是 spring 云,它提供了与 aws secrets manager 的某种集成。 请参阅spring 云的文档

此外,您可以在此处找到此类集成的示例

要在 Spring BOOT 应用程序中从 AWS Secrets Manager 捕获 AWS Secrets 值,请使用 Secrets Manager Java API V2。 您可以在此处的 AWS Java 开发人员指南中找到示例:

https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-secretsmanager.html

In the Java V2 Github repo , you will find examples of using various AWS Java V2 APIs within Spring Boot apps. 您可以使用 V2 服务客户端调用 AWS 服务。

(另一个线程显示了一些挂钩应用程序属性的方法)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM