Skip to content

Commit df23de8

Browse files
guruchairsarvananraju-saravanan
authored
Support Private Networks (#15)
* Add level-1 private networking to deploy tool. * Support creation of multiple nat gateway and private route table. * Place all the private network changes behind a flag * Use env.tunnel instead of globals.env_network_type and fix syntactic issues * Excluding CDP Cidr from inbound security group. * Addressed the comments using existing properties and introduced publicendpoint access for AWS * Add public endpoint gateway support for experiences * Support level-1 network for CDW * Avoids duplicate route table creation of one exists and fixes error handling in NAT gateway failures Signed-off-by: guruchai <ggchaitanya@gmail.com> Co-authored-by: Saravanan Raju <sraju@cloudera.com> Co-authored-by: Saravanan Raju <saravanan.footloose@gmail.com>
1 parent 2f94396 commit df23de8

File tree

15 files changed

+207
-40
lines changed

15 files changed

+207
-40
lines changed

docs/configuration.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ env:
169169
delete_policies:
170170
delete_roles:
171171
delete_user_group:
172+
# Setting tunnel option to true enables CCM gateway which removes the need for the environment hosts to have a public IP address
172173
tunnel:
174+
# Setting public_endpoint_access to true enables public workload endpoint access gateway which lets user access workload from internet
175+
# default is false. Needing when tunneling is enabled but dont have the direct connectivity with the VPC.
176+
public_endpoint_access:
173177
workload_analytics:
174178
globals:
175179
admin_password:
@@ -205,7 +209,6 @@ globals:
205209
public:
206210
ranger_audit:
207211
role:
208-
route_table:
209212
service_network:
210213
storage:
211214
subnet:
@@ -237,9 +240,10 @@ infra:
237240
name:
238241
suffix:
239242
labels:
240-
route_table:
241-
route_table:
242-
suffix:
243+
public_route_table:
244+
private_route_table:
245+
public_route_table_suffix:
246+
private_route_table_suffix:
243247
azure:
244248
metagroup:
245249
name:
@@ -323,6 +327,7 @@ ml:
323327
k8s_request_base:
324328
suffix:
325329
tags:
330+
public_loadbalancer:
326331
opdb:
327332
definitions:
328333
suffix:

roles/common/defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ common__datalake_admin_suffix: "{{ globals.labels.datalake_admin | de
4545
common__ranger_audit_suffix: "{{ globals.labels.ranger_audit | default('audit') }}"
4646
common__cml_suffix: "{{ globals.labels.cml | default('cml') }}"
4747
common__igw_suffix: "{{ globals.labels.internet_gateway | default('igw') }}"
48-
common__route_table_suffix: "{{ globals.labels.route_table | default('rtb') }}"
4948
common__app_suffix: "{{ globals.labels.app | default('app') }}"
5049
common__group_suffix: "{{ globals.labels.group | default('group') }}"
5150
common__admin_suffix: "{{ globals.labels.admin | default('admin') }}"
5251
common__user_suffix: "{{ globals.labels.user | default('user') }}"
52+
common__ngw_suffix: "{{ globals.labels.nat_gateway | default('ngw') }}"
5353

5454
common__unique_storage_name_suffix: "{{ globals.storage.name | default((common__region + common__aws_profile) if 'aws' in common__infra_type else common__region) }}"
5555

@@ -121,6 +121,8 @@ common__env_name_suffix: "{{ env.suffix | default(common__env_s
121121

122122
common__datalake_name: "{{ env.datalake.name | default([common__namespace_cdp, common__datalake_name_suffix] | join('-')) }}"
123123
common__datalake_name_suffix: "{{ env.datalake.suffix | default(common__datalake_suffix) }}"
124+
common__tunnel: "{{ env.tunnel | default(False) }}"
125+
common__public_endpoint_access: "{{ env.public_endpoint_access | default(not common__tunnel) }}"
124126

125127
common__env_admin_password: "{{ globals.admin_password | mandatory }}"
126128
# Deploy

roles/infrastructure/defaults/main.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ infra__vpc_public_subnets_suffix: "{{ common__vpc_public_subnets_suffix }}"
2828

2929
# Infra
3030
infra__type: "{{ common__infra_type }}"
31+
infra__tunnel: "{{ common__tunnel }}"
3132

3233
# Dynamic Inventory for Clusters
3334
infra__private_key_file: "{{ globals.ssh.private_key_file | default('') }}"
@@ -90,8 +91,14 @@ infra__aws_dynamodb_table_name: "{{ common__aws_dynamodb_table_name }}"
9091
infra__aws_vpc_az_count: "{{ infra.aws.vpc.az_count | default(3) }}"
9192
infra__aws_igw_name: "{{ infra.aws.vpc.internet_gateway.name | default([infra__namespace, infra__aws_igw_suffix] | join('-')) }}"
9293
infra__aws_igw_suffix: "{{ infra.aws.vpc.internet_gateway.suffix | default(common__igw_suffix) }}"
93-
infra__aws_route_table_name: "{{ infra.aws.vpc.labels.route_table | default([infra__namespace, infra__aws_route_table_suffix] | join('-')) }}"
94-
infra__aws_route_table_suffix: "{{ infra.aws.vpc.route_table.suffix | default(common__route_table_suffix) }}"
94+
95+
infra__aws_public_route_table_suffix: "{{ infra.aws.vpc.labels.public_route_table_suffix | default('public-rtb') }}"
96+
infra__aws_private_route_table_suffix: "{{ infra.aws.vpc.labels.private_route_table_suffix | default('private-rtb') }}"
97+
infra__aws_public_route_table_name: "{{ infra.aws.vpc.labels.public_route_table | default([infra__namespace, infra__aws_public_route_table_suffix] | join('-')) }}"
98+
infra__aws_private_route_table_name: "{{ infra.aws.vpc.labels.private_route_table | default([infra__namespace, infra__aws_private_route_table_suffix] | join('-')) }}"
99+
100+
infra__aws_nat_gateway_name: "{{ infra.aws.vpc.nat_gateway.name | default([infra__namespace, infra__aws_nat_gateway_suffix] | join('-')) }}"
101+
infra__aws_nat_gateway_suffix: "{{ infra.aws.vpc.nat_gateway.suffix | default(common__ngw_suffix) }}"
95102

96103
# GCP
97104
infra__gcp_project: "{{ common__gcp_project }}"

roles/infrastructure/tasks/initialize_setup_aws.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
cidr_ip: "{{ infra__vpc_extra_cidr }}"
9292

9393
- name: Add CDP Public Cloud security group rules for AWS
94+
when: not infra__tunnel
9495
ansible.builtin.set_fact:
9596
infra__aws_security_group_rules: "{{ infra__aws_security_group_rules | union([rule]) }}"
9697
vars:

roles/infrastructure/tasks/setup_aws_network.yml

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,28 @@
4040
ansible.builtin.set_fact:
4141
infra__aws_igw_id: "{{ __aws_igw.gateway_id }}"
4242

43-
- name: Create AWS VPC Subnets
43+
- name: Create AWS VPC Public Subnets
4444
amazon.aws.ec2_vpc_subnet:
4545
region: "{{ infra__region }}"
4646
vpc_id: "{{ infra__aws_vpc_id }}"
47-
cidr: "{{ __aws_subnet_create_item.cidr }}"
47+
cidr: "{{ __aws_public_subnet_item.cidr }}"
4848
state: present
49-
tags: "{{ infra__tags | combine(__aws_subnet_create_item.tags, recursive=True) }}"
49+
tags: "{{ infra__tags | combine(__aws_public_subnet_item.tags, recursive = true) }}"
5050
map_public: yes
5151
az: "{{ __aws_az_info.availability_zones[__aws_subnet_index % infra__aws_vpc_az_count | int].zone_name }}"
5252
loop_control:
53-
loop_var: __aws_subnet_create_item
53+
loop_var: __aws_public_subnet_item
5454
index_var: __aws_subnet_index
55-
label: __aws_subnet_create_item.name
56-
loop: "{{ infra__vpc_public_subnets_info | union(infra__vpc_private_subnets_info) }}"
57-
register: __aws_subnets
55+
loop: "{{ infra__vpc_public_subnets_info }}"
56+
register: __aws_public_subnets
5857

59-
- name: Set fact for AWS Subnet IDs
58+
- name: Set fact for AWS Public Subnet IDs
6059
ansible.builtin.set_fact:
61-
infra__aws_subnet_ids: "{{ infra__aws_subnet_ids | default([]) | union([__aws_subnet_item.subnet.id | default('')]) }}"
60+
infra__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids | default([]) | union([__aws_subnet_item.subnet.id | default('')]) }}"
6261
loop_control:
6362
loop_var: __aws_subnet_item
6463
label: "{{ __aws_subnet_item.subnet.id }}"
65-
loop: "{{ __aws_subnets.results }}"
64+
loop: "{{ __aws_public_subnets.results }}"
6665

6766
- name: List the Route Tables for the VPC
6867
community.aws.ec2_vpc_route_table_info:
@@ -71,20 +70,84 @@
7170
vpc-id: "{{ infra__aws_vpc_id }}"
7271
register: __aws_route_table_list
7372

74-
- name: Configure the Route Table
73+
- name: Configure the Public Route Table
7574
community.aws.ec2_vpc_route_table:
7675
region: "{{ infra__region }}"
7776
vpc_id: "{{ infra__aws_vpc_id }}"
7877
route_table_id: "{{ __aws_route_table_id }}"
7978
lookup: id
8079
state: present
81-
tags: "{{ infra__tags | combine({ 'Name': infra__aws_route_table_name }, recursive=True) }}"
80+
tags: "{{ infra__tags | combine({ 'Name': infra__aws_public_route_table_name }, recursive=True) }}"
8281
routes:
8382
- dest: "0.0.0.0/0"
8483
gateway_id: "{{ infra__aws_igw_id }}"
85-
subnets: "{{ infra__aws_subnet_ids }}"
84+
subnets: "{{ infra__aws_public_subnet_ids }}"
8685
vars:
87-
__aws_route_table_id: "{{ __aws_route_table_list.route_tables[0].associations[0].route_table_id }}"
86+
__aws_route_table_id: "{{ __aws_route_table_list.route_tables | json_query(__aws_rtb_jq) | flatten | first }}"
87+
__aws_rtb_jq: "[*].associations[?main == `true` ].route_table_id"
88+
89+
- name: Set the fact for Subnet Ids
90+
when: not infra__tunnel
91+
ansible.builtin.set_fact:
92+
infra__aws_subnet_ids: "{{ infra__aws_public_subnet_ids }}"
93+
94+
- name: Setup for private networking
95+
when: infra__tunnel
96+
block:
97+
- name: Create AWS VPC Private Subnets
98+
amazon.aws.ec2_vpc_subnet:
99+
region: "{{ infra__region }}"
100+
vpc_id: "{{ infra__aws_vpc_id }}"
101+
cidr: "{{ __aws_private_subnet_item.cidr }}"
102+
state: present
103+
tags: "{{ infra__tags | combine(__aws_private_subnet_item.tags, recursive = true) }}"
104+
map_public: no
105+
az: "{{ __aws_az_info.availability_zones[__aws_subnet_index % infra__aws_vpc_az_count | int].zone_name }}"
106+
loop_control:
107+
loop_var: __aws_private_subnet_item
108+
index_var: __aws_subnet_index
109+
label: "{{ __aws_private_subnet_item.name }}"
110+
loop: "{{ infra__vpc_private_subnets_info }}"
111+
register: __aws_private_subnets
112+
113+
- name: Set fact for AWS Private Subnet IDs
114+
ansible.builtin.set_fact:
115+
infra__aws_private_subnet_ids: "{{ infra__aws_private_subnet_ids | default([]) | union([__aws_subnet_item.subnet.id | default('')]) }}"
116+
loop_control:
117+
loop_var: __aws_subnet_item
118+
loop: "{{ __aws_private_subnets.results }}"
119+
120+
- name: Set fact for Subnet Ids
121+
ansible.builtin.set_fact:
122+
infra__aws_subnet_ids: "{{ infra__aws_public_subnet_ids | union(infra__aws_private_subnet_ids) }}"
123+
124+
- name: Creates NAT gateways and allocates EIPs
125+
community.aws.ec2_vpc_nat_gateway:
126+
state: present
127+
subnet_id: "{{ __aws_public_subnet_id }}"
128+
wait: true
129+
if_exist_do_not_create: true
130+
region: "{{ infra__region }}"
131+
tags: "{{ infra__tags | combine({ 'Name': '-'.join([infra__aws_nat_gateway_name, __aws_public_subnet_index | string]) }, recursive=True) }}"
132+
loop_control:
133+
loop_var: __aws_public_subnet_id
134+
index_var: __aws_public_subnet_index
135+
loop: "{{ infra__aws_public_subnet_ids }}"
136+
register: __aws_ngws
137+
138+
- name: Configure Private Route Tables
139+
community.aws.ec2_vpc_route_table:
140+
vpc_id: "{{ infra__aws_vpc_id }}"
141+
region: "{{ infra__region }}"
142+
tags: "{{ infra__tags | combine({ 'Name': '-'.join([infra__aws_private_route_table_name, __aws_private_subnet_id_index | string]) }, recursive=True) }}"
143+
subnets: "{{ __aws_private_subnet_id_item }}"
144+
routes:
145+
- dest: "0.0.0.0/0"
146+
nat_gateway_id: "{{ __aws_ngws.results[ __aws_private_subnet_id_index % __aws_ngws.results | length ].nat_gateway_id }}"
147+
loop_control:
148+
loop_var: __aws_private_subnet_id_item
149+
index_var: __aws_private_subnet_id_index
150+
loop: "{{ infra__aws_private_subnet_ids }}"
88151

