-
-
Notifications
You must be signed in to change notification settings - Fork 96
Add strict-mode smoke test lane (HTTPS + signature verification) #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sij411
wants to merge
5
commits into
fedify-dev:main
Choose a base branch
from
sij411:feat/smoke-strict
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
906e389
Add interoperability smoke tests for Mastodon
sij411 49a296b
Add strict-mode smoke test lane (HTTPS + signature verification)
sij411 9fc7c4f
Align strict-mode connectivity check with non-strict lane
sij411 ae280f3
Pin Caddy images, add healthchecks, and fix sidekiq dependency
sij411 c6db09a
Update deno.lock
sij411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | ||
| # | ||
| # Strict-mode interoperability smoke tests (HTTPS + HTTP signature verification). | ||
| # Uses a standalone Docker Compose file with Caddy TLS proxies to verify that | ||
| # Fedify correctly signs and verifies requests over HTTPS. | ||
| # See: https://github.com/fedify-dev/fedify/issues/481 | ||
| name: smoke-mastodon-strict | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| smoke: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 25 | ||
|
|
||
| env: | ||
| COMPOSE: >- | ||
| docker compose | ||
| -f test/smoke/mastodon/docker-compose.strict.yml | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: ./.github/actions/setup-mise | ||
|
|
||
| - name: Generate TLS certificates | ||
| run: bash test/smoke/mastodon/generate-certs.sh test/smoke/mastodon/.certs | ||
|
|
||
| - name: Verify certificates | ||
| run: | | ||
| openssl verify -CAfile test/smoke/mastodon/.certs/ca.crt \ | ||
| test/smoke/mastodon/.certs/fedify-harness.crt | ||
| openssl verify -CAfile test/smoke/mastodon/.certs/ca.crt \ | ||
| test/smoke/mastodon/.certs/mastodon.crt | ||
|
|
||
| - name: Generate Mastodon secrets | ||
| run: | | ||
| IMAGE=ghcr.io/mastodon/mastodon:v4.3.9 | ||
| docker pull "$IMAGE" | ||
|
|
||
| SECRET1=$(docker run --rm "$IMAGE" bundle exec rails secret) | ||
| SECRET2=$(docker run --rm "$IMAGE" bundle exec rails secret) | ||
|
|
||
| { | ||
| echo "SECRET_KEY_BASE=$SECRET1" | ||
| echo "OTP_SECRET=$SECRET2" | ||
| docker run --rm "$IMAGE" bundle exec rails mastodon:webpush:generate_vapid_key \ | ||
| | grep -E '^[A-Z_]+=.+' | ||
| docker run --rm "$IMAGE" bundle exec rails db:encryption:init \ | ||
| | grep -E '^[A-Z_]+=.+' | ||
| } >> test/smoke/mastodon/mastodon-strict.env | ||
|
|
||
| - name: Start database and redis | ||
| run: | | ||
| $COMPOSE up -d db redis | ||
| $COMPOSE exec -T db \ | ||
| sh -c 'until pg_isready -U mastodon; do sleep 1; done' | ||
|
|
||
| - name: Run DB setup and migrations | ||
| run: | | ||
| $COMPOSE run --rm -T \ | ||
| mastodon-web-backend bundle exec rails db:setup | ||
| timeout-minutes: 5 | ||
|
|
||
| - name: Start Mastodon stack | ||
| run: $COMPOSE up --wait | ||
| timeout-minutes: 12 | ||
|
|
||
| - name: Provision Mastodon | ||
| run: bash test/smoke/mastodon/provision-strict.sh | ||
|
|
||
| - name: Verify connectivity | ||
| run: | | ||
| echo "=== Harness health (from mastodon-web-backend, via Caddy TLS) ===" | ||
| $COMPOSE exec -T mastodon-web-backend \ | ||
| curl -sf https://fedify-harness/_test/health | ||
| echo " OK" | ||
|
|
||
| echo "=== Harness health (from mastodon-sidekiq, via Caddy TLS) ===" | ||
| $COMPOSE exec -T mastodon-sidekiq \ | ||
| curl -sf https://fedify-harness/_test/health | ||
| echo " OK" | ||
|
|
||
| - name: Run smoke tests | ||
| run: | | ||
| set -a && source test/smoke/.env.test && set +a | ||
| deno run --allow-net --allow-env --unstable-temporal \ | ||
| test/smoke/orchestrator.ts | ||
|
|
||
| - name: Collect logs on failure | ||
| if: failure() | ||
| run: | | ||
| echo "=== Docker Compose logs ===" | ||
| $COMPOSE logs --tail=500 | ||
|
|
||
| - name: Teardown | ||
| if: always() | ||
| run: $COMPOSE down -v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| auto_https off | ||
| } | ||
|
|
||
| :443 { | ||
| tls /certs/fedify-harness.crt /certs/fedify-harness.key | ||
| reverse_proxy fedify-harness-backend:3001 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| auto_https off | ||
| } | ||
|
|
||
| :443 { | ||
| tls /certs/mastodon.crt /certs/mastodon.key | ||
| reverse_proxy mastodon-web-backend:3000 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| # Standalone Docker Compose for strict-mode smoke tests (HTTPS + signatures). | ||
| # Usage: docker compose -f docker-compose.strict.yml ... | ||
| # | ||
| # This is a standalone file (NOT an override) because Docker Compose merges | ||
| # network aliases additively and cannot remove a service's own DNS name from | ||
| # a network. Using an override would cause both the backend service and its | ||
| # Caddy proxy to resolve to the same hostname, breaking TLS routing. | ||
| # | ||
| # Architecture: | ||
| # - Backend services are renamed (e.g. fedify-harness-backend) so they | ||
| # don't collide with the TLS hostnames on the network | ||
| # - Caddy proxies claim the canonical hostnames (fedify-harness, mastodon) | ||
| # via network aliases and terminate TLS | ||
| # - All services share a single network for simplicity; DNS resolution | ||
| # is unambiguous because backend names differ from Caddy aliases | ||
|
|
||
| volumes: | ||
| harness-node-modules: | ||
|
|
||
| networks: | ||
| smoke: | ||
| driver: bridge | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:15-alpine | ||
| environment: | ||
| POSTGRES_DB: mastodon | ||
| POSTGRES_USER: mastodon | ||
| POSTGRES_PASSWORD: mastodon | ||
| networks: [smoke] | ||
| healthcheck: | ||
| test: ["CMD", "pg_isready", "-U", "mastodon"] | ||
| interval: 5s | ||
| retries: 10 | ||
|
|
||
| redis: | ||
| image: redis:7-alpine | ||
| networks: [smoke] | ||
| healthcheck: | ||
| test: ["CMD", "redis-cli", "ping"] | ||
| interval: 5s | ||
| retries: 10 | ||
|
|
||
| # Fedify test harness — renamed to avoid colliding with the Caddy alias. | ||
| fedify-harness-backend: | ||
| image: denoland/deno:2.7.1 | ||
sij411 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| working_dir: /workspace | ||
| volumes: | ||
| - ../../../:/workspace | ||
| - harness-node-modules:/workspace/node_modules | ||
| - ./.certs:/certs:ro | ||
| command: | ||
| - run | ||
| - --allow-net | ||
| - --allow-env | ||
| - --allow-read | ||
| - --allow-write | ||
| - --unstable-temporal | ||
| - test/smoke/harness/main.ts | ||
| environment: | ||
| HARNESS_ORIGIN: "https://fedify-harness" | ||
| STRICT_MODE: "1" | ||
| DENO_CERT: "/certs/ca.crt" | ||
| networks: [smoke] | ||
| ports: ["3001:3001"] | ||
| healthcheck: | ||
| test: | ||
| [ | ||
| "CMD", | ||
| "deno", | ||
| "eval", | ||
| "const r = await fetch('http://localhost:3001/_test/health'); if (!r.ok) Deno.exit(1);", | ||
| ] | ||
| interval: 5s | ||
| retries: 30 | ||
|
|
||
| # Caddy TLS proxy for the Fedify harness. | ||
| # Owns the "fedify-harness" hostname so other containers reach TLS. | ||
| caddy-harness: | ||
| image: caddy:2.11.2-alpine | ||
sij411 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| volumes: | ||
| - ./Caddyfile.fedify-harness:/etc/caddy/Caddyfile:ro | ||
| - ./.certs:/certs:ro | ||
| networks: | ||
| smoke: | ||
| aliases: [fedify-harness] | ||
| depends_on: | ||
| fedify-harness-backend: { condition: service_healthy } | ||
| healthcheck: | ||
| test: ["CMD", "caddy", "version"] | ||
| interval: 5s | ||
| retries: 5 | ||
|
|
||
| # Mastodon web — renamed to avoid colliding with the Caddy alias. | ||
| mastodon-web-backend: | ||
| image: ghcr.io/mastodon/mastodon:v4.3.9 | ||
| command: | ||
| - bash | ||
| - -c | ||
| - | | ||
| cat /usr/lib/ssl/cert.pem /certs/ca.crt > /tmp/ca-bundle.crt | ||
| bundle exec rails s -p 3000 -b 0.0.0.0 | ||
| env_file: mastodon-strict.env | ||
| environment: | ||
| SSL_CERT_FILE: /tmp/ca-bundle.crt | ||
| volumes: | ||
| - ./disable_force_ssl.rb:/opt/mastodon/config/initializers/zz_disable_force_ssl.rb:ro | ||
| - ./.certs:/certs:ro | ||
| networks: [smoke] | ||
| ports: ["3000:3000"] | ||
| depends_on: | ||
| db: { condition: service_healthy } | ||
| redis: { condition: service_healthy } | ||
| healthcheck: | ||
| test: | ||
| [ | ||
| "CMD-SHELL", | ||
| "curl -sf http://localhost:3000/health | grep -q OK", | ||
| ] | ||
| interval: 10s | ||
| retries: 18 | ||
|
|
||
| # Caddy TLS proxy for Mastodon. | ||
| # Owns the "mastodon" hostname so other containers reach TLS. | ||
| caddy-mastodon: | ||
| image: caddy:2.11.2-alpine | ||
| volumes: | ||
| - ./Caddyfile.mastodon:/etc/caddy/Caddyfile:ro | ||
| - ./.certs:/certs:ro | ||
| networks: | ||
| smoke: | ||
| aliases: [mastodon] | ||
| ports: ["4443:443"] | ||
| depends_on: | ||
| mastodon-web-backend: { condition: service_healthy } | ||
| healthcheck: | ||
| test: ["CMD", "caddy", "version"] | ||
| interval: 5s | ||
| retries: 5 | ||
|
|
||
| mastodon-sidekiq: | ||
| image: ghcr.io/mastodon/mastodon:v4.3.9 | ||
| command: | ||
| - bash | ||
| - -c | ||
| - | | ||
| cat /usr/lib/ssl/cert.pem /certs/ca.crt > /tmp/ca-bundle.crt | ||
| bundle exec sidekiq -q ingress -q default -q push | ||
| env_file: mastodon-strict.env | ||
| environment: | ||
| SSL_CERT_FILE: /tmp/ca-bundle.crt | ||
| volumes: | ||
| - ./disable_force_ssl.rb:/opt/mastodon/config/initializers/zz_disable_force_ssl.rb:ro | ||
| - ./.certs:/certs:ro | ||
| networks: [smoke] | ||
| depends_on: | ||
| mastodon-web-backend: { condition: service_healthy } | ||
| caddy-harness: { condition: service_healthy } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env bash | ||
| # Generate a self-signed CA and leaf certificates for strict-mode smoke tests. | ||
| # Usage: bash generate-certs.sh [output-dir] | ||
| # | ||
| # Output directory defaults to .certs/ (relative to this script). | ||
| # The CA is ephemeral — generated fresh each run. | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| OUT="${1:-$SCRIPT_DIR/.certs}" | ||
| mkdir -p "$OUT" | ||
|
|
||
| HOSTS=(fedify-harness mastodon) | ||
|
|
||
| echo "→ Generating CA key + certificate..." | ||
| openssl genrsa -out "$OUT/ca.key" 2048 2>/dev/null | ||
sij411 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| openssl req -x509 -new -nodes \ | ||
| -key "$OUT/ca.key" \ | ||
| -sha256 -days 1 \ | ||
| -subj "/CN=Smoke Test CA" \ | ||
| -out "$OUT/ca.crt" 2>/dev/null | ||
|
|
||
| for HOST in "${HOSTS[@]}"; do | ||
| echo "→ Generating certificate for $HOST..." | ||
| openssl genrsa -out "$OUT/$HOST.key" 2048 2>/dev/null | ||
| openssl req -new \ | ||
| -key "$OUT/$HOST.key" \ | ||
| -subj "/CN=$HOST" \ | ||
| -out "$OUT/$HOST.csr" 2>/dev/null | ||
|
|
||
| # Create a SAN extension config so the cert is valid for the hostname | ||
| cat > "$OUT/$HOST.ext" <<EOF | ||
| authorityKeyIdentifier=keyid,issuer | ||
| basicConstraints=CA:FALSE | ||
| subjectAltName=DNS:$HOST,DNS:localhost | ||
| EOF | ||
|
|
||
| openssl x509 -req \ | ||
| -in "$OUT/$HOST.csr" \ | ||
| -CA "$OUT/ca.crt" -CAkey "$OUT/ca.key" -CAcreateserial \ | ||
| -days 1 -sha256 \ | ||
| -extfile "$OUT/$HOST.ext" \ | ||
| -out "$OUT/$HOST.crt" 2>/dev/null | ||
|
|
||
| rm -f "$OUT/$HOST.csr" "$OUT/$HOST.ext" | ||
| done | ||
|
|
||
| rm -f "$OUT/ca.srl" | ||
|
|
||
| echo "✓ Certificates written to $OUT/" | ||
| ls -la "$OUT" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.