Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingress restrictions #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions external/sketch/ansible/roles/ingress-restrictions/README.md
devzspy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ingress-restrictions
=========

This role is used to help reduce the chances for backflip correlation from public ssh keys from tools like Censys.

This will automatically tell middle hosts to only allow connections on port 2222 from edge hosts.

This role only handles the sketch infrastructure as of now.

Requirements
------------

Once you've ran this in your Sketch infrastructure, you will need to grab the IP Addresses or IP Address range from your middles and add them to your OCI/AWS infrastructure manually.
devzspy marked this conversation as resolved.
Show resolved Hide resolved

Whenever we do the grand restructure, this should be done automatically for you everywhere.

Example Playbook
----------------

```yml
- hosts: all
roles:
- ingress-restrictions
```
devzspy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
33 changes: 33 additions & 0 deletions external/sketch/ansible/roles/ingress-restrictions/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# tasks file for ingress-restrictions

- name: Set fact for 'edge' hosts
set_fact:
is_edge_host: true
when: "'edge' in inventory_hostname"

- name: Gather Edge IPs into a dictionary
set_fact:
edge_ips_dict: >-
{{
edge_ips_dict | default({}) | combine(
{ item: hostvars[item]['host_ip_address'] }
)
}}
loop: "{{ groups['all'] }}"
when: hostvars[item]['is_edge_host'] is defined and hostvars[item]['is_edge_host']
delegate_to: localhost

- name: Allow port 2222 from Edges to Middles
ufw:
rule: allow
port: 2222
from_ip: "{{ item.value }}"
with_items: "{{ edge_ips_dict | dict2items }}"
when: "'middle' in inventory_hostname"

- name: Deny port 2222
ufw:
rule: deny
port: 2222
when: "'middle' in inventory_hostname"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ingress-restrictions