about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-06 22:26:21 +0000
committerPjotr <wrk@bosa.lan>2026-11-06 22:26:21 +0000
commit2af6978846121e75175bd329c3d3cdbd3cb835fb (patch)
tree6a7afde888944a525db32b1b53d9f732846795fb /scripts
parent9a6c5f36e4435c3f8dd04b21458e18074310e2fa (diff)
downloadgenenetwork4-2af6978846121e75175bd329c3d3cdbd3cb835fb.tar.gz
ai-instruction: issue a token per user without gn-auth
The page told the operator to mint with POST /get-test-token, which is
gn-auth's dev password grant and does not exist in the deployment being
set up. Issuing a second user's token also had no good answer: the stub
minted exactly one token per process, so a new user meant starting a
throwaway instance, grabbing --token-file and killing it.

So add --mint-only: mint for --subject, print, write --token-file and
exit without listening. Verification only depends on the key (committed,
so shared by every instance) and on iss, which now falls back to
AUTH_SERVER_URL -- a token minted this way verifies against the
long-running stub untouched.

* scripts/gn-auth-stub.py (main): --mint-only; --issuer defaults to
AUTH_SERVER_URL before the port-derived default. Docstring says how a
second user's token is issued.
* docs/www/ai-instruction.md (1. Get a token): the operator's command is
the stub, not /get-test-token; the token lasts whatever --expires-in said
rather than an hour, and there is no early revocation. (4. What is
public): minting is operator-side. Appendix: "Token issuance" rewritten
around the stub -- public-data-only, expiry as the only revocation, sub
as attribution, one token per user -- with gn-auth kept as what replaces
it later; the stub is no longer listed as a dev leftover to delete, but
as the auth server that must never be routed publicly.
* README.md (Tests): mention --mint-only next to the stub's other flags.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gn-auth-stub.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/scripts/gn-auth-stub.py b/scripts/gn-auth-stub.py
index 15d6a18..13489d0 100755
--- a/scripts/gn-auth-stub.py
+++ b/scripts/gn-auth-stub.py
@@ -43,7 +43,18 @@ as long as anything serving `test/data/test_jwks.json` is up.
 `iss` has to match genenetwork4's `AUTH_SERVER_URL` exactly (it is
 passed to `Validation::set_issuer` verbatim), including the trailing
 slash the default `http://127.0.0.1:8081/` carries -- that is what
-`--port`/`--issuer` are for.
+`--port`/`--issuer` are for, and why `--issuer` falls back to
+`AUTH_SERVER_URL` when that is set in the environment.
+
+To issue a token for one more user, run a second instance with
+`--mint-only` and the *same* issuer as the long-running one:
+
+    scripts/gn-auth-stub.py --mint-only --subject alice \
+        --expires-in 30d --token-file /run/gn4/alice.token
+
+It mints, prints and exits without listening; the token verifies against
+the long-running stub, because verification only depends on the key
+(committed, therefore shared) and on `iss`.
 """
 
 import argparse
@@ -202,6 +213,14 @@ def main():
         "test_jwks.json is up.",
     )
     parser.add_argument(
+        "--mint-only",
+        action="store_true",
+        help="mint the token, print it (and write --token-file) and exit "
+        "without listening. Mints for --subject with the same key and iss as "
+        "the long-running stub, so the token verifies against it -- this is "
+        "how a token is issued for one more user.",
+    )
+    parser.add_argument(
         "--grant-resource-id",
         action="append",
         default=[],
@@ -217,11 +236,22 @@ def main():
     )
     args = parser.parse_args()
 
-    issuer = args.issuer or f"http://127.0.0.1:{args.port}/"
+    issuer = (
+        args.issuer
+        or os.environ.get("AUTH_SERVER_URL")
+        or f"http://127.0.0.1:{args.port}/"
+    )
     jwks_document = open(JWKS_FILE).read()
     kid = json.loads(jwks_document)["jwks"][0]["kid"]
     token = sign(issuer, kid, args.subject, args.scope, args.expires_in)
 
+    if args.mint_only:
+        if args.token_file:
+            with open(args.token_file, "w") as handle:
+                handle.write(token + "\n")
+        print(token, flush=True)
+        return
+
     # Bind before writing or printing anything: a second instance started
     # while one is already listening fails here, and must leave the first
     # one's token file alone rather than clobber it with a token nothing