Git initial commit

This commit is contained in:
Lars Hahn 2023-09-17 10:56:23 +02:00
commit 65d8187fb8
9 changed files with 230 additions and 0 deletions

9
LICENSE Executable file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.md Executable file
View File

@ -0,0 +1,3 @@
# cloud-vault
Ansible role in order to setup Hashicorp Vault.

50
defaults/main.yml Executable file
View File

@ -0,0 +1,50 @@
---
cloud_apps: /opt
cloud_storage: /opt/storage
cloud_stage: prod
cloud_update: false
vault_source: https://releases.hashicorp.com/vault
vault_version: 1.17.2
vault_arch: linux_amd64
vault_pid: "{{ cloud_apps }}/vault/vault.pid"
vault_ui: "true"
vault_no_mlock: "false"
vault_port: 8200
vault_listener: 127.0.0.1
vault_api_addr: "http://{{ vault_listener }}:{{ vault_port }}"
vault_cluster_addr: ""
vault_cluster_name: "vault"
vault_storage:
storage: "storage"
type: "file"
conf: |
path = "{{ vault_home }}/data"
vault_listener_tcp:
address: "{{ vault_listener }}:{{ vault_port }}"
tls_disable: "true"
proxy_protocol_behavior: "{{ vault_proxy_behaviour }}"
vault_config_options:
max_lease_ttl: "10h"
default_lease_ttl: "10h"
vault_config_blocks:
- conf: telemetry
type:
options: |
prometheus_retention_time = "30s"
disable_hostname = true
# required only, when vault_proxy_behaviour is e.g. set to allow_authorized
# see https://www.vaultproject.io/docs/configuration/listener/tcp#proxy_protocol_authorized_addrs
vault_proxy_authorised_addr: []
vault_proxy_behaviour: use_always

5
handlers/main.yml Executable file
View File

@ -0,0 +1,5 @@
---
- name: restart vault
systemd:
name: vault
state: restarted

16
meta/main.yml Executable file
View File

@ -0,0 +1,16 @@
---
galaxy_info:
role_name: vault
namespace: hahn-cloud
author: Lars Hahn
company: OpenDevChain
license: MIT
description: Role to setup vault from HashiCorp
min_ansible_version: 2.7
platforms:
- name: Debian
versions:
- 11
galaxy_tags:
- vault
dependencies: []

67
tasks/main.yml Executable file
View File

@ -0,0 +1,67 @@
---
- name: setup vault group
group:
name: "{{ vault_usr }}"
state: "present"
- name: setup vault user
user:
name: "{{ vault_usr }}"
group: "{{ vault_grp }}"
groups:
- "{{ vault_grp }}"
comment: Virtual Vault User
shell: /sbin/nologin
state: present
- name: setup vault directories
file:
state: directory
path: "{{ item }}"
owner: "{{ vault_usr }}"
group: "{{ vault_grp }}"
mode: 0750
loop:
- "{{ vault_inst }}"
- "{{ vault_home }}"
- "{{ vault_log }}"
- name: setup vault installation link
file:
state: link
src: "{{ vault_inst }}"
dest: "{{ vault_link }}"
owner: "{{ vault_usr }}"
group: "{{ vault_grp }}"
mode: 0750
- name: download vault and unarchive
unarchive:
src: "{{ vault_source }}/{{ vault_version }}/vault_{{ vault_version }}_{{ vault_arch }}.zip"
dest: "{{ vault_link }}"
remote_src: yes
owner: "{{ vault_usr }}"
group: "{{ vault_grp }}"
mode: "o-rwx"
creates: "{{ vault_link }}/vault"
- name: setup vault config
template:
src: opt/vault/vault.conf.hcl.j2
dest: "{{ vault_home }}/vault.conf.hcl"
owner: "{{ vault_usr }}"
group: "{{ vault_grp }}"
notify: restart vault
- name: setup vault systemd unit
template:
src: etc/systemd/system/vault.service.j2
dest: /etc/systemd/system/vault.service
notify: restart vault
- name: enable vault systemd unit
systemd:
name: vault
enabled: yes
daemon_reload: yes
state: started

View File

@ -0,0 +1,36 @@
[Unit]
Description=Vault agent
Requires=network-online.target
After=network-online.target
[Service]
User={{ vault_usr }}
Group={{ vault_grp }}
ProtectSystem=full
ProtectHome=read-only
PrivateTmp=yes
PrivateDevices=yes
SecureBits=keep-caps
AmbientCapabilities=CAP_IPC_LOCK
Capabilities=CAP_IPC_LOCK+ep
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
NoNewPrivileges=yes
ExecStart={{ vault_link }}/vault server -config {{ vault_home }}/vault.conf.hcl
ExecReload=/bin/kill --signal HUP $MAINPID
ExecStop={{ vault_link }}/vault operator step-down
KillMode=process
KillSignal=SIGINT
LimitMEMLOCK=infinity
LimitNOFILE=65536
PIDFile={{ vault_pid }}
Restart=on-failure
RestartSec=5
StartLimitInterval=20
StartLimitBurst=5
TimeoutStartSec=30
StandardOutput=append:{{ vault_log }}/vault.log
StandardError=append:{{ vault_log }}/vault.err
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,36 @@
disable_mlock = {{ vault_no_mlock }}
ui = {{ vault_ui }}
api_addr = "{{ vault_api_addr }}"
{% if vault_cluster_addr != '' %}
cluster_addr = "{{ vault_cluster_addr }}"
cluster_name = "{{ vault_cluster_name }}"
disable_clustering = false
{% else %}
disable_clustering = true
{% endif %}
pid_file = "{{ vault_pid }}"
{{vault_storage.storage }} "{{ vault_storage.type }}" {
{{ vault_storage.conf }}
}
listener "tcp" {
{% for key, value in vault_listener_tcp.items() %}
{{ key }} = "{{ value }}"
{% endfor %}
}
{% for key, value in vault_config_options.items() %}
{{ key }} = "{{ value }}"
{% endfor %}
{% for block in vault_config_blocks %}
{{ block.conf }}{% if block.type is defined and block.type is not none and block.type != '' %} "{{ block.type }}"{% endif %} {
{% filter indent(width=2) %}
{{ block.options }}
{% endfilter %}
}
{% endfor %}

8
vars/main.yml Executable file
View File

@ -0,0 +1,8 @@
---
vault_usr: vault
vault_grp: "{{ vault_usr }}"
vault_link: "{{ cloud_apps }}/vault/inst"
vault_inst: "{{ cloud_apps }}/vault/vault_{{ vault_version }}"
vault_home: "{{ cloud_apps }}/vault/home"
vault_log: "{{ cloud_apps }}/vault/log"