fix(remnawave): admin password v3 + bootstrap под Remnawave 3.4 API
ansible-core-mon / deploy (push) Failing after 2s
ansible-core-net / deploy (push) Failing after 1s
ansible-core-secrets / deploy (push) Failing after 2s
ansible-ger-nod-02 / deploy (push) Failing after 1s
ansible-opnsense / deploy (push) Failing after 2s
ansible-rus-central / deploy (push) Failing after 2s
ansible-core-mon / deploy (push) Failing after 2s
ansible-core-net / deploy (push) Failing after 1s
ansible-core-secrets / deploy (push) Failing after 2s
ansible-ger-nod-02 / deploy (push) Failing after 1s
ansible-opnsense / deploy (push) Failing after 2s
ansible-rus-central / deploy (push) Failing after 2s
Генерируем REMNAWAVE_ADMIN_* (≥24) в /services/remnawave; токены через name/expiresInDays/scopes; SECRET_KEY ноды из GET /api/keygen/. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
5e0c2553ca
commit
58aba40bc0
4 files changed
+112
-55
No files matched your search
@@ -2,7 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
API_BASE="https://${RW_PANEL_DOMAIN}/api"
|
||||
CURL=(curl -fsSk --resolve "${RW_PANEL_DOMAIN}:443:127.0.0.1")
|
||||
CURL=(curl -sSk --resolve "${RW_PANEL_DOMAIN}:443:127.0.0.1")
|
||||
AUTH_HDR=()
|
||||
|
||||
admin_created=0
|
||||
@@ -16,30 +16,46 @@ active_token="${RW_API_TOKEN:-}"
|
||||
api() {
|
||||
local method="$1"; shift
|
||||
local path="$1"; shift
|
||||
local tmp code
|
||||
tmp=$(mktemp)
|
||||
if [ "${#AUTH_HDR[@]}" -gt 0 ]; then
|
||||
"${CURL[@]}" -X "$method" "${AUTH_HDR[@]}" -H "Content-Type: application/json" "${API_BASE}${path}" "$@"
|
||||
code=$("${CURL[@]}" -o "$tmp" -w '%{http_code}' -X "$method" "${AUTH_HDR[@]}" \
|
||||
-H "Content-Type: application/json" "${API_BASE}${path}" "$@") || true
|
||||
else
|
||||
"${CURL[@]}" -X "$method" -H "Content-Type: application/json" "${API_BASE}${path}" "$@"
|
||||
code=$("${CURL[@]}" -o "$tmp" -w '%{http_code}' -X "$method" \
|
||||
-H "Content-Type: application/json" "${API_BASE}${path}" "$@") || true
|
||||
fi
|
||||
}
|
||||
|
||||
json_first() {
|
||||
jq -r "$1" 2>/dev/null || true
|
||||
if [[ ! "${code}" =~ ^2 ]]; then
|
||||
echo "API ${method} ${path} → HTTP ${code}" >&2
|
||||
cat "$tmp" >&2 || true
|
||||
echo >&2
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
cat "$tmp"
|
||||
rm -f "$tmp"
|
||||
}
|
||||
|
||||
status_json=$("${CURL[@]}" "${API_BASE}/auth/status")
|
||||
is_login=$(printf '%s' "${status_json}" | jq -r '.response.isLoginAllowed // .isLoginAllowed // false')
|
||||
is_register=$(printf '%s' "${status_json}" | jq -r '.response.isRegisterAllowed // .isRegisterAllowed // false')
|
||||
|
||||
if [ "${is_register}" = "true" ]; then
|
||||
reg_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
|
||||
api POST /auth/register -d "${reg_payload}" >/dev/null
|
||||
reg_resp=$(api POST /auth/register -d "${reg_payload}")
|
||||
access=$(printf '%s' "${reg_resp}" | jq -r '.response.accessToken // .accessToken // empty')
|
||||
if [ -z "${access}" ]; then
|
||||
echo "Не удалось зарегистрировать админа Remnawave" >&2
|
||||
printf '%s\n' "${reg_resp}" >&2
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${access}")
|
||||
admin_created=1
|
||||
is_login=true
|
||||
login_ok=1
|
||||
else
|
||||
login_ok=0
|
||||
fi
|
||||
|
||||
login_ok=0
|
||||
if [ -n "${active_token}" ]; then
|
||||
if [ "${login_ok:-0}" -eq 0 ] && [ -n "${active_token}" ]; then
|
||||
code=$("${CURL[@]}" -o /dev/null -w '%{http_code}' \
|
||||
-H "Authorization: Bearer ${active_token}" "${API_BASE}/nodes/" || true)
|
||||
if [ "${code}" = "200" ]; then
|
||||
@@ -48,7 +64,7 @@ if [ -n "${active_token}" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${login_ok}" -eq 0 ]; then
|
||||
if [ "${login_ok:-0}" -eq 0 ]; then
|
||||
login_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
|
||||
login_resp=$(api POST /auth/login -d "${login_payload}")
|
||||
access=$(printf '%s' "${login_resp}" | jq -r '.response.accessToken // .accessToken // empty')
|
||||
@@ -58,18 +74,28 @@ if [ "${login_ok}" -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
AUTH_HDR=(-H "Authorization: Bearer ${access}")
|
||||
fi
|
||||
|
||||
# Постоянный API-токен (v3: name + expiresInDays + scopes)
|
||||
if [ -z "${active_token}" ] || [ "${admin_created}" -eq 1 ]; then
|
||||
tokens_json=$(api GET /tokens/ || echo '{"response":[]}')
|
||||
old_uuid=$(printf '%s' "${tokens_json}" | jq -r --arg n "$RW_TOKEN_NAME" '
|
||||
(.response // .)
|
||||
| if type=="array" then . elif .tokens then .tokens else [] end
|
||||
| map(select(.tokenName == $n or .name == $n))
|
||||
| map(select(.name == $n or .tokenName == $n))
|
||||
| .[0].uuid // empty')
|
||||
if [ -n "${old_uuid}" ]; then
|
||||
api DELETE "/tokens/${old_uuid}" >/dev/null || true
|
||||
fi
|
||||
|
||||
token_payload=$(jq -n --arg n "$RW_TOKEN_NAME" '{tokenName: $n}')
|
||||
scopes_json=$(api GET /tokens/scopes || echo '{"response":[]}')
|
||||
scopes=$(printf '%s' "${scopes_json}" | jq -c '
|
||||
(.response // .)
|
||||
| if type=="array" then .
|
||||
elif .scopes then .scopes
|
||||
else [] end')
|
||||
token_payload=$(jq -n --arg n "$RW_TOKEN_NAME" --argjson s "${scopes}" \
|
||||
'{name: $n, expiresInDays: 3650, scopes: $s}')
|
||||
token_resp=$(api POST /tokens/ -d "${token_payload}")
|
||||
active_token=$(printf '%s' "${token_resp}" | jq -r '
|
||||
.response.token // .response.apiToken // .token // .apiToken // empty')
|
||||
@@ -82,6 +108,19 @@ if [ "${login_ok}" -eq 0 ]; then
|
||||
token_updated=1
|
||||
fi
|
||||
|
||||
# SECRET_KEY ноды — отдельный endpoint /api/keygen/ (не ответ create node)
|
||||
if [ -n "${RW_NODE_SECRET:-}" ]; then
|
||||
node_secret="${RW_NODE_SECRET}"
|
||||
else
|
||||
keygen_resp=$(api GET /keygen/)
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
profiles_json=$(api GET /config-profiles/)
|
||||
profile_uuid=$(printf '%s' "${profiles_json}" | jq -r --arg n "$RW_PROFILE_NAME" '
|
||||
(.response.configProfiles // .response // [])
|
||||
@@ -89,7 +128,7 @@ profile_uuid=$(printf '%s' "${profiles_json}" | jq -r --arg n "$RW_PROFILE_NAME"
|
||||
pub=""
|
||||
|
||||
if [ -z "${profile_uuid}" ]; then
|
||||
key_resp=$(api GET /system/tools/x25519/generate 2>/dev/null || api GET /keygen/ 2>/dev/null || echo '{}')
|
||||
key_resp=$(api GET /system/tools/x25519/generate 2>/dev/null || echo '{}')
|
||||
priv=$(printf '%s' "${key_resp}" | jq -r '
|
||||
.response.privateKey // .response.privKey // .privateKey // .privKey // empty')
|
||||
pub=$(printf '%s' "${key_resp}" | jq -r '
|
||||
@@ -134,7 +173,6 @@ fi
|
||||
nodes_json=$(api GET /nodes/)
|
||||
node_uuid=$(printf '%s' "${nodes_json}" | jq -r --arg n "$RW_NODE_NAME" '
|
||||
(.response // []) | map(select(.name == $n)) | .[0].uuid // empty')
|
||||
node_secret="${RW_NODE_SECRET:-}"
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
node_payload=$(jq -n \
|
||||
@@ -154,24 +192,8 @@ if [ -z "${node_uuid}" ]; then
|
||||
activeInbounds: [$iu]
|
||||
}
|
||||
}')
|
||||
node_resp=$(api POST /nodes/ -d "${node_payload}" 2>/dev/null || true)
|
||||
node_resp=$(api POST /nodes/ -d "${node_payload}")
|
||||
node_uuid=$(printf '%s' "${node_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
node_secret=$(printf '%s' "${node_resp}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // .SECRET_KEY // empty')
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
node_payload=$(jq -n \
|
||||
--arg name "$RW_NODE_NAME" \
|
||||
--arg addr "$RW_NODE_ADDR" \
|
||||
--argjson port "$RW_NODE_PORT" \
|
||||
--arg cc "$RW_NODE_CC" \
|
||||
'{name: $name, address: $addr, port: $port, countryCode: $cc}')
|
||||
node_resp=$(api POST /nodes/ -d "${node_payload}")
|
||||
node_uuid=$(printf '%s' "${node_resp}" | jq -r '.response.uuid // .uuid // empty')
|
||||
node_secret=$(printf '%s' "${node_resp}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // .SECRET_KEY // empty')
|
||||
fi
|
||||
|
||||
if [ -z "${node_uuid}" ]; then
|
||||
echo "Не удалось создать ноду" >&2
|
||||
printf '%s\n' "${node_resp}" >&2
|
||||
@@ -195,12 +217,6 @@ api PATCH /nodes/ -d "${node_update}" >/dev/null 2>&1 \
|
||||
|| api PUT /nodes/ -d "${node_update}" >/dev/null 2>&1 \
|
||||
|| true
|
||||
|
||||
if [ -z "${node_secret}" ] && [ "${node_created}" -eq 1 ]; then
|
||||
node_full=$(api GET "/nodes/${node_uuid}")
|
||||
node_secret=$(printf '%s' "${node_full}" | jq -r '
|
||||
.response.secretKey // .response.SECRET_KEY // .secretKey // empty')
|
||||
fi
|
||||
|
||||
hosts_json=$(api GET /hosts/)
|
||||
host_uuid=$(printf '%s' "${hosts_json}" | jq -r --arg a "$RW_SELFSTEAL" '
|
||||
(.response // []) | map(select(.address == $a)) | .[0].uuid // empty')
|
||||
|
||||
Reference in new issue
Block a user