fix(remnawave): не светить ключи в CI + заметка в BOOTSTRAP
ansible-core-net / deploy (push) Failing after 1m0s
ansible-core-net / deploy (push) Failing after 1m0s
no_log на bootstrap; stderr API редáctит privateKey/SECRET_KEY/токены; в BOOTSTRAP — правило для новых установок. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a4a0655888
commit
dd19301c33
3 files changed
+48
-16
No files matched your search
@@ -196,7 +196,8 @@
|
||||
register: remnawave_bootstrap_raw
|
||||
changed_when: false
|
||||
failed_when: remnawave_bootstrap_raw.rc != 0
|
||||
no_log: false
|
||||
# no_log обязателен: stdout содержит api_token и node_secret; без него ключи утекут в CI.
|
||||
no_log: true
|
||||
|
||||
- name: Разобрать результат bootstrap
|
||||
ansible.builtin.set_fact:
|
||||
|
||||
@@ -14,6 +14,28 @@ host_created=0
|
||||
node_secret=""
|
||||
active_token="${RW_API_TOKEN:-}"
|
||||
|
||||
# В stderr/CI никогда не светить privateKey, SECRET_KEY, JWT, API-токены.
|
||||
# publicKey оставляем — он не секрет.
|
||||
redact_json() {
|
||||
jq 'walk(
|
||||
if type == "object" then
|
||||
with_entries(
|
||||
if (.key | test("(?i)privateKey|privKey|secretKey|SECRET_KEY|accessToken|apiToken|password|^token$"))
|
||||
then .value = "[REDACTED]"
|
||||
else .
|
||||
end
|
||||
)
|
||||
else . end
|
||||
)' 2>/dev/null || echo '[body redacted]'
|
||||
}
|
||||
|
||||
log_api_error() {
|
||||
local method="$1" path="$2" code="$3" body="$4"
|
||||
echo "API ${method} ${path} → HTTP ${code}" >&2
|
||||
printf '%s\n' "${body}" | redact_json >&2 || true
|
||||
echo >&2
|
||||
}
|
||||
|
||||
api() {
|
||||
local method="$1"; shift
|
||||
local path="$1"; shift
|
||||
@@ -27,9 +49,7 @@ api() {
|
||||
-H "Content-Type: application/json" "${API_BASE}${path}" "$@") || true
|
||||
fi
|
||||
if [[ ! "${code}" =~ ^2 ]]; then
|
||||
echo "API ${method} ${path} → HTTP ${code}" >&2
|
||||
cat "$tmp" >&2 || true
|
||||
echo >&2
|
||||
log_api_error "$method" "$path" "$code" "$(cat "$tmp" 2>/dev/null || true)"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
@@ -48,7 +68,8 @@ if [ "${is_register}" = "true" ]; then
|
||||
access=$(printf '%s' "${reg_resp}" | jq -r '.response.accessToken // .accessToken // empty')
|
||||
if [ -z "${access}" ]; then
|
||||
echo "Не удалось зарегистрировать админа Remnawave" >&2
|
||||
printf '%s\n' "${reg_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${reg_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${access}")
|
||||
@@ -59,7 +80,8 @@ else
|
||||
access=$(printf '%s' "${login_resp}" | jq -r '.response.accessToken // .accessToken // empty')
|
||||
if [ -z "${access}" ]; then
|
||||
echo "Не удалось войти в панель Remnawave (REMNAWAVE_ADMIN_* из /services/remnawave)" >&2
|
||||
printf '%s\n' "${login_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${login_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${access}")
|
||||
@@ -89,7 +111,8 @@ if [ -z "${active_token}" ] || [ "${admin_created}" -eq 1 ]; then
|
||||
token_updated=1
|
||||
else
|
||||
echo "WARN: POST /tokens/ без поля token — положите REMNAWAVE_API_TOKEN вручную" >&2
|
||||
printf '%s\n' "${token_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${token_resp}" | redact_json >&2
|
||||
fi
|
||||
else
|
||||
echo "WARN: не удалось создать API-токен автоматически — создайте в UI и положите в Infisical /services/remnawave как REMNAWAVE_API_TOKEN" >&2
|
||||
@@ -104,7 +127,8 @@ else
|
||||
node_secret=$(printf '%s' "${keygen_resp}" | jq -r '.response.secretKey // .secretKey // empty')
|
||||
if [ -z "${node_secret}" ]; then
|
||||
echo "Не удалось получить SECRET_KEY ноды из /api/keygen/" >&2
|
||||
printf '%s\n' "${keygen_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${keygen_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@@ -126,7 +150,8 @@ if [ -z "${profile_uuid}" ]; then
|
||||
// .response.publicKey // .response.pubKey // .publicKey // .pubKey // empty')
|
||||
if [ -z "${priv}" ] || [ -z "${pub}" ]; then
|
||||
echo "Не удалось сгенерировать X25519 ключи Reality" >&2
|
||||
printf '%s\n' "${key_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${key_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
short_id=$(openssl rand -hex 8)
|
||||
@@ -139,7 +164,8 @@ if [ -z "${profile_uuid}" ]; then
|
||||
profile_uuid=$(printf '%s' "${profile_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
if [ -z "${profile_uuid}" ]; then
|
||||
echo "Не удалось создать config profile" >&2
|
||||
printf '%s\n' "${profile_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${profile_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
profile_created=1
|
||||
@@ -187,7 +213,8 @@ if [ -z "${node_uuid}" ]; then
|
||||
node_uuid=$(printf '%s' "${node_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
echo "Не удалось создать ноду" >&2
|
||||
printf '%s\n' "${node_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${node_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
node_created=1
|
||||
@@ -252,7 +279,8 @@ if [ -z "${host_uuid}" ]; then
|
||||
host_uuid=$(printf '%s' "${host_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
if [ -z "${host_uuid}" ]; then
|
||||
echo "Не удалось создать host" >&2
|
||||
printf '%s\n' "${host_resp}" >&2
|
||||
printf \'%s
|
||||
\' "${host_resp}" | redact_json >&2
|
||||
exit 1
|
||||
fi
|
||||
host_created=1
|
||||
|
||||
Reference in new issue
Block a user