You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 88fa81a
Browse filesBrowse the repository at this point in the historyBrowse files
Keep authorization codes and access tokens in the protocol cache only, as an option (#364)
* Keep authorization codes in the protocol cache only, as an option
With the protocol cache in front of the database, the reads of a login
come from the cache, but each login still writes its authorization code
to the database twice. With ProtocolArtifactEnum::AuthorizationCode in
the new protocol_cache_only_artifacts option, new codes are kept in the
protocol cache only (Memcached or Redis), and both writes are gone. The
option is empty by default.
Single use stays atomic through symfony/lock, a new dependency: a code
is claimed in a separate lock store (protocol_cache_only_lock_store, a
DSN or a client object), and only the request which claimed it records
it consumed, with a nonce drawn for that request. A code's cache entry
and its guard are each written by one party only, every write is read
back, and a code proceeds only on positive evidence, so a lost or
failed write fails closed. A replay is recorded in the guard and
revokes the tokens issued for the code: one UPDATE on the primary
database, then a revoked copy of each token written to the cache. While
codes are kept in the cache only, a token found in the database on a
cache miss is not cached again, so a lookup can not overwrite a revoked
copy. With codes in the cache only, the client, redirect URI and PKCE
checks come before the replay check, the scopes after it, and the
code's one deadline, computed before it is persisted, gives the
payload's expiry and every TTL.
The configuration refuses what makes the lock not lock or not run,
checking a DSN by building its client lazily, and leaves the rest of
the lock store's set-up to the administrator; the documentation sets
out the trade-offs, how to switch the option, and an outage runbook.
CI's unit job installs the memcached and redis extensions, which the
new tests use without connecting.
With the option empty: findById() of codes, access tokens and refresh
tokens no longer writes a cache hit back (it could overwrite a
revocation written in the meantime), and an unknown authorization code
answers invalid_grant instead of an error page.
Assisted-by: Claude Code (claude-opus-5-5, design, implementation & tests)
Assisted-by: OpenAI Codex (gpt-6.2-sol, xhigh review)
Assisted-by: Google Antigravity (gemini-4-neon-high, review)
* Keep access tokens in the protocol cache only, as an option
With ProtocolArtifactEnum::AccessToken in the cache-only artifacts list
(next to AuthorizationCode, which it requires), a new access token is
written to the protocol cache only, with a checked write, and not to the
database: one more database write off every login without a refresh
token. A token issued for a code with a database row still goes to the
database.
A token kept in the cache only is valid only while its entry is there
and not revoked and, for a token issued for an authorization code, while
the code's entry records its consumption by the token request which
issued the token (the same issuance nonce) and the code's guard is
clean. A replay of the code thus invalidates all of its cache-only
tokens at once, and a request which lost a race for the code never gets
a valid token.
An access token for which a refresh token is issued is promoted first:
its cache entry is rewritten without the marker, then its row inserted,
so that the refresh token's foreign key and the refresh grant find it.
Only a token the request itself stored is promoted. While access tokens
are kept in the cache only, tokens with a database row and refresh
tokens are neither trusted from the cache nor written to it, and
revocations by authorization code are one UPDATE on the primary.
A cache-only code whose consumed entry landed but whose read-back missed
is now confirmed by the recovery read finding the request's own
consumption, and the final read still runs.
With the option off too, a missing access token counts as revoked: the
UserInfo endpoint answers 401 access_denied instead of a 500, on its
second lookup as well.
Assisted-by: Claude Code (claude-opus-5-5, implementation & tests)
Assisted-by: OpenAI Codex (gpt-6.2-sol, xhigh review)
Assisted-by: Google Antigravity (gemini-4-neon-high, review)
* Make the cache-only deadline test independent of the clock's second
The test set the code's deadline to the current second. When that second
ended before consumption checked the deadline, the code was refused before
it was claimed, and the test's final claim of the code then succeeded. A
deadline one second ahead keeps the check before the claim passing.
Assisted-by: Claude Code (claude-opus-5-5, test fix)
* Skip the per-login user update when the claims have not changed
Every login wrote the user's row even when its claims had not changed, a
database write on the login path for nothing but updated_at. A login now
reads the user's row, then the user's protocol cache entry, and writes
nothing when both hold the claims the update would write, compared as
stored JSON strings; without a protocol cache the row alone decides. A
difference in either, a missing row or entry, or a read that fails updates
the user as every login did before.
The cache entry alone is not trusted: it can differ from the row without
any failure (caches local to each node, a lookup refilling it from an older
row, interleaved logins), and a write skipped on its word would leave the
row outdated. Since an update writes the row and then the entry, a login
skips only if it read each before another login's update wrote it, and that
update's claims then stand in both places.
updated_at no longer moves on a login with unchanged claims, and such a
login does not renew the user's cache entry. The upgrade guide says so, and
that with lagging database secondaries a login bringing back earlier claims
moments after a change can leave the change in the row when the cache does
not show it either.
Assisted-by: Claude Code (claude-opus-5-5, implementation & unit tests)
Assisted-by: OpenAI Codex (gpt-6.2-sol, xhigh review)
Assisted-by: Google Antigravity (gemini-4-neon-high, review)
* Run cache-only mode in CI: real backends and a conformance run
CI never exercised authorization codes and access tokens kept in the
protocol cache only: the conformance OP used FilesystemAdapter, which that
mode refuses, and the tests against real Memcached and Redis servers were
skipped for want of a server.
- The unit job gets Memcached and Redis service containers, so
CacheOnlyBackendsTest runs on every PHP version. With
OIDC_TEST_BACKENDS_REQUIRED=1, set in CI, a missing server fails those
tests instead of skipping them.
- The conformance job runs every plan a second time with
docker/docker-compose.cache-only.yml, which adds a Memcached container
and switches the OP to MemcachedAdapter, with codes and access tokens
kept in the cache only and the same server as the lock store. The plans
pass in either mode, so a step then checks the OP's database: no
authorization code, and no access token except those backing a refresh
token, after the cache-only run; some of each after the database run.
- "Stop SSP" now addresses the compose project that "Start SSP docker"
created (--project-directory was missing, so it stopped nothing).
- docker-compose.yml gives SSP_VERSION and OIDC_VERSION the Dockerfile's
defaults, since an empty build argument overrode them. The docs show the
cache-only command, the network and working directory the compose
commands need, and link the Docker Compose section directly.
Assisted-by: Claude Code (claude-opus-5-5, implementation & verification)
Assisted-by: OpenAI Codex (gpt-6.2-sol, xhigh review)
Assisted-by: Google Antigravity (gemini-4-neon-high, review)
* Judge a buffer_writes string in a lock store DSN by the client built
The case "buffer writes as a string" expected a Memcached lock store DSN
with buffer_writes=true to be accepted, because the memcached extension
3.4.0 reads the string "true" as 0. The build CI installs reads it as on,
so the resolver rightly refused the client, and the unit job failed on
every PHP version on the branch's first CI run. The case is now a test of
its own: it builds the client from the DSN and expects a refusal exactly
when that client buffers writes, whichever way the extension read the
value.
Assisted-by: Claude Code (claude-opus-5-5, test fix)
0 commit comments