-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ansible): Add role for managing ingress restrictions
Introduces a new Ansible role `ingress-restrictions` with tasks to manage ingress restrictions between edge and middle hosts. Also includes necessary files such as handlers, vars, defaults, and README.
- Loading branch information
Showing
8 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
external/sketch/ansible/roles/ingress-restrictions/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
Whenever we do the grand restructure, this should be done automatically for you everywhere. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
```yml | ||
- hosts: all | ||
roles: | ||
- ingress-restrictions | ||
``` |
2 changes: 2 additions & 0 deletions
2
external/sketch/ansible/roles/ingress-restrictions/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# defaults file for ingress-restrictions |
2 changes: 2 additions & 0 deletions
2
external/sketch/ansible/roles/ingress-restrictions/handlers/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# handlers file for ingress-restrictions |
52 changes: 52 additions & 0 deletions
52
external/sketch/ansible/roles/ingress-restrictions/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
galaxy_info: | ||
author: your name | ||
description: your role description | ||
company: your company (optional) | ||
|
||
# If the issue tracker for your role is not on github, uncomment the | ||
# next line and provide a value | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
|
||
# Choose a valid license ID from https://spdx.org - some suggested licenses: | ||
# - BSD-3-Clause (default) | ||
# - MIT | ||
# - GPL-2.0-or-later | ||
# - GPL-3.0-only | ||
# - Apache-2.0 | ||
# - CC-BY-4.0 | ||
license: license (GPL-2.0-or-later, MIT, etc) | ||
|
||
min_ansible_version: 2.1 | ||
|
||
# If this a Container Enabled role, provide the minimum Ansible Container version. | ||
# min_ansible_container_version: | ||
|
||
# | ||
# Provide a list of supported platforms, and for each platform a list of versions. | ||
# If you don't wish to enumerate all versions for a particular platform, use 'all'. | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
# platforms: | ||
# - name: Fedora | ||
# versions: | ||
# - all | ||
# - 25 | ||
# - name: SomePlatform | ||
# versions: | ||
# - all | ||
# - 1.0 | ||
# - 7 | ||
# - 99.99 | ||
|
||
galaxy_tags: [] | ||
# List tags for your role here, one per line. A tag is a keyword that describes | ||
# and categorizes the role. Users find roles by searching for tags. Be sure to | ||
# remove the '[]' above, if you add tags to this list. | ||
# | ||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
# Maximum 20 tags per role. | ||
|
||
dependencies: [] | ||
# List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
# if you add dependencies to this list. |
33 changes: 33 additions & 0 deletions
33
external/sketch/ansible/roles/ingress-restrictions/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
2 changes: 2 additions & 0 deletions
2
external/sketch/ansible/roles/ingress-restrictions/tests/inventory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
localhost | ||
|
5 changes: 5 additions & 0 deletions
5
external/sketch/ansible/roles/ingress-restrictions/tests/test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- hosts: localhost | ||
remote_user: root | ||
roles: | ||
- ingress-restrictions |
2 changes: 2 additions & 0 deletions
2
external/sketch/ansible/roles/ingress-restrictions/vars/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# vars file for ingress-restrictions |