Skip to content

Commit be906ff

Browse files
committed
added Docker support for Header Testing Server
1 parent 8723b89 commit be906ff

File tree

6 files changed

+192
-5
lines changed

6 files changed

+192
-5
lines changed

.dockerignore

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.gitattributes
5+
6+
# Documentation
7+
README.md
8+
README_original.md
9+
DOCKER_README.md
10+
CODE_OF_CONDUCT.md
11+
CONTRIBUTING.md
12+
CODEOWNERS
13+
14+
# Docker
15+
Dockerfile
16+
docker-compose.yml
17+
.dockerignore
18+
19+
# Python
20+
__pycache__
21+
*.pyc
22+
*.pyo
23+
*.pyd
24+
.Python
25+
env
26+
pip-log.txt
27+
pip-delete-this-directory.txt
28+
.tox
29+
.coverage
30+
.coverage.*
31+
.cache
32+
nosetests.xml
33+
coverage.xml
34+
*.cover
35+
*.log
36+
.git
37+
.mypy_cache
38+
.pytest_cache
39+
.hypothesis
40+
41+
# Poetry
42+
poetry.lock
43+
44+
# Jupyter
45+
.ipynb_checkpoints
46+
47+
# IDE
48+
.vscode
49+
.idea
50+
*.swp
51+
*.swo
52+
*~
53+
54+
# OS
55+
.DS_Store
56+
.DS_Store?
57+
._*
58+
.Spotlight-V100
59+
.Trashes
60+
ehthumbs.db
61+
Thumbs.db
62+
63+
# Temporary files
64+
*.tmp
65+
*.temp
66+
*.bak
67+
*.backup
68+
69+
# Logs
70+
*.log
71+
logs/
72+
73+
# Database
74+
*.db
75+
*.sqlite
76+
*.sqlite3
77+
78+
# Test results
79+
test-results/
80+
results/

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV PYTHONUNBUFFERED=1
5+
6+
# Set working directory
7+
WORKDIR /app
8+
9+
# Install system dependencies
10+
RUN apt-get update && apt-get install -y \
11+
curl git postgresql-client tzdata sudo \
12+
build-essential libssl-dev zlib1g-dev libcap2-bin \
13+
libbz2-dev libreadline-dev libsqlite3-dev \
14+
libncursesw5-dev xz-utils tk-dev libxml2-dev \
15+
libxmlsec1-dev libffi-dev liblzma-dev \
16+
libatk-bridge2.0-0 libdbus-glib-1-2 \
17+
libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev \
18+
libasound2 unzip x11vnc xvfb fluxbox \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
COPY . /app
22+
WORKDIR /app/_hp
23+
RUN chmod +x setup.bash
24+
RUN bash ./setup.bash
25+
ENV PATH="/root/.local/bin:${PATH}"
26+
WORKDIR /app
27+
# Add entrypoint script
28+
COPY entrypoint.sh /app/entrypoint.sh
29+
RUN chmod +x /app/entrypoint.sh
30+
31+
# Expose ports
32+
EXPOSE 80 443 8443 9000
33+
34+
# WORKDIR /app

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Our modified version of the wptserve HTTP server implementation can be found in
2020
- Manually check if the server and the tests are working: Visit http://sub.headers.websec.saarland:80/_hp/tests/framing.sub.html and confirm that tests are loaded and executed.
2121
- Optional: Run tests to check that everything is working correctly: `poetry run -C _hp pytest _hp`
2222
- Optional: Change the used domains in [_hp/wpt-config.json](_hp/wpt-config.json) and [_hp/host-config.txt](_hp/host-config.txt)
23+
- To run it inside a Docker container: `docker compose up --build`. This should spin up the server.
2324

2425

2526
## Reproduce or Enhance our Results

