mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-03 08:17:52 +00:00
fix(security): hand container exec credentials over on stdin, not environment
ffed838bc7moved 24 credentials from `container exec -e NAME=VALUE` to `-e NAME` plus the task's `environment:`. That kept the value out of the docker argv but not out of the host process table: for command, shell and script alike, Ansible runs `/bin/sh -c 'NAME=value ... && sleep 0'` (plugins/action/script.py joins the environment string onto the command; the trailing `sleep 0` keeps that shell and its argv alive for the whole task). Only a task's stdin reaches no argv. - Every site offfed838bc7on this branch now sends its secrets as the first lines of `stdin:`; the calling shell runs `IFS= read -r NAME && export NAME && container exec -e NAME ...`, one line per secret. Where `container exec -i` feeds the container a payload (SQL, PHP, Ruby, a shell script), the payload follows on the next lines and passes through untouched. Non-secret values stay in `environment:`. Elasticsearch keeps one read prefix, ELASTICSEARCH_AUTH_FROM_STDIN, for its five exec tasks. - Nextcloud's admin realignment and the Postgres pg_hba rescue move from `script` (which takes no stdin) to `command` with `bash -c` over the script; both scripts read the password themselves and fail loudly on empty stdin. dump_pg_hba.sh also stops passing `--env "PGPASSWORD=${PGPASSWORD}"`, which put the value straight into the docker argv. - test_exec_env_passes_no_value now also reads `--env` and a quoted `"NAME=..."`, the spelling that hid the pg_hba leak. That surfaced the agent-broker probe key and the MCP contract's path key and bearer header on `container exec`/`run` argv; they now reach the engine through the calling process' environment, as does LiteLLM's MIN_CHARS_PER_TOKEN (a count, but caught by its name). - The docstrings and failure messages of the three exec lints name stdin as the remedy and say why `environment:` is not one. Left for later, by agreement with feature/updater: the Postgres superuser script and its two callers, and the Nextcloud OpenProject provisioning, which that branch rewrites. Detecting a credential bound in `environment:` lands once those are merged. Probed with ansible-core 2.20 against a stub `container` that records argv, the forwarded variables, stdin and a full-width `ps` snapshot: every shape used here (read prefix with `args: stdin` under bash and dash, a secret line plus payload through `exec -i`, two secrets with `cmd`/`stdin` in the module mapping, `command` with `bash -c` and `stdin`, an `until` retry) delivers the exact value and payload and leaves the secret out of every argv, while the old `environment:` form shows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d28bd8c25
commit
54ea4890e7
31 files changed
+182
-137
No files matched your search
@@ -60,9 +60,9 @@ kc_membership() {
|
||||
|
||||
probe() {
|
||||
# nocheck: container-exec-resolver address resolved by the caller and passed in
|
||||
container exec -i \
|
||||
KEY="$1" container exec -i \
|
||||
-e "PORT=${AGENT_BROKER_PORT}" \
|
||||
-e "KEY=$1" \
|
||||
-e KEY \
|
||||
-e "OWNER=$2" \
|
||||
-e "EMAIL=$3" \
|
||||
-e "MODEL=$4" \
|
||||
|
||||
@@ -44,9 +44,9 @@ interpreter() {
|
||||
|
||||
probe() {
|
||||
# nocheck: container-exec-resolver address resolved by the caller and passed in
|
||||
container exec -i \
|
||||
MIN_CHARS_PER_TOKEN="${LITELLM_ROUTER_MIN_CHARS_PER_TOKEN}" container exec -i \
|
||||
-e "PORT=${LITELLM_PORT}" \
|
||||
-e "MIN_CHARS_PER_TOKEN=${LITELLM_ROUTER_MIN_CHARS_PER_TOKEN}" \
|
||||
-e MIN_CHARS_PER_TOKEN \
|
||||
-e "CHAT_MODEL=${LITELLM_CHAT_MODEL}" \
|
||||
-e "CHAT_MODEL_SERVED=${LITELLM_CHAT_MODEL_SERVED}" \
|
||||
-e "EXPECTED_MODELS=${LITELLM_EXPECTED_MODELS}" \
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
{{ ELASTICSEARCH_EXEC_SHELL }}
|
||||
'{{ 30 | curl }} -fS -u "elastic:$ELASTIC_PW"
|
||||
"{{ ELASTICSEARCH_API_BASE }}/_cluster/health?wait_for_status=yellow&timeout=5s" >/dev/null'
|
||||
environment:
|
||||
ELASTIC_PW: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
register: es_health_ready
|
||||
retries: 60
|
||||
delay: 5
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
{{ ELASTICSEARCH_EXEC_SHELL }}
|
||||
'{{ 30 | curl }} -fS -u "elastic:$ELASTIC_PW"
|
||||
"{{ ELASTICSEARCH_API_BASE }}/_security/_authenticate" >/dev/null'
|
||||
environment:
|
||||
ELASTIC_PW: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
register: es_security_ready
|
||||
until: es_security_ready.rc == 0
|
||||
retries: 30
|
||||
@@ -42,8 +42,8 @@
|
||||
}
|
||||
],
|
||||
} | to_json | quote }}'
|
||||
environment:
|
||||
ELASTIC_PW: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
register: es_role_result
|
||||
until: es_role_result.rc == 0
|
||||
retries: "{{ ELASTICSEARCH_RETRIES }}"
|
||||
@@ -68,9 +68,9 @@
|
||||
-X PUT "{{ ELASTICSEARCH_API_BASE }}/_security/user/{{ elasticsearch_consumer_username }}"
|
||||
-H "Content-Type: application/json"
|
||||
--data-binary @-'
|
||||
stdin: "{{ es_user_payload | to_json }}"
|
||||
environment:
|
||||
ELASTIC_PW: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
stdin: |-
|
||||
{{ ELASTICSEARCH_PASSWORD }}
|
||||
{{ es_user_payload | to_json }}
|
||||
register: es_user_result
|
||||
until: es_user_result.rc == 0
|
||||
retries: "{{ ELASTICSEARCH_RETRIES }}"
|
||||
@@ -83,8 +83,8 @@
|
||||
{{ ELASTICSEARCH_EXEC_SHELL }}
|
||||
'{{ 30 | curl }} -S -o /dev/null -w "%{http_code}" -u "elastic:$ELASTIC_PW"
|
||||
-X PUT "{{ ELASTICSEARCH_API_BASE }}/{{ elasticsearch_consumer_entity }}-default"'
|
||||
environment:
|
||||
ELASTIC_PW: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ ELASTICSEARCH_PASSWORD }}"
|
||||
register: es_index_result
|
||||
until: es_index_result.rc == 0 and es_index_result.stdout is search('20[0-9]|400')
|
||||
retries: "{{ ELASTICSEARCH_RETRIES }}"
|
||||
|
||||
@@ -14,5 +14,6 @@ ELASTICSEARCH_HEAP_MB: "{{ lookup('service_memory_mb', application_id, entity_na
|
||||
ELASTICSEARCH_RETRIES: 5
|
||||
ELASTICSEARCH_DELAY: 2
|
||||
ELASTICSEARCH_API_BASE: "http://{{ ELASTICSEARCH_LOCAL_HOST }}:{{ ELASTICSEARCH_INTERNAL_PORT }}"
|
||||
ELASTICSEARCH_EXEC_SHELL: "container exec -e ELASTIC_PW {{ ELASTICSEARCH_CONTAINER_ADDRESS }} sh -lc"
|
||||
ELASTICSEARCH_EXEC_SHELL_STDIN: "container exec -i -e ELASTIC_PW {{ ELASTICSEARCH_CONTAINER_ADDRESS }} sh -lc"
|
||||
ELASTICSEARCH_AUTH_FROM_STDIN: "IFS= read -r ELASTIC_PW && export ELASTIC_PW &&"
|
||||
ELASTICSEARCH_EXEC_SHELL: "{{ ELASTICSEARCH_AUTH_FROM_STDIN }} container exec -e ELASTIC_PW {{ ELASTICSEARCH_CONTAINER_ADDRESS }} sh -lc"
|
||||
ELASTICSEARCH_EXEC_SHELL_STDIN: "{{ ELASTICSEARCH_AUTH_FROM_STDIN }} container exec -i -e ELASTIC_PW {{ ELASTICSEARCH_CONTAINER_ADDRESS }} sh -lc"
|
||||
@@ -8,10 +8,12 @@
|
||||
#
|
||||
# Required environment:
|
||||
# POSTGRES_CONTAINER_ADDRESS exec address of the postgres container
|
||||
# PGPASSWORD postgres superuser password
|
||||
# stdin:
|
||||
# the postgres superuser password on its first line, exported as PGPASSWORD
|
||||
set -u
|
||||
|
||||
: "${POSTGRES_CONTAINER_ADDRESS:?POSTGRES_CONTAINER_ADDRESS not set}"
|
||||
IFS= read -r PGPASSWORD
|
||||
: "${PGPASSWORD:?PGPASSWORD not set}"
|
||||
export PGPASSWORD
|
||||
|
||||
@@ -28,7 +30,7 @@ runtime() {
|
||||
}
|
||||
|
||||
{
|
||||
hba="$(runtime exec --env "PGPASSWORD=${PGPASSWORD}" "${POSTGRES_CONTAINER_ADDRESS}" \
|
||||
hba="$(runtime exec --env PGPASSWORD "${POSTGRES_CONTAINER_ADDRESS}" \
|
||||
psql -U postgres -d postgres -Atc 'SHOW hba_file;' 2>/dev/null || true)"
|
||||
if [ -n "${hba}" ]; then
|
||||
echo "hba_file=${hba}"
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
- name: ⏳ Wait for Postgres TCP auth
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver POSTGRES_LOCAL_CID resolved at delegate_to runtime
|
||||
container exec -e PGPASSWORD {{ POSTGRES_LOCAL_CID | quote }} sh -lc
|
||||
IFS= read -r PGPASSWORD && export PGPASSWORD && container exec -e PGPASSWORD {{ POSTGRES_LOCAL_CID | quote }} sh -lc
|
||||
'psql -h "{{ POSTGRES_LOCAL_HOST }}" -p "{{ POSTGRES_PORT }}"
|
||||
-U postgres -d postgres -c "SELECT 1"'
|
||||
environment:
|
||||
PGPASSWORD: "{{ POSTGRES_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ POSTGRES_PASSWORD }}"
|
||||
delegate_to: "{{ POSTGRES_HOST_NODE }}"
|
||||
register: pg_ready
|
||||
until: pg_ready.rc == 0
|
||||
@@ -26,10 +26,15 @@
|
||||
|
||||
rescue:
|
||||
- name: "💾 Postgres | Dump pg_hba.conf into the diagnostics folder" # nocheck: rescue-extra-diagnostics pg_hba.conf is postgres-specific auth config the generic rescue script cannot capture, and it is what a failed TCP-auth wait needs
|
||||
ansible.builtin.script: "{{ lookup('path_absolute', 'roles/svc-db-postgres/files/shell/dump_pg_hba.sh') }}"
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- bash
|
||||
- -c
|
||||
- "{{ lookup('file', lookup('path_absolute', 'roles/svc-db-postgres/files/shell/dump_pg_hba.sh')) }}"
|
||||
- dump_pg_hba.sh
|
||||
stdin: "{{ POSTGRES_PASSWORD }}"
|
||||
environment:
|
||||
POSTGRES_CONTAINER_ADDRESS: "{{ POSTGRES_LOCAL_CID }}"
|
||||
PGPASSWORD: "{{ POSTGRES_PASSWORD }}"
|
||||
delegate_to: "{{ POSTGRES_HOST_NODE }}"
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
@@ -46,15 +46,15 @@
|
||||
|
||||
- name: "🔧 REDIS | Provision ACL user {{ redis_acl_username }} (auth-isolated)"
|
||||
ansible.builtin.shell: >
|
||||
container exec
|
||||
IFS= read -r REDIS_ACL_PASSWORD && export REDIS_ACL_PASSWORD && container exec
|
||||
-e REDIS_ACL_PASSWORD
|
||||
{{ REDIS_CONTAINER_ADDRESS }} sh -lc
|
||||
'printf "%s" ">$REDIS_ACL_PASSWORD" | {{ REDIS_CLI }} -x ACL SETUSER {{ redis_acl_username }}
|
||||
on resetkeys resetchannels
|
||||
allkeys allchannels
|
||||
+@all'
|
||||
environment:
|
||||
REDIS_ACL_PASSWORD: "{{ redis_acl_password }}"
|
||||
args:
|
||||
stdin: "{{ redis_acl_password }}"
|
||||
register: redis_acl_set
|
||||
until: redis_acl_set.rc == 0
|
||||
retries: "{{ REDIS_RETRIES }}"
|
||||
|
||||
@@ -18,13 +18,14 @@ set -euo pipefail
|
||||
: "${MCP_READ_ARGUMENTS:?}"
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
export MCP_PATH_KEY MCP_AUTH_HEADER
|
||||
|
||||
container run --rm -i \
|
||||
--network "${MCP_TEST_NETWORK}" \
|
||||
-e "MCP_URL=${MCP_URL}" \
|
||||
-e "MCP_TRANSPORT=${MCP_TRANSPORT}" \
|
||||
-e "MCP_PATH_KEY=${MCP_PATH_KEY}" \
|
||||
-e "MCP_AUTH_HEADER=${MCP_AUTH_HEADER}" \
|
||||
-e MCP_PATH_KEY \
|
||||
-e MCP_AUTH_HEADER \
|
||||
-e "MCP_EXPECTED_TOOLS=${MCP_EXPECTED_TOOLS}" \
|
||||
-e "MCP_UPSTREAM_SERVES=${MCP_UPSTREAM_SERVES}" \
|
||||
-e "MCP_READ_TOOL=${MCP_READ_TOOL}" \
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
- name: "🔐 Configure Checkmk header-auth and LDAP connection"
|
||||
ansible.builtin.shell:
|
||||
cmd: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -i
|
||||
IFS= read -r LDAP_BIND_PASSWORD && export LDAP_BIND_PASSWORD && container exec -i
|
||||
-e CMK_SITE_ID={{ CHECKMK_SITE | quote }}
|
||||
-e CHECKMK_SSO_ENABLED={{ CHECKMK_SSO_ENABLED | string | lower | quote }}
|
||||
-e CHECKMK_LDAP_ENABLED={{ CHECKMK_LDAP_ENABLED | string | lower | quote }}
|
||||
@@ -59,9 +59,9 @@
|
||||
-e LDAP_UID_ATTR={{ CHECKMK_LDAP_USER_ID_ATTR | quote }}
|
||||
{{ CHECKMK_LOCAL_CID | quote }}
|
||||
bash -s
|
||||
stdin: "{{ lookup('file', 'shell/configure-sso.sh') }}"
|
||||
environment:
|
||||
LDAP_BIND_PASSWORD: "{{ CHECKMK_LDAP_BIND_PASSWORD }}"
|
||||
stdin: |-
|
||||
{{ CHECKMK_LDAP_BIND_PASSWORD }}
|
||||
{{ lookup('file', 'shell/configure-sso.sh') }}
|
||||
delegate_to: "{{ CHECKMK_HOST_NODE }}"
|
||||
when: (CHECKMK_SSO_ENABLED | bool) or (CHECKMK_LDAP_ENABLED | bool)
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
@@ -74,15 +74,15 @@
|
||||
|
||||
- name: "✅ Decidim | Ensure administrator user exists with correct credentials"
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver DECIDIM_LOCAL_CID resolved at delegate_to runtime
|
||||
container exec -i -e RAILS_ENV={{ ENVIRONMENT | quote }}
|
||||
IFS= read -r DECIDIM_ADMIN_PASSWORD && export DECIDIM_ADMIN_PASSWORD && container exec -i -e RAILS_ENV={{ ENVIRONMENT | quote }}
|
||||
-e DECIDIM_ADMIN_EMAIL={{ lookup('users', 'platform_administrator').email | quote }}
|
||||
-e DECIDIM_ADMIN_PASSWORD
|
||||
{{ DECIDIM_LOCAL_CID | quote }}
|
||||
bundle exec rails runner -
|
||||
args:
|
||||
stdin: "{{ lookup('file', 'ruby/ensure/admin_user.rb') }}"
|
||||
environment:
|
||||
DECIDIM_ADMIN_PASSWORD: "{{ lookup('users', 'platform_administrator').password }}"
|
||||
stdin: |-
|
||||
{{ lookup('users', 'platform_administrator').password }}
|
||||
{{ lookup('file', 'ruby/ensure/admin_user.rb') }}
|
||||
register: decidim_admin_result
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
changed_when: "'Admin user ready' in decidim_admin_result.stdout"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# Idempotently set a single PHP config key inside the EspoCRM container.
|
||||
# Runs INSIDE the espocrm container (piped via `container exec -i ... sh < this-file`).
|
||||
# Required env, supplied via `container exec -e KEY=VALUE`:
|
||||
# Required env, supplied by the calling task via `container exec -e KEY`:
|
||||
# CONFIG_KEY PHP array key to update (host / dbname / user / password / ...)
|
||||
# CONFIG_VALUE desired value (raw, may contain `/`, `&`, or `|`)
|
||||
# CONFIG_FILE absolute path to config-internal.php
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
- name: "🩹 Patch EspoCRM DB config key (idempotent)"
|
||||
ansible.builtin.shell:
|
||||
cmd: >-
|
||||
container exec -i --user root
|
||||
IFS= read -r CONFIG_VALUE && export CONFIG_VALUE && container exec -i --user root
|
||||
-e CONFIG_KEY -e CONFIG_VALUE -e CONFIG_FILE
|
||||
{{ ESPOCRM_LOCAL_CID | quote }} sh
|
||||
stdin: "{{ lookup('file', 'shell/patch_config_key.sh') }}"
|
||||
stdin: |-
|
||||
{{ item.value }}
|
||||
{{ lookup('file', 'shell/patch_config_key.sh') }}
|
||||
environment:
|
||||
CONFIG_KEY: "{{ item.key }}"
|
||||
CONFIG_VALUE: "{{ item.value }}"
|
||||
CONFIG_FILE: "{{ ESPOCRM_CONFIG_FILE_PRIVATE }}"
|
||||
loop:
|
||||
- { key: host, value: "{{ lookup('database', application_id, 'host') }}" }
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
- name: 🩹 Patch Friendica local.config.php (DB credentials, system.url)
|
||||
ansible.builtin.shell:
|
||||
cmd: >- # nocheck: container-exec-resolver FRIENDICA_LOCAL_CID resolved at delegate_to runtime
|
||||
container exec -i --user {{ FRIENDICA_USER }}
|
||||
IFS= read -r PATCH_PASSWORD && export PATCH_PASSWORD && container exec -i --user {{ FRIENDICA_USER }}
|
||||
-e PATCH_HOSTNAME -e PATCH_DATABASE -e PATCH_USERNAME -e PATCH_PASSWORD -e PATCH_URL
|
||||
{{ FRIENDICA_LOCAL_CID | quote }}
|
||||
sh -s -- {{ FRIENDICA_CONFIG_FILE | quote }}
|
||||
stdin: "{{ lookup('file', 'shell/patch/local_config.sh') }}"
|
||||
stdin: |-
|
||||
{{ lookup('database', application_id, 'password') | sed_escape('/') }}
|
||||
{{ lookup('file', 'shell/patch/local_config.sh') }}
|
||||
environment:
|
||||
PATCH_HOSTNAME: "{{ lookup('database', application_id, 'host') | sed_escape('/') }}:{{ lookup('database', application_id, 'port') | sed_escape('/') }}"
|
||||
PATCH_DATABASE: "{{ lookup('database', application_id, 'name') | sed_escape('/') }}"
|
||||
PATCH_USERNAME: "{{ lookup('database', application_id, 'username') | sed_escape('/') }}"
|
||||
PATCH_PASSWORD: "{{ lookup('database', application_id, 'password') | sed_escape('/') }}"
|
||||
PATCH_URL: "{{ FRIENDICA_BASE_URL | sed_escape('#') }}"
|
||||
delegate_to: "{{ FRIENDICA_HOST_NODE }}"
|
||||
register: friendica_config_patch
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
- name: "✅ Ensure configuration.php DB settings match inventory"
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
shell: >
|
||||
container exec -i
|
||||
IFS= read -r J_DBPASS && export J_DBPASS && container exec -i
|
||||
-e J_CONFIG_FILE={{ JOOMLA_CONFIG_FILE | quote }}
|
||||
-e J_DBTYPE={{ JOOMLA_DB_CONNECTOR | quote }}
|
||||
-e J_DBHOST={{ (lookup('database', application_id, 'host') ~ ':' ~ lookup('database', application_id, 'port')) | quote }}
|
||||
@@ -11,9 +11,9 @@
|
||||
-e J_DBNAME={{ lookup('database', application_id, 'name') | quote }}
|
||||
{{ JOOMLA_LOCAL_CID | quote }} php --
|
||||
args:
|
||||
stdin: "{{ lookup('file', role_path ~ '/files/php/configure_db.php') }}"
|
||||
environment:
|
||||
J_DBPASS: "{{ lookup('database', application_id, 'password') }}"
|
||||
stdin: |-
|
||||
{{ lookup('database', application_id, 'password') }}
|
||||
{{ lookup('file', role_path ~ '/files/php/configure_db.php') }}
|
||||
register: cfg_patch
|
||||
changed_when: cfg_patch.stdout == "changed"
|
||||
failed_when: cfg_patch.rc != 0
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
- name: "🔎 Check for Mailu DB domain table"
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver MAILU_DB_LOCAL_CID resolved at delegate_to runtime
|
||||
container exec
|
||||
IFS= read -r MARIADB_PWD && export MARIADB_PWD && container exec
|
||||
-e MARIADB_PWD
|
||||
{{ MAILU_DB_LOCAL_CID | quote }} sh -c
|
||||
'mariadb -u {{ lookup('database', application_id, 'username') }} -p"$MARIADB_PWD"
|
||||
-e "SHOW TABLES FROM {{ lookup('database', application_id, 'name') }} LIKE \"domain\";"'
|
||||
environment:
|
||||
MARIADB_PWD: "{{ lookup('database', application_id, 'password') }}"
|
||||
args:
|
||||
stdin: "{{ lookup('database', application_id, 'password') }}"
|
||||
register: mailu_db_schema_check
|
||||
retries: 30
|
||||
delay: 5
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
- name: "🔑 Hash the declared password for {{ realign_localpart }}"
|
||||
ansible.builtin.shell:
|
||||
cmd: >-
|
||||
IFS= read -r MATRIX_REALIGN_PASSWORD && export MATRIX_REALIGN_PASSWORD &&
|
||||
container exec -i -e MATRIX_REALIGN_PASSWORD {{ MATRIX_SYNAPSE_CONTAINER_ADDRESS }}
|
||||
sh -c 'hash_password -c "{{ MATRIX_SYNAPSE_CONFIG_PATH_CONTAINER }}"
|
||||
-p "$MATRIX_REALIGN_PASSWORD"'
|
||||
stdin: "{{ realign_password }}"
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
MATRIX_REALIGN_PASSWORD: "{{ realign_password }}"
|
||||
register: matrix_password_hash
|
||||
changed_when: false
|
||||
|
||||
- name: "🔑 Point {{ realign_localpart }} at the declared password"
|
||||
ansible.builtin.shell:
|
||||
cmd: >-
|
||||
IFS= read -r PGPASSWORD && export PGPASSWORD &&
|
||||
container exec -i -e PGPASSWORD
|
||||
{{ lookup('database', application_id, 'address') }}
|
||||
psql -v ON_ERROR_STOP=1 -U {{ MATRIX_POSTGRES_USER | quote }}
|
||||
@@ -23,11 +24,10 @@
|
||||
-v hash={{ (matrix_password_hash.stdout | trim) | quote }}
|
||||
-v name={{ lookup('mxid', realign_localpart) | quote }}
|
||||
-f -
|
||||
stdin: >-
|
||||
stdin: |-
|
||||
{{ MATRIX_POSTGRES_PASSWORD }}
|
||||
{{ lookup('file', 'sql/realign_user_password.sql') }}
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
PGPASSWORD: "{{ MATRIX_POSTGRES_PASSWORD }}"
|
||||
register: matrix_password_update
|
||||
changed_when: "'UPDATE 1' in matrix_password_update.stdout"
|
||||
failed_when: >-
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
- name: "🤖 Point the Moodle AI provider instance at the platform gateway"
|
||||
ansible.builtin.shell: >
|
||||
container exec -i --user {{ MOODLE_RUNTIME_USER }}
|
||||
IFS= read -r AI_API_KEY && export AI_API_KEY && container exec -i --user {{ MOODLE_RUNTIME_USER }}
|
||||
-e MOODLE_CONFIG={{ MOODLE_CONFIG | quote }}
|
||||
-e AI_PROVIDER_NAME={{ MOODLE_LITELLM_PROVIDER_NAME | quote }}
|
||||
-e AI_API_KEY
|
||||
@@ -13,9 +13,9 @@
|
||||
-e AI_IMAGE_ENDPOINT={{ MOODLE_LITELLM_IMAGE_ENDPOINT | quote }}
|
||||
{{ MOODLE_CONTAINER_ADDRESS }} php
|
||||
args:
|
||||
stdin: "{{ lookup('file', 'php/provision/ai_gateway.php') }}"
|
||||
environment:
|
||||
AI_API_KEY: "{{ MOODLE_LITELLM_API_KEY }}"
|
||||
stdin: |-
|
||||
{{ MOODLE_LITELLM_API_KEY }}
|
||||
{{ lookup('file', 'php/provision/ai_gateway.php') }}
|
||||
register: moodle_ai_provider
|
||||
changed_when: false
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
- name: "🔑 Register the MCP web service and mint its permanent token"
|
||||
ansible.builtin.shell: | # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -i --user {{ MOODLE_RUNTIME_USER }} \
|
||||
IFS= read -r MCP_ACCOUNT_PASSWORD && export MCP_ACCOUNT_PASSWORD && container exec -i --user {{ MOODLE_RUNTIME_USER }} \
|
||||
-e MOODLE_CONFIG={{ MOODLE_CONFIG | quote }} \
|
||||
-e MCP_SERVICE_NAME={{ MOODLE_MCP_EXTERNAL_SERVICE_NAME | quote }} \
|
||||
-e MCP_SERVICE_SHORTNAME={{ MOODLE_MCP_EXTERNAL_SERVICE_SHORTNAME | quote }} \
|
||||
@@ -14,9 +14,9 @@
|
||||
-e MCP_ROLE_CAPABILITIES={{ MOODLE_MCP_ROLE_CAPABILITIES | join(',') | quote }} \
|
||||
{{ MOODLE_MCP_LOCAL_CID | quote }} php
|
||||
args:
|
||||
stdin: "{{ lookup('file', 'php/provision/mcp.php') }}"
|
||||
environment:
|
||||
MCP_ACCOUNT_PASSWORD: "{{ MOODLE_MCP_ACCOUNT_PASSWORD }}"
|
||||
stdin: |-
|
||||
{{ MOODLE_MCP_ACCOUNT_PASSWORD }}
|
||||
{{ lookup('file', 'php/provision/mcp.php') }}
|
||||
register: moodle_mcp_provision
|
||||
changed_when: false
|
||||
delegate_to: "{{ MOODLE_MCP_HOST_NODE }}"
|
||||
|
||||
@@ -3,7 +3,7 @@ set -euo pipefail
|
||||
|
||||
# Usage:
|
||||
# realign_admin_password.sh <container> <run_as_user> <admin_username> <occ_path>
|
||||
# OC_PASS: the declared password, read from the environment only.
|
||||
# stdin: the declared password on its first line, exported as OC_PASS.
|
||||
#
|
||||
# Exit: 0 with [CHANGED] or [UNCHANGED] on stdout, 1 with [FAIL] on stderr.
|
||||
|
||||
@@ -17,7 +17,13 @@ if [[ -z "$container" || -z "$run_as" || -z "$admin_user" || -z "$occ" ]]; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -z "${OC_PASS:-}" ]]; then
|
||||
if ! IFS= read -r OC_PASS; then
|
||||
echo "[FAIL] No administrator password on stdin." >&2
|
||||
exit 1
|
||||
fi
|
||||
export OC_PASS
|
||||
|
||||
if [[ -z "$OC_PASS" ]]; then
|
||||
echo "[FAIL] OC_PASS is empty; refusing to set an empty administrator password." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
---
|
||||
- name: "🔑 Realign the administrator password with the declared one"
|
||||
ansible.builtin.script: > # nocheck: container-exec-resolver NEXTCLOUD_LOCAL_CID resolved at delegate_to runtime
|
||||
{{ lookup('path_absolute', 'roles/web-app-nextcloud/files/shell/realign_admin_password.sh') }}
|
||||
{{ NEXTCLOUD_LOCAL_CID | quote }}
|
||||
{{ NEXTCLOUD_DOCKER_USER | quote }}
|
||||
{{ NEXTCLOUD_ADMINISTRATOR_USERNAME | quote }}
|
||||
{{ NEXTCLOUD_INTERNAL_OCC_COMMAND | quote }}
|
||||
environment:
|
||||
OC_PASS: "{{ NEXTCLOUD_ADMINISTRATOR_PASSWORD }}"
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- bash
|
||||
- -c
|
||||
- "{{ lookup('file', lookup('path_absolute', 'roles/web-app-nextcloud/files/shell/realign_admin_password.sh')) }}"
|
||||
- realign_admin_password.sh
|
||||
- "{{ NEXTCLOUD_LOCAL_CID }}"
|
||||
- "{{ NEXTCLOUD_DOCKER_USER }}"
|
||||
- "{{ NEXTCLOUD_ADMINISTRATOR_USERNAME }}"
|
||||
- "{{ NEXTCLOUD_INTERNAL_OCC_COMMAND }}"
|
||||
stdin: "{{ NEXTCLOUD_ADMINISTRATOR_PASSWORD }}"
|
||||
register: _nextcloud_admin_password
|
||||
changed_when: _nextcloud_admin_password.stdout is search('\[CHANGED\]')
|
||||
failed_when: >-
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
- name: "✅ Ensure Shopware admin exists and has the desired password"
|
||||
ansible.builtin.shell:
|
||||
cmd: >- # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -i --user {{ SHOPWARE_USER }}
|
||||
IFS= read -r ADMIN_PASSWORD && export ADMIN_PASSWORD && container exec -i --user {{ SHOPWARE_USER }}
|
||||
-e SHOPWARE_ROOT={{ SHOPWARE_ROOT | quote }}
|
||||
-e ADMIN_USER={{ lookup('users', 'platform_administrator').username | quote }}
|
||||
-e ADMIN_PASSWORD
|
||||
@@ -11,9 +11,9 @@
|
||||
-e ADMIN_EMAIL={{ lookup('users', 'platform_administrator').email | quote }}
|
||||
{{ SHOPWARE_WEB_LOCAL_CID | quote }}
|
||||
sh
|
||||
stdin: "{{ lookup('ansible.builtin.file', role_path ~ '/files/shell/admin/user.sh') }}"
|
||||
environment:
|
||||
ADMIN_PASSWORD: "{{ lookup('users', 'platform_administrator').password }}"
|
||||
stdin: |-
|
||||
{{ lookup('users', 'platform_administrator').password }}
|
||||
{{ lookup('ansible.builtin.file', role_path ~ '/files/shell/admin/user.sh') }}
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
- name: "🛡️ Ensure the Shopware admin still holds the admin privilege"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
- name: "🔐 Ensure the Keycloak login provider is configured"
|
||||
ansible.builtin.shell:
|
||||
cmd: >- # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -i --user {{ SHOPWARE_USER }}
|
||||
IFS= read -r ADMIN_PASSWORD && IFS= read -r OIDC_CLIENT_SECRET && export ADMIN_PASSWORD OIDC_CLIENT_SECRET && container exec -i --user {{ SHOPWARE_USER }}
|
||||
-e SHOPWARE_API_BASE={{ SHOPWARE_API_BASE | quote }}
|
||||
-e ADMIN_USER={{ lookup('users', 'platform_administrator').username | quote }}
|
||||
-e ADMIN_PASSWORD
|
||||
@@ -30,10 +30,10 @@
|
||||
-e OIDC_CLIENT_SECRET
|
||||
{{ SHOPWARE_WEB_LOCAL_CID | quote }}
|
||||
php
|
||||
stdin: "{{ lookup('ansible.builtin.file', role_path ~ '/files/php/oidc/client.php') }}"
|
||||
environment:
|
||||
ADMIN_PASSWORD: "{{ lookup('users', 'platform_administrator').password }}"
|
||||
OIDC_CLIENT_SECRET: "{{ OIDC.CLIENT.SECRET }}"
|
||||
stdin: |-
|
||||
{{ lookup('users', 'platform_administrator').password }}
|
||||
{{ OIDC.CLIENT.SECRET }}
|
||||
{{ lookup('ansible.builtin.file', role_path ~ '/files/php/oidc/client.php') }}
|
||||
changed_when: false
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
- name: ▶️ Run Snipe-IT migrations (idempotent)
|
||||
ansible.builtin.shell: >-
|
||||
container exec -i
|
||||
IFS= read -r APP_KEY && export APP_KEY && container exec -i
|
||||
-e APP_KEY
|
||||
-e XDG_CONFIG_HOME=/tmp
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }}
|
||||
php artisan migrate --force
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
args:
|
||||
stdin: "{{ SNIPE_IT_APP_KEY }}"
|
||||
register: snipeit_migrate
|
||||
changed_when: >
|
||||
('Migrating:' in snipeit_migrate.stdout)
|
||||
@@ -39,13 +39,13 @@
|
||||
|
||||
- name: 🌱 Seed the Snipe-IT demo data
|
||||
ansible.builtin.shell: >-
|
||||
container exec -i
|
||||
IFS= read -r APP_KEY && export APP_KEY && container exec -i
|
||||
-e APP_KEY
|
||||
-e XDG_CONFIG_HOME=/tmp
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }}
|
||||
php -d memory_limit={{ lookup('service_memory_mb', application_id, SNIPE_IT_SERVICE, 0.25) }}M artisan db:seed --force
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
args:
|
||||
stdin: "{{ SNIPE_IT_APP_KEY }}"
|
||||
register: snipeit_demo_seed
|
||||
changed_when: true
|
||||
when: MODE_DEMO | bool
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
- name: "📌 snipe-it: apply LDAP configuration via Setting model"
|
||||
ansible.builtin.shell:
|
||||
cmd: >-
|
||||
container exec -i
|
||||
IFS= read -r APP_KEY && IFS= read -r LDAP_BIND_PASSWORD_B64 && export APP_KEY LDAP_BIND_PASSWORD_B64 && container exec -i
|
||||
-e APP_KEY
|
||||
-e LDAP_SERVER_URI={{ LDAP.SERVER.URI | quote }}
|
||||
-e LDAP_SERVER_PORT={{ LDAP.SERVER.PORT | quote }}
|
||||
@@ -29,10 +29,10 @@
|
||||
-e LDAP_AUTH_FILTER_QUERY={{ SNIPE_IT_LDAP_AUTH_FILTER_QUERY | quote }}
|
||||
-e OIDC_RESET_URL={{ OIDC.CLIENT.RESET_CREDENTIALS | quote }}
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }} php
|
||||
stdin: "{{ lookup('file', 'php/apply/ldap_config.php') }}"
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
LDAP_BIND_PASSWORD_B64: "{{ LDAP.BIND_CREDENTIAL | b64encode }}"
|
||||
stdin: |-
|
||||
{{ SNIPE_IT_APP_KEY }}
|
||||
{{ LDAP.BIND_CREDENTIAL | b64encode }}
|
||||
{{ lookup('file', 'php/apply/ldap_config.php') }}
|
||||
changed_when: true
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
- name: "🔎 Check if Snipe-IT admin user already exists (by username)"
|
||||
ansible.builtin.shell: |
|
||||
container exec -i \
|
||||
IFS= read -r APP_KEY && export APP_KEY && container exec -i \
|
||||
-e APP_KEY \
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }} \
|
||||
php -r '
|
||||
@@ -13,15 +13,15 @@
|
||||
->exists();
|
||||
exit($exists ? 0 : 1);
|
||||
'
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
args:
|
||||
stdin: "{{ SNIPE_IT_APP_KEY }}"
|
||||
register: snipe_it_admin_exists
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: "📁 Create Snipe-IT administrator account"
|
||||
ansible.builtin.shell: |
|
||||
container exec -i -e APP_KEY -e SNIPE_IT_REALIGN_PASSWORD \
|
||||
IFS= read -r APP_KEY && IFS= read -r SNIPE_IT_REALIGN_PASSWORD && export APP_KEY SNIPE_IT_REALIGN_PASSWORD && container exec -i -e APP_KEY -e SNIPE_IT_REALIGN_PASSWORD \
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }} sh -lc '
|
||||
php artisan snipeit:create-admin \
|
||||
--first_name "{{ lookup('users', 'platform_administrator').firstname }}" \
|
||||
@@ -31,9 +31,10 @@
|
||||
--password "$SNIPE_IT_REALIGN_PASSWORD" \
|
||||
--no-interaction
|
||||
'
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
SNIPE_IT_REALIGN_PASSWORD: "{{ lookup('users', 'platform_administrator').password }}"
|
||||
args:
|
||||
stdin: |-
|
||||
{{ SNIPE_IT_APP_KEY }}
|
||||
{{ lookup('users', 'platform_administrator').password }}
|
||||
when: snipe_it_admin_exists.rc != 0
|
||||
register: snipe_it_admin_create
|
||||
changed_when: "'New user created' in snipe_it_admin_create.stdout"
|
||||
@@ -48,14 +49,16 @@
|
||||
- name: "🔑 Realign the administrator password Snipe-IT persisted at install"
|
||||
ansible.builtin.shell:
|
||||
cmd: >
|
||||
IFS= read -r APP_KEY && IFS= read -r SNIPE_IT_REALIGN_PASSWORD && export APP_KEY SNIPE_IT_REALIGN_PASSWORD &&
|
||||
container exec -i
|
||||
-e APP_KEY -e SNIPE_IT_REALIGN_USERNAME -e SNIPE_IT_REALIGN_PASSWORD
|
||||
{{ SNIPE_IT_CONTAINER_ADDRESS }} php
|
||||
stdin: "{{ lookup('file', 'php/realign_admin_password.php') }}"
|
||||
stdin: |-
|
||||
{{ SNIPE_IT_APP_KEY }}
|
||||
{{ lookup('users', 'platform_administrator').password }}
|
||||
{{ lookup('file', 'php/realign_admin_password.php') }}
|
||||
environment:
|
||||
APP_KEY: "{{ SNIPE_IT_APP_KEY }}"
|
||||
SNIPE_IT_REALIGN_USERNAME: "{{ lookup('users', 'platform_administrator').username }}"
|
||||
SNIPE_IT_REALIGN_PASSWORD: "{{ lookup('users', 'platform_administrator').password }}"
|
||||
when: snipe_it_admin_exists.rc == 0
|
||||
register: snipe_it_admin_realign
|
||||
changed_when: snipe_it_admin_realign.stdout is search('\[CHANGED\]')
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
|
||||
- name: "📁 Create Taiga admin user (idempotent)"
|
||||
ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
container exec -i
|
||||
IFS= read -r DJANGO_SUPERUSER_PASSWORD && export DJANGO_SUPERUSER_PASSWORD && container exec -i
|
||||
-e DJANGO_SUPERUSER_PASSWORD
|
||||
{{ TAIGA_MANAGER_LOCAL_CID | quote }}
|
||||
python manage.py createsuperuser --noinput
|
||||
--username {{ TAIGA_SUPERUSER_NAME }}
|
||||
--email {{ TAIGA_SUPERUSER_EMAIL }}
|
||||
environment:
|
||||
DJANGO_SUPERUSER_PASSWORD: "{{ TAIGA_SUPERUSER_PASSWORD }}"
|
||||
args:
|
||||
stdin: "{{ TAIGA_SUPERUSER_PASSWORD }}"
|
||||
register: taiga_create_admin
|
||||
delegate_to: "{{ TAIGA_MANAGER_HOST_NODE }}"
|
||||
changed_when: taiga_create_admin.rc == 0
|
||||
@@ -41,15 +41,17 @@
|
||||
- name: "📝 Upsert Taiga admin via manage.py shell"
|
||||
ansible.builtin.shell: # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
|
||||
cmd: >
|
||||
IFS= read -r DJANGO_SUPERUSER_PASSWORD && export DJANGO_SUPERUSER_PASSWORD &&
|
||||
container exec -i
|
||||
-e TAIGA_SUPERUSER_NAME -e TAIGA_SUPERUSER_EMAIL -e DJANGO_SUPERUSER_PASSWORD
|
||||
{{ TAIGA_MANAGER_LOCAL_CID | quote }}
|
||||
python manage.py shell
|
||||
stdin: "{{ lookup('file', 'python/upsert_admin.py') }}"
|
||||
stdin: |-
|
||||
{{ TAIGA_SUPERUSER_PASSWORD }}
|
||||
{{ lookup('file', 'python/upsert_admin.py') }}
|
||||
environment:
|
||||
TAIGA_SUPERUSER_NAME: "{{ TAIGA_SUPERUSER_NAME }}"
|
||||
TAIGA_SUPERUSER_EMAIL: "{{ TAIGA_SUPERUSER_EMAIL }}"
|
||||
DJANGO_SUPERUSER_PASSWORD: "{{ TAIGA_SUPERUSER_PASSWORD }}"
|
||||
register: taiga_upsert_admin
|
||||
when: taiga_create_admin.rc != 0
|
||||
delegate_to: "{{ TAIGA_MANAGER_HOST_NODE }}"
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
|
||||
- name: 🔄 Update DB password in {{ WORDPRESS_CONFIG_FILE }}
|
||||
shell: >
|
||||
container exec --user root
|
||||
IFS= read -r PATCH_PASSWORD && export PATCH_PASSWORD && container exec --user root
|
||||
-e PATCH_PASSWORD
|
||||
{{ WORDPRESS_CONTAINER_ADDRESS }}
|
||||
sh -c "sed -i \"s/define(\\s*'DB_PASSWORD'\\s*,\\s*'[^']*'\\s*);/define( 'DB_PASSWORD', '\${PATCH_PASSWORD}' );/i\" {{ WORDPRESS_DOCKER_CONF_PATH }}"
|
||||
environment:
|
||||
PATCH_PASSWORD: "{{ lookup('database', application_id, 'password') | sed_escape('/') }}"
|
||||
args:
|
||||
stdin: "{{ lookup('database', application_id, 'password') | sed_escape('/') }}"
|
||||
notify: compose-up
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Single quotes are what make the difference; inside them the host shell leaves
|
||||
'…'`` is the same shape with the interpreter chosen by flag, and passes.
|
||||
|
||||
The half-fixed form survives every other check: it carries the ``-e NAME``
|
||||
and the ``environment:``, it renders, it parses, and the two sibling rules
|
||||
and the value on ``stdin:``, it renders, it parses, and the two sibling rules
|
||||
see nothing wrong with it.
|
||||
|
||||
Per-line opt-out
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Ban ``-e NAME=VALUE`` in role files wherever VALUE is not a literal.
|
||||
"""Ban ``-e NAME=VALUE`` (or ``--env``) in role files wherever VALUE is not a literal.
|
||||
|
||||
Rationale
|
||||
=========
|
||||
@@ -9,13 +9,15 @@ table. A deployment rotates its credentials between the two passes of a
|
||||
matrix-deploy round, so the values that travel this way are live secrets.
|
||||
|
||||
The safer form is ``-e NAME`` with no value. The engine then forwards the
|
||||
variable from its own environment, which an Ansible task fills with a
|
||||
task-level ``environment:`` mapping and a shell script with ``export``.
|
||||
variable from its own environment, which the calling shell fills from the
|
||||
task's ``stdin:``: ``IFS= read -r NAME && export NAME && container exec -e
|
||||
NAME …``, one line per secret, ahead of any payload that ``container exec
|
||||
-i`` passes on to the container.
|
||||
|
||||
With ``ansible.builtin.script`` the value then reaches no argv; with
|
||||
``shell`` and ``command`` it still appears once on the module wrapper's own
|
||||
line, which ``Shell.env_prefix`` builds, so the exposure shrinks rather than
|
||||
vanishes.
|
||||
Only ``stdin:`` keeps the value out of every argv. A task-level
|
||||
``environment:`` does not: for ``command``, ``shell`` and ``script`` alike,
|
||||
Ansible runs ``/bin/sh -c 'NAME=value … && sleep 0'`` on the executing host,
|
||||
and that shell keeps the line in its argv for as long as the task runs.
|
||||
|
||||
The check is on the flag, not on the command before it: associating an ``-e``
|
||||
with its ``container exec`` is unreliable across a YAML block scalar, and
|
||||
@@ -48,8 +50,8 @@ line convicts too. A
|
||||
fact or task var defined in the same file whose value holds a credential key
|
||||
(``password:``) or source counts as a secret under any name. The first rule
|
||||
also reads the Jinja-built ``-e {{ ('NAME=' ~ …) }}``. Hand such a value over on
|
||||
the task's ``stdin:`` (``curl -H @-``, ``psql`` reading SQL) or as ``-e NAME``
|
||||
plus ``environment:``.
|
||||
the task's ``stdin:``, either to the program itself (``curl -H @-``, ``psql``
|
||||
reading SQL) or to the calling shell, which exports it for ``-e NAME``.
|
||||
|
||||
Per-line opt-out
|
||||
================
|
||||
@@ -78,7 +80,8 @@ from .test_exec_requires_shell_module import _variable_values
|
||||
_RULE = "container-exec-env-value"
|
||||
_EXTENSIONS = (".yml", ".yaml", ".j2", ".sh")
|
||||
_ENV_WITH_VALUE = re.compile(
|
||||
r"(?:^|\s)-e\s+(?:\{\{\s*\(*\s*['\"])?([A-Za-z_][A-Za-z0-9_]*)="
|
||||
r"(?:^|\s)(?:-e|--env)(?:\s+|=)(?:\{\{\s*\(*\s*['\"])?['\"]?"
|
||||
r"([A-Za-z_][A-Za-z0-9_]*)="
|
||||
)
|
||||
_INTERPOLATED = re.compile(r"\{\{|\$|`")
|
||||
_SECRET_NAME = re.compile(r"PASS|PWD|SECRET|TOKEN|KEY|CRED", re.IGNORECASE)
|
||||
@@ -523,8 +526,11 @@ class TestExecArgvSecret(unittest.TestCase):
|
||||
self.fail(
|
||||
"Secrets on a `container exec` / `docker exec` command line reach "
|
||||
"the host process list and the daemon's exec_create event. Hand "
|
||||
"them over on the task's `stdin:` (`curl -H @-`, SQL on psql's "
|
||||
"stdin) or as `-e NAME` plus the task's `environment:`, or add "
|
||||
"them over on the task's `stdin:`, to the program itself "
|
||||
"(`curl -H @-`, SQL on psql's stdin) or to the calling shell "
|
||||
"(`IFS= read -r NAME && export NAME`) for `-e NAME`; a task-level "
|
||||
"`environment:` puts `NAME=value` on the host's `/bin/sh -c` "
|
||||
"line instead. Or add "
|
||||
f"`# nocheck: {_ARGV_RULE} <reason>` above the module key.\n"
|
||||
+ "\n".join(sorted(findings))
|
||||
)
|
||||
@@ -537,6 +543,13 @@ class TestEnvAssignments(unittest.TestCase):
|
||||
self.assertEqual(name, "DB")
|
||||
self.assertTrue(_carries_credential(name, value))
|
||||
|
||||
def test_the_long_flag_with_a_quoted_assignment_is_read_too(self) -> None:
|
||||
line = 'runtime exec --env "PGPASSWORD=${PGPASSWORD}" "${CID}" psql'
|
||||
[(name, value)] = list(_env_assignments(line))
|
||||
self.assertEqual(name, "PGPASSWORD")
|
||||
self.assertTrue(_carries_credential(name, value))
|
||||
self.assertEqual(list(_env_assignments("--env-file=x.env --env=MODE=prod")), [])
|
||||
|
||||
def test_a_literal_or_a_plain_neutral_value_passes(self) -> None:
|
||||
self.assertEqual(list(_env_assignments("-e RAILS_ENV=production x")), [])
|
||||
[(name, value)] = list(_env_assignments("-e SITE_URL={{ BASE_URL }} x"))
|
||||
@@ -606,12 +619,13 @@ class TestContainerExecEnvPassesNoValue(unittest.TestCase):
|
||||
"account while the call runs, and `no_log` cannot mask a "
|
||||
"process table.\n\n"
|
||||
"Fix one of:\n"
|
||||
" - pass the name alone, `-e NAME`, and supply the value "
|
||||
"through the task's `environment:` mapping (Ansible) or an "
|
||||
"`export NAME=...` in the script (shell). With `script` the "
|
||||
"value then reaches no argv; with `shell` and `command` it "
|
||||
"appears once on the module wrapper's line instead of on "
|
||||
"every container call;\n"
|
||||
" - pass the name alone, `-e NAME`, and hand the value to the "
|
||||
"calling shell on the task's `stdin:`, which reads and exports "
|
||||
"it ahead of the call (`IFS= read -r NAME && export NAME && "
|
||||
"container exec -e NAME ...`). A task-level `environment:` is "
|
||||
"no substitute: for `command`, `shell` and `script` alike "
|
||||
"Ansible puts `NAME=value` on the host's `/bin/sh -c` line, "
|
||||
"where `ps` shows it for the whole task;\n"
|
||||
" - for a templated value that provably carries no secret, "
|
||||
"add `# nocheck: container-exec-env-value -- <reason>` on the "
|
||||
"same line or the line above, naming what the value is.\n\n"
|
||||
|
||||
@@ -25,9 +25,12 @@ The remedy, in order of preference
|
||||
==================================
|
||||
1. Hand the value over on **stdin**, where it reaches no argv at all.
|
||||
``curl -K -`` does this, as ``web-app-stalwart/tasks/jmap_call.yml`` shows.
|
||||
2. Otherwise ``-e NAME`` plus the task's ``environment:``, with ``"$NAME"``
|
||||
inside an ``sh -lc`` wrapper so the container's shell expands it. The
|
||||
secret leaves the host argv but remains in the in-container process's.
|
||||
2. Otherwise ``-e NAME``, with the value on the task's ``stdin:`` read and
|
||||
exported by the calling shell (``IFS= read -r NAME && export NAME``) and
|
||||
``"$NAME"`` inside an ``sh -lc`` wrapper so the container's shell expands
|
||||
it. The secret leaves the host argv but remains in the in-container
|
||||
process's. A task-level ``environment:`` is no substitute: Ansible puts
|
||||
``NAME=value`` on the host's ``/bin/sh -c`` line.
|
||||
|
||||
Scope is task files and shell payloads. A compose ``command:`` is the
|
||||
container's own argv in a file the deploy protects, which is a different
|
||||
@@ -110,9 +113,12 @@ class TestContainerFlagPassesNoCredential(unittest.TestCase):
|
||||
" - give the value to the program on stdin, which keeps it out "
|
||||
"of every argv; `curl -K -` is the form "
|
||||
"roles/web-app-stalwart/tasks/jmap_call.yml already uses;\n"
|
||||
" - forward it as `-e NAME` with the value in the task's "
|
||||
'`environment:`, and reference `"$NAME"` inside an `sh -lc` '
|
||||
"wrapper so the container's shell expands it, not the host's;\n"
|
||||
" - forward it as `-e NAME` with the value on the task's "
|
||||
"`stdin:`, read and exported by the calling shell (`IFS= read "
|
||||
'-r NAME && export NAME`), and reference `"$NAME"` inside an '
|
||||
"`sh -lc` wrapper so the container's shell expands it, not the "
|
||||
"host's; a task-level `environment:` lands on the host's "
|
||||
"`/bin/sh -c` line;\n"
|
||||
" - add `# nocheck: container-flag-credential -- <reason>` where "
|
||||
"the value provably carries no secret.\n\n"
|
||||
f"Offending lines:\n{formatted}"
|
||||
|
||||
Reference in new issue
Block a user