Skip to content

Commit

Permalink
Merge pull request #746 from cisagov/improvement/bullseye_to_bookworm
Browse files Browse the repository at this point in the history
Upgrade select CyHy instances from Debian Bullseye to Debian Bookworm
  • Loading branch information
mcdonnnj authored Mar 6, 2024
2 parents bd817ec + 8812309 commit 4b794f2
Show file tree
Hide file tree
Showing 24 changed files with 264 additions and 26 deletions.
3 changes: 1 addition & 2 deletions ansible/roles/client_cert_update/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: client_cert_update
3 changes: 1 addition & 2 deletions ansible/roles/code_gov_update/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: code_gov_update
2 changes: 1 addition & 1 deletion ansible/roles/cyhy_mailer/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: cyhy_mailer
2 changes: 1 addition & 1 deletion ansible/roles/cyhy_ops/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: cyhy_ops
2 changes: 1 addition & 1 deletion ansible/roles/groups/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: groups
2 changes: 1 addition & 1 deletion ansible/roles/mgmt_ops/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: mgmt_ops
3 changes: 1 addition & 2 deletions ansible/roles/nessus/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: nessus
6 changes: 3 additions & 3 deletions ansible/roles/nessus/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@

# The expect Ansible module requires pexpect
- name: Install pexpect
ansible.builtin.pip:
name:
- pexpect
ansible.builtin.apt:
name: python3-pexpect
state: present
when: username not in nessus_users.stdout

- name: Create scanner user if necessary
Expand Down
3 changes: 1 addition & 2 deletions ansible/roles/orchestrator/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: orchestrator
2 changes: 1 addition & 1 deletion ansible/roles/swap/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: swap
3 changes: 1 addition & 2 deletions ansible/roles/vdp_scanner/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- bookworm
role_name: vdp_scanner
12 changes: 12 additions & 0 deletions packer/ansible/bookworm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- hosts: bastion,docker,nessus,nmap
name: Perform additional tasks to support Debian Bookworm
become: yes
become_method: ansible.builtin.sudo
tasks:
# We have a cloud-init script to fix the Netplan configuration that needs
# this Python package.
- name: Ensure the PyYAML package is installed
ansible.builtin.package:
name:
- python3-yaml
3 changes: 3 additions & 0 deletions packer/ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
- name: Import base image playbook
ansible.builtin.import_playbook: base.yml

- name: Import Debian Bookworm playbook
ansible.builtin.import_playbook: bookworm.yml

- name: Import AWS playbook
ansible.builtin.import_playbook: aws.yml

Expand Down
4 changes: 2 additions & 2 deletions packer/bastion.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"region": "{{user `build_region`}}",
"source_ami_filter": {
"filters": {
"name": "debian-11-amd64-*",
"name": "debian-12-amd64-*",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
Expand All @@ -38,7 +38,7 @@
"tags": {
"Application": "Cyber Hygiene",
"Base_AMI_Name": "{{ .SourceAMIName }}",
"OS_Version": "Debian Bullseye",
"OS_Version": "Debian Bookworm",
"Release": "Latest",
"Team": "VM Fusion - Development"
},
Expand Down
4 changes: 2 additions & 2 deletions packer/docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"region": "{{user `build_region`}}",
"source_ami_filter": {
"filters": {
"name": "debian-11-amd64-*",
"name": "debian-12-amd64-*",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
Expand All @@ -38,7 +38,7 @@
"tags": {
"Application": "Cyber Hygiene",
"Base_AMI_Name": "{{ .SourceAMIName }}",
"OS_Version": "Debian Bullseye",
"OS_Version": "Debian Bookworm",
"Release": "Latest",
"Team": "VM Fusion - Development"
},
Expand Down
4 changes: 2 additions & 2 deletions packer/nessus.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"region": "{{user `build_region`}}",
"source_ami_filter": {
"filters": {
"name": "debian-11-amd64-*",
"name": "debian-12-amd64-*",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
Expand All @@ -38,7 +38,7 @@
"tags": {
"Application": "Cyber Hygiene",
"Base_AMI_Name": "{{ .SourceAMIName }}",
"OS_Version": "Debian Bullseye",
"OS_Version": "Debian Bookworm",
"Release": "Latest",
"Team": "VM Fusion - Development"
},
Expand Down
4 changes: 2 additions & 2 deletions packer/nmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"region": "{{user `build_region`}}",
"source_ami_filter": {
"filters": {
"name": "debian-11-amd64-*",
"name": "debian-12-amd64-*",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
Expand All @@ -38,7 +38,7 @@
"tags": {
"Application": "Cyber Hygiene",
"Base_AMI_Name": "{{ .SourceAMIName }}",
"OS_Version": "Debian Bullseye",
"OS_Version": "Debian Bookworm",
"Release": "Latest",
"Team": "VM Fusion - Development"
},
Expand Down
38 changes: 38 additions & 0 deletions terraform/bod_bastion_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,42 @@ data "cloudinit_config" "bod_bastion_cloud_init_tasks" {
filename = "set_hostname.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Fix the DHCP options in the Canonical Netplan configuration
# created by cloud-init.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = templatefile(
"${path.module}/cloud-init/fix_dhcp.tpl.py", {
netplan_config = "/etc/netplan/50-cloud-init.yaml"
})
content_type = "text/x-shellscript"
filename = "fix_dhcp.py"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Now that the DHCP options in the Canonical Netplan configuration
# created by cloud-init have been fixed, reapply the Netplan
# configuration.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = file("${path.module}/cloud-init/fix_dhcp.yml")
content_type = "text/cloud-config"
filename = "fix_dhcp.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}
}
38 changes: 38 additions & 0 deletions terraform/bod_docker_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,42 @@ data "cloudinit_config" "bod_docker_cloud_init_tasks" {
content_type = "text/x-shellscript"
filename = "04_cyhy_docker_chown_vdp_output_directory.sh"
}

# Fix the DHCP options in the Canonical Netplan configuration
# created by cloud-init.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = templatefile(
"${path.module}/cloud-init/fix_dhcp.tpl.py", {
netplan_config = "/etc/netplan/50-cloud-init.yaml"
})
content_type = "text/x-shellscript"
filename = "fix_dhcp.py"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Now that the DHCP options in the Canonical Netplan configuration
# created by cloud-init have been fixed, reapply the Netplan
# configuration.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = file("${path.module}/cloud-init/fix_dhcp.yml")
content_type = "text/cloud-config"
filename = "fix_dhcp.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}
}
31 changes: 31 additions & 0 deletions terraform/cloud-init/fix_dhcp.tpl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

"""Append the necessary DHCP options to the Netplan configuration.
The Netplan configuration is created by cloud-init, but it needs to be
slightly modified and reapplied. This script takes care of the
modification.
See these issues for more details:
- cisagov/skeleton-packer#300
- canonical/cloud-init#4764
This file is a template. It should be processed by Terraform.
"""

# Third-Party Libraries
import yaml

# Inputs from Terraform
NETPLAN_CONFIG = "${netplan_config}"

with open(NETPLAN_CONFIG) as f:
# Load the current Netplan configuration
config = yaml.safe_load(f)
# Add a dhcp4-overrides section to each network
config["network"]["ethernets"] = {
k: v | {"dhcp4-overrides": {"use-domains": True}}
for (k, v) in config["network"]["ethernets"].items()
}

# Write the results back out to the Netplan configuration file
with open(NETPLAN_CONFIG, "w") as f:
f.write(yaml.dump(config))
7 changes: 7 additions & 0 deletions terraform/cloud-init/fix_dhcp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

# There is a Python script that fixes the DHCP4 options in the Netplan
# configuration already generated by cloud-init. The following simply
# reapplies the Netplan configuration after the modification.
runcmd:
- [netplan, apply]
38 changes: 38 additions & 0 deletions terraform/cyhy_bastion_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,42 @@ data "cloudinit_config" "cyhy_bastion_cloud_init_tasks" {
filename = "set_hostname.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Fix the DHCP options in the Canonical Netplan configuration
# created by cloud-init.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = templatefile(
"${path.module}/cloud-init/fix_dhcp.tpl.py", {
netplan_config = "/etc/netplan/50-cloud-init.yaml"
})
content_type = "text/x-shellscript"
filename = "fix_dhcp.py"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Now that the DHCP options in the Canonical Netplan configuration
# created by cloud-init have been fixed, reapply the Netplan
# configuration.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = file("${path.module}/cloud-init/fix_dhcp.yml")
content_type = "text/cloud-config"
filename = "fix_dhcp.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}
}
38 changes: 38 additions & 0 deletions terraform/cyhy_nessus_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,42 @@ data "cloudinit_config" "cyhy_nessus_cloud_init_tasks" {
content_type = "text/x-shellscript"
filename = "02_cyhy_nessus_chown_runner_directory.sh"
}

# Fix the DHCP options in the Canonical Netplan configuration
# created by cloud-init.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = templatefile(
"${path.module}/cloud-init/fix_dhcp.tpl.py", {
netplan_config = "/etc/netplan/50-cloud-init.yaml"
})
content_type = "text/x-shellscript"
filename = "fix_dhcp.py"
merge_type = "list(append)+dict(recurse_array)+str()"
}

# Now that the DHCP options in the Canonical Netplan configuration
# created by cloud-init have been fixed, reapply the Netplan
# configuration.
#
# The issue is that Netplan uses a default of false for
# dhcp4-overrides.use-domains, and cloud-init does not explicitly
# set this key or provide any way to do so.
#
# See these issues for more details:
# - cisagov/skeleton-packer#300
# - canonical/cloud-init#4764
part {
content = file("${path.module}/cloud-init/fix_dhcp.yml")
content_type = "text/cloud-config"
filename = "fix_dhcp.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}
}
Loading

0 comments on commit 4b794f2

Please sign in to comment.