Basic security group ports required to run AWS opsworks instances - amazon-web-services

I was trying to create some instances in aws opsworks stack. I am performing this on secured vpc. Which is not default one. That VPC have internet connection. However I have been instructed to restrict sources to required inbound ports to specific address only not to 0.0.0.0/0. Generally the ports we are using - ssh, http and https. ssh is ok to restrict to vpc subnet. but I have problem with http and httpd.
I have some queries-
1. What are the minimal inbound ports required to run opsworks properly and what will be the source? Hence we are not using 0.0.0.0/0
2. Since my cookbook stored in s3 which is accessible inside vpc. what will be the minimal port required.
3. I am not using Opsworks default security group. I am trying to use other security cookbook.
4. I have seen Opsworks are using some cookbooks from github.com. If I restrict then will it fail.
5. AWS said the following http and https source should be 0.0.0.0/0. link
6. When I am restricting ec2 instances are booting up but opsworks it is showing "setting-up" does not show any log messages.
Kindly advise what are the essential inbound ports to be opened and static source required to run in production vpc.
Regards
Biswajit Das

Chef client and solo in general require no inbound ports of any kind other than the usual ephemeral ports required for outbound TCP to function.

Related

EC2 Instance cannot connect to github using SSH

I'm trying to deploy a web with Laravel Forge and AWS. I created an EC2 instance using Laravel Forge control panel. I created a security group for this instance.
Outbund rules
Inound rules v1
Inbound rules v2
All SHH connections allowed are described in this Laravel Forge guide:
https://forge.laravel.com/docs/1.0/servers/providers.html
So, the problem is when I try to install the repository I get this error into EC2 instance.
SHH error
I also checked that my instance's SHH public key is registered in my github account
Your Outbound rules are permitting connections on port 80 (HTTP) and port 443 (HTTPS).
However, SSH uses port 22. This is causing the connection to fail.
You should add port 22 to the Outbound rules.
However, it is generally considered acceptable to Allow all outbound connections from an Amazon EC2 instance since you can 'trust' the software running on the instance. I would recommend allowing all outbound connections rather than restricting it to specific ports.

Update security group with specific IP range to only allow gitlab-ci to communicate with custom runner

I've followed https://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate/ to create a custom runner which has a public IP attached and sits in a VPC alongside "private" resources. The runner is used to apply migrations using gitlab ci/cd.
ALLOW 22 0.0.0.0/0 has been applied within the security group; but it's wide open to attacks. What IP range do I need to add to only allow gitlab ci/cd runners access via SSH? I've removed that rule for the moment so we're getting connection errors, but the IPs connecting on port 22 all come from AWS (assuming gitlab runners are also on AWS).
Is there something I'm missing or not understanding?
I had a look at the tutorial. you should only allow EC2 instances to be able to ssh into the Fargate tasks.
One way to do that is, You could define EC2 instance's security group as the source in the Fargate task's security group instead of using an ip address(or CIDR block). You don't have to explicitly mention any ip ranges. This is my preferred approach.
When you specify a security group as the source for a rule, traffic is allowed from the network interfaces that are associated with the source security group for the specified protocol and port. Incoming traffic is allowed based on the private IP addresses of the network interfaces that are associated with the source security group (and not the public IP or Elastic IP addresses).specify a security group as the source
Second approach is, As #samtoddler mentioned, you can allow the entire VPC network, or you can restrict it to a subnet.
I was misunderstood; gitlab-runner talks to gitlab, not the other way round, my understanding was gitlab talks to runners over SSH.
My immediate solution was 2 things:
Move the EC2 instance into a private subnet
As per #Aruk Ks answer, only allow EC2 to communicate over SSH to ECS Fargate tasks
This answered my question as well https://forum.gitlab.com/t/gitlab-runner-on-private-ip/19673

2 ec2 instance interacting with each other

I am new to aws and ec2 interaction with traffic flow.
I have one ec2 instance which I am using as a web server and other as an application server.
how can my two ec2 interact with each other maintaining all the security required?
Both the ec2 machines are on the ubuntu image.
I tried adding All ICMP - IPv4 with source 0.0.0.0/0. I feel it's not the correct way I want only my other instance to access it.
I also tried adding source as other instance security group but didn't work. I was not able to ping from one machine to other
The recommended security configuration would be:
Create a Security Group for the web server (Web-SG) that permits Inbound traffic for HTTP and HTTPS (ports 80, 443). Leave the Outbound configuration as the default "Allow All".
Create a Security Group for the app server (App-SG) that permits Inbound traffic from Web-SG on the desired ports. Leave the Outbound configuration as the default "Allow All".
That is, App-SG should specifically refer to Web-SG in the Inbound rules. This will permit traffic from Web-SG to enter App-SG.
You might want to add additional access so that you can manage the instances (eg SSH), or you can use AWS Systems Manager Session Manager to connect.
Do not use Ping to test access since that requires additional settings and only proves that Ping works. Instead, test the actual access on the desired ports (eg port 80).

Amazon EC2 Security Group with Host / Dynamic IP / DNS

I am seeking some guidance on the best approach to take with EC2 security groups and services with dynamic IP's. I want to make use of services such as SendGrid, Elastic Cloud etc which all use dyanmic IP's over port 80/443. However access to Port 80/443 is closed with the exception of whitelisted IPs. So far the solutions I have found are:
CRON Job to ping the service, take IP's and update EC2 Security Group via EC2 API.
Create a new EC2 to act as a proxy with port 80/443 open. New server communicates with Sendgrid/ElasticCloud, inspects responses and returns parts to main server.
Are there any other better solutions?
Firstly, please bear in mind that security groups in AWS are stateful, meaning that, for example, if you open ports 80 and 443 to all destinations (0.0.0.0/0) in your outbound rules, your EC2 machines will be able to connect to remote hosts and get the response back even if there are no inbound rules for a given IP.
However, this approach works only if the connection is always initiated by your EC2 instance and remote services are just responding. If you require the connections to your EC2 instances to be initiated from the outside, you do need to specify inbound rules in security group(s). If you know a CIDR block of their public IP addresses, that can solve the problem as you can specify it as a destination in security group rule. If you don't know IP range of the hosts that are going to reach your machines, then access restriction at network level is not feasible and you need to implement some form of authorisation of the requester.
P.S. Please also bear in mind that there is a soft default limit of 50 inbound or outbound rules per security group.

How to establish SSH connection between two machines from different cloud providers?

I have one CentOS instance in AWS and another instance in Hybris Cloud.
The AWS instance is running a Jenkins Server and I want to install a slave for it in the Hybris Cloud Instance.
I have followed the steps to establish SSH connection between two machine but still can't get them to connect.
What am I missing? Is there any special SSH configuration for establishing connection between different cloud providers?
I cant speak for Hybris, but AWS has a security group for your EC2 instance. The security group for your AWS instance must allow port 22 from the IP address of your Hybris server (or a range of IP addresses). In addition, the host firewall on the EC2 Jenkins server must allow for this as well.
Likewise, the Hybris server must have the same ports opened up.
If you continue having issues after checking security groups and host firewalls, check the Network ACL in AWS. If you are in your default VPC and there have been no alterations, the Network ACL should allow for your use case. However if you are in a non-default VPC, whoever created it may have adjusted the Network ACL.