Skip to content

KNOX-3599: Write empty pac4j session cookie instead of "null" #797

KNOX-3599: Write empty pac4j session cookie instead of "null"

KNOX-3599: Write empty pac4j session cookie instead of "null" #797

Workflow file for this run

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Apache Knox Docker Compose Tests
on:
pull_request:
branches:
- '**' # triggers for all PRs
workflow_dispatch:
jobs:
build-and-test:
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'skip-tests')
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven
run: |
mvn clean -Ppackage,release install -T 1C \
-Dmaven.test.skip=true -Dpmd.skip=true -Dcpd.skip=true -Dcheckstyle.skip=true \
-Dspotbugs.skip=true -Drat.skip=true -Dforbiddenapis.skip=true -Denforcer.skip=true \
-Djacoco.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true \
-Dshellcheck.skip=true -Dxml.skip=true \
-s .github/workflows/build/settings.xml
- name: Set up Docker Compose
run: docker compose version
- name: Build Docker Images
run: |
# Build only knox-dev which is the runtime image using artifacts
docker compose -f ./.github/workflows/compose/docker-compose.yml build knox-dev
# The image carries the gateway and knoxshell exactly as released. Its
# BouncyCastle jars must all be jdk18on artifacts on <bouncycastle.version>,
# each shipped once: mixed BouncyCastle versions, or a legacy jdk15on jar next
# to the jdk18on ones, only fail at runtime on the code paths that hit them.
- name: Check shipped BouncyCastle jars
run: ./.github/workflows/compose/check-bc-jars.sh
- name: Start Knox and LDAP Services
run: docker compose -f ./.github/workflows/compose/docker-compose.yml up -d
- name: Wait for services to stabilize
run: sleep 30 # Adjust as needed for services startup time
- name: Run Knox Integration Tests
run: |
# Run the tests service defined in docker-compose.yml
docker compose -f ./.github/workflows/compose/docker-compose.yml up --exit-code-from tests tests
# KnoxIDF federation E2E runs only when the PR carries the 'test-federation'
# label. It stands up a real Keycloak (external OpenID Provider) via the
# override compose file and pulls a multi-hundred-MB image plus minutes of
# realm import, so it is opt-in rather than on every PR. It runs here, before
# the single-EKU steps, so 'knox' is still in its base (non-mTLS) config; the
# override only adds a keycloak dependency to knox, it does not reconfigure it.
- name: Start Keycloak + Knox for federation
if: contains(github.event.pull_request.labels.*.name, 'test-federation')
run: |
# 'up -d knox' blocks until keycloak is service_healthy (override depends_on).
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-federation.yml \
up -d knox keycloak
- name: Wait for federation stack to stabilize
if: contains(github.event.pull_request.labels.*.name, 'test-federation')
run: sleep 30 # Adjust as needed for services startup time
- name: Run KnoxIDF Federation Tests
id: knoxidf_federation_tests
if: contains(github.event.pull_request.labels.*.name, 'test-federation')
run: |
# Emit a distinct JUnit file so it reports as its own test suite.
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-federation.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test_knoxidf_federation.py --junitxml=test-results-federation.xml"
# Evidence gathering mirrors the single-EKU dumps: on a federation failure,
# capture container status and the knox + keycloak logs so a broker-flow
# failure (bad callback/issuer/JWKS) can be told apart from a Keycloak that
# never came up.
- name: Dump federation diagnostics on failure
if: failure() && steps.knoxidf_federation_tests.outcome == 'failure'
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-federation.yml \
ps -a || true
echo '===== knox container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-federation.yml \
logs --no-color knox || true
echo '===== keycloak container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-federation.yml \
logs --no-color keycloak || true
echo '===== gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
# HashiCorp Vault alias-service E2E. Unlike the Keycloak federation run,
# this is NOT label-gated: the Vault dev image is small and boots in
# seconds, so it runs on every PR to guard the spring-vault integration
# (e.g. after a Spring / Spring Vault bump). It stands up a dev-mode Vault
# and recreates 'knox' with the Vault-backed RemoteAliasService, then
# round-trips an alias through the admin API and confirms it in Vault. It
# runs here, before the single-EKU steps, so 'knox' is still in its base
# config when the override recreates it.
- name: Start Vault + Knox for HashiCorp Vault alias service
run: |
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.hashicorp-vault.yml \
up -d knox vault
- name: Wait for Vault stack to stabilize
run: sleep 30 # Adjust as needed for services startup time
- name: Run HashiCorp Vault Alias Tests
id: hashicorp_vault_tests
run: |
# Emit a distinct JUnit file so it reports as its own test suite.
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.hashicorp-vault.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test_knox_hashicorp_vault_alias.py --junitxml=test-results-hashicorp-vault.xml"
# Evidence gathering: an alias-API failure could be a gateway that never
# reached Vault (bad address/token/engine) or a Vault that never came up.
# Dump container status plus the knox and vault logs so the two can be told
# apart.
- name: Dump HashiCorp Vault diagnostics on failure
if: failure() && steps.hashicorp_vault_tests.outcome == 'failure'
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.hashicorp-vault.yml \
ps -a || true
echo '===== knox container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.hashicorp-vault.yml \
logs --no-color knox || true
echo '===== vault container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.hashicorp-vault.yml \
logs --no-color vault || true
echo '===== gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
# LDAP proxy roles-lookup E2E with the REST strategy. Like the Vault run, this
# is NOT label-gated. The override adds 'roles-api', a small stdlib-only mock
# of the roles REST API serving the role assignments in role-lookup/roles.json,
# and recreates 'knox' with the REST roles lookup and
# gateway.ldap.interceptor.roleslookup.lowercaseIds=true. Role entries replace
# group entries, which would break the default suite's group expectations, so
# it runs as its own pass, before the single-EKU steps, which recreate 'knox'
# with their own config anyway.
- name: Start roles API mock + Knox for REST roles lookup
run: |
# 'up -d knox' blocks until roles-api is service_healthy (override depends_on).
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.role-lookup-rest.yml \
up -d knox roles-api
- name: Wait for REST roles-lookup gateway to stabilize
run: sleep 30 # Adjust as needed for services startup time
- name: Run LDAP REST Roles Lookup Tests
id: rest_role_lookup_tests
run: |
# Emit a distinct JUnit file so it reports as its own test suite.
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.role-lookup-rest.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test*_with_rest_role_lookup.py --junitxml=test-results-rest-role-lookup.xml"
# Evidence gathering: a missing role could be a gateway that never reached
# the roles API (bad endpoint), an unexpected request (check the user_id the
# gateway sent in its roles lookup log lines) or a mock that never came up.
# Dump container status plus the knox and roles-api logs.
- name: Dump LDAP REST roles lookup diagnostics on failure
if: failure() && steps.rest_role_lookup_tests.outcome == 'failure'
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.role-lookup-rest.yml \
ps -a || true
echo '===== knox container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.role-lookup-rest.yml \
logs --no-color knox || true
echo '===== roles-api container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.role-lookup-rest.yml \
logs --no-color roles-api || true
echo '===== gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
# KnoxIDF HA E2E runs only when the PR carries the 'test-ha' label. The
# override recreates 'knox' on a shared PostgreSQL database and adds a
# second gateway, 'knox2', on the same database; the suite changes the
# KnoxIDF registries through one gateway and checks the other picks the
# changes up. It runs here, before the single-EKU steps, which recreate
# 'knox' with their own config anyway.
- name: Start PostgreSQL + two Knox gateways for KnoxIDF HA
id: knoxidf_ha_start
if: contains(github.event.pull_request.labels.*.name, 'test-ha')
run: |
# 'up -d' starts knox2 only once knox is service_healthy (override depends_on).
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
up -d knox knox2 postgres
- name: Wait for KnoxIDF HA stack to become healthy
id: knoxidf_ha_wait
if: contains(github.event.pull_request.labels.*.name, 'test-ha')
run: |
for service in knox knox2; do
container=$(docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
ps -a -q "$service")
if [ -z "$container" ]; then
echo "$service: no container"
exit 1
fi
# Up to 5 minutes; stop early once Docker gives up and marks it unhealthy,
# or the container exits (an exited container keeps its last health status).
for _ in $(seq 1 60); do
state=$(docker inspect -f '{{.State.Status}}' "$container")
status=$(docker inspect -f '{{.State.Health.Status}}' "$container")
if [ "$state" = exited ] || [ "$state" = dead ]; then
status="$state ($(docker inspect -f '{{.State.ExitCode}}' "$container"))"
break
fi
if [ "$status" = healthy ] || [ "$status" = unhealthy ]; then
break
fi
sleep 5
done
echo "$service: $status"
[ "$status" = healthy ] || exit 1
done
- name: Run KnoxIDF HA Tests
id: knoxidf_ha_tests
if: contains(github.event.pull_request.labels.*.name, 'test-ha')
run: |
# Emit a distinct JUnit file so it reports as its own test suite.
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test_knoxidf_ha.py --junitxml=test-results-ha.xml"
# Evidence gathering: a change that never reached the other gateway could be
# a gateway that is not on the shared database, a failing registry reload or
# a gateway that never came up. Dump container status, both gateways' logs
# and the database logs so these can be told apart. knox2 has no logs bind
# mount, so its gateway.log is copied out of the container.
- name: Dump KnoxIDF HA diagnostics on failure
if: >-
failure() && (steps.knoxidf_ha_start.outcome == 'failure'
|| steps.knoxidf_ha_wait.outcome == 'failure'
|| steps.knoxidf_ha_tests.outcome == 'failure')
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
ps -a || true
for service in knox knox2 postgres; do
echo "===== $service container logs ====="
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
logs --no-color "$service" || true
done
echo '===== knox gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
echo '===== knox2 gateway.log ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
cp knox2:/knox-runtime/logs/gateway.log /tmp/knox2-gateway.log \
&& cat /tmp/knox2-gateway.log || true
# The remaining steps only use 'knox'; stop the second gateway and the
# database so they do not hold runner memory.
- name: Stop KnoxIDF HA services
if: always() && contains(github.event.pull_request.labels.*.name, 'test-ha')
run: |
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.knoxidf-ha.yml \
stop knox2 postgres || true
# Single-EKU mTLS runs as its own pass. Its override turns on
# gateway.client.auth.needed=true, which would break the default
# (no-client-cert) tests above, so the gateway is recreated with the
# single-EKU config and the mTLS suite runs against that instance. The
# already-built apache/knox-dev image is reused -- no second Maven build.
- name: Restart Knox in single-EKU mode
run: |
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku.yml \
up -d knox
- name: Wait for single-EKU gateway to stabilize
run: sleep 30 # Adjust as needed for services startup time
- name: Run Single-EKU mTLS Tests
id: single_eku_tests
run: |
# KNOX_SINGLE_EKU=true (set by the override) un-skips the suite.
# Emit a distinct JUnit file so it reports as its own test suite.
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test_single_eku_mtls.py --junitxml=test-results-single-eku.xml"
# Evidence gathering: a "Connection refused" from the suite means the
# single-EKU gateway never listened. Dump container status, the knox
# container's stdout/stderr (includes the entrypoint's create-alias output
# and any Java startup stacktrace), and the gateway log so we can tell a
# failed entrypoint apart from single-EKU fail-fast validation.
- name: Dump single-EKU diagnostics on failure
if: failure() && steps.single_eku_tests.outcome == 'failure'
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku.yml \
ps -a || true
echo '===== knox container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku.yml \
logs --no-color knox || true
echo '===== gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
# Second single-EKU scenario: mTLS OFF. Proves single-EKU does not force
# inbound client authentication -- a no-client-cert request must succeed.
- name: Restart Knox in single-EKU (no mTLS) mode
run: |
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku-no-mtls.yml \
up -d knox
- name: Wait for single-EKU (no mTLS) gateway to stabilize
run: sleep 30 # Adjust as needed for services startup time
- name: Run Single-EKU (no mTLS) Tests
id: single_eku_no_mtls_tests
run: |
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku-no-mtls.yml \
run --rm tests bash -c "pip install -r requirements.txt \
&& pytest test_single_eku_no_mtls.py --junitxml=test-results-single-eku-no-mtls.xml"
- name: Dump single-EKU (no mTLS) diagnostics on failure
if: failure() && steps.single_eku_no_mtls_tests.outcome == 'failure'
run: |
echo '===== docker compose ps -a ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku-no-mtls.yml \
ps -a || true
echo '===== knox container logs ====='
docker compose \
-f ./.github/workflows/compose/docker-compose.yml \
-f ./.github/workflows/compose/docker-compose.single-eku-no-mtls.yml \
logs --no-color knox || true
echo '===== gateway.log ====='
cat ./.github/workflows/compose/logs/gateway.log || true
# The gateway generates its TLS identity with BouncyCastle on first start. If
# that fails it has no TLS and every suite reports "Connection refused", so
# surface the underlying error.
- name: Dump certificate generation errors on failure
if: failure()
run: |
grep -n -A20 'Error in generating certificate' ./.github/workflows/compose/logs/gateway.log \
|| echo 'No certificate generation errors in gateway.log'
- name: Collect Knox Logs and Conf
if: always()
run: |
mkdir -p .github/workflows/artifacts/knox-logs
mkdir -p .github/workflows/artifacts/knox-conf
docker compose -f ./.github/workflows/compose/docker-compose.yml cp knox:/knox-runtime/logs .github/workflows/artifacts/knox-logs
docker compose -f ./.github/workflows/compose/docker-compose.yml cp knox:/knox-runtime/conf .github/workflows/artifacts/knox-conf
- name: Upload Test Results
if: (!cancelled())
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
.github/workflows/tests/test-results.xml
.github/workflows/tests/test-results-single-eku.xml
.github/workflows/tests/test-results-single-eku-no-mtls.xml
.github/workflows/tests/test-results-federation.xml
.github/workflows/tests/test-results-hashicorp-vault.xml
.github/workflows/tests/test-results-rest-role-lookup.xml
.github/workflows/tests/test-results-ha.xml
- name: Archive Knox Logs
if: always()
run: tar -cvzf knox-logs.tar.gz -C .github/workflows/artifacts/knox-logs .
- name: Upload Knox Logs
if: always()
uses: actions/upload-artifact@v4
with:
name: knox-logs
path: knox-logs.tar.gz
- name: Archive Knox Conf
if: always()
run: tar -cvzf knox-conf.tar.gz -C .github/workflows/artifacts/knox-conf .
- name: Upload Knox Conf
if: always()
uses: actions/upload-artifact@v4
with:
name: knox-conf
path: knox-conf.tar.gz
- name: Upload Event File
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
- name: Tear Down Docker Compose
if: always()
run: |
# --remove-orphans also removes the services only the override files define
# (vault, roles-api, keycloak, knox2, postgres).
docker compose -f ./.github/workflows/compose/docker-compose.yml down --volumes --remove-orphans
TAG=${IMAGE_TAG:-master}
if docker image inspect "apache/knox-dev:$TAG" >/dev/null 2>&1; then
docker rmi "apache/knox-dev:$TAG"
fi