Spring Framework based Service which is mirroring requests with the option to delay requests and alter http response codes
At least: Java 25 and Maven 3.9 (or use the Maven wrapper ./mvnw)
mvn package -DskipTests=truemvn spring-boot:runjava -jar target\mirrorservice-0.3.1-SNAPSHOT.jar./target/mirrorservice-0.3.1-SNAPSHOT.jar startdocker build -f Dockerfile.25 -t mirrorservice:latest .
docker build -f Dockerfile.25Jlink -t mirrorservice:jlink .
docker build -f Dockerfile.native -t mirrorservice:native .
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep "mirrorservice"
mirrorservice latest 636MB
mirrorservice jlink 297MBBoth variants use Spring AOT, the JDK 25 AOT cache and virtual threads. Details: docker.md
docker run --rm --name mirrorservice -m 256M -p 8003:8003 -v /tmp:/tmp mirrorservice:latest
Started MirrorserviceApplication in 0.552 seconds (process running for 0.692)
docker run --rm --name mirrorservice -m 256M -p 8003:8003 -v /tmp:/tmp mirrorservice:jlink
Started MirrorserviceApplication in 0.505 seconds (process running for 0.636)Multi-stage build with GraalVM CE 25 (native-image) on distroless/base-nossl. No local GraalVM needed, takes about 2.5 minutes and ~4.5 GB RAM.
docker build -f Dockerfile.native -t mirrorservice:native .
docker run --rm --name mirrorservice -m 256M -p 8003:8003 mirrorservice:native
Started MirrorserviceApplication in 0.076 seconds (process running for 0.08)Image 181 MB, RSS 65 MiB after start, 70 MiB after 600 requests.
docker tag mirrorservice:native wlanboy/mirrorservice:nativelatest
docker push wlanboy/mirrorservice:nativelatestRequires a local GraalVM 25 (GRAALVM_HOME) plus build-essential and zlib1g-dev:
./mvnw -Pnative native:compile
./target/mirrorserviceActuator (Health, Info, Metrics, Prometheus) läuft auf dem eigenen Management-Port 8081, nicht auf dem API-Port 8003:
Result
{"status":"UP","groups":["liveness","readiness"]}returns http status code 201 and waits for 10 ms / mirrors body and headers
/mirror returns any body and any headers the caller asks for. Anyone can build a link that
serves HTML with a script, sets a cookie or redirects to another site via Location. The
service adds two headers to every mirror response unless the caller sets them in
responseHeaders:
Content-Security-Policy: sandboxblocks scripts and forms and gives the page an opaque origin, so it cannot read cookies or storage of the service's domain.X-Content-Type-Options: nosniffstops browsers from rendering atext/plainbody as HTML.
A test that needs a different policy sets the header itself, for example
responseHeaders[Content-Security-Policy]=default-src 'self'.
The service drops Set-Cookie by default and returns X-Mirror-Blocked-Header: Set-Cookie
instead. To pass cookies through, set mirror.allow-set-cookie=true. As an environment
variable this is MIRROR_ALLOW_SET_COOKIE=true; in the Helm chart add it to extraEnv.
Location stays unrestricted, so the service is an open redirect. Run it under a domain of
its own, not as a subdomain next to other applications. The browser treats mirror.gmk.lan
and app.gmk.lan as the same site because .lan is not on the Public Suffix List. A cookie
set with Domain=.gmk.lan would reach every application under gmk.lan, and a redirect from
the mirror to another application counts as a same-site request, so the browser sends
SameSite cookies along.
Result
["192.168.100.101"]Result
{"hostname":"gmk.lan","resolvedIp":"192.168.100.101","reachable":true,"responseTimeMs":3}timeoutMs must be between 1 and 10000 (default 1000); other values return 400.
An unreachable host returns 408, a hostname that cannot be resolved returns 404.
The check uses InetAddress.isReachable. Java sends an ICMP echo only if the process has
CAP_NET_RAW. The container images run as a non-root user, so the JVM has no such
capability and opens a TCP connection to port 7 (echo) instead. In that case
reachable: true only means the target host accepted the connection or rejected it with
a TCP RST. It does not mean that any service on that host is up. If a firewall drops
packets to port 7, the endpoint reports reachable: false even for a host that is running.
- curl -H "Authorization: Bearer abc" "http://localhost:8003/echo/some/path?x=1"
Result
{"method":"GET","url":"http://localhost:8003/echo/some/path","path":"/echo/some/path","query":"x=1",
"remoteAddress":"127.0.0.1","peerAddress":"127.0.0.1",
"headers":{"Host":["localhost:8003"],"User-Agent":["curl/8.18.0"],"Accept":["*/*"],"Authorization":["Bearer ***"]},
"body":"","bodyBytes":0,"bodyTruncated":false}/echo and every path below it accept GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS. The
response shows the request as the service received it behind an ingress, Istio sidecar or proxy.
headerslists the headers exactly as received, includingForwardedandX-Forwarded-*. The service masks the values ofAuthorizationandProxy-Authorizationbut keeps the scheme (Bearer ***). It also masks cookie values and keeps the cookie names (session=***).urlandremoteAddressare the values after Spring evaluated the forwarded headers (server.forward-headers-strategy: framework). Ifurlstill starts withhttp://behind a TLS ingress, the ingress does not sendX-Forwarded-Proto.peerAddressis the address of the direct TCP peer, usually the ingress pod or the sidecar.bodycontains at most 64 KiB of the request body.bodyTruncatedistrueif the body was longer.
cd ~
git clone https://github.com/wlanboy/MirrorService.gitkubectl cluster-info
kubectl get pods --all-namespacescd ~/MirrorService
kubectl create namespace mirror
kubectl apply -f mirrorservice-deployment.yaml
kubectl apply -f mirrorservice-service.yaml
kubectl get pods -n mirror -o widekubectl describe deployments -n mirror mirrorservice
kubectl describe services -n mirror mirrorservice-servicedocker run --name mirrorservice -m 256M -d -p 8003:8003 -v /tmp:/tmp mirrorservice:latest
kubectl expose deployment -n mirror mirrorservice --type=NodePort --name=mirrorservice-serviceexternal --port 8003
kubectl describe services -n mirror mirrorservice-serviceexternal Result:
Name: mirrorservice-serviceexternal
Namespace: mirror
Labels: app=mirrorservice
Annotations: <none>
Selector: app=mirrorservice
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.108.40.139
IPs: 10.108.40.139
Port: <unset> 8003/TCP
TargetPort: 8002/TCP
NodePort: <unset> 30412/TCP <--- THIS IS THE PORT WE NEED
Endpoints: 10.10.0.7:8003
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>sdk install java 25-tem
sdk install maven 3.9.9