How to make my instance access private in Google Compute Engine - google-cloud-platform

I have 2 instances in google cloud engine. let say:
a-instance and b-instance, I want to make a-instance not have access in public but the b-instance can access a-instance. for example:
The b-instance want to access a-instance in below:
curl ip-external-a-instance:7713/v1/healthcheck
For right now, the a-instance still can access public. How to make a-instance private access?

better remove the external IP from instance A and access it through it's private IP.
see the documentation for Securely Connecting to VM Instances, below bastion hosts
(which would be instance B).
tip: always make a snapshot, before messing around with the SSHd configuration.

You need to create firewall rules to do something like that. If you wish for the internet to not be able to access your VM but the b-instance to do it, you should create the firewall rule only allowing b-instance to access a-instance.

Related

AWS beginner question - Is my connection using public internet?

For example, in my python code inside lambda I have the following string:
conexao = (
"Driver={/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.1.so.2.1};"
"Server=example.xxxxxxxxxxxxx.us-east-1.rds.amazonaws.com;"
"Database=example;"
"TrustServerCertificate=yes;"
"Uid=admin;"
"Pwd=xxxxxx;"
)
The endpoint of my RDS database is example.xxxxxxxxxxxxx.us-east-1.rds.amazonaws.com
Both RDS database and lambda database is in the same VPC and subnet.
Since it's in the same VPC and subnet, this mean I am not going over the internet right? or maybe it is? my RDS has the option Publicly accessible = Yes (because I need to access through my SSMS).
I'd like to access over the internet only in SSMS, when accessing thought lambda I'd like to use privatly.
Does AWS understand that, in this case, python code inside lambda don't need to access over the internet?
this mean I am not going over the internet right?
Yes, that's correct.
You can very easily check it yourself if you want. In your lambda function, resolve example.xxxxxxxxxxxxx.us-east-1.rds.amazonaws.com into an IP address. What you should get, is a private IP address of the RDS instance, not public.

Direct access a database in a private subnet without SSH tunnel

I have a database set up (use RDS) in a private subnet, and a bastion is set up in front of it in a public subnet. The traditional way to access this database from local laptops is to set up an ssh tunnel on that bastion/jumpbox and map the database port to local. But this is not convenient to development because we need to set up that tunnel everytime before we want to connect. I am looking for a way to access this database without setting up an ssh tunnel first. I have seen a case where the local laptop directly uses that bastion's ip and its 3306 port to connect to the database behind. I have no idea how it is done.
BTW, in that case I saw, they don't use port forwarding because I didn't find any special rules in the bastion's iptable.
There are several ways to accomplish what you are trying to do, but without understanding the motivation fully it is hard to say which is the "Best Solution".
SSH Tunneling is the defacto standard of accessing a resource in a private subnet behind a public bastion host. I will agree that SSH Tunnels are not very convenient, fortunately, some ide's and many apps are available to make this as easy as a click of a button once configured.
Alternatively, you can set up a client to site VPN to your EC2 environment which would also provide access to the private subnet.
I would caution anything you do which proxies or exposes the DB cluster to the outside world in a naked way such as using IP tables, Nginx, etc. should be avoided. If your goal is this, then the correct solution is to just make the DB instance publicly exposed. But be aware any of these solutions which do not make use of tunneling in (such as VPN or SSH Tunnel) would be an auditory finding, and open your database to various attack vectors. To mitigate it would be recommended that your security groups should restrict port 3306 to the public IP's of your corporate network.

Restrict the access to aws instance from specific IP

I want to set the security groups for the web server running in aws instance.My website should be accessible to through http/https. But file modification access to be set to particular IP address.I am currently connected to a Wifi router, and as I know IP that my PC assigned changes everytime.
Can someone please guide me on how to get a static IP address that I can allow access to my website.Thanks in advance.
You would need to see if you ISP can sell you a static IP - it's not always possible. I can't get one from my ISP when working from home, your ISP may be different for example.
However, if it is just you that needs static IP address (i.e. you as the developer/admin as opposed to users in the public), it is only a few clicks of the mouse to update the security rule thru the aws console each time you need elevated access. I do this for several servers running on EC2 which I keep locked down, and when I need to RDP into them, I open up the security groups to just my (dynamic) IP, and remove the rule when I am done - this will work if you only occasionally need access. You could also automate this process using a little scripting and/or lambda function.
Other option that I also do: I have an service that I need to access continually from a static IP - I use an another EC2 instance (with fixed IP) as the whitelist IP for this, and then I connect to that services by first connecting via RDP to the EC2 instance - and the EC2 instance with the fixed IP then accesses the service using its static IP.
You first have to know if your external IP changes if so you have to ask your ISP to change your IP to a static one
If it's the internal IP the one that changes but the external IP is the same you will have no problem accessing the aws.

EC2 inbound custom ip rule not working

I am trying to set up a testing website on EC2 which can only be accessed internally. What I am trying to do is ask every one to give me their public ip. (By googling the word 'ip') Then I add a rule to the EC2 security group. (Add a rule Type=All TCP, protocol=TCP, port=0-65535, source=[public ip]/32) However this doesn't seem work. They still cannot access the website.
For example, if I make the source to be "Anywhere", I can access the website. If I just change it to "custom ip" with the same ip + "/32", I cannot access the website. Is there anything I am doing incorrectly?

Connect private EC2 instances using ssh via public instance

I have a few EC2 instances.
Only one instance is accessible (ssh port 22) from the Internet.
I want to connect to the others EC2 instances in ssh through the first one.
The public key is set on all EC2 instance.
I enable the forward agent (.ssh/config) for my first instance:
Host my-first-instance
ForwardAgent yes
I thought it was enough but when I connect to the first instance and try to connect to another one (ssh my-second-instance-private-IP), I have a "permission denied". They both use the same user.
I use the same ssh key to access Github from the first instance and it works (so the ForwardAgent works as well).
I don't want to use a VPC feature.
Any idea ?
Thanks in advance.
Jeremy
I had done similar thing earlier by changing the ip-tables of the public instance so that I can connect to different private instances by connecting on different ports. Here is the link to blog that I wrote to explain the same. Hope it helps
http://cloudpages.wordpress.com/2013/08/05/ssh-to-an-instance-in-private-subnet/
Bests,
Himanshu
You are getting permission denied probably because you may not have pub keys of your jump server in your ec2 server's authorized_keys. please do the following -
ssh to the 1st ec2 instance.
generate public and private key pair using keygen.
put the content of the public key (default is .ssh/id_rsa.pub (in case you are
using rsa)) in other ec2 instance's .ssh/authorized_keys.
Now check again.