docker-compose.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
services:
2+
postgres:
3+
image: postgres:15
4+
environment:
5+
POSTGRES_DB: http_header_demo
6+
POSTGRES_USER: header_user
7+
POSTGRES_PASSWORD: header_password
8+
volumes:
9+
- postgres_data:/var/lib/postgresql/data
10+
ports:
11+
- "5432:5432"
12+
healthcheck:
13+
test: ["CMD-SHELL", "pg_isready -U header_user -d http_header_demo"]
14+
interval: 10s
15+
timeout: 10s
16+
retries: 10
17+
18+
header-testing-server:
19+
build: .
20+
extra_hosts:
21+
- "headers.websec.saarland:0.0.0.0"
22+
- "sub.headers.websec.saarland:0.0.0.0"
23+
- "sub.sub.headers.websec.saarland:0.0.0.0"
24+
- "headers.webappsec.eu:0.0.0.0"
25+
- "sub.headers.webappsec.eu:0.0.0.0"
26+
- "sub.sub.headers.webappsec.eu:0.0.0.0"
27+
depends_on:
28+
postgres:
29+
condition: service_healthy
30+
environment:
31+
DB_HOST: postgres
32+
DB_PORT: 5432
33+
DB_USER: header_user
34+
DB_PASSWORD: header_password
35+
DB_NAME: http_header_demo
36+
ports:
37+
- "80:80"
38+
- "443:443"
39+
- "8443:8443"
40+
- "9000:9000"
41+
volumes:
42+
- .:/app
43+
- ./_hp/hp/tools/certs:/app/_hp/hp/tools/certs
44+
cap_add:
45+
- NET_BIND_SERVICE
46+
restart: unless-stopped
47+
command: [
48+
"poetry", "run", "-C", "/app/_hp", "python", "/app/wpt", "serve", "--config", "/app/_hp/wpt-config.json"
49+
]
50+
51+
volumes:
52+
postgres_data:

entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Wait for Postgres to be ready
5+
echo "Waiting for Postgres..."
6+
until pg_isready -h $DB_HOST -U $DB_USER -d $DB_NAME; do
7+
sleep 2
8+
done
9+
10+
# Run DB migrations / model setup
11+
echo "Initializing database schema..."
12+
poetry run python _hp/hp/tools/models.py
13+
cd _hp/hp/tools && poetry run python create_responses.py
14+
# Start server
15+
exec "$@"

tools/serve/serve.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ def start_http_server(logger, host, port, paths, routes, bind_address, config, *
804804
key_file=None,
805805
certificate=None,
806806
latency=kwargs.get("latency"))
807-
except Exception:
807+
except Exception as error:
808+
logger.critical(f"start_http_server: Caught exception from wptserve.WebTestHttpd: {error}")
808809
startup_failed(logger)
809810

810811

@@ -822,7 +823,8 @@ def start_https_server(logger, host, port, paths, routes, bind_address, config,
822823
certificate=config.ssl_config["cert_path"],
823824
encrypt_after_connect=config.ssl_config["encrypt_after_connect"],
824825
latency=kwargs.get("latency"))
825-
except Exception:
826+
except Exception as error:
827+
logger.critical(f"start_https_server: Caught exception from wptserve.WebTestHttpd: {error}")
826828
startup_failed(logger)
827829

828830

@@ -843,7 +845,8 @@ def start_http2_server(logger, host, port, paths, routes, bind_address, config,
843845
encrypt_after_connect=config.ssl_config["encrypt_after_connect"],
844846
latency=kwargs.get("latency"),
845847
http2=True)
846-
except Exception:
848+
except Exception as error:
849+
logger.critical(f"start_http2_server: Caught exception from wptserve.WebTestHttpd: {error}")
847850
startup_failed(logger)
848851

849852

@@ -910,7 +913,8 @@ def start_ws_server(logger, host, port, paths, routes, bind_address, config, **k
910913
config.paths["ws_doc_root"],
911914
bind_address,
912915
ssl_config=None)
913-
except Exception:
916+
except Exception as error:
917+
logger.critical(f"start_ws_server: Caught exception from WebSocketDaemon: {error}")
914918
startup_failed(logger)
915919

916920

@@ -922,7 +926,8 @@ def start_wss_server(logger, host, port, paths, routes, bind_address, config, **
922926
config.paths["ws_doc_root"],
923927
bind_address,
924928
config.ssl_config)
925-
except Exception:
929+
except Exception as error:
930+
logger.critical(f"start_wss_server: Caught exception from WebSocketDaemon: {error}")
926931
startup_failed(logger)
927932

928933

0 commit comments

Comments
 (0)