A containerized HTTP reverse proxy that exposes internal services on a public domain. It comes with a web admin panel, per-route rate limiting, optional API keys and a tamper-evident audit log (a hash chain stored in PostgreSQL, signed with HMAC-SHA256 and anchored outside the database).
https://<domain>/myservice/api/x ──▶ http://localhost:8080/api/x
cp .env.example .env # set POSTGRES_PASSWORD, GATEWAY_ADMIN_PASSWORD, GATEWAY_AUDIT_HMAC_KEY
docker compose up --build- Admin panel: http://localhost:8080/_gatekeeper/ (user
admin) - Prebuilt image (amd64, arm64):
docker pull peppe289/security_gatekeeper, published from every green build ofmaster
Every request outside /_gatekeeper goes through a pipeline of filters:
AuditFilter ─▶ RouteResolution ─▶ RouteEnabled ─▶ ApiKey ─▶ RateLimit ─▶ Forwarding
(records every outcome) (calls the upstream)
| Outcome | HTTP |
|---|---|
| unknown prefix | 404 |
| route disabled | 503 |
| API key missing / wrong | 401 / 403 |
| rate limit exceeded | 429 + Retry-After |
| upstream unreachable / timed out | 502 / 504 |
Rejections are returned as application/problem+json (RFC 9457).
- Routes. The first path segment selects the route and is stripped before forwarding.
Routes are managed from the admin panel and stored in PostgreSQL. Each instance keeps an
in-memory copy and reloads it periodically (
gateway.routes.refresh-interval), so several instances behind a load balancer stay in sync. - Forwarding. Bodies are streamed in both directions. Hop-by-hop headers are removed,
and
X-Forwarded-For/Proto/Host/Prefixare added. The API key and the admin session cookie never reach the upstream. Redirects are passed back to the client unchanged, and upstream TLS certificates are validated. - API keys (optional, per route). They protect an internal service that has no
authentication of its own: only clients that send the key in the
X-Api-Keyheader get through. The gateway stores only the key's SHA-256 hash and shows the key once. API keys suit programmatic clients (scripts, apps, devices). Browsers do not send custom headers, so leave web UIs public or rely on their own login. - Audit log. The request thread only enqueues an event. A background thread extends
the hash chain and writes to the database in batches, so auditing never slows down
proxied traffic. Each instance (
gateway.node-id) writes its own chain. The database rejectsUPDATEs through a trigger.- Every record is also signed with HMAC-SHA256, using a key that exists only in the
configuration (
GATEWAY_AUDIT_HMAC_KEY). Anyone can recompute plain hashes, but not these signatures, so the chain cannot be rewritten without the key. - At most once per
gateway.audit.anchor-interval(60 s), and on shutdown, the writer signs the chain head (an anchor) and writes it to the log and togateway.audit.anchor-dir, outside the database. The latest records of a chain cannot be deleted without contradicting an anchor. - Verification from the admin panel recomputes every chain, checks every signature and compares the chains with the anchors. It detects records that were modified, inserted, removed or reordered, and chains truncated or deleted before their last anchor. Current limitations lists what it cannot detect.
- To rotate the key, set the new one and list the old ones in
gateway.audit.previous-hmac-keys, so older records still verify. Records written before signatures were introduced (migrationV2) have no signature and fail verification.
- Every record is also signed with HMAC-SHA256, using a key that exists only in the
configuration (
- Admin panel. It has login brute-force protection, CSRF tokens and a strict
Content-Security-Policy. Statistics are cached and recomputed at most every
gateway.dashboard.stats-refresh(5 s by default). Nothing updates in real time. - Machine load. The panel also shows how loaded the container is, to judge how much
more traffic it can take. Every
gateway.monitoring.sample-interval(5 s) the gateway samples CPU and memory (container-aware, so measured against the container's limits; memory excludes the reclaimable page cache, like theavailablecolumn offree), the JVM heap, busy worker threads, the audit queue and the network traffic of the container's interfaces (from/proc/net/dev, so Linux only). Each resource shows its current value and its peak overgateway.monitoring.window(15 min); a resource is High from a 70% peak and Critical from 90%, and a summary names the most loaded one. CPU, bandwidth in and out, and requests per second also have a trend line.
Terminate TLS on the public domain, in one of two ways:
- On the gateway itself: set
SERVER_SSL_ENABLED=true,SERVER_SSL_CERTIFICATEandSERVER_SSL_CERTIFICATE_PRIVATE_KEY(PEM), plusGATEWAY_SECURE_COOKIE=true. - Behind a load balancer or TLS terminator: set
SERVER_FORWARD_HEADERS_STRATEGY=nativeandGATEWAY_SECURE_COOKIE=true.
| Variable | Default | Description |
|---|---|---|
DATABASE_URL / DATABASE_USERNAME / DATABASE_PASSWORD |
jdbc:postgresql://localhost:5432/gatekeeper |
PostgreSQL connection |
GATEWAY_ADMIN_PASSWORD |
(required) | admin panel password; {bcrypt}… hashes are accepted |
GATEWAY_NODEID |
hostname | identifies this instance's audit chain |
GATEWAY_AUDIT_HMAC_KEY |
(required) | secret of at least 32 characters that signs the audit log (openssl rand -base64 48) |
GATEWAY_AUDIT_ANCHOR_DIR |
(empty: log only) | directory outside the database for audit anchors; share it between instances so any of them can verify every chain |
GATEWAY_RATELIMIT_DEFAULTBURSTCAPACITY / …DEFAULTREFILLPERSECOND |
100 / 50 | default limits for new routes |
GATEWAY_ROUTES_SEED_0_PREFIX / …_TARGETURL |
— | routes created at first startup |
PORT |
8080 | HTTP port |
Every setting is listed in src/main/resources/application.yml.
Requires Java 25. Integration tests need Docker, because they use Testcontainers. Building
the image needs BuildKit (the buildx plugin): the classic builder is not supported.
./mvnw verify # unit and integration tests, coverage check
./mvnw -Pmutation verify # adds PiTest mutation testing on the core package
./mvnw -Pmutation-all test-compile org.pitest:pitest-maven:mutationCoverage # whole-project mutation campaign (analysis)
./mvnw -Pbenchmark -DskipTests verify # JMH benchmarks
./mvnw -Pbenchmark,amber -DskipTests verify -Djmh.args=AmberWarmupBenchmark # AMBER dynamic warm-up (setup: `amber` profile in pom.xml)- Unit tests (JUnit 6, Mockito 5) cover each component in isolation. The
coredomain is pure Java and needs no mocks; services and filters get their collaborators (repositories, HTTP client, audit service, rate limiter) as Mockito mocks. - Time is injected (
Clock,NanoClock, or the instant passed toTokenBucket), so rate limiting, caches and cooldowns are tested with fake clocks instead of sleeps. Asynchronous effects are awaited with Mockito timeouts, never with fixed delays. - Integration tests (
*IntegrationTest) start the whole application with a real PostgreSQL from Testcontainers: proxying end to end, the admin panel, audit tampering, and the audit flush on shutdown. - Test cases come from equivalence classes and boundary values of the specification, and JaCoCo branch coverage shows what is still missing.
Details and figures: docs/testing.md.
Package layout:
| Package | Contents |
|---|---|
core |
pure-Java domain (token bucket, route policy, audit chain), with no framework dependencies |
gateway |
servlet entry point, filter pipeline, HTTP forwarder |
route |
route management (in-memory cache and PostgreSQL) |
audit |
asynchronous audit writer, HMAC signing, anchors and chain verification |
ratelimit |
per-client token buckets with eviction |
admin |
admin panel and login throttling |
config |
configuration properties, security, shared beans |
GitHub Actions workflows live in .github/workflows:
| Workflow | Trigger | What it does |
|---|---|---|
ci.yml |
push, pull request | ./mvnw verify (unit and integration tests, JaCoCo gates on core and on the whole project), PiTest with blocking mutation and coverage thresholds, Docker image build. The JaCoCo and PiTest reports are attached to each run as artifacts. |
security.yml |
push, pull request, weekly | Dependabot-alert gate (fails on open High/Critical alerts), GitGuardian secret scanning, Snyk scans of the Maven dependencies and the Docker image, SonarQube Cloud analysis with coverage. |
codeql-analysis.yml |
push, pull request, weekly | CodeQL static analysis (security-and-quality), results in Security › Code scanning; fails on High/Critical security alerts or error-level findings. |
openjml.yml |
changes to core, its tests or src/main/jml |
OpenJML type check, static verification (ESC) and runtime assertion checking (RAC) of the JML specifications, all blocking. |
benchmark.yml |
manual | JMH benchmarks, with results in the run summary. |
docker-build.yml |
CI succeeded on a push to master |
Builds the tested commit for amd64 and arm64 and pushes it to Docker Hub (peppe289/security_gatekeeper) as :latest and :sha-<commit>. |
release.yml |
tag v* |
Multi-arch image (amd64, arm64) published to ghcr.io/<owner>/<repository>. |
Dependabot (.github/dependabot.yml) opens weekly updates for Maven, the Docker base images
and the GitHub Actions, assigned to the maintainer; .github/CODEOWNERS requests their review.
One-time setup on GitHub:
-
Secrets (Settings › Secrets and variables › Actions). A scanner without its token is skipped, not failed.
Secret Where to get it GITGUARDIAN_API_KEYGitGuardian dashboard › API › Personal access tokens SNYK_TOKENSnyk › Account settings › Auth token SONAR_TOKENSonarQube Cloud › My account › Security DOCKER_USERNAMEDocker Hub username DOCKER_PASSWORDDocker Hub › Account settings › Personal access tokens (read & write) -
SonarQube Cloud: import the repository there first. If the organization or project key differs from the defaults (
<owner>and<owner>_<repository>), set the repository variablesSONAR_ORGANIZATIONandSONAR_PROJECT_KEY. Turn off Automatic Analysis in the project settings, since the analysis runs from CI.
Please do not open a public issue. Report it privately as described in
SECURITY.md (GitHub's Report a vulnerability).
- One upstream per route: no load balancing or upstream health checks.
- No WebSocket or other protocol upgrades: plain HTTP requests only.
- Rate limits and statistics are per instance, not shared across nodes.
- The audit log resists anyone who can write to the database but holds neither the HMAC key nor write access to the anchor storage. Whoever has the key can forge records, and whoever controls both the database and the anchor storage can delete the latest records undetected.
- Records written after the last anchor (at most
gateway.audit.anchor-interval, 60 s by default) can be deleted from the end of a chain without verification noticing. - Without
gateway.audit.anchor-dir, anchors only reach the log: verification cannot detect deletions from the end of a chain, unless someone compares the logged anchors by hand. - Removing the oldest records looks the same as retention. A node whose records were all purged on purpose fails verification until its anchor file is removed too.
Progress against the project assignments of the Software Dependability labs. Every report is a Markdown file of at most 5,000 characters, linked from this README. Items marked (GitHub) depend on repository settings or accounts and cannot be checked from the code.
-
.github/workflows/ci.ymlruns on push and pull request tomaster - The pipeline builds the project and runs the test suite (
./mvnw verify) - GitHub Actions verified green on push (GitHub)
-
CICD.mdreport: pipeline stages, build reproducibility, code quality
- Multi-stage
Dockerfilefollowing best practices (non-root user, layered jar,HEALTHCHECK,.dockerignore) -
docker-compose.ymlwith the application and a supporting service (PostgreSQL) - Named volume for the database data
- Secrets kept out of the compose file (
.env, not committed) -
healthcheckdeclared for every service indocker-compose.yml -
restart: on-failurerecovery policy -
.github/workflows/docker-build.yml: runs after a successful CI, builds and pushes the image to DockerHub -
DOCKER_USERNAME/DOCKER_PASSWORDsecrets configured and image published (GitHub) -
Docker.mdreport: anti-patterns avoided, audit of the course's reference Docker build workflow - Fault-injection experiment on the database (
fault-tolerance.md)
- Unit tests for the critical components (core domain, gateway filters and forwarding, rate limiter, audit writer, route, login and dashboard services, load report)
- Tests follow the FIRST principles; unit tests need no external service (integration tests use Testcontainers)
- JUnit 6.1.3 and Mockito 5.24.0
- External dependencies mocked with Mockito (repository, forwarder, audit service, rate limiter, clock)
- Tests run in the CI pipeline
- README section describing the testing approach
-
testing.mdreport
- JaCoCo with quality gates in
pom.xml(95% lines and branches oncore, 85% lines and 80% branches on the whole project) - PiTest with quality gates in
pom.xml(90% mutation score and 95% line coverage oncore) - Coverage and mutation testing run in the CI pipeline
- CodeCov upload in CI with the
CODECOV_TOKENsecret (GitHub) - Coverage and mutation badges in this README (mutation score published by CI on the
badgesbranch) -
coverage.mdreport: configuration, line and branch coverage, least-covered classes, improvement plan -
mutation.mdreport: configuration, mutation score, killed vs. survived, improvement plan
- Components suited to formal verification identified (
corepackage) - Invariants, preconditions and postconditions on the core classes
- OpenJML set up (
.github/workflows/openjml.yml) - Static verification with ESC
- Runtime assertion checking with RAC (core unit tests on instrumented classes, gated in
openjml.yml) -
verification.mdreport: setup, specifications, ESC and RAC results, lessons learned
- JMH dependencies in
pom.xmland abenchmarkpackage - At least three microbenchmarks (
TokenBucketBenchmark) - Warm-up, measurement and fork parameters configured
- Separate, manually triggered benchmark workflow (
benchmark.yml) - Benchmarks for other performance-critical methods (audit chain, hashing, request pipeline, rate limiter)
- At least two test cases converted to benchmarks with JU2JMH (
Sha256Test,AuditChainTest) - Warm-up phases configured with AMBER (opt-in
-Pamberprofile) - Benchmarks run locally, results analysed and bottlenecks identified (SHA-256 digest lookup, now reused per thread)
-
benchmarking.mdreport: methods and why, configuration, results, improvements
-
.github/dependabot.ymlwith weekly updates (Maven, Docker, GitHub Actions) -
.github/workflows/codeql-analysis.yml(Java,security-and-qualityqueries) - Code scanning enabled and its alerts reviewed: 11 found, 8 fixed in code, 3 dismissed as by design with a written reason (GitHub)
- Secret scanning and push protection enabled (GitHub), plus private vulnerability reporting and a
SECURITY.mdpolicy - Reviewers and assignees for Dependabot pull requests (
CODEOWNERS/assignees) - CodeQL and a Dependabot-alert check integrated as CI quality gates
- Dependabot alerts and security updates enabled; alerts reviewed (none open or closed so far) (GitHub)
-
security.mdreport: configuration, security policy, alert metrics
- GitGuardian, Snyk and SonarQube Cloud integrated in the pipeline (
security.yml) - Accounts created and
GITGUARDIAN_API_KEY,SNYK_TOKEN,SONAR_TOKENconfigured (GitHub) - Pipeline results reviewed in the three dashboards
-
Security_and_Quality.mdreport: integration, findings, SonarQube metrics, lessons learned