Skip to content

Commit 00b64b8

Browse files
authored
fix(clawdock): keep credentials out of diagnostic output (#133547)
Keep routine repair and config inspection output free of credential values and prefixes while preserving explicit clawdock-token reveal. Use validated config setters and fail closed when diagnostic rendering fails. Fixes #133535.
1 parent 596df18 commit 00b64b8

4 files changed

Lines changed: 344 additions & 84 deletions

File tree

‎docs/install/clawdock.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ ClawDock reads two separate `.env` files, matching the split described in [Docke
9494
- The project `.env` next to `docker-compose.yml`: Docker-specific values like image name, ports, and `OPENCLAW_GATEWAY_TOKEN`. `clawdock-token` reads the token from here.
9595
- `~/.openclaw/.env` (mounted into the container): env-backed secrets OpenClaw itself manages, alongside `openclaw.json` and the shared and per-agent SQLite auth stores.
9696

97-
`clawdock-fix-token` copies the token from the project `.env` into the container's `gateway.remote.token` and `gateway.auth.token` config values and restarts the gateway.
97+
`clawdock-fix-token` copies the token from the project `.env` into the container's `gateway.remote.token` and `gateway.auth.token` through the validated config setters and restarts the gateway only after both writes succeed. It reports success or failure without printing tokens or token prefixes. `clawdock-token` explicitly prints the full token when you need it.
9898

99-
Use `clawdock-show-config` to inspect `openclaw.json` and both `.env` files quickly; it redacts `.env` values in its printed output.
99+
Use `clawdock-show-config` to inspect JSON5 config structure and `.env` key names with all values redacted and comments omitted. It uses Node, JSON5, and dotenv from the built OpenClaw Docker image in temporary containers without starting dependencies; no host parser or running gateway is required. If Docker, parsing, or file access fails, it returns a failure with guidance and withholds that file's contents. Ambiguous `.env` values beginning with a literal quote are also withheld to avoid exposing unterminated multiline content. Source files are unchanged.
100100

101101
## Related
102102

‎scripts/clawdock/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ The Docker setup uses three config files on the host. The container never stores
160160

161161
**Do NOT** put API keys or bot tokens in `openclaw.json`. Use `~/.openclaw/.env` for all secrets.
162162

163+
`clawdock-show-config` displays JSON5 structure and `.env` key names with all values redacted and comments omitted. It requires Docker and the built OpenClaw image; temporary containers use the image's Node, JSON5, and dotenv without starting dependencies or requiring host parsers. Processing failures withhold the affected file's contents and return a failure with guidance. Ambiguous `.env` values beginning with a literal quote are also withheld to protect unterminated multiline content. Source files are unchanged.
164+
165+
`clawdock-fix-token` checks both config writes and reports success or failure without showing tokens or prefixes. Use `clawdock-token` only when you explicitly want the full token printed.
166+
163167
### Initial Setup
164168

165169
`./scripts/docker/setup.sh` handles first-time Docker configuration:
@@ -333,9 +337,8 @@ clawdock-fix-token
333337
This will:
334338

335339
1. Read the token from your `.env` file
336-
2. Configure it in the OpenClaw config
337-
3. Restart the gateway
338-
4. Verify the configuration
340+
2. Configure both token values through the validated OpenClaw config setters
341+
3. Restart the gateway only after both writes succeed
339342

340343
### Permission Denied
341344

‎scripts/clawdock/clawdock-helpers.sh‎

Lines changed: 45 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ _clawdock_trim_quotes() {
5454
printf "%s" "$value"
5555
}
5656

57-
_clawdock_mask_value() {
58-
local value="$1"
59-
local length=${#value}
60-
if (( length == 0 )); then
61-
printf "%s" "<empty>"
62-
return 0
63-
fi
64-
if (( length == 1 )); then
65-
printf "%s" "<redacted:1 char>"
66-
return 0
67-
fi
68-
printf "%s" "<redacted:${length} chars>"
69-
}
70-
7157
_clawdock_browser_url_for_gateway_url() {
7258
local url="$1"
7359
case "$url" in
@@ -222,54 +208,41 @@ clawdock-config() {
222208

223209
clawdock-show-config() {
224210
_clawdock_ensure_dir >/dev/null 2>&1 || true
225-
local config_dir="${HOME}/.openclaw"
211+
local config_dir="${HOME}/.openclaw" file rendered result=0
212+
local files=("${config_dir}/openclaw.json" "${config_dir}/.env")
213+
[[ -z "$CLAWDOCK_DIR" ]] || files+=("${CLAWDOCK_DIR}/.env")
226214
echo -e "${_CLR_BOLD}Config directory:${_CLR_RESET} ${_CLR_CYAN}${config_dir}${_CLR_RESET}"
227215
echo ""
228216

229-
# Show openclaw.json
230-
if [[ -f "${config_dir}/openclaw.json" ]]; then
231-
echo -e "${_CLR_BOLD}${config_dir}/openclaw.json${_CLR_RESET}"
232-
echo -e "${_CLR_DIM}$(cat "${config_dir}/openclaw.json")${_CLR_RESET}"
233-
else
234-
echo -e "${_CLR_YELLOW}No openclaw.json found${_CLR_RESET}"
235-
fi
236-
echo ""
237-
238-
# Show .env (mask secret values)
239-
if [[ -f "${config_dir}/.env" ]]; then
240-
echo -e "${_CLR_BOLD}${config_dir}/.env${_CLR_RESET}"
241-
while IFS= read -r line || [[ -n "$line" ]]; do
242-
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
243-
echo -e "${_CLR_DIM}${line}${_CLR_RESET}"
244-
elif [[ "$line" == *=* ]]; then
245-
local key="${line%%=*}"
246-
local val="${line#*=}"
247-
echo -e "${_CLR_CYAN}${key}${_CLR_RESET}=${_CLR_DIM}$(_clawdock_mask_value "$val")${_CLR_RESET}"
248-
else
249-
echo -e "${_CLR_DIM}${line}${_CLR_RESET}"
250-
fi
251-
done < "${config_dir}/.env"
252-
else
253-
echo -e "${_CLR_YELLOW}No .env found${_CLR_RESET}"
254-
fi
255-
echo ""
256-
257-
# Show project .env if available
258-
if [[ -n "$CLAWDOCK_DIR" && -f "${CLAWDOCK_DIR}/.env" ]]; then
259-
echo -e "${_CLR_BOLD}${CLAWDOCK_DIR}/.env${_CLR_RESET}"
260-
while IFS= read -r line || [[ -n "$line" ]]; do
261-
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then
262-
echo -e "${_CLR_DIM}${line}${_CLR_RESET}"
263-
elif [[ "$line" == *=* ]]; then
264-
local key="${line%%=*}"
265-
local val="${line#*=}"
266-
echo -e "${_CLR_CYAN}${key}${_CLR_RESET}=${_CLR_DIM}$(_clawdock_mask_value "$val")${_CLR_RESET}"
267-
else
268-
echo -e "${_CLR_DIM}${line}${_CLR_RESET}"
269-
fi
270-
done < "${CLAWDOCK_DIR}/.env"
271-
fi
272-
echo ""
217+
for file in "${files[@]}"; do
218+
printf '%b%s%b\n' "$_CLR_BOLD" "$file" "$_CLR_RESET"
219+
if [[ ! -f "$file" ]]; then
220+
echo "Not found"
221+
continue
222+
fi
223+
# Buffer the renderer: neither partial output nor parser errors are safe to show.
224+
if rendered=$(_clawdock_compose run --rm --no-deps -T --entrypoint node openclaw-gateway -e '
225+
const input = require("node:fs").readFileSync(0, "utf8");
226+
if (process.argv[1] === "openclaw.json") {
227+
const config = require("json5").parse(input);
228+
console.log(JSON.stringify(config, (_key, value) =>
229+
value !== null && typeof value === "object" ? value : "<redacted>", 2));
230+
} else {
231+
const env = require("dotenv").parse(input);
232+
// Unterminated quotes can turn secret continuation lines into keys.
233+
// Reject ambiguous quote-leading values before displaying any keys.
234+
if (Object.values(env).some(value => /^[\x22\x27`]/.test(value))) process.exit(1);
235+
console.log(Object.keys(env).map(key => `${key}=<redacted>`).join("\n"));
236+
}
237+
' "${file##*/}" 2>/dev/null < "$file"); then
238+
printf '%s\n' "$rendered"
239+
else
240+
echo "Unable to safely display file. Check its syntax and permissions, Docker availability, and the built OpenClaw image."
241+
result=1
242+
fi
243+
echo ""
244+
done
245+
return "$result"
273246
}
274247

275248
clawdock-workspace() {
@@ -350,33 +323,27 @@ clawdock-fix-token() {
350323

351324
echo "🔧 Configuring gateway token..."
352325
local token
353-
token=$(clawdock-token)
354-
if [[ -z "$token" ]]; then
326+
if ! token=$(clawdock-token 2>/dev/null) || [[ -z "$token" ]]; then
355327
echo "❌ Error: Could not find gateway token"
356328
echo " Check: ${CLAWDOCK_DIR}/.env"
357329
return 1
358330
fi
359331

360-
echo "📝 Setting token: ${token:0:20}..."
361-
362-
_clawdock_compose exec -e "TOKEN=$token" openclaw-gateway \
363-
bash -c './openclaw.mjs config set gateway.remote.token "$TOKEN" && ./openclaw.mjs config set gateway.auth.token "$TOKEN"' 2>&1 | _clawdock_filter_warnings
364-
365-
echo "🔍 Verifying token was saved..."
366-
local saved_token
367-
saved_token=$(_clawdock_compose exec openclaw-gateway \
368-
bash -c "./openclaw.mjs config get gateway.remote.token 2>/dev/null" 2>&1 | _clawdock_filter_warnings | tr -d '\r\n' | head -c 64)
369-
370-
if [[ "$saved_token" == "$token" ]]; then
371-
echo "✅ Token saved correctly!"
372-
else
373-
echo "⚠️ Token mismatch detected"
374-
echo " Expected: ${token:0:20}..."
375-
echo " Got: ${saved_token:0:20}..."
332+
# config set owns validation/persistence; config get intentionally redacts tokens.
333+
# Check both writes without forwarding diagnostics that may contain credentials.
334+
if ! _clawdock_compose exec -T -e "TOKEN=$token" openclaw-gateway \
335+
bash -c './openclaw.mjs config set gateway.remote.token "$TOKEN" && ./openclaw.mjs config set gateway.auth.token "$TOKEN"' >/dev/null 2>&1; then
336+
echo "❌ Token configuration failed. Check Docker and config permissions, then retry clawdock-fix-token."
337+
return 1
376338
fi
377339

340+
echo "✅ Token configured!"
341+
378342
echo "🔄 Restarting gateway..."
379-
_clawdock_compose restart openclaw-gateway 2>&1 | _clawdock_filter_warnings
343+
if ! _clawdock_compose restart openclaw-gateway >/dev/null 2>&1; then
344+
echo "❌ Gateway restart failed. Check Docker, then try clawdock-restart."
345+
return 1
346+
fi
380347

381348
echo "⏳ Waiting for gateway to start..."
382349
sleep 5

0 commit comments

Comments
 (0)