Skip to content

Commit 14bc4f6

Browse files
committed
Create network infrastructure in Azure with blocked outbound traffic
1 parent 0528bbb commit 14bc4f6

File tree

5 files changed

+114
-37
lines changed

5 files changed

+114
-37
lines changed

roles/azure_controllers/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ az_subnets: |
4747
4848
# Security group
4949
az_network_security_group: "{{ az_resources_prefix }}-nsg"
50+
az_nsg_block_edgess: false
5051

5152

5253
# VPN subnets from which we can connect to Azure EIPs (Network Security Group config)

roles/azure_controllers/tasks/azure_vbond_vm.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@
3636
azure.azcollection.azure_rm_securitygroup:
3737
resource_group: "{{ az_resource_group }}"
3838
name: "{{ az_network_security_group }}"
39-
rules:
40-
- name: "{{ public_ip_state.state.name }}"
41-
protocol: "*"
42-
destination_port_range: "*"
43-
source_port_range: "*"
44-
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
45-
access: Allow
46-
priority: "{{ 1500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
47-
direction: Inbound
39+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
4840
tags:
4941
Name: "{{ az_network_security_group }}"
5042
Creator: "{{ az_tag_creator }}"
@@ -55,6 +47,25 @@
5547
index_var: my_idx
5648
label: public_ip_state.state.name
5749
when: public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
50+
vars:
51+
inbound_rule:
52+
name: "{{ public_ip_state.state.name }}"
53+
protocol: "*"
54+
destination_port_range: "*"
55+
source_port_range: "*"
56+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
57+
access: Allow
58+
priority: "{{ 1500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
59+
direction: Inbound
60+
outbound_rule:
61+
name: "{{ public_ip_state.state.name }}-out"
62+
protocol: "*"
63+
destination_port_range: "*"
64+
source_port_range: "*"
65+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
66+
access: Allow
67+
priority: "{{ 1500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
68+
direction: Outbound
5869

5970
- name: "Create virtual network interface cards"
6071
azure.azcollection.azure_rm_networkinterface:

roles/azure_controllers/tasks/azure_vmanage_vm.yml

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@
3838
azure.azcollection.azure_rm_securitygroup:
3939
resource_group: "{{ az_resource_group }}"
4040
name: "{{ az_network_security_group }}"
41-
rules:
42-
- name: "{{ public_ip_state.state.name }}"
43-
protocol: "*"
44-
destination_port_range: "*"
45-
source_port_range: "*"
46-
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
47-
access: Allow
48-
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
49-
direction: Inbound
41+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
5042
tags:
5143
Name: "{{ az_network_security_group }}"
5244
Creator: "{{ az_tag_creator }}"
@@ -59,6 +51,25 @@
5951
when:
6052
- public_ip_state.state is defined
6153
- public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
54+
vars:
55+
inbound_rule:
56+
name: "{{ public_ip_state.state.name }}"
57+
protocol: "*"
58+
destination_port_range: "*"
59+
source_port_range: "*"
60+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
61+
access: Allow
62+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
63+
direction: Inbound
64+
outbound_rule:
65+
name: "{{ public_ip_state.state.name }}-out"
66+
protocol: "*"
67+
destination_port_range: "*"
68+
source_port_range: "*"
69+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
70+
access: Allow
71+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
72+
direction: Outbound
6273

6374
- name: "Create virtual network interface cards for public interfaces"
6475
azure.azcollection.azure_rm_networkinterface:
@@ -120,22 +131,33 @@
120131
azure.azcollection.azure_rm_securitygroup:
121132
resource_group: "{{ az_resource_group }}"
122133
name: "{{ az_network_security_group }}"
123-
rules:
124-
- name: "{{ cluster_vmanage_nic.state.name }}"
125-
protocol: "*"
126-
destination_port_range: "*"
127-
source_port_range: "*"
128-
source_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
129-
access: Allow
130-
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
131-
direction: Inbound
134+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
132135
tags:
133136
Name: "{{ az_network_security_group }}"
134137
Creator: "{{ az_tag_creator }}"
135138
Organization: "{{ organization_name }}"
136139
when:
137140
- cluster_subnet is defined
138141
- cluster_subnet != ""
142+
vars:
143+
inbound_rule:
144+
name: "{{ cluster_vmanage_nic.state.name }}"
145+
protocol: "*"
146+
destination_port_range: "*"
147+
source_port_range: "*"
148+
source_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
149+
access: Allow
150+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
151+
direction: Inbound
152+
outbound_rule:
153+
name: "{{ cluster_vmanage_nic.state.name }}-out"
154+
protocol: "*"
155+
destination_port_range: "*"
156+
source_port_range: "*"
157+
destination_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
158+
access: Allow
159+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
160+
direction: Outbound
139161

