Repository navigation
feat: developer-entrypoint reads TRENTINA_MCP_TOKEN_FILE - #78
Conversation
Exedore delivers a seat's secrets as files under /run/srv-secrets. The entrypoint now reads the gateway token from TRENTINA_MCP_TOKEN_FILE when set, stripping one trailing newline, and it wins over TRENTINA_MCP_TOKEN. It is read into TRENTINA_MCP_TOKEN, so it reaches exactly what the variable always reached and is unset with it before Claude Code starts. A missing, unreadable, empty or multi-line file stops the start, naming the variable and never the value. Closes #77 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh
| fi | ||
| # read is a builtin, so the token is never in a process's arguments. | ||
| token_from_file= | ||
| IFS= read -r -d '' token_from_file < "$TRENTINA_MCP_TOKEN_FILE" || true |
There was a problem hiding this comment.
HIGH (Bug Hunter): With -d '', Bash reads until the first NUL byte. A file containing a valid token prefix followed by a NUL and additional bytes is therefore accepted as the prefix, without detecting that the file contained extra data. The resulting credential can differ silently from the contents of the token file.
Suggestion: Reject token files containing NUL bytes before reading them, or use a byte-level read and validation method that confirms the entire file was consumed and contains no NULs.
Evidence:
IFS= read -r -d '' token_from_file < "$TRENTINA_MCP_TOKEN_FILE" || true
There was a problem hiding this comment.
Fixed in 88fbe32
read -d '' -n 4097 now succeeds only when it stops on a NUL or hits the length cap, and the start is refused in that case; reaching EOF is the only way through. Covered by test_a_token_file_with_a_nul_stops_the_start.
| fi | ||
| # read is a builtin, so the token is never in a process's arguments. | ||
| token_from_file= | ||
| IFS= read -r -d '' token_from_file < "$TRENTINA_MCP_TOKEN_FILE" || true |
There was a problem hiding this comment.
HIGH (Performance Check): This read consumes the entire file into a shell variable before checking whether it contains multiple lines. An unexpectedly large token file can therefore cause substantial memory use or exhaust the container before the entrypoint rejects it.
Suggestion: Bound the amount read to the maximum acceptable token size plus enough data to detect overflow, and reject files that exceed that limit.
Evidence:
IFS= read -r -d '' token_from_file < "$TRENTINA_MCP_TOKEN_FILE" || true
There was a problem hiding this comment.
Fixed in 88fbe32
The read is capped at 4097 characters; a file longer than 4096 bytes is refused without being read further. Covered by test_an_oversized_token_file_stops_the_start and test_a_token_file_at_the_size_limit_is_accepted.
| # start, naming the variable and never the value: a seat that came up without | ||
| # its gateway would look healthy and do nothing. | ||
| if [ -n "${TRENTINA_MCP_TOKEN_FILE:-}" ]; then | ||
| if ! [ -f "$TRENTINA_MCP_TOKEN_FILE" ] || ! [ -r "$TRENTINA_MCP_TOKEN_FILE" ]; then |
There was a problem hiding this comment.
LOW (Test Coverage): The new unreadable-file failure path is not covered. The tests exercise a missing path and a directory, but neither is a regular file that exists and cannot be read.
Suggestion: Add a test for an unreadable regular token file and verify startup is refused without exposing the token. Ensure the test runs in a context where the file is actually unreadable to the entrypoint.
Evidence:
if ! [ -f "$TRENTINA_MCP_TOKEN_FILE" ] || ! [ -r "$TRENTINA_MCP_TOKEN_FILE" ]; then
log "TRENTINA_MCP_TOKEN_FILE is set but is not a readable file; not starting"
exit 1
fi
There was a problem hiding this comment.
Fixed in 88fbe32
Added test_an_unreadable_token_file_stops_the_start (a 0000 regular file). Root reads through file modes, so it is skipped for root under the same scoped gourmand exception the read-only-checkout test already has.
A NUL cut the token short unnoticed and the whole file was read into memory. read now stops at a NUL or 4097 characters and succeeds only then, so reaching EOF is the one way through. Adds tests for an unreadable, NUL-bearing, oversized and at-limit file; the unreadable one cannot hold for root, so it gets the same gourmand exception as the read-only-checkout test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh
There was a problem hiding this comment.
Gatehouse found 2 issues (2 medium)
Reviewed 1 commit since e844243 (incremental).
7 finding(s) dropped: their evidence is not in the diff.
| # the end of the file is the one way through. So a NUL cannot cut the token | ||
| # short unnoticed, and a huge file is not read into memory. | ||
| token_from_file= | ||
| if IFS= read -r -d '' -n 4097 token_from_file < "$TRENTINA_MCP_TOKEN_FILE"; then |
There was a problem hiding this comment.
MEDIUM (Security Scan): Bash read -n counts characters according to the active locale, not bytes. In a multibyte locale, a token file can exceed the documented 4096-byte limit while containing fewer than 4097 characters, so the size check can accept oversized files.
Suggestion: Make the read count bytes, for example by running this builtin with LC_ALL=C, or enforce the byte limit with a bounded byte-oriented read.
Evidence:
if IFS= read -r -d '' -n 4097 token_from_file < "$TRENTINA_MCP_TOKEN_FILE"; then
There was a problem hiding this comment.
Fixed in 6665633
The read now runs as LC_ALL=C IFS= read -r -d '' -n 4097, so -n counts bytes whatever the seat's locale.
| def test_a_token_file_with_a_nul_stops_the_start(self) -> None: | ||
| self.assert_refused(self.token_file("file-token\0extra\n")) | ||
|
|
||
| def test_an_oversized_token_file_stops_the_start(self) -> None: |
There was a problem hiding this comment.
MEDIUM (Test Coverage): The oversized-file test uses only ASCII, so it does not check the documented 4096-byte limit when the shell runs in a multibyte locale. Bash read -n counts characters in that case; a file with more than 4096 bytes but fewer than 4097 characters could evade the intended limit.
Suggestion: Add a test using a multibyte value whose byte length exceeds 4096 while its character count is below 4097, and run it with a UTF-8 locale to verify the file is refused.
Evidence:
def test_an_oversized_token_file_stops_the_start(self) -> None:
self.assert_refused(self.token_file("x" * 4097))
There was a problem hiding this comment.
Fixed in 6665633
Added test_the_size_limit_is_in_bytes_in_a_multibyte_locale: 2049 × é (4098 bytes, 2049 characters) under LC_ALL=C.UTF-8. It fails without the fix and passes with it.
read -n counts characters in the locale, so under UTF-8 a file over 4096 bytes passed. The read runs under LC_ALL=C; a multibyte test covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh
There was a problem hiding this comment.
Gatehouse found no issues.
Reviewed 1 commit since 88fbe32 (incremental).
|
Second-seat review (a270) at 6665633: changes requested. One change, to the gourmand exception. The entrypoint change itself is correct. Change
Verified
Not requested: 🤖 Generated with Claude Code |
gourmand 0.16.5 matches an exception by path and ignores `pattern`, so the EV003 exceptions excused every skipIf in test_entrypoint.py and test_skills_sync.py. The two root-skipped tests move to files of their own, with the helpers they need in a base class, and each exception now names only that file. A probe skipIf in test_entrypoint.py is flagged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh
There was a problem hiding this comment.
Gatehouse found no issues.
Reviewed 1 commit since 6665633 (incremental).
Closes #77.
Exedore delivers a seat's secrets as files under
/run/srv-secrets/maxN. The entrypoint now reads the gateway token fromTRENTINA_MCP_TOKEN_FILEwhen set (one trailing newline stripped), and the file wins overTRENTINA_MCP_TOKEN.readbuiltin intoTRENTINA_MCP_TOKEN, so the token reaches exactly what the variable always reached (Claude Code's state file, git's include file,gatehouse.env, all 0600) and is unset with it before Claude Code starts. Never in argv or a log.\r\n) exits 1 with a message naming the variable, never the value, before anything is written.TRENTINA_MCP_TOKENis the only one; the Matrix token is already a file (JOSUI_MATRIX_TOKEN_FILE) read by claude-agent itself.Tests: file wins over the variable (state file, gitconfig, gatehouse.env), file without the variable, token and variable absent from the agent's env, and refusal for missing / directory / empty / multi-line files.
.sdlc/bin/sdlc cigreen locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh