-
Notifications
You must be signed in to change notification settings - Fork 28
/
trusted.ci.jenkins.io.tf
588 lines (538 loc) · 31.8 KB
/
trusted.ci.jenkins.io.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
####################################################################################
## Resources for the Controller VM
####################################################################################
module "trusted_ci_jenkins_io" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-controller"
providers = {
azurerm = azurerm
azurerm.dns = azurerm
azuread = azuread
}
service_fqdn = data.azurerm_dns_zone.trusted_ci_jenkins_io.name
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
admin_username = local.admin_username
admin_ssh_publickey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ=="
controller_network_name = data.azurerm_virtual_network.trusted_ci_jenkins_io.name
controller_network_rg_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
controller_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_controller.name
controller_data_disk_size_gb = 128
controller_vm_size = "Standard_D2as_v5"
default_tags = local.default_tags
controller_resourcegroup_name = "jenkinsinfra-trusted-ci-controller"
controller_datadisk_name = "trusted-ci-controller-data-disk"
jenkins_infra_ips = {
ldap_ipv4 = azurerm_public_ip.ldap_jenkins_io_ipv4.ip_address
puppet_ipv4 = azurerm_public_ip.puppet_jenkins_io.ip_address
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
controller_service_principal_ids = [
# Commenting out to migrate to new AzureAD provider
# data.azuread_service_principal.terraform_production.id,
"b847a030-25e1-4791-ad04-9e8484d87bce",
]
controller_service_principal_end_date = "2025-02-16T00:00:00Z"
controller_packer_rg_ids = [
azurerm_resource_group.packer_images["prod"].id
]
agent_ip_prefixes = concat(
data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefixes,
data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes,
[azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address],
)
}
module "trusted_ci_jenkins_io_azurevm_agents" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-azurevm-agents"
custom_resourcegroup_name = "jenkinsinfra-trusted-ephemeral-agents"
service_fqdn = module.trusted_ci_jenkins_io.service_fqdn
service_short_stripped_name = module.trusted_ci_jenkins_io.service_short_stripped_name
ephemeral_agents_network_rg_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.resource_group_name
ephemeral_agents_network_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.virtual_network_name
ephemeral_agents_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.name
controller_rg_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
controller_ips = compact([module.trusted_ci_jenkins_io.controller_public_ipv4])
controller_service_principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
default_tags = local.default_tags
jenkins_infra_ips = {
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
}
# Required to allow azcopy sync of jenkins.io File Share
module "trustedci_jenkinsio_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "trustedci-jenkinsio-fileshare_serviceprincipal_writer"
active_directory_owners = [data.azuread_service_principal.terraform_production.object_id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2025-01-12T00:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.jenkins_io.resource_manager_id
storage_account_id = azurerm_storage_account.jenkins_io.id
default_tags = local.default_tags
}
# Required to allow azcopy sync of javadoc.jenkins.io File Share
module "trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "trustedci-javadocjenkinsio-fileshare_serviceprincipal_writer"
active_directory_owners = [data.azuread_service_principal.terraform_production.object_id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2025-01-12T00:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.javadoc_jenkins_io.resource_manager_id
storage_account_id = azurerm_storage_account.javadoc_jenkins_io.id
default_tags = local.default_tags
}
## Sponsorship subscription specific resources for controller
resource "azurerm_resource_group" "trusted_ci_jenkins_io_controller_jenkins_sponsorship" {
provider = azurerm.jenkins-sponsorship
name = module.trusted_ci_jenkins_io.controller_resourcegroup_name # Same name on both subscriptions
location = var.location
tags = local.default_tags
}
# Required to allow controller to check for subnets inside the sponsorship network
resource "azurerm_role_definition" "trusted_ci_jenkins_io_controller_vnet_sponsorship_reader" {
provider = azurerm.jenkins-sponsorship
name = "Read-trusted-ci-jenkins-io-sponsorship-VNET"
scope = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.id
permissions {
actions = ["Microsoft.Network/virtualNetworks/read"]
}
}
resource "azurerm_role_assignment" "trusted_controller_vnet_reader" {
provider = azurerm.jenkins-sponsorship
scope = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.id
role_definition_id = azurerm_role_definition.trusted_ci_jenkins_io_controller_vnet_sponsorship_reader.role_definition_resource_id
principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
}
module "trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship" {
providers = {
azurerm = azurerm.jenkins-sponsorship
}
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-azurevm-agents"
service_fqdn = module.trusted_ci_jenkins_io.service_fqdn
service_short_stripped_name = module.trusted_ci_jenkins_io.service_short_stripped_name
ephemeral_agents_network_rg_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.resource_group_name
ephemeral_agents_network_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.virtual_network_name
ephemeral_agents_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.name
controller_rg_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
controller_ips = compact([module.trusted_ci_jenkins_io.controller_public_ipv4])
controller_service_principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
default_tags = local.default_tags
storage_account_name = "trustedciagentssub" # Max 24 chars
jenkins_infra_ips = {
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
}
resource "azurerm_private_dns_a_record" "trusted_ci_controller" {
name = "@"
zone_name = module.trustedci_permanent_agent_private_resources.zone_name
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
ttl = 300
records = [module.trusted_ci_jenkins_io.controller_private_ipv4]
}
####################################################################################
## Resources for the bounce (SSH bastion) VM
####################################################################################
resource "azurerm_network_interface" "trusted_bounce" {
name = "bounce.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
tags = local.default_tags
ip_configuration {
name = "external"
private_ip_address_allocation = "Dynamic"
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_controller.id
}
}
resource "azurerm_linux_virtual_machine" "trusted_bounce" {
name = "bounce.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
size = "Standard_B1s"
admin_username = local.admin_username
disable_password_authentication = true
network_interface_ids = [
azurerm_network_interface.trusted_bounce.id,
]
admin_ssh_key {
username = local.admin_username
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ=="
}
user_data = base64encode(
templatefile("./.shared-tools/terraform/cloudinit.tftpl", {
hostname = "bounce.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}",
admin_username = local.admin_username
}
)
)
computer_name = "bounce.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
# Encrypt all disks (ephemeral, temp dirs and data volumes) - https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell
encryption_at_host_enabled = true
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS" # Use HDD (cheaper than SSD) as this machine does not need performances
disk_size_gb = 32 # Minimal size for ubuntu 22.04 image
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-minimal-jammy"
sku = "minimal-22_04-lts-gen2"
version = "latest"
}
}
####################################################################################
## Resources for the permanent agent VM
####################################################################################
resource "azurerm_resource_group" "trusted_ci_jenkins_io_permanent_agents" {
name = "jenkinsinfra-trusted-permanent-agents"
location = var.location
tags = local.default_tags
}
resource "azurerm_network_interface" "trusted_permanent_agent" {
name = "agent.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
tags = local.default_tags
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "trusted_permanent_agent" {
name = "agent.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
tags = local.default_tags
size = "Standard_D2as_v5"
admin_username = local.admin_username
disable_password_authentication = true
network_interface_ids = [
azurerm_network_interface.trusted_permanent_agent.id,
]
admin_ssh_key {
username = local.admin_username
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ== [email protected]"
}
user_data = base64encode(
templatefile("./.shared-tools/terraform/cloudinit.tftpl", {
hostname = "agent.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}",
admin_username = local.admin_username,
}
))
computer_name = "agent.${data.azurerm_dns_zone.trusted_ci_jenkins_io.name}"
# Encrypt all disks (ephemeral, temp dirs and data volumes) - https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell
encryption_at_host_enabled = true
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
disk_size_gb = "128" # existing is 100GB, but as we will pay for 128GB, let's use it
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-minimal-jammy"
sku = "minimal-22_04-lts-gen2"
version = "latest"
}
}
resource "azurerm_managed_disk" "trusted_permanent_agent_data_disk" {
name = "trusted-permanent-agent-data-disk"
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1024" # no intermediate between 512 and 1024
tags = local.default_tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "trusted_permanent_agent_data_disk" {
managed_disk_id = azurerm_managed_disk.trusted_permanent_agent_data_disk.id
virtual_machine_id = azurerm_linux_virtual_machine.trusted_permanent_agent.id
lun = "20"
caching = "ReadWrite"
}
resource "azurerm_private_dns_a_record" "trusted_permanent_agent" {
name = "agent"
zone_name = module.trustedci_permanent_agent_private_resources.zone_name
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
ttl = 300
records = [azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address]
}
####################################################################################
## Network Security Group and rules
####################################################################################
resource "azurerm_subnet_network_security_group_association" "trusted_ci_permanent_agent" {
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
network_security_group_id = module.trusted_ci_jenkins_io.controller_nsg_id
}
## Outbound Rules (different set of priorities than Inbound rules) ##
resource "azurerm_network_security_rule" "allow_out_many_from_trusted_ephemeral_agents_to_pe" {
provider = azurerm.jenkins-sponsorship
name = "allow-out-many-from-ephemeral-agents-to-pe"
priority = 4050
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = [
"22", # SSH (for rsync)
"3390", # mirrorbits CLI (content-secured)
"3391", # mirrorbits CLI (content-unsecured)
]
source_address_prefixes = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes
destination_address_prefix = module.trustedci_ephemeral_agents_private_resources.endpoint_ip
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
network_security_group_name = module.trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship.ephemeral_agents_nsg_name
}
resource "azurerm_network_security_rule" "allow_out_many_from_trusted_ephemeral_agents_to_pkg" {
provider = azurerm.jenkins-sponsorship
name = "allow-out-many-from-ephemeral-agents-to-pkg"
priority = 4055
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = [
"22", # SSH (for rsync)
]
source_address_prefixes = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes
destination_address_prefix = local.external_services["pkg.origin.jenkins.io"]
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
network_security_group_name = module.trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship.ephemeral_agents_nsg_name
}
resource "azurerm_network_security_rule" "allow_out_many_from_trusted_ephemeral_agents_to_archive" {
provider = azurerm.jenkins-sponsorship
name = "allow-out-many-from-ephemeral-agents-to-archive"
priority = 4060
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = [
"22", # SSH (for rsync)
]
source_address_prefixes = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes
destination_address_prefix = local.external_services["archives.jenkins.io"]
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
network_security_group_name = module.trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship.ephemeral_agents_nsg_name
}
# Ignore the rule as it does not detect the IP restriction to only update.jenkins.io"s host
#trivy:ignore:azure-network-no-public-egress
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_permanent_agent_to_updatecenter" {
name = "allow-outbound-ssh-from-permanent-agent-to-updatecenter"
priority = 4080
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
destination_address_prefix = local.external_services["updates.${data.azurerm_dns_zone.jenkinsio.name}"]
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_from_bounce_to_controller" {
name = "allow-outbound-from-bounce-to-controller"
priority = 4090
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_port_range = "22"
destination_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_bounce_to_permanent_agent" {
name = "allow-outbound-ssh-from-bounce-to-permanent-agent"
priority = 4093
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_bounce_to_ephemeral_agents" {
name = "allow-outbound-ssh-from-bounce-to-ephemeral-agents"
priority = 4094
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefix
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
## Inbound Rules (different set of priorities than Outbound rules) ##
resource "azurerm_network_security_rule" "allow_in_many_from_trusted_ephemeral_agents_to_pe" {
provider = azurerm.jenkins-sponsorship
name = "allow-in-many-from-ephemeral-agents-to-pe"
priority = 4050
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = [
"22", # SSH (for rsync)
"3390", # mirrorbits CLI (content-secured)
"3391", # mirrorbits CLI (content-unsecured)
]
source_address_prefixes = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes
destination_address_prefix = module.trustedci_ephemeral_agents_private_resources.endpoint_ip
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
network_security_group_name = module.trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship.ephemeral_agents_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_controller" {
name = "allow-inbound-ssh-from-bounce-to-controller"
priority = 3500
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_controller_to_permanent_agent" {
name = "allow-inbound-ssh-from-controller-to-permanent-agent"
priority = 3600
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_permanent_agent" {
name = "allow-inbound-ssh-from-bounce-to-permanent-agent"
priority = 3800
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_ephemeral_agents" {
name = "allow-inbound-ssh-from-bounce-to-ephemeral-agents"
priority = 3900
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefix
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
#trivy:ignore:azure-network-no-public-ingress
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_internet_to_bounce" {
name = "allow-inbound-ssh-from-internet-to-bounce"
priority = 4000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefixes = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
destination_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
####################################################################################
## Public DNS records
####################################################################################
resource "azurerm_dns_a_record" "trusted_bounce" {
name = "bounce"
zone_name = data.azurerm_dns_zone.trusted_ci_jenkins_io.name
resource_group_name = data.azurerm_resource_group.proddns_jenkinsio.name
ttl = 60
records = [azurerm_linux_virtual_machine.trusted_bounce.private_ip_address]
tags = local.default_tags
}
####################################################################################
## Private network resources (endpoint, DNS, etc.)
####################################################################################
## updates.jenkins.io's internal services (RsyncDs, mirrorbits CLI, etc.)
module "trustedci_permanent_agent_private_resources" {
source = "./modules/private-resources"
providers = {
azurerm.pls = azurerm
azurerm.resources = azurerm
}
name = "trustedci-permanent_agent"
location = var.location
default_tags = local.default_tags
dns_rg_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
fqdn = "trusted.ci.jenkins.io"
vnet_id = data.azurerm_virtual_network.trusted_ci_jenkins_io.id
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
rg_name = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.resource_group_name
# TODO: track with updatecli
# https://github.com/jenkins-infra/kubernetes-management/blob/8b026b6e13ab726ce8064e842479839b371daf13/config/updates.jenkins.io-rsyncd-data.yaml#L40-L41
pls_name = "updates.jenkins.io-data"
pls_rg_name = azurerm_kubernetes_cluster.publick8s.node_resource_group
dns_a_record = "updates.jenkins.io-data"
}
module "trustedci_ephemeral_agents_private_resources" {
source = "./modules/private-resources"
providers = {
azurerm.pls = azurerm
azurerm.resources = azurerm.jenkins-sponsorship
}
name = "trustedci-ephemeral-agents"
location = var.location
default_tags = local.default_tags
dns_rg_name = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.resource_group_name
fqdn = "trusted.ci.jenkins.io"
vnet_id = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.id
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.id
rg_name = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.resource_group_name
# TODO: track with updatecli
# https://github.com/jenkins-infra/kubernetes-management/blob/8b026b6e13ab726ce8064e842479839b371daf13/config/updates.jenkins.io-rsyncd-data.yaml#L40-L41
pls_name = "updates.jenkins.io-data"
pls_rg_name = azurerm_kubernetes_cluster.publick8s.node_resource_group
dns_a_record = "updates.jenkins.io-data"
}
## updates.jenkins.io's mirrorbits CLI Kubernetes Service (internal LB)
## TODO: use updates_jenkins_io_data instead
data "azurerm_private_link_service" "updates_jenkins_io_cli" {
# https://github.com/jenkins-infra/kubernetes-management/blob/67e5741bf926c72c143604301132cbe6ada0bab8/config/updates.jenkins.io.yaml#L126
name = "updates.jenkins.io-cli"
resource_group_name = azurerm_kubernetes_cluster.publick8s.node_resource_group
}
resource "azurerm_private_endpoint" "updates_jio_mirrorbits_cli_for_trustedci" {
name = "${data.azurerm_private_link_service.updates_jenkins_io_cli.name}-for-trustedci"
location = var.location
resource_group_name = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.resource_group_name
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
custom_network_interface_name = "${data.azurerm_private_link_service.updates_jenkins_io_cli.name}-for-trustedci-nic"
private_service_connection {
name = "${data.azurerm_private_link_service.updates_jenkins_io_cli.name}-for-trustedci"
private_connection_resource_id = data.azurerm_private_link_service.updates_jenkins_io_cli.id
is_manual_connection = false
}
private_dns_zone_group {
name = "trusted.ci.jenkins.io"
private_dns_zone_ids = [module.trustedci_permanent_agent_private_resources.zone_id]
}
tags = local.default_tags
}
resource "azurerm_private_dns_a_record" "updates_jio_mirrorbits_cli_for_trustedci" {
name = "updates.jio-cli"
zone_name = module.trustedci_permanent_agent_private_resources.zone_name
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
ttl = 60
records = [azurerm_private_endpoint.updates_jio_mirrorbits_cli_for_trustedci.private_service_connection[0].private_ip_address]
}