I have 2 AWS RDS MySQL instances that are not publicly accessible.
And I have a bastion server that is created using an EC2 instance.
This bastion server has several users in it. And they can use their own ssh key to login to the EC2 to run some commands.
For anyone who wants to connect to the RDS instances. He/She needs to create an SSH tunnel with the bastion server first. Then he/she can interact with the RDS instance.
Is it possible to make people in group 1 only able to connect to RDS 1 through the bastion server, and not able to connect to RDS 2 through bastion server, even if they know the username and password of RDS 2?
I think I can run a bash script to check the username when the ssh tunnel is established. Then if the user is not allowed to connect to RDS 2 and he/she runs the command to connect to RDS 2, destroy the ssh tunnel.
But I can't find an easy way to run a script when an ssh tunnel is established.