Skip to content

Commit

Permalink
secret-engine pki update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelvenema committed Dec 4, 2023
1 parent f8139a6 commit 1e43d42
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 15 deletions.
1 change: 0 additions & 1 deletion BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
- Vault service in podman start niet automatisch na reboot.

- Configuratie van update action.
- Configuratie van destroy_secret_engine action.
- Configuratie van destroy_secret action.
- Configuratie van get_policy action.
- Configuratie van destroy_policy action.
Expand Down
4 changes: 2 additions & 2 deletions inventory/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ ansible_host:
lab_server:
hosts:
# 192.168.11.20 # 11 LAB
192.168.29.21 # 29 LAB
# 192.168.29.21 # 29 TST
# 192.168.29.21 # 29 LAB
192.168.11.22 # 11 TST
# 192.168.178.107 # TFLab
5 changes: 5 additions & 0 deletions roles/gogs/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
repository_tag: "latest"
when: repository_tag is not defined or repository_tag == "" or repository_tag == none

# Show information message
- name: Show information message
ansible.builtin.debug:
msg: "Download container image from registry, this may take a while..."

# Pull image from repository to local image repository. If failed, lookup local image file.
- name: Pull Gogs container image from repository
containers.podman.podman_image:
Expand Down
5 changes: 5 additions & 0 deletions roles/mysql/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
when:
- repository_tag is not defined or repository_tag == "" or repository_tag == none

# Show information message
- name: Show information message
ansible.builtin.debug:
msg: "Download container image from registry, this may take a while..."

# Pull image from repository to local image repository. If failed, lookup local image file.
- name: "Pull MySQL container image from repository {{ repository_url}}:{{ repository_tag }}"
containers.podman.podman_image:
Expand Down
5 changes: 5 additions & 0 deletions roles/nexus_repository/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
repository_tag: "latest"
when: repository_tag is not defined or repository_tag == "" or repository_tag == none

# Show information message
- name: Show information message
ansible.builtin.debug:
msg: "Download container image from registry, this may take a while..."

# Pull image from repository to local image repository. If failed, lookup local image file.
- name: "Pull Nexus container image from repository {{ repository_url }}:{{ repository_tag }}"
containers.podman.podman_image:
Expand Down
5 changes: 5 additions & 0 deletions roles/semaphore/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
repository_tag: "latest"
when: repository_tag is not defined or repository_tag == "" or repository_tag == none

# Show information message
- name: Show information message
ansible.builtin.debug:
msg: "Download container image from registry, this may take a while..."

# Pull image from repository to local image repository. If failed, lookup local image file.
- name: Pull Semaphore container image from repository
containers.podman.podman_image:
Expand Down
7 changes: 6 additions & 1 deletion roles/server_config_linux/tasks/auto_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
## Installation ##
#########################################################

# Debug messg
- name: Show message
ansible.builtin.debug:
msg: "Install auto update packages, this may take a while..."

# Install cockpit packages
- name: Install auto update package
ansible.builtin.package:
Expand All @@ -13,7 +18,7 @@

# Enable auto update service
# https://access.redhat.com/solutions/2823901
- name: Make sure a service unit is running
- name: Enable auto-update service
ansible.builtin.systemd:
enabled: true
state: started
Expand Down
31 changes: 30 additions & 1 deletion roles/server_config_linux/tasks/configure_vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


#########################################################
## Configuration ##
## Configuration Vault KV ##
#########################################################

# Clear variable, be sure it is not used from a previous run.
Expand Down Expand Up @@ -59,3 +59,32 @@
vault_name: "{{ ansible_fqdn | replace('.', '-') }}"
secret_name: "{{ ansible_fqdn | replace('.', '-') }}"
secret_keyvalue: "{ 'admin_username': '{{ admin_username }}', 'admin_password': '{{ admin_password }}', 'admin_email': '{{ admin_email }}' }"

#########################################################
## Configuration Vault PKI ##
#########################################################

# Clear variable, be sure it is not used from a previous run.
- name: Clear variable vault_name
ansible.builtin.set_fact:
vault_name: ""
no_log: true

# Clear variable, be sure it is not used from a previous run.
- name: Clear variable vault_description
ansible.builtin.set_fact:
vault_description: ""
no_log: true

# Create secret engine
- name: Create secret engine
ansible.builtin.include_role:
name: vault
tasks_from: secret_engine.yml
vars:
action: create_secret_engine
vault_address: "http://192.168.11.22:8200"
vault_token: "hvs.5XYaP4XJwdV5FqeJpQalQRXr"
vault_name: "certificates"
vault_description: "Certificates secrets store"
vault_type: "pki"
5 changes: 5 additions & 0 deletions roles/vault/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
repository_tag: "latest"
when: repository_tag is not defined or repository_tag == "" or repository_tag == none

# Show information message
- name: Show information message
ansible.builtin.debug:
msg: "Download container image from registry, this may take a while..."

# Pull image from repository to local image repository. If failed, lookup local image file.
- name: "Pull Vault container image from repository {{ repository_url}}:{{ repository_tag }}"
containers.podman.podman_image:
Expand Down
4 changes: 4 additions & 0 deletions roles/vault/tasks/secret_engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
ansible.builtin.include_tasks: secret_engine_pki.yml
when: vault_type == 'pki'

