fix(security): move dashboard auth and netbird secrets to Infisical lifecycle
ansible-core-net / deploy (push) Successful in 21s
ansible-core-net / deploy (push) Successful in 21s
This commit is contained in:
1 parent
309b6538d0
commit
4ab29058fe
7 files changed
+58
-61
No files matched your search
@@ -4,3 +4,4 @@ traefik_dir: "/opt/traefik"
|
||||
traefik_dynamic_dir: "/opt/traefik/dynamic"
|
||||
traefik_log_dir: "/var/log/traefik"
|
||||
traefik_acme_email: "vvkarpenok@gmail.com"
|
||||
traefik_dashboard_auth: "{{ lookup('env', 'TRAEFIK_DASHBOARD_AUTH') }}"
|
||||
@@ -60,6 +60,12 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Проверить наличие обязательных секретов Traefik
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_dashboard_auth is defined and traefik_dashboard_auth | length > 0
|
||||
fail_msg: "Переменная TRAEFIK_DASHBOARD_AUTH не передана из Infisical!"
|
||||
|
||||
- name: Синхронизировать динамические конфигурации маршрутов
|
||||
ansible.builtin.copy:
|
||||
src: dynamic/
|
||||
@@ -68,6 +74,14 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Установить конфигурацию Traefik dashboard
|
||||
ansible.builtin.template:
|
||||
src: dynamic/dashboard.yml.j2
|
||||
dest: "{{ traefik_dynamic_dir }}/dashboard.yml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Найти существующие файлы маршрутов на сервере
|
||||
ansible.builtin.find:
|
||||
paths: "{{ traefik_dynamic_dir }}"
|
||||
@@ -80,7 +94,7 @@
|
||||
state: absent
|
||||
loop: "{{ remote_dynamic_files.files }}"
|
||||
vars:
|
||||
repo_files: "{{ q('fileglob', role_path ~ '/files/dynamic/*.yml') | map('basename') | list }}"
|
||||
repo_files: "{{ (q('fileglob', role_path ~ '/files/dynamic/*.yml') | map('basename') | list) + ['dashboard.yml'] }}"
|
||||
when: item.path | basename not in repo_files
|
||||
|
||||
- name: Запустить Traefik через Docker Compose
|
||||
|
||||
+1
-2
@@ -14,5 +14,4 @@ http:
|
||||
dashboard-auth:
|
||||
basicAuth:
|
||||
users:
|
||||
- "karpenok:$apr1$dYhfMHp0$/xqbASu5jj55Ev058YImp."
|
||||
|
||||
- "{{ traefik_dashboard_auth }}"
|
||||
@@ -5,4 +5,9 @@ netbird_ports:
|
||||
- 443/tcp
|
||||
- 3478/udp
|
||||
|
||||
netbird_letsencrypt_email: "{{ letsencrypt_email | default(admin_email) }}"
|
||||
netbird_domain: "{{ lookup('env', 'NETBIRD_DOMAIN') | default('central.myguni.ru', true) }}"
|
||||
netbird_letsencrypt_email: "{{ lookup('env', 'NETBIRD_LETSENCRYPT_EMAIL') | default(letsencrypt_email | default(admin_email | default('vvkarpenok@gmail.com')), true) }}"
|
||||
|
||||
netbird_auth_secret: "{{ lookup('env', 'NETBIRD_AUTH_SECRET') }}"
|
||||
netbird_datastore_key: "{{ lookup('env', 'NETBIRD_DATASTORE_KEY') }}"
|
||||
netbird_session_key: "{{ lookup('env', 'NETBIRD_SESSION_KEY') }}"
|
||||
@@ -18,60 +18,14 @@
|
||||
group: root
|
||||
mode: "0700"
|
||||
|
||||
- name: Проверить, созданы ли уже ключи
|
||||
ansible.builtin.stat:
|
||||
path: "{{ netbird_dir }}/.env"
|
||||
register: netbird_env
|
||||
tags:
|
||||
- config
|
||||
|
||||
- name: Проверить почту Let's Encrypt
|
||||
- name: Проверить наличие обязательных секретов NetBird
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- netbird_letsencrypt_email is defined
|
||||
- netbird_letsencrypt_email | length > 3
|
||||
fail_msg: Укажите почту Let's Encrypt при запуске плейбука.
|
||||
when: not netbird_env.stat.exists
|
||||
|
||||
- name: Сгенерировать ключи панели
|
||||
ansible.builtin.shell: openssl rand -base64 32 | tr -d '\n'
|
||||
register: netbird_generated_keys
|
||||
changed_when: false
|
||||
no_log: true
|
||||
loop:
|
||||
- auth
|
||||
- datastore
|
||||
- session
|
||||
when: not netbird_env.stat.exists and netbird_auth_secret is not defined
|
||||
|
||||
- name: Запомнить новые ключи
|
||||
ansible.builtin.set_fact:
|
||||
netbird_auth_secret: "{{ netbird_generated_keys.results[0].stdout }}"
|
||||
netbird_datastore_key: "{{ netbird_generated_keys.results[1].stdout }}"
|
||||
netbird_session_key: "{{ netbird_generated_keys.results[2].stdout }}"
|
||||
no_log: true
|
||||
when: not netbird_env.stat.exists and netbird_auth_secret is not defined
|
||||
|
||||
- name: Прочитать сохранённые ключи
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ netbird_dir }}/.env"
|
||||
register: netbird_env_raw
|
||||
no_log: true
|
||||
when: netbird_env.stat.exists and netbird_auth_secret is not defined
|
||||
tags:
|
||||
- config
|
||||
|
||||
- name: Разобрать сохранённые ключи
|
||||
ansible.builtin.set_fact:
|
||||
netbird_auth_secret: "{{ env_map['NETBIRD_AUTH_SECRET'] }}"
|
||||
netbird_datastore_key: "{{ env_map['NETBIRD_DATASTORE_KEY'] }}"
|
||||
netbird_session_key: "{{ env_map['NETBIRD_SESSION_KEY'] }}"
|
||||
netbird_letsencrypt_email: "{{ env_map['NETBIRD_LETSENCRYPT_EMAIL'] }}"
|
||||
vars:
|
||||
env_lines: "{{ (netbird_env_raw.content | b64decode).splitlines() | reject('equalto', '') | list }}"
|
||||
env_map: "{{ dict(env_lines | map('split', '=', 1)) }}"
|
||||
no_log: true
|
||||
when: netbird_env.stat.exists and netbird_auth_secret is not defined
|
||||
- netbird_auth_secret is defined and netbird_auth_secret | length > 0
|
||||
- netbird_datastore_key is defined and netbird_datastore_key | length > 0
|
||||
- netbird_session_key is defined and netbird_session_key | length > 0
|
||||
- netbird_letsencrypt_email is defined and netbird_letsencrypt_email | length > 3
|
||||
fail_msg: "Один или несколько обязательных секретов NetBird (NETBIRD_AUTH_SECRET, NETBIRD_DATASTORE_KEY, NETBIRD_SESSION_KEY, NETBIRD_LETSENCRYPT_EMAIL) не переданы из Infisical!"
|
||||
tags:
|
||||
- config
|
||||
|
||||
|
||||
Reference in new issue
Block a user