从Java连接到AWS RDS而不暴露密码 [英] Connecting to AWS RDS from java without exposing password

查看:97
本文介绍了从Java连接到AWS RDS而不暴露密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够像其他任何数据库连接一样成功连接到RDS. 我使用spring jpa数据(存储库)对postgres db进行CRUD操作. 目前,我在属性文件中提供了db url和凭据

I was successfully able to connect to RDS like any other database connection. I use spring jpa data ( repository ) to do CRUD operation on postgres db. currently I provide the db url and the credential in the properties file

spring:
  datasource:
    url: jdbc:postgresql://<rds-endpoint>:5432/<dbschema>
    username: <dbuser>
    password: <dbpassword>

但是,在连接到生产或预生产时,这不是选项. 这里的最佳做法是什么? AWS是否提供任何内置机制来从端点读取这些详细信息,例如在访问S3的情况下?

However this is not an option while connecting to production or preproduction. what is the best practise here. Does AWS provide any inbuild mechanism to read these details from an endpoint like in the case of accessing S3 ?

我的意图不是公开密码.

My intention is not expose the password.

推荐答案

您可以使用以下几种选择:

Several options are available to you:

  1. 使用最近宣布的 IAM访问Postgres RDS
  2. 使用Systems Manager参数存储来存储密码
  3. 使用Secrets Manager存储密码并自动轮换凭据

对于2和3,使用PropertyPlaceholderConfiguration和AWSSimpleSystemsManagement客户端(GetParameter请求)在Spring中启动应用程序时查找密码. SystemsManager可以代理请求到SecretsManager在代码中保留一个接口来访问参数.

For 2 and 3, look up the password on application start in Spring using a PropertyPlaceholderConfiguration and the AWSSimpleSystemsManagement client (GetParameter request). SystemsManager can proxy requests to SecretsManager to keep a single interface in your code to access parameters.

IAM凭证在以下方面更安全:

IAM credentials is more secure in that:

  1. 如果使用EC2实例配置文件,则对数据库的访问将使用短期的临时凭据.
  2. 如果不在EC2上,则可以生成短暂的身份验证令牌.
  3. 密码未存储在您的配置中.
  4. 如果您有单独的数据库团队,他们可以独立于应用程序用户来管理访问.
  5. 可以通过IAM删除访问权限

这篇关于从Java连接到AWS RDS而不暴露密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