Azure MySQL Flexible Server and Read Replica Connection Path - mysql

My understanding is that if i wanted to setup a read replica for a non-flexible Azure MySQL server that is connected to a virtual network using a private link, any replication will be done "over the open internet" rather then through the address exposed by the private link as private links are a "one way street" so to speak. The source IP accoridng to the replica will be that of the public IP address of the mysql server within azure (regardless if you had provided public access to it or not).
My situation on the other hand is with an Azure MySQL Flexible Server deployed in my tenant with private vnet integration. As i understand this is different then private links. I am trying to understand if replication happens the same way via some hidden public ip address or if the replication source from the private ip address assigned to the flexible server within the vnet that is deployed that i can then apply normal vnet routing rules to send it.. wherever i want be it through a private firewall or perhaps to a replication source over a VPN.
See my diagram below - im pretty confidant my understanding of the diagram on the left is correct, am trying to understand which path the replication for the flexible server will take here, via some hidden public ip, or be routed properly through the firewall?

Related

The peering connection cloudsql-mysql-googleapis-com is not established when a Cloud SQL instance is configured to use Private IP

I have created a private Cloud SQL instance in an app project. The network used is a shared VPC and it is hosted in a network project.
In the shared VPC:
The private access connection is enabled
An automatic internal IP range has been allocated for private connection
A private connection has been created
If I go to the VPC Network > VPC Network Peering page, I don't see a peering connection named cloudsql-mysql-googleapis-com. Therefore, I cannot connect to my cloud SQL instance using its private IP address. I can only reach the cloud SQL instance using its public IP address.
The same infrastructure works for the development environment, I use terraform to generate the GCP resources. The two environments have exactly the same configuration.
Source code: https://gitlab.com/Chabane87/cloudsql-issue
Does anyone know when this problem can happen?
Thanks
Based on the discussion about this issue on our another support channel, it seems connectivity tests were run to zero in on the problem. While the connection from one of your instances to Cloud SQL succeeded using public IP, it failed when using private IP but that is the intended behaviour.
The Telnet test was conducted later using live traffic from the instance to Cloud SQL and found that a port is missing in the production environment while it is defined correctly in the development environment and hence it is confirmed there is no issue with the Networking. So, please try to connect to the Cloud SQL after adding the missing port to the prod project.

Is there a way to have AWS RDS Public Accessibility = No but still accessible outside of EC2 instance?

For management-related reasons, I need the Public Accessibility option set to "No" for the RDS.
However, we're also looking into being able to access the RDS from our local devices. The only way we're able to do so is by selecting "Yes" in Public Accessibility. Of course, the VPC, Gateway, Subnet, and Security Groups are already set with the appropriate public-facing stuff, which is probably why the Yes option is working.
But the moment we set it to No, only the EC2 instances are now able to connect to the database.
Is there a way around this or is that really what the Public Accessibility flag does by design?
Thanks in advance.
Setting Public Accessibility to "No" will not allow any access from the internet. There are plenty of ways to connect your RDS to your local.
Add your public IP in the security group of your rds database instance
Jump Server / Bastion
VPN / Direct Connect
Your asking for the best approach on how to secure this.. The best option is #3.
But to do this, you will need to build your database instance in the private subnet.
How?
Navigate to RDS > Subnet Groups.
Create a DB Subnet Group.
Select your VPC and the private subnet to use.
Yes Public Accessibility flag prevent you from accessing the RDS directly through Internet, but you can indirectly access through a jumpserver(like ssh bashtion) which is placed in public subnet. Most of the popular Mysql UI editors like sequel pro has a in build option for ssh config, using this option you can access RDS from local devices. you can also configure tunneling to bastion.
As #user11389395 mentioned, you must have Public Accessibility set to "Yes" in the RDS "Modify" page (this won't cause any outage of your database, or cause it to go down).
Once you have enabled it, you must jump into the Security Group that your RDS server is on, add an Inbound rule with the TCP Protocol, port 3306 (if using MySQL), and then in the Source dropdown, select "My IP":
When you select "My IP", you should see the source input field gray out and display your public IP address. You can confirm this public IP address by checking it online through Google. This grants only your public IP address access to your RDS database through the internet.
Once you save the rule, you should then be able to connect using TablePlus (or another SQL client) from your local computer by entering your RDS "Endpoint" (shown on the RDS "Connectivity and Security" tab) as the hostname, and your master username and password.

Connect to GCE Cloudsql instance via private IP

I am currently setting up my first GCE kubernetes cluster, having previously used mainly AWS for this.
Cluster is up and running and can access a local NFS server on the same compute engine VPC via private IP, so one stage of private network connection is fine.
Cloudsql server is running and can access this fine from the cluster if I open up public ip to the world.
Have enabled private ip address on the cloudsql which looks good, but I cannot ping or connect from the same container that can reach the public ip.
Cloudsql private ip is a different subnet which I believe is to be expected.
Checked VPC Network peering and got a relevant looking rule.
Checked VPC routes and got the matching peering route with next hop.
I have seen in docs that private ip is still beta, so guess potential to be a glitch beyond my control.
Also read up on running a proxy container inside each pod - hesitant to do this unless only option, app may end up across platforms so would prefer more standard config.
There's currently a requirement that the GKE cluster must be created with "VPC-Native" networking in order to access Cloud SQL via private IP. Unfortunately you need to re-create the cluster in order to make it VPC-Native.
https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips

Load Balancer + Autoscaling + Mysql on EC2

We have an EC2 instance which is a website, which uses a mysql database which is on another EC2 instance in the same region. In mysql, we have provided restricted access based on server elastic IP to prevent intrusion.
Now, we have decided to install ELB on this server. The ELB part actually works fine, but when auto-scaling spins up a new instance, it has a random public IP address, hence cannot be added to mysql's exceptions.
I tried adding ELB dns(A Name) to mysql for providing access, but it is still not working. The ELB works, Auto scaling spins up a new instance, but the website shows error due to not-connected to database.
How can I correct this?
Rather than restricting access via IP addresses, use Security Groups:
Create a security group (eg App-SG) and associate it with any instance that is permitted to communicate with the MySQL server
Create a security group for the MySQL instance (eg call it SQL-SG) and permit Inbound connections from App-SG
This way, only machines with the App-SG will be allowed to communicate with the MySQL instance. When Auto Scaling launches new instances that are associated with the App-SG, they will also be able to communicate with MySQL.
You should avoid hard-coded IP addresses as much as possible (as in... never use them!).
Instead of restriciting your database access by IP, consider restricting by subnet.
You will have a public subent (webserver and ELB are there) and a private one (database server is there)
Computers in a public subnet is accessible to everyone in internet, computers in a private subnet is available to only computers in a public subnet.
More information about such configuration is here:
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html
In order to manage your database server, you can setup a bastion host:
http://blogs.aws.amazon.com/security/post/Tx2ZWDW1QA6D62Y/Controlling-Network-Access-to-EC2-Instances-Using-a-Bastion-Server

AWS RDS MySQL How to restrict db access to a single EC2 instance

I recently inherited an AWS account's maintenance and noticed that the db access is wide open to any network, anywhere! So I decided it must be simple like it is when we do it with our own VMs. Except on Amazon AWS EC2 instances have an internal IP and a public IP and sometimes an elastic IP. So I thought ok I'll search google and find a simple quick writeup, and there doesn't seem to be one. So can someone please provide a simple writeup, here, on how to do this. I understand there are three methods on the RDS security and so forth. If you don't have time or desire to cover all three please just pick the one you like and have used for the example. If I don't get a good response on this within a day or so I'll hit the docs and piece it together myself, thank you in advance!
Well I tinkered with it a bit. The docs are not too suggestive. I found on an EC2 instance that has an Elastic IP assigned I had to use the Private IP allowed in the security group I applied to the RDS MySQL database. The Elastic IP assigned or UN-assigned did not affect connection. On the EC2 instance which had no Elastic IP assigned I had to use the Public IP allowed in the security group. The Private IP did not matter. This seems a bit strange to me.
An Amazon Relational Database Service (RDS) instance should typically be kept private to prevent access from the Internet. Only in rare circumstances should an RDS instance be accessible on the Internet.
An RDS instance can be secured in several ways:
1. Launch it in a Private Subnet
A Virtual Private Cloud (VPC) can be configured with public and private subnets. Launching the RDS instance in the private subnet will prevent access from the Internet. If access is still required across the Internet (eg to your corporate network), create a secure VPN connection between the VPC and your corporate network.
2. Use Security Groups
Security Groups operate like a firewall around each individual EC2 instance. They define which ports and IP address ranges are permitted for inbound and outbound access. By default, outbound access is permitted but inbound access is NOT permitted.
3. No Public IP address
If an RDS instance does NOT have a Public IP address, it cannot be directly accessed from the Internet.
4. Network Access Control Lists
These are like Security Groups, but they operate at the Subnet level. Good for controlling which app layers can talk to each other, but not good for securing specific EC2 or RDS instances.
Thus, for an RDS instance to be publicly accessible, it must have all the following:
A public IP address
A Security Group permitting inbound access
Located in a public subnet
Open Network ACL rules
For your situation, I would recommend:
Modify the RDS instance and set PubliclyAccessible to False. This will remove the public IP address.
Create a new Security Group (I'll refer to it as "SG1") and assign it to the single EC2 instance that you want to allow to communicate with the RDS instance
Modify the Security Group associated with the RDS instance and allow Inbound communication from SG1 (which permits communication from the EC2 instance). Note that this refers to the SG1 security group itself, rather than referring to any specific IP addresses.