89152
- name: Create Security Groups
90153
amazon.aws.ec2_group:

roles/infrastructure/tasks/teardown_aws_network.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,47 @@
2929
- "{{ infra__security_group_knox_name }}"
3030
- "{{ infra__security_group_default_name }}"
3131

32+
- name: Remove the private networking setup
33+
when: infra__tunnel
34+
block:
35+
- name: Delete the private route tables
36+
community.aws.ec2_vpc_route_table:
37+
vpc_id: "{{ infra__aws_vpc_id }}"
38+
region: "{{ infra__region }}"
39+
lookup: tag
40+
tags: "{{ { 'Name': '-'.join([infra__aws_private_route_table_name, __aws_private_subnet_id_index | string])} }}"
41+
state: absent
42+
loop_control:
43+
index_var: __aws_private_subnet_id_index
44+
loop: "{{ infra__vpc_private_subnet_cidrs }}"
45+
46+
- name: List all managed nat gateways within this VPC
47+
community.aws.ec2_vpc_nat_gateway_info:
48+
region: "{{ infra__region }}"
49+
filters:
50+
vpc-id: "{{ infra__aws_vpc_id }}"
51+
register: __aws_all_ngws
52+
53+
- name: Delete nat gateway using discovered nat gateways from facts module.
54+
community.aws.ec2_vpc_nat_gateway:
55+
state: absent
56+
region: "{{ infra__region }}"
57+
wait: true
58+
nat_gateway_id: "{{ item.nat_gateway_id }}"
59+
release_eip: true
60+
register: __aws_ngw_teardown
61+
loop_control:
62+
label: "{{ item.nat_gateway_id }}"
63+
loop: "{{ __aws_all_ngws.result }}"
64+
ignore_errors: true
65+
66+
- name: Check if NAT gateways are deleted succesfully
67+
when: __aws_ngw_teardown is defined and __aws_ngw_teardown.results is defined and __aws_ngw_teardown.results | count > 0
68+
ansible.builtin.fail:
69+
msg: "Failed to delete a NAT gateway"
70+
failed_when: item.rc is defined and item.rc != 1 and ('InvalidAllocationID.NotFound' in item.module_stderr)
71+
loop: "{{ __aws_ngw_teardown.results }}"
72+
3273
- name: Remove VPC subnets
3374
amazon.aws.ec2_vpc_subnet:
3475
region: "{{ infra__region }}"

