From 69aac61b0c5b2d8a4f909de6a6d6af8d6ee293a3 Mon Sep 17 00:00:00 2001 From: Pjotr Date: Thu, 8 Oct 2026 14:57:35 +0000 Subject: * src/routes/dev.rs: POST /get-test-token answers local callers only, not tied to dev mode. The endpoint no longer depends on GENENETWORK4_DEV_MODE or on the bind address. It decides per request whether to answer. * src/routes/dev.rs (get_test_token): answers a caller only when the TCP peer (axum ConnectInfo) is in 127.0.x.x (or ::1, or an IPv4-mapped 127.x) and the request carries no X-Forwarded-For, Forwarded or X-Real-IP header (a reverse proxy on the same host would otherwise make every client look local). Anything else, including an unknown peer, is a 403. Local is never established from a header. * src/main.rs: serve with into_make_service_with_connect_info, which provides the peer address. * src/config.rs: remove dev_mode, GENENETWORK4_DEV_MODE and dev_token_enabled(). Add GENENETWORK4_TEST_TOKEN (on by default); when it is not a clearly affirmative value (true/1/yes/on) the route is not registered: a 404, absent from /openapi.json. It fails closed, so a typo ("flase") turns the endpoint off. * src/lib.rs: register the route unless that switch is off. * tests: tests/get_test_token.rs rewritten (remote, unknown and proxied peers refused; 127.x and ::1 answered; always documented by default); tests/get_test_token_off.rs for the switch (own process: it sets an environment variable); common::post_from supplies a peer address to the in-process requests. Python: test_get_test_token.py rewritten, TOKEN_ENV is now empty (no setting needed). * README.md, docs/gn-auth.md, docs/SKILL.md, RELEASE_NOTES.md: document the check, the switch, and "Behind nginx or in a container" (a bridge container sees the gateway as the peer; a host-network container behind nginx sees 127.0.0.1, so block the path in nginx, set X-Forwarded-For, or switch the endpoint off). Co-Authored-By: Claude Sonnet 5.5 --- test/python/auth_helpers.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'test/python/auth_helpers.py') diff --git a/test/python/auth_helpers.py b/test/python/auth_helpers.py index 091c823..c16a7dd 100644 --- a/test/python/auth_helpers.py +++ b/test/python/auth_helpers.py @@ -16,10 +16,11 @@ from server_test_case import HOST, PORT AUTH_SERVER_URL = os.environ.get("AUTH_SERVER_URL", "http://127.0.0.1:8081/") -# Every endpoint needs a token now (see docs/gn-auth.md) -- a test class -# that calls auth_token() needs its server started with this so it can -# self-issue one. -TOKEN_ENV = {"GENENETWORK4_DEV_MODE": "true", "GENENETWORK4_BIND": "127.0.0.1"} +# Every endpoint needs a token (see docs/gn-auth.md), and a test server +# issues one to a local caller with no configuration at all (POST +# /get-test-token is not tied to a mode). Kept as an empty environment so +# the test classes that set `EXTRA_ENV = TOKEN_ENV` need no change. +TOKEN_ENV = {} def auth_server_reachable(): @@ -36,14 +37,12 @@ def auth_server_reachable(): def auth_token(): - """A bearer token to use against the already-running test server - (started with TOKEN_ENV). Tries POST /get-test-token first -- this - just works once the server was started with TOKEN_ENV, no - externally managed token needed -- falling back to the - GN4_TEST_AUTH_TOKEN env var (see docs/gn-auth.md) for a gn-auth - setup that doesn't want dev mode on even for tests. Returns None, - rather than raising, if neither produces a token; callers should - skipTest() in that case. + """A bearer token to use against the already-running test server. + Tries POST /get-test-token first -- the test client is local, so + this just works with a reachable gn-auth, no externally managed + token needed -- falling back to the GN4_TEST_AUTH_TOKEN env var (see + docs/gn-auth.md). Returns None, rather than raising, if neither + produces a token; callers should skipTest() in that case. """ conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) try: -- cgit 1.4.1