# include task if vault_type is pki
- name: Include SSH Secret Engine
ansible.builtin.include_tasks: secret_engine_ssh.yml
when: vault_type == 'ssh'
13 changes: 9 additions & 4 deletions roles/vault/tasks/secret_engine_kv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
loop:
- vault_name
- vault_description
- vault_type

# Create Hashicorp secrets engine via api. Authenticate with vault_token.
- name: Create Hashicorp secrets engine via api
Expand Down Expand Up @@ -109,6 +108,12 @@
loop:
- vault_name

# Stop playbook
- name: Stop playbook
ansible.builtin.meta: end_play
# Destroy Hashicorp secrets engine via api. Authenticate with vault_token.
- name: "Destroy Hashicorp secrets engine {{ vault_name }}"
ansible.builtin.uri:
url: "{{ vault_address }}/v1/sys/mounts/{{ vault_name }}"
validate_certs: false
method: DELETE
status_code: 204
headers:
X-Vault-Token: "{{ vault_token }}"
18 changes: 12 additions & 6 deletions roles/vault/tasks/secret_engine_pki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
loop:
- vault_name
- vault_description
- vault_type

# Create Hashicorp secrets engine via api. Authenticate with vault_token.
- name: Create Hashicorp secrets engine via api
Expand All @@ -87,8 +86,9 @@
body:
type: pki
description: "{{ vault_description }}"
options:
version: 2
config:
max_lease_ttl: "87600h"
default_lease_ttl: "87600h"

#########################################################
## Destroy PKI Secrets engine ##
Expand All @@ -109,6 +109,12 @@
loop:
- vault_name

# Stop playbook
- name: Stop playbook
ansible.builtin.meta: end_play
# Destroy Hashicorp secrets engine via api. Authenticate with vault_token.
- name: "Destroy Hashicorp secrets engine {{ vault_name }}"
ansible.builtin.uri:
url: "{{ vault_address }}/v1/sys/mounts/{{ vault_name }}"
validate_certs: false
method: DELETE
status_code: 204
headers:
X-Vault-Token: "{{ vault_token }}"
76 changes: 76 additions & 0 deletions roles/vault/tasks/secret_engine_ssh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---

#########################################################
## Hashicorp Vault SSH Secret Engine module ##
#########################################################

#########################################################
## Get SSH Secrets engine ##
#########################################################


#########################################################
## Create SSH Secrets engine ##
#########################################################

- name: Create Vault KV secret engine
when: action == 'create_secret_engine'
block:

# Validate variables
- name: Validate variables for Vault create_secret_engine action.
ansible.builtin.assert:
that: "{{ varitem }} is defined"
fail_msg: "Required variable '{{ varitem }}' has not been provided."
quiet: true
loop_control:
loop_var: varitem
loop:
- vault_name
- vault_description

# Create Hashicorp secrets engine via api. Authenticate with vault_token.
- name: Create Hashicorp secrets engine via api
ansible.builtin.uri:
url: "{{ vault_address }}/v1/sys/mounts/{{ vault_name }}"
validate_certs: false
method: POST
status_code: 204
headers:
X-Vault-Token: "{{ vault_token }}"
body_format: json
body:
type: ssh
description: "{{ vault_description }}"




#########################################################
## Destroy KV Secrets engine ##
#########################################################

- name: Destroy Vault SSH secret engine
when: action == 'destroy_secret_engine'
block:

# Validate local variables
- name: Validate variables for Vault destroy_secret_engine action.
ansible.builtin.assert:
that: "{{ varitem }} is defined"
fail_msg: "Required variable '{{ varitem }}' has not been provided."
quiet: true
loop_control:
loop_var: varitem
loop:
- vault_name

# Destroy Hashicorp secrets engine via api. Authenticate with vault_token.
- name: "Destroy Hashicorp secrets engine {{ vault_name }}"
ansible.builtin.uri:
url: "{{ vault_address }}/v1/sys/mounts/{{ vault_name }}"
validate_certs: false
method: DELETE
status_code: 204
headers:
X-Vault-Token: "{{ vault_token }}"
51 changes: 51 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---

- name: Playbook to test development
hosts: lab_server
tasks:




#########################################################
## Configuration Vault PKI ##
#########################################################

# Clear variable, be sure it is not used from a previous run.
- name: Clear variable vault_name
ansible.builtin.set_fact:
vault_name: ""
no_log: true

# Clear variable, be sure it is not used from a previous run.
- name: Clear variable vault_description
ansible.builtin.set_fact:
vault_description: ""
no_log: true

# Create secret engine
- name: Create secret engine
ansible.builtin.include_role:
name: vault
tasks_from: secret_engine.yml
vars:
action: create_secret_engine
vault_address: "http://192.168.11.22:8200"
vault_token: "hvs.5XYaP4XJwdV5FqeJpQalQRXr"
vault_name: "certificates"
vault_description: "Certificates secrets store"
vault_type: "pki"

# Delete secret engine
- name: Delete secret engine
ansible.builtin.include_role:
name: vault
tasks_from: secret_engine.yml
vars:
action: destroy_secret_engine
vault_address: "http://192.168.11.22:8200"
vault_token: "hvs.5XYaP4XJwdV5FqeJpQalQRXr"
vault_name: "lab-marcelvenema-com"
vault_type: "kv"


0 comments on commit 1e43d42

Please sign in to comment.