简体   繁体   English

AWS RDS 公开访问

[英]AWS RDS public access

I am stumped with AWS configuration.我对 AWS 配置感到困惑。 My goal is to create a database that's accessible from inside and outside the network.我的目标是创建一个可从网络内部和外部访问的数据库。

Here is what I have.这就是我所拥有的。 RDS instance runs postgresql. RDS 实例运行 postgresql。 Connections from inside the VPC work correctly.来自 VPC 内部的连接正常工作。

The endpoint is set up to be publicly accessible - and when accessed from the outside, does in fact resolve.端点设置为可公开访问 - 当从外部访问时,实际上确实解决了。 However, the connection hangs, indicating the traffic is blocked by somebody.但是,连接挂起,表明流量被某人阻止。

Security group is good:安全组好:
Inbound: Port 5432 from 0.0.0.0/0 Outbound: all from 0.0.0.0/0入站:端口 5432 来自 0.0.0.0/0 出站:全部来自 0.0.0.0/0

Subnets.子网。 I assume that's where something is wrong, right?我认为这就是问题所在,对吧? At first I had two private and two public subnets in the subnet group.起初,我在子网组中有两个私有子网和两个公共子网。 To simplify, I removed the private ones without changing the outcome.为了简化,我在不改变结果的情况下删除了私有的。

So we have two public subnets:所以我们有两个公共子网:

子网组

Both have the same route table with an Internet Gateway两者都具有与 Internet 网关相同的路由表

子网

互联网网关

As far as I can tell, everything is in working order... So who is blocking my database connection?据我所知,一切正常……那么谁在阻止我的数据库连接?

By default, even you have set "Public accessibility" to "Yes" during the setup of RDS, the "Security Group" still not allowing the port 3306 yet.默认情况下,即使您在 RDS 设置过程中将“公共可访问性”设置为“是”,“安全组”仍然不允许端口 3306。

Therefore you have to click on the Security Group of the RDS, then add a Rule to allow 3306 from anywhere IP.因此,您必须单击 RDS 的安全组,然后添加规则以允许来自任何 IP 的 3306。

Here is the reference setting.这是参考设置。 But here I have to warn you first, this public accessibility would expose your database to the internet.但在这里我必须首先警告你,这种公开的可访问性会将你的数据库暴露在互联网上。 Please do at your own risk.请自行承担风险。

在此处输入图像描述

Two things to check:要检查的两件事:

  1. Ensure that the RDS instance has the publicly accessible attribute set so that it is assigned a public address确保 RDS 实例具有可公开访问的属性集,以便为其分配公共地址

  2. Also according to the AWS RDS docs, "If you want your DB instance in the VPC to be publicly accessible, you must enable the VPC attributes DNS hostnames and DNS resolution ."此外,根据 AWS RDS 文档,“如果您希望 VPC 中的数据库实例可公开访问, 则必须启用 VPC 属性 DNS 主机名和 DNS 解析。”

Also, check that the IP that your RDS instance hostname resolves to is a public IP address.此外,请检查您的 RDS 实例主机名解析到的 IP 是否为公共 IP 地址。

As per new AWS RDS UI.根据新的 AWS RDS UI。 Follow Following steps.遵循以下步骤。

  1. Open the Amazon RDS console.打开 Amazon RDS 控制台。
  2. Choose Databases from the navigation pane, and then select the DB instance.从导航窗格中选择数据库,然后选择数据库实例。
  3. Choose Modify.选择修改。
  4. Connectivity连接性在此处输入图像描述

Additionally[important]: inbound and outbound policy update with PORT and IPs另外[重要]:使用 PORT 和 IP 更新入站和出站策略

Unable to connect to my publicly accessible RDS as well following https://aws.amazon.com/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/ .https://aws.amazon.com/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/之后,也无法连接到我的可公开访问的 RDS。

It turns out one of my subnet route table does not have route record to public 0.0.0.0/0, when added it works.事实证明,我的一个子网路由表没有到公共 0.0.0.0/0 的路由记录,添加后它可以工作。

The default security group AWS created did only allowed traffic originating from the same security group. AWS 创建的默认安全组只允许来自同一安全组的流量。 I had to add a rule in security group to allow incoming traffic from any IP in order for it to work.我必须在安全组中添加一条规则以允许来自任何 IP 的传入流量才能正常工作。

As of Oct 2021, RDS instances may have its own security groups.自 2021 年 10 月起,RDS 实例可能拥有自己的安全组。 Hence you just need to create or edit security group to allow public access*.因此,您只需要创建或编辑安全组以允许公共访问*。

In general RDS instance has a default security group.通常 RDS 实例有一个默认的安全组。 I would recommend to create a new security group to allow public access instead of editing default group though.我建议创建一个新的安全组以允许公共访问,而不是编辑default组。

To add new security group.添加新的安全组。

  • Go to RDS > Security groups转到 RDS > 安全组
  • Click on Create DB Security Group单击Create DB Security Group
  • Enter name and description and click Create button to save输入namedescription ,然后单击Create按钮保存
  • Click new created security group name on the list of security groups点击安全组列表中新建的安全组名称
  • Click on Add Rule located on top right corner of the box单击位于框右上角的Add Rule
  • Check CIDR/IP radio button检查CIDR/IP单选按钮
  • Enter 0.0.0.0/0 in CIDR/IP to Authorize text fieldCIDR/IP to Authorize文本字段
  • Save by clicking Add Rule button单击Add Rule按钮保存

Once saved, Go back to the list of RDS instances, RDS > Databases保存后,返回 RDS 实例列表,RDS > 数据库

  • Check the RDS instance and click Modify at top right勾选RDS实例,点击右上角修改
  • Find and Select new created security group under Connectivity > Security groupConnectivity > Security group下查找并选择新创建的安全组
  • Make sure that Publicly accessible is checked under Connectivity > Additional Settings确保在“ Connectivity > Additional Settings下选中“ Publicly accessible
  • Save节省

Optionally, you may edit an existing security group.或者,您可以编辑现有的安全组。 This could prevent the step of modifying RDS instance.这可能会阻止修改 RDS 实例的步骤。

In order to edit security group.为了编辑安全组。

  • Go to RDS > Security groups转到 RDS > 安全组
  • Click on a security group to edit, for example default单击要编辑的安全组,例如default
  • Click on Add Rule located on top right corner of the box单击位于框右上角的Add Rule
  • Check CIDR/IP radio button检查CIDR/IP单选按钮
  • Enter 0.0.0.0/0 in CIDR/IP to Authorize text fieldCIDR/IP to Authorize文本字段
  • Save by clicking Add Rule button单击Add Rule按钮保存

[*] - You should consider adding an ip or range of ips if you have got ones. [*] - 如果你有 IP,你应该考虑添加一个 IP 或 IP 范围。

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

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