Skip to content

LLM helper: the stores sign in with a token instead of a password (AWS first) - #97

Draft
skofgar wants to merge 2 commits into
Accenture:mainfrom
skofgar:feat/llm-helper-workload-identity
Draft

skofgar wants to merge 2 commits into
Accenture:mainfrom
skofgar:feat/llm-helper-workload-identity

Conversation

@skofgar

@skofgar skofgar commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Part of #96: the Python helper, with AWS as the first cloud. The Node.js twin and the other clouds follow in separate changes.

What

The LLM helper's two stores, the transcript store (Redis) and the transcript audit store (PostgreSQL), can sign in with a short-lived token instead of a stored password. llm.transcript.redis.auth and llm.transcript.audit.postgres.auth take password (the default, unchanged) or the name of a token source. The first source is aws: an IAM authentication token for Amazon ElastiCache and Amazon RDS for PostgreSQL, presigned locally from the AWS credential chain.

Why

The helper already signs its Bedrock calls with the identity the deployment gives the process (a pod's role, a task role, an instance profile). Its stores still needed a password that someone stores, rotates and hands to it. Managed Redis and PostgreSQL on AWS, Google Cloud and Azure all accept a token from the workload's identity instead (#96 compares the three). With this change, a deployment on AWS needs no secret for the helper at all.

Description

A cloud-neutral seam. The stores know only a user and a token. They don't know which cloud made it.

  • StoreToken caches a token and renews it a minute before it expires, so a burst of new connections signs once. The asynchronous path signs in a worker thread.
  • store_token() makes the checks every source shares: a username, no password beside the token, and TLS.
  • A source is a function in TOKEN_SOURCES that receives a StoreEndpoint (store kind, settings prefix, host, port, user) and returns a StoreToken. Another cloud's source is added there without a change to the stores. A test registers a made-up source and signs in to both stores with it.

How each store takes the token.

  • Redis: redis-py's credential provider returns the user and a current token each time the client connects.
  • PostgreSQL: psycopg_pool's kwargs becomes a function, so each new pooled connection gets a current token as its password. A pool takes a function from psycopg-pool 3.3 on, so with a token source the helper checks for 3.3 at start. The postgres extra still allows 3.2 for password users.

The source aws.

  • ElastiCache: the request connect for the user on the replication group llm.transcript.redis.aws.cache, presigned with SigV4 for elasticache and valid 900 seconds, without its scheme. This is AWS's documented form.
  • RDS: boto3's generate_db_auth_token for the host and port.

Neither call reaches the network. The region is llm.aws.region, else the AWS environment. A new aws extra adds boto3, for deployments that use the token without Bedrock.

Refused at start, by name: a missing user, a password beside the token, TLS off, and for aws a missing cache name, region or boto3. For example: llm.transcript.redis.auth aws needs llm.transcript.redis.username - the user the token signs in.

Files: extensions/llm-helper/llm_helper.py; tests/test_llm_store_auth.py (24 tests); the helper's README ("Signing in to the stores with a token" and the configuration table); the sample resources/application.yml; pyproject.toml (the aws extra); CHANGELOG.md (Unreleased); a session log and the thread store-token-sign-in.

Known limitations

  • ElastiCache Serverless is not covered. Its token adds ResourceType=ServerlessCache, and it offers only a cluster endpoint, which the helper's client (single server) cannot use.
  • Azure Cache for Redis will need open connections re-authenticated (AUTH) before their token expires. The seam renews tokens for new connections only, so the Azure source would add that.
  • redis-py 5.x asks the credential provider synchronously, so the token is signed on the event loop: microseconds, plus a few milliseconds when the role's credentials refresh, about every 14 minutes. redis-py 6 and later ask asynchronously and the token is signed off the loop. The extra's floor stays redis>=5.
  • botocore logs signatures. It logs each signature it computes at DEBUG (botocore.auth), as it already does for the Bedrock calls. Keep that logger above DEBUG where tokens matter. This is documented in the README.
  • Python only. The Node.js twin and the other clouds' sources are left for later changes (the thread store-token-sign-in).

How to test

1. Unit tests (no network, no AWS account)

Setup: uv venv .venv && uv pip install -e '.[dev]'

Steps:

.venv/bin/pytest -q tests/test_llm_store_auth.py
.venv/bin/pytest -q
uvx ruff check . && uvx basedpyright

Expected result: 24 passed for the new file; the full suite 3040 passed, 76 skipped; ruff clean; basedpyright 0 errors. The ElastiCache token test compares the helper's token with botocore's RequestSigner presign, using fixed credentials and a fixed clock.

2. The start-up checks (no network, no AWS account)

Steps:

.venv/bin/mercury-serve extensions/llm-helper/llm_helper.py -Drest.server.port=9481 \
  -Dllm.transcript.store=redis -Dllm.transcript.redis.auth=aws

Then run it again with the settings complete:

.venv/bin/mercury-serve extensions/llm-helper/llm_helper.py -Drest.server.port=9481 \
  -Dllm.transcript.store=redis -Dllm.transcript.redis.auth=aws \
  -Dllm.transcript.redis.username=llm-helper -Dllm.transcript.redis.ssl=true \
  -Dllm.transcript.redis.aws.cache=transcripts -Dllm.aws.region=us-east-1

Expected result: the first run stops with llm.helper cannot start - llm.transcript.redis.auth aws needs llm.transcript.redis.username - the user the token signs in. The second starts: Event API service started on port 9481. It connects on the first loop turn, so it needs no Redis to start.

3. Live on AWS (signs in to real stores)

Setup:

  • ElastiCache: a replication group on Valkey 7.2 or later (or Redis OSS 7 or later) with encryption in transit, cluster mode off. An IAM user (aws elasticache create-user --user-id llm-helper --user-name llm-helper --engine valkey --authentication-mode Type=iam --access-string "on ~transcript:* +@all"), in a user group attached to the replication group.
  • RDS for PostgreSQL: IAM database authentication on. A role created with CREATE USER llm_helper; GRANT rds_iam TO llm_helper;, the schema extensions/llm-helper/schema/postgres.sql applied, and the role granted what the schema's comments give the writer.
  • The process's AWS role: elasticache:Connect on the replication group and the user, and rds-db:connect on arn:aws:rds-db:<region>:<account>:dbuser:<DbiResourceId>/llm_helper. Run it inside the VPC (on EKS with Pod Identity, ECS, or EC2), with pip install -e '.[llm,bedrock,redis,postgres,aws]'.

Steps: in extensions/llm-helper, save this as check_stores.py and run it with the settings as -D options, as for mercury-serve:

import asyncio, sys
import llm_helper as h
from mercury_composable import app_config

async def main():
    store = h.get_store()
    print("redis:", await store.load("0" * 32))  # None: signed in, no such conversation
    audit = h.get_audit_store()
    await audit.open()
    print("postgres:", await audit.turns("0" * 32))  # set(): signed in, no rows
    await audit.close()

asyncio.run(main())
python check_stores.py \
  -Dllm.transcript.store=redis -Dllm.transcript.redis.host=<primary endpoint> \
  -Dllm.transcript.redis.ssl=true -Dllm.transcript.redis.username=llm-helper \
  -Dllm.transcript.redis.auth=aws -Dllm.transcript.redis.aws.cache=<replication group id> \
  -Dllm.transcript.audit=postgres -Dllm.transcript.audit.postgres.host=<RDS endpoint> \
  -Dllm.transcript.audit.postgres.username=llm_helper -Dllm.transcript.audit.postgres.auth=aws \
  -Dllm.aws.region=<region>

Then run the helper itself with the same settings and the Bedrock backend, and drive one agent loop turn (llm.chat with tools) from an engine.

Expected result:

  • The script prints redis: None and postgres: set(), with no authentication error.
  • The loop turn answers. Its transcript appears under transcript:<conversation> in Redis and in the transcript_turn table.
  • Negative control: remove elasticache:Connect from the role. A new connection then fails with an authentication error, and a loop turn answers 503 transcript store unreachable.
  • Renewal: leave the helper running for more than 15 minutes, then restart Redis's connection (for example with CLIENT KILL for the helper's user). The next turn reconnects with a new token.

Co-Authored-By: Claude Code noreply@anthropic.com

🤖 Generated with Claude Code

skofgar and others added 2 commits December 1, 2026 14:44
llm.transcript.redis.auth and llm.transcript.audit.postgres.auth take
password (the default, unchanged) or a token source. With a source, each
new connection signs in as the store's user with a short-lived token made
from the identity the deployment already gives the process, so nothing is
stored or rotated. Proposed in Accenture#96.

The stores know only a user and a token (StoreToken: cached, renewed a
minute before it expires). A source is a function in TOKEN_SOURCES that
receives the store's endpoint, so another cloud's source joins without a
change to the stores.

- Redis: redis-py's credential provider returns the user and a current
  token at each connection.
- PostgreSQL: psycopg_pool's callable kwargs give each new connection a
  current token as its password (psycopg-pool 3.3 or later).
- Checks every source shares, at start and by name: a user, no password
  beside the token, TLS.
- The first source, aws: an IAM authentication token presigned locally
  from the AWS credential chain, which Amazon ElastiCache and Amazon RDS
  for PostgreSQL accept for 15 minutes; llm.transcript.redis.aws.cache
  names the replication group; the aws extra adds boto3.

Tests: tests/test_llm_store_auth.py pins the ElastiCache token against
botocore's RequestSigner with fixed credentials and a fixed clock, the RDS
token's form, the renewal, a made-up source signing in both stores, both
stores' construction and every refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oken (Accenture#96)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant