Skip to content

Commit 9d22ee0

Browse files
Merge pull request #6 from andresionek91/adjust-ip-whitelisting
Adjust ip whitelisting + Create automated tests
2 parents 7cf236c + 7a817d2 commit 9d22ee0

13 files changed

+81
-19
lines changed

.circleci/config.yml

Whitespace-only changes.

.github/workflows/run_tests.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Python 3.8
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.8
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements.txt
24+
pip install -r tests/requirements.txt
25+
- name: Lint with flake8
26+
run: |
27+
# stop the build if there are Python syntax errors or undefined names
28+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
29+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
30+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
31+
- name: Test with pytest
32+
run: |
33+
python -m pytest
34+
- name: Validate Cloudformation Tempates
35+
env:
36+
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
37+
ENVIRONMENT: dev
38+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
39+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
run: |
41+
python -c "from deploy_cloudformation import validate_templates; validate_templates()"

cloudformation/60_databases.yml.j2

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Resources:
88
GroupDescription: Security group for Postgres Metadata DB. Public access
99
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-metadata-db-public-security-group"
1010
SecurityGroupEgress:
11-
- CidrIp: 0.0.0.0/0
11+
{% for ip in whitelistedIPs %}
12+
- CidrIp: "{{ ip }}"
1213
FromPort: "{{ metadataDb.port }}"
13-
IpProtocol: -1
14+
IpProtocol: tcp
1415
ToPort: "{{ metadataDb.port }}"
16+
{% endfor %}
1517
SecurityGroupIngress:
1618
- CidrIp: 0.0.0.0/0
1719
FromPort: "{{ metadataDb.port }}"

cloudformation/70_redis.yml.j2

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ Resources:
1717
GroupDescription: Security group for Redis
1818
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-redis-security-group"
1919
SecurityGroupEgress:
20-
- CidrIp: 0.0.0.0/0
21-
FromPort: 0
22-
IpProtocol: -1
23-
ToPort: 0
20+
{% for ip in whitelistedIPs %}
21+
- CidrIp: "{{ ip }}"
22+
FromPort: "{{ celeryBackend.port }}"
23+
IpProtocol: tcp
24+
ToPort: "{{ celeryBackend.port }}"
25+
{% endfor %}
2426
SecurityGroupIngress:
2527
- CidrIp: "{{ service.cidrBlock }}/16"
2628
FromPort: "{{ celeryBackend.port }}"

cloudformation/83_airflow-flower.yml.j2

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ Resources:
77
GroupDescription: Security group for Airflow Flower. Allow all inbound traffic.
88
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-flower-external-security-group"
99
SecurityGroupEgress:
10-
{{ securityGroupEgressRules }}
10+
{% for ip in whitelistedIPs %}
11+
- CidrIp: "{{ ip }}"
12+
FromPort: 80
13+
IpProtocol: tcp
14+
ToPort: 80
15+
- CidrIp: "{{ ip }}"
16+
FromPort: 443
17+
IpProtocol: tcp
18+
ToPort: 443
19+
{% endfor %}
1120
SecurityGroupIngress:
1221
- CidrIp: 0.0.0.0/0
1322
FromPort: "{{ service.port }}"

cloudformation/84_airflow-scheduler.yml.j2

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Resources:
66
Properties:
77
GroupDescription: Security group for Airflow Scheduler
88
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-scheduler-security-group"
9-
SecurityGroupEgress:
10-
{{ securityGroupEgressRules }}
119
VpcId: !ImportValue network-VpcId
1210
Tags:
1311
- Key: Name

cloudformation/85_airflow-webserver.yml.j2

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ Resources:
77
GroupDescription: Security group for Airflow webserver. Allow all inbound traffic.
88
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-webserver-security-group"
99
SecurityGroupEgress:
10-
{{ securityGroupEgressRules }}
10+
{% for ip in whitelistedIPs %}
11+
- CidrIp: "{{ ip }}"
12+
FromPort: 80
13+
IpProtocol: tcp
14+
ToPort: 80
15+
- CidrIp: "{{ ip }}"
16+
FromPort: 443
17+
IpProtocol: tcp
18+
ToPort: 443
19+
{% endfor %}
1120
SecurityGroupIngress:
1221
- CidrIp: 0.0.0.0/0
1322
FromPort: "{{ service.port }}"

cloudformation/86_airflow-workers.yml.j2

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Resources:
66
Properties:
77
GroupDescription: Security group for Airflow workers
88
GroupName: "{{ serviceName }}-{{ ENVIRONMENT }}-workers-security-group"
9-
SecurityGroupEgress:
10-
{{ securityGroupEgressRules }}
119
SecurityGroupIngress:
1210
- CidrIp: "{{ service.cidrBlock }}/16"
1311
FromPort: "{{ service.workers.port }}"

deploy_cloudformation.py

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def get_cloudformation_templates(reverse=False):
4444

4545
def validate_templates():
4646
cf_templates = get_cloudformation_templates()
47-
4847
for cf_template in cf_templates:
4948
logging.info('Validating CF template {}'.format(cf_template['filename']))
5049
cloudformation_client.validate_template(

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
boto3==1.13.19
22
cryptography==2.9.2
3-
pandas==0.24.0
3+
pandas==1.1.2
4+
numpy==1.18.4
45
toolz==0.9.0
56
jinja2==2.11.2
67
click==7.1.2

service.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ publicSubnet:
8383

8484
# List of SecurityGroupEgress.
8585
# Will be used to whitelist IPs for webserver, flower, workers and scheduler
86-
securityGroupEgressRules:
87-
- CidrIp: 0.0.0.0/0
88-
FromPort: 0
89-
IpProtocol: -1
90-
ToPort: 0
86+
whitelistedIPs:
87+
- 0.0.0.0/0
9188

9289
metadataDb:
9390
instanceType: db.t3.micro
@@ -103,6 +100,7 @@ metadataDb:
103100
maxConnections: 100
104101

105102

103+
106104
celeryBackend:
107105
port: 6379
108106
azMode: single-az

tests/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flake8==3.8.3
2+
pytest==6.0.1

tests/test_dummy.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def test_dummy():
3+
assert True

0 commit comments

Comments
 (0)