140162
- name: Set az_network_interfaces_vmanage fact with a list of interfaces for vmanage
141163
ansible.builtin.set_fact:

roles/azure_controllers/tasks/azure_vsmart_vm.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@
3636
azure.azcollection.azure_rm_securitygroup:
3737
resource_group: "{{ az_resource_group }}"
3838
name: "{{ az_network_security_group }}"
39-
rules:
40-
- name: "{{ public_ip_state.state.name }}"
41-
protocol: "*"
42-
destination_port_range: "*"
43-
source_port_range: "*"
44-
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
45-
access: Allow
46-
priority: "{{ 2000 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
47-
direction: Inbound
39+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
4840
tags:
4941
Name: "{{ az_network_security_group }}"
5042
Creator: "{{ az_tag_creator }}"
@@ -55,6 +47,25 @@
5547
index_var: my_idx
5648
label: public_ip_state.state.name
5749
when: public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
50+
vars:
51+
inbound_rule:
52+
name: "{{ public_ip_state.state.name }}"
53+
protocol: "*"
54+
destination_port_range: "*"
55+
source_port_range: "*"
56+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
57+
access: Allow
58+
priority: "{{ 2000 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
59+
direction: Inbound
60+
outbound_rule:
61+
name: "{{ public_ip_state.state.name }}-out"
62+
protocol: "*"
63+
destination_port_range: "*"
64+
source_port_range: "*"
65+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
66+
access: Allow
67+
priority: "{{ 2000 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
68+
direction: Outbound
5869

5970
- name: "Create virtual network interface cards"
6071
azure.azcollection.azure_rm_networkinterface:

roles/azure_network_infrastructure/tasks/azure_network_infrastructure.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,46 @@
8080
Creator: "{{ az_tag_creator }}"
8181
Organization: "{{ organization_name }}"
8282

83-
- name: "Create Network Security Group: {{ az_network_security_group }}"
83+
- name: "Block Outbound traffic: {{ az_network_security_group }}"
8484
azure.azcollection.azure_rm_securitygroup:
8585
resource_group: "{{ az_resource_group }}"
8686
name: "{{ az_network_security_group }}"
8787
rules:
8888
- name: DenyAll
8989
access: Deny
9090
direction: Outbound
91+
priority: 4000
92+
- name: ExternalTCP-out
93+
protocol: Tcp
94+
destination_port_range:
95+
- 22
96+
- 443
97+
- 830 # NETCONF over SSH
98+
- 8443
99+
source_address_prefix: "{{ az_allowed_subnets }}"
100+
access: Allow
101+
priority: 1001
102+
direction: Outbound
103+
- name: InternalTCP-out
104+
protocol: Tcp
105+
destination_port_range: 23456-24156
106+
source_address_prefix: "{{ az_allowed_subnets }}"
107+
access: Allow
108+
priority: 1002
109+
direction: Outbound
110+
- name: InternalUDP-out
111+
protocol: Udp
112+
destination_port_range: 12346-13046
113+
source_address_prefix: "{{ az_allowed_subnets }}"
114+
access: Allow
115+
priority: 1003
116+
direction: Outbound
117+
- name: ICMP-out
118+
protocol: Icmp
119+
source_address_prefix: "{{ az_allowed_subnets }}"
120+
access: Allow
121+
priority: 1004
122+
direction: Outbound
91123
tags:
92124
Name: "{{ az_network_security_group }}"
93125
Creator: "{{ az_tag_creator }}"

0 commit comments

Comments
 (0)