Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ jobs:
fail-fast: false
matrix:
php-versions: ["8.3", "8.4", "8.5"]
# Servers for the cache-only artifact tests which run against real backends (CacheOnlyBackendsTest).
services:
memcached:
image: memcached:1.6
ports:
- 11211:11211
redis:
image: redis:7
ports:
- 6379:6379

steps:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml
# memcached and redis: the cache-only artifact tests build clients of both, and the integration tests
# connect them to the servers above.
extensions: mbstring, xml, memcached, redis
tools: composer:v2
coverage: pcov

Expand Down Expand Up @@ -65,6 +77,11 @@ jobs:
./vendor/bin/phpunit $NO_COVERAGE

- name: Run integration tests
env:
OIDC_TEST_MEMCACHED_HOST: 127.0.0.1:11211
OIDC_TEST_REDIS_HOST: 127.0.0.1:6379
# Fail, rather than skip, the real-backend tests if a server is not given.
OIDC_TEST_BACKENDS_REQUIRED: "1"
run: |
echo $NO_COVERAGE
./vendor/bin/phpunit $NO_COVERAGE --no-configuration -c phpunit.integration.xml
Expand Down Expand Up @@ -207,11 +224,20 @@ jobs:
run: php vendor/bin/psalm --show-info=true

conformance-suite:
# Named, since the default name would list every matrix value, the compose file arguments included.
name: Conformance suite, SSP ${{ matrix.ssp-version }}, ${{ matrix.protocol-storage }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ssp-version: ["v2.5.0"]
# cache-only: authorization codes and access tokens kept in the protocol cache only, on Memcached.
protocol-storage: ["database", "cache-only"]
include:
- protocol-storage: database
compose-files: -f docker/docker-compose.yml
- protocol-storage: cache-only
compose-files: -f docker/docker-compose.yml -f docker/docker-compose.cache-only.yml
env:
SUITE_BASE_URL: https://localhost.emobix.co.uk:8443
VERSION: release-v5.3.4
Expand Down Expand Up @@ -244,7 +270,7 @@ jobs:
working-directory: ./main
# Must run after conformance suite since they share a docker network.
run: |
SSP_VERSION=${{ matrix.ssp-version }} OIDC_VERSION=@dev docker compose -f docker/docker-compose.yml --project-directory . up -d --build
SSP_VERSION=${{ matrix.ssp-version }} OIDC_VERSION=@dev docker compose ${{ matrix.compose-files }} --project-directory . up -d --build
sleep 30
# while ! curl -skfail https://op.local.stack-dev.cirrusidentity.com/.well-known/openid-configuration >/dev/null; do sleep 2; done
- name: Run Basic conformance tests
Expand All @@ -259,6 +285,31 @@ jobs:
- name: Run RP backchannel
run: |
./conformance-suite/scripts/run-test-plan.py "oidcc-backchannel-rp-initiated-logout-certification-test-plan[response_type=code][client_registration=static_client]" ./main/conformance-tests/conformance-back-channel-logout-ci.json
- name: Check where codes and access tokens were stored
working-directory: ./main
# The plans pass in either mode, so they can not tell a cache-only run which fell back to the database. A
# code or access token kept in the cache only never gets a database row; one stored in the database always
# does. Access tokens that back a refresh token are written to the database in both modes, so only the others
# are counted. Users are written in both modes (the seeded database has none), which shows the queries read
# the OP's database.
run: |
count() {
docker compose ${{ matrix.compose-files }} --project-directory . exec -T oidc-op \
sqlite3 /var/simplesamlphp/data/mydb.sq3 "SELECT COUNT(*) FROM $1"
}
users=$(count oidc_user)
codes=$(count oidc_auth_code)
tokens=$(count "oidc_access_token a WHERE NOT EXISTS
(SELECT 1 FROM oidc_refresh_token r WHERE r.access_token_id = a.id)")
echo "User rows: $users, authorization code rows: $codes, access token rows without a refresh token: $tokens"
[ "$users" -gt 0 ] || { echo "::error::No user in the database: the check does not read the OP's."; exit 1; }
if [ "${{ matrix.protocol-storage }}" = "cache-only" ]; then
[ "$codes" = "0" ] || { echo "::error::Codes reached the database in a cache-only run."; exit 1; }
[ "$tokens" = "0" ] || { echo "::error::Access tokens reached the database in a cache-only run."; exit 1; }
else
[ "$codes" -gt 0 ] || { echo "::error::No code reached the database in a database run."; exit 1; }
[ "$tokens" -gt 0 ] || { echo "::error::No access token reached the database in a database run."; exit 1; }
fi
- name: Dump OP logs
if: failure()
working-directory: ./main
Expand All @@ -267,11 +318,11 @@ jobs:
# failed check anywhere. The reason is in the OP's log, which otherwise leaves with the container.
# Same compose invocation as "Start SSP docker", so this addresses the project that step created.
run: |
docker compose -f docker/docker-compose.yml --project-directory . logs --no-color --tail 2000 oidc-op || true
docker compose ${{ matrix.compose-files }} --project-directory . logs --no-color --tail 2000 oidc-op || true
- name: Stop SSP
working-directory: ./main
run: |
docker compose -f docker/docker-compose.yml down
docker compose ${{ matrix.compose-files }} --project-directory . down
- name: Stop Conformance Suite
working-directory: ./conformance-suite
# cleaning up errors out on removing the network, so add "|| true" to prevent that from breaking the build
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"spomky-labs/base64url": "^2.0",
"symfony/cache": "^7.4",
"symfony/expression-language": "^7.4",
"symfony/lock": "^7.4",
"symfony/psr-http-message-bridge": "^7.4",
"web-token/jwt-framework": "^3.4.10"
},
Expand Down
36 changes: 36 additions & 0 deletions config/module_oidc.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,42 @@ $config = [
// 60 * 60 * 6, // Default lifetime in seconds (used when particular cache item doesn't define its own lifetime)
// ],

/**
* (optional) Protocol artifacts kept in the protocol cache only, without a database row. Empty by default: the
* database stores every artifact, and the protocol cache (if set) sits in front of it. Keeping authorization
* codes in the cache only takes two database writes off every login. Keeping access tokens in the cache only as
* well takes one more off every login without a refresh token; it requires AuthorizationCode in the list.
*
* Requires the protocol cache adapter above to be MemcachedAdapter or RedisAdapter, and a lock store (next
* option). Read "Keeping authorization codes and access tokens in the cache only" in the configuration
* documentation first: switching this on or off has to be coordinated across all nodes, and logins stop while
* the cache is down.
*/
ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_ARTIFACTS => [
// \SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AuthorizationCode,
// \SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AccessToken,
],

/**
* Lock store which lets an authorization code kept in the cache only be redeemed once: a DSN, from which the
* module builds a client of its own, connected lazily (memcached:, redis:, rediss:, valkey: or valkeys:), or a
* client object (Memcached, Redis, RedisCluster, RedisArray, a Relay or a Predis client). Only used when the
* option above is not empty. The documentation explains the trade-offs of each choice.
*/
ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE => null,
// The cache's own Memcached servers: the simplest set-up.
// ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE => 'memcached://localhost:11211',
// A dedicated instance which never evicts (Redis with "maxmemory-policy noeviction", or memcached -M).
// ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE => 'redis://locks.example.org:6379',
// A client object, for a set-up a DSN can not express. It must not be left in a transaction or a pipeline.
// ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE => (static function (): \Memcached {
// $client = new \Memcached();
// $client->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
// $client->setSaslAuthData('user', 'password');
// $client->addServer('locks.example.org', 11211);
// return $client;
// })(),

/**
* Protocol cache duration for particular entities. This is only relevant if protocol cache adapter is set up.
* For duration format info, check https://www.php.net/manual/en/dateinterval.construct.php.
Expand Down
11 changes: 11 additions & 0 deletions docker/docker-compose.cache-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Used on top of docker-compose.yml: the OP keeps authorization codes and access tokens in the protocol cache only,
# on a Memcached server which is its lock store too (docker/ssp/module_oidc.php reads OIDC_CONFORMANCE_MEMCACHED).
# docker compose -f docker/docker-compose.yml -f docker/docker-compose.cache-only.yml --project-directory . up
services:
oidc-memcached:
image: memcached:1.6
oidc-op:
environment:
- OIDC_CONFORMANCE_MEMCACHED=oidc-memcached:11211
depends_on:
- oidc-memcached
5 changes: 3 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ services:
context: .
dockerfile: docker/Dockerfile
args:
SSP_VERSION: "${SSP_VERSION}"
OIDC_VERSION: "${OIDC_VERSION}"
# Unset, the defaults of docker/Dockerfile: an empty build argument would override them.
SSP_VERSION: "${SSP_VERSION:-v2.5.0}"
OIDC_VERSION: "${OIDC_VERSION:-@dev}"
environment:
- STAGINGCOMPOSERREPOS=oidc
- SSP_ADMIN_PASSWORD=secret1
Expand Down
16 changes: 16 additions & 0 deletions docker/ssp/module_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@
// Use defaults
],
];

// Set by docker/docker-compose.cache-only.yml: authorization codes and access tokens kept in the protocol cache only,
// on this Memcached server ("host:port"), which is the lock store too.
$cacheOnlyMemcached = getenv('OIDC_CONFORMANCE_MEMCACHED');
if (is_string($cacheOnlyMemcached) && $cacheOnlyMemcached !== '') {
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ADAPTER] = \Symfony\Component\Cache\Adapter\MemcachedAdapter::class;
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ADAPTER_ARGUMENTS] = [
\Symfony\Component\Cache\Adapter\MemcachedAdapter::createConnection("memcached://$cacheOnlyMemcached"),
'oidcConformance',
];
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_ARTIFACTS] = [
\SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AuthorizationCode,
\SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AccessToken,
];
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE] = "memcached://$cacheOnlyMemcached";
}
Loading
Loading