smoke: the MCP server's secret compared by hash, per server process, never printed

This commit is contained in:
feder-cr committed 2026-10-11 04:39:08 +02:00
1 parent 46ba8330c8
commit f542349ce7
1 file changed
+2 -2
+2 -2
View File
@@ -456,10 +456,10 @@ wait_mcp_state() { for _ in $(seq 1 60); do [ "$(mcp_state "$1")" = "$2" ] && re
check "GET /tools: the declared server connects through the relay, with its tools under mcp.tools" "wait_mcp_state tools connected && api $A/tools | jq -e '([.tools[]|select(.permission==\"mcp.tools\")|.name]|sort) == [\"mcp_tools_echo\",\"mcp_tools_env\",\"mcp_tools_exit\",\"mcp_tools_header\",\"mcp_tools_picture\"] and ([.tools[]|select(.permission==\"mcp.tools\")|.offered]|all)' >/dev/null"
check "GET /tools: the server whose program is not installed is failed, saying what the relay found" "wait_mcp_state missing failed && api $A/tools | jq -e '.mcp_servers[]|select(.name==\"missing\")|.error|test(\"not-installed\")' >/dev/null"
# A process's environment is its own user's to read: dot reads the server's, as a command of the model would.
server_env_of_dot() { su -s /bin/bash dot -c 'for p in $(pgrep -u dot -f fake_tool_server.py); do tr "\\0" "\\n" < /proc/$p/environ; done'; }
echo "the declared server's processes: $(ps -eo user=,pid=,args= | grep 'fake_tool_serve[r]' | tr '\n' ';')"
check "the declared server runs as dot, and nothing of it as another user" "pgrep -u dot -f 'python.*fake_tool_server' >/dev/null && ! ps -eo user=,args= | grep 'fake_tool_serve[r]' | grep -v '^dot ' | grep -qv 'dot-agentd relay'"
check "the declared server's secret is in its environment, which dot reads" "server_env_of_dot | grep -qx 'TOKEN=$MCP_SECRET' || { echo \"variables read: \$(server_env_of_dot 2>&1 | cut -d= -f1 | sort -u | tr '\n' ' ')\"; false; }"
server_token_of_dot() { su -s /bin/bash dot -c 'for p in $(pgrep -u dot -f "[p]ython.*fake_tool_server"); do echo "$p $(tr "\\0" "\\n" < /proc/$p/environ | sed -n "s/^TOKEN=//p" | sha256sum | cut -c1-12) $(tr "\\0" "\\n" < /proc/$p/environ | grep -c ^TOKEN=)"; done'; }
check "the declared server's secret is in its environment, which dot reads" "[ \"\$(server_token_of_dot | awk '{print \$2}' | sort -u)\" = \"\$(printf '%s\n' '$MCP_SECRET' | sha256sum | cut -c1-12)\" ] || { echo \"server processes (pid, hash of TOKEN, how many TOKEN): \$(server_token_of_dot | tr '\n' ';') expected \$(printf '%s\n' '$MCP_SECRET' | sha256sum | cut -c1-12)\"; false; }"
check "the declared server's secret is on no command line" "! cat /proc/[0-9]*/cmdline 2>/dev/null | tr '\\0' '\\n' | grep -q '$MCP_SECRET_SEEN' || { echo \"found in: \$(grep -l '$MCP_SECRET_SEEN' /proc/[0-9]*/cmdline 2>/dev/null | tr '\n' ' ')\"; false; }"
ev msg-mcp user.message '{"text":"RUN-TOOL mcp_tools_env {\"name\":\"MODE\"}"}' >/dev/null
check "a call of the server's tool runs under mcp.tools and answers with the server's environment" "wait_event $STREAM '.type==\"tool.called\" and .data.tool==\"mcp_tools_env\" and .data.ok==true and .data.permission==\"mcp.tools\"' && wait_event $STREAM '.type==\"message.assistant\" and .data.in_reply_to==\"msg-mcp\" and (.data.text|test(\"smoke\"))'"