Skip to content

Commit 03e6636

Browse files
committed
Create network infrastructure in Azure with blocked outbound traffic
1 parent 7625474 commit 03e6636

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
@@ -55,6 +55,7 @@ az_subnets: |
5555
5656
# Security group
5757
az_network_security_group: "{{ az_resources_prefix }}-nsg"
58+
az_nsg_block_edgess: false
5859

5960

6061
# Private DNS zone

roles/azure_controllers/tasks/azure_vbond_vm.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@
5757
azure.azcollection.azure_rm_securitygroup:
5858
resource_group: "{{ az_resource_group }}"
5959
name: "{{ az_network_security_group }}"
60-
rules:
61-
- name: "{{ public_ip_state.state.name }}"
62-
protocol: "*"
63-
destination_port_range: "*"
64-
source_port_range: "*"
65-
source_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: Inbound
60+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
6961
tags:
7062
Name: "{{ az_network_security_group }}"
7163
Creator: "{{ az_tag_creator }}"
@@ -76,6 +68,25 @@
7668
index_var: my_idx
7769
label: public_ip_state.state.name
7870
when: public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
71+
vars:
72+
inbound_rule:
73+
name: "{{ public_ip_state.state.name }}"
74+
protocol: "*"
75+
destination_port_range: "*"
76+
source_port_range: "*"
77+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
78+
access: Allow
79+
priority: "{{ 1500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
80+
direction: Inbound
81+
outbound_rule:
82+
name: "{{ public_ip_state.state.name }}-out"
83+
protocol: "*"
84+
destination_port_range: "*"
85+
source_port_range: "*"
86+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
87+
access: Allow
88+
priority: "{{ 1500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
89+
direction: Outbound
7990

8091
- name: "Create virtual network interface cards"
8192
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
@@ -60,15 +60,7 @@
6060
azure.azcollection.azure_rm_securitygroup:
6161
resource_group: "{{ az_resource_group }}"
6262
name: "{{ az_network_security_group }}"
63-
rules:
64-
- name: "{{ public_ip_state.state.name }}"
65-
protocol: "*"
66-
destination_port_range: "*"
67-
source_port_range: "*"
68-
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
69-
access: Allow
70-
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
71-
direction: Inbound
63+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
7264
tags:
7365
Name: "{{ az_network_security_group }}"
7466
Creator: "{{ az_tag_creator }}"
@@ -81,6 +73,25 @@
8173
when:
8274
- public_ip_state.state is defined
8375
- public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
76+
vars:
77+
inbound_rule:
78+
name: "{{ public_ip_state.state.name }}"
79+
protocol: "*"
80+
destination_port_range: "*"
81+
source_port_range: "*"
82+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
83+
access: Allow
84+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
85+
direction: Inbound
86+
outbound_rule:
87+
name: "{{ public_ip_state.state.name }}-out"
88+
protocol: "*"
89+
destination_port_range: "*"
90+
source_port_range: "*"
91+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
92+
access: Allow
93+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
94+
direction: Outbound
8495

8596
- name: "Create virtual network interface cards for public interfaces"
8697
azure.azcollection.azure_rm_networkinterface:
@@ -148,22 +159,33 @@
148159
azure.azcollection.azure_rm_securitygroup:
149160
resource_group: "{{ az_resource_group }}"
150161
name: "{{ az_network_security_group }}"
151-
rules:
152-
- name: "{{ cluster_vmanage_nic.state.name }}"
153-
protocol: "*"
154-
destination_port_range: "*"
155-
source_port_range: "*"
156-
source_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
157-
access: Allow
158-
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
159-
direction: Inbound
162+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
160163
tags:
161164
Name: "{{ az_network_security_group }}"
162165
Creator: "{{ az_tag_creator }}"
163166
Organization: "{{ organization_name }}"
164167
when:
165168
- cluster_subnet is defined
166169
- cluster_subnet != ""
170+
vars:
171+
inbound_rule:
172+
name: "{{ cluster_vmanage_nic.state.name }}"
173+
protocol: "*"
174+
destination_port_range: "*"
175+
source_port_range: "*"
176+
source_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
177+
access: Allow
178+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
179+
direction: Inbound
180+
outbound_rule:
181+
name: "{{ cluster_vmanage_nic.state.name }}-out"
182+
protocol: "*"
183+
destination_port_range: "*"
184+
source_port_range: "*"
185+
destination_address_prefix: "{{ cluster_vmanage_nic.state.ip_configuration.private_ip_address }}"
186+
access: Allow
187+
priority: "{{ 2500 + ((az_res_gr.securitygroups | first).rules | length) + 1 }}"
188+
direction: Outbound
167189

168190
- name: Set az_network_interfaces_vmanage fact with a list of interfaces for vmanage
169191
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
@@ -57,15 +57,7 @@
5757
azure.azcollection.azure_rm_securitygroup:
5858
resource_group: "{{ az_resource_group }}"
5959
name: "{{ az_network_security_group }}"
60-
rules:
61-
- name: "{{ public_ip_state.state.name }}"
62-
protocol: "*"
63-
destination_port_range: "*"
64-
source_port_range: "*"
65-
source_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: Inbound
60+
rules: "{{ [inbound_rule, outbound_rule] if az_nsg_block_edgess else [inbound_rule] }}"
6961
tags:
7062
Name: "{{ az_network_security_group }}"
7163
Creator: "{{ az_tag_creator }}"
@@ -76,6 +68,25 @@
7668
index_var: my_idx
7769
label: public_ip_state.state.name
7870
when: public_ip_state.state.name not in az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='name') | list
71+
vars:
72+
inbound_rule:
73+
name: "{{ public_ip_state.state.name }}"
74+
protocol: "*"
75+
destination_port_range: "*"
76+
source_port_range: "*"
77+
source_address_prefix: "{{ public_ip_state.state.ip_address }}"
78+
access: Allow
79+
priority: "{{ 2000 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
80+
direction: Inbound
81+
outbound_rule:
82+
name: "{{ public_ip_state.state.name }}-out"
83+
protocol: "*"
84+
destination_port_range: "*"
85+
source_port_range: "*"
86+
destination_address_prefix: "{{ public_ip_state.state.ip_address }}"
87+
access: Allow
88+
priority: "{{ 2000 + ((az_res_gr.securitygroups | first).rules | length) + 1 + my_idx }}"
89+
direction: Outbound
7990

8091
- name: "Create virtual network interface cards"
8192
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)