roles/platform/defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ plat__teardown_deletes_user_group: "{{ env.teardown.delete_user_group
6161
plat__xacccount_credential_name: "{{ common__xaccount_credential_name }}"
6262

6363
plat__workload_analytics: "{{ env.workload_analytics | default(True) }}"
64-
plat__tunnel: "{{ env.tunnel | default(True) }}"
64+
plat__tunnel: "{{ common__tunnel }}"
65+
plat__public_endpoint_access: "{{ common__public_endpoint_access }}"
6566

6667
plat__env_admin_password: "{{ common__env_admin_password }}"
6768

roles/platform/tasks/initialize_setup_aws.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
ansible.builtin.set_fact:
9393
plat__aws_subnet_ids: "{{ infra__aws_subnet_ids }}"
9494

95+
- name: Set public subnets for public endpoint access
96+
when: plat__public_endpoint_access
97+
ansible.builtin.set_fact:
98+
plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}"
99+
plat__endpoint_access_scheme: "PUBLIC"
100+
95101
- name: Discover AWS Security Group for Knox
96102
when: infra__aws_security_group_knox_id is undefined
97103
block:

roles/platform/tasks/setup_aws_env.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
subnet_ids: "{{ plat__aws_subnet_ids }}"
3232
s3_guard_name: "{{ plat__aws_dynamodb_table_name }}"
3333
tags: "{{ plat__tags }}"
34+
tunnel: "{{ plat__tunnel }}"
35+
endpoint_access_scheme: "{{ plat__endpoint_access_scheme | default(omit) }}"
36+
endpoint_access_subnets: "{{ plat__aws_public_subnet_ids | default(omit) }}"

roles/platform/vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
# Vars for platform
18-
plat__aws_policy_urls_default_root: "https://github.com/hortonworks/cloudbreak/raw/master/cloud-aws-common/src/main/resources/definitions/cdp"
18+
plat__aws_policy_urls_default_root: "https://raw.githubusercontent.com/hortonworks/cloudbreak/master/cloud-aws-common/src/main/resources/definitions/cdp"
1919
plat__aws_policy_urls_default:
2020
log: "{{ plat__aws_policy_urls_default_root }}/aws-cdp-log-policy.json"
2121
ranger_audit_s3: "{{ plat__aws_policy_urls_default_root }}/aws-cdp-ranger-audit-s3-policy.json"

0 commit comments

Comments
 (0)