Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cyhy user creation to AMI build time #640

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packer/ansible/create_cyhy_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# The bastion is the only instance that does not need a cyhy user for
# operational functionality.
- hosts: all:!bastion
name: Create the cyhy user and set up SSH access
become: yes
become_method: sudo
tasks:
- name: Create the cyhy user
ansible.builtin.user:
home: /var/cyhy
name: cyhy
shell: /bin/bash
uid: 2048
register: user_info

- name: Modify permissions on the home directory
ansible.builtin.file:
mode: 0750
path: "{{ user_info.home }}"

- name: Add the SSH public key as an authorized key
ansible.posix.authorized_key:
key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOreUDnms12MPI0gh7K+YGaESYgC2TY1zA+kSK/g+n5+ cyhy
user: cyhy
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 AWS playbook
ansible.builtin.import_playbook: aws.yml

- name: Import cyhy user creation playbook
ansible.builtin.import_playbook: create_cyhy_user.yml

- hosts: all
name: Add a banner, persist journald, install ClamAV, and setup dev team ssh
become: yes
Expand Down
7 changes: 0 additions & 7 deletions terraform/bod_docker_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ data "cloudinit_config" "bod_docker_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down
9 changes: 0 additions & 9 deletions terraform/cloud-init/cyhy_user_ssh_setup.yml

This file was deleted.

7 changes: 0 additions & 7 deletions terraform/cyhy_dashboard_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ data "cloudinit_config" "cyhy_dashboard_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down
7 changes: 0 additions & 7 deletions terraform/cyhy_mongo_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ data "cloudinit_config" "cyhy_mongo_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down
7 changes: 0 additions & 7 deletions terraform/cyhy_nessus_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ data "cloudinit_config" "cyhy_nessus_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down
7 changes: 0 additions & 7 deletions terraform/cyhy_nmap_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ data "cloudinit_config" "cyhy_nmap_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down
7 changes: 0 additions & 7 deletions terraform/cyhy_reporter_cloud_init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ data "cloudinit_config" "cyhy_reporter_cloud_init_tasks" {
base64_encode = true
gzip = true

part {
content = file("${path.module}/cloud-init/cyhy_user_ssh_setup.yml")
content_type = "text/cloud-config"
filename = "cyhy_user_ssh_setup.yml"
merge_type = "list(append)+dict(recurse_array)+str()"
}

part {
content = templatefile("${path.module}/cloud-init/set_hostname.tpl.yml", {
# Note that the hostname here is identical to what is set in
Expand Down