Skip to content
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

267 make server more secure #324

Merged
merged 26 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
db76c46
#267 backend: new deployment that hopefully runs https
Toni000 Jul 10, 2024
9372041
267: clean up frontend url and vite server url
Toni000 Jul 10, 2024
aa3b9bf
#267: change vite server url based on dev/prod
Toni000 Jul 10, 2024
f732a2a
#267: update prod env files
Toni000 Jul 10, 2024
ba89627
#267: clean up frontend env vars
Toni000 Jul 10, 2024
74e287c
#267: remove args from frontend docker-compose
Toni000 Jul 10, 2024
66ff9ac
#267: fix run config issue
Toni000 Jul 10, 2024
ce2febd
#267: persist frontend env vars in image
Toni000 Jul 10, 2024
16f3e45
#267: fix cypress tests
Toni000 Jul 10, 2024
5e670aa
#267 backend: fix CORS error
Toni000 Jul 10, 2024
e3b0e02
#267: split deploy compose setup to fix tests
Toni000 Jul 10, 2024
062061c
#267: fix image tags not working
Toni000 Jul 10, 2024
973f578
#267: fix error in preparing deployment files
Toni000 Jul 10, 2024
0cc93b2
#267: create another nginx.conf for dev deploy
Toni000 Jul 10, 2024
5893268
#267: add ports to websocket URLs
Toni000 Jul 10, 2024
1af4860
#267 frontend: fix env variables for non-docker execution
Wolkenfarmer Jul 10, 2024
afe20af
Merge branch 'refs/heads/main' into 267-making-the-server-more-secure
Wolkenfarmer Jul 10, 2024
db75b47
#267 frontend: fix environment variable access in dockerized environm…
Wolkenfarmer Jul 10, 2024
194c090
#267: ignore inconsequential warning in ci
Wolkenfarmer Jul 10, 2024
e66f708
#267 frontend: resolve hmr error when running dockerized in dev mode
Wolkenfarmer Jul 11, 2024
7f52a08
#267 frontend: disable hmr in dockerized environments
Wolkenfarmer Jul 11, 2024
f490250
#267 frontend: set correct hmr host depending on host environment
Wolkenfarmer Jul 11, 2024
35a5a69
#267: adjustments after review and slightly changed prod docker-compose
Toni000 Jul 11, 2024
0c69432
#267 backend: fix patient information import not using defaults
Toni000 Jul 11, 2024
df44eb6
#267 backend: fix initialization issue when using defaults
Toni000 Jul 11, 2024
437705b
#267 backend: fix fixture starting with pk 2
Toni000 Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=dps

FRONTEND_URL=localhost
2 changes: 0 additions & 2 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=ozuCk0rrF6nzkzcR1TQMR93m3iYUzMBG

FRONTEND_URL=klinik-dps.de
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- name: Run docker containers with deploy dev configuration
run: |
docker-compose --env-file .env.dev up -d
docker-compose -f docker-compose.dev.yml up -d

- name: Run integration tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ jobs:
- name: Prepare deployment files
run: |
mkdir deployment_files
cp docker-compose.yml deployment_files/
cp docker-compose.prod.yml deployment_files/docker-compose.yml
cp ./.env.prod deployment_files/
cp ./.env.dev deployment_files/
cp backend/dps_training_k/deployment/nginx/nginx_deploy_prod.conf deployment_files/nginx.conf

- name: Archive deployment files
uses: actions/upload-artifact@v2
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Replace `<prod/dev>` with `prod` or `dev` in the following commands to use the r
/docker-compose.yml, ./.env.<prod/dev>).
2. Recommended: As the env files are probably stored in a public repository, it is strongly encouraged to change the SECRET_KEY and the
POSTGRES_PASSWORD variables in the used `.env.<prod/dev>` file.
3. Log into the GitHub Packages registry with the following command. Ask a team member for valid credentials.
3. Log into the GitHub Packages registry with the following command. Ask a team member for valid credentials. Note: passing secrets as
command line arguments is insecure. consider using `--password-stdin` instead
```bash
docker login ghcr.io -u <username> -p <token>
```
Expand All @@ -43,8 +44,8 @@ The application is now deployed and the website should be accessible on port 517
the containers restarted accordingly.

Keep in mind that the IP address of the server running the back- and frontend are hardcoded in the environment files. For
the backend a simple correction of the `FRONTEND_URL` variable within the `.env.<prod/dev>` file on the server is enough, but fot the frontend the
`SERVER_URL` variable (and `VITE_SERVER_URL` variable for building without docker) has to be adjusted in the associated env file and the image has
the backend a simple correction of the `CORS_ALLOWED_ORIGINS` variable within the `backend/dps_training_k/configuration/settings.py` file on the
server is enough, but for the frontend the `VITE_SERVER_URL` variable has to be adjusted in the associated env file and the image has
to be rebuilt and re-uploaded to the GitHub Packages registry.

## Changing the project configuration
Expand Down
2 changes: 0 additions & 2 deletions backend/dps_training_k/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=dps

FRONTEND_URL=localhost
2 changes: 0 additions & 2 deletions backend/dps_training_k/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=ozuCk0rrF6nzkzcR1TQMR93m3iYUzMBG

FRONTEND_URL=localhost
11 changes: 1 addition & 10 deletions backend/dps_training_k/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG")
CORS_ORIGIN_ALLOW_ALL = DEBUG
CORS_ALLOWED_ORIGINS = ["http://" + env.str("FRONTEND_URL") + ":5173"]
CORS_ALLOWED_ORIGINS = ["https://klinik-dps.de", "https://www.klinik-dps.de", "http://localhost"]
Toni000 marked this conversation as resolved.
Show resolved Hide resolved
RUN_CONFIG = env.str("RUN_CONFIG", default="dev")

CSRF_TRUSTED_ORIGINS = ["http://localhost:8000"]
Expand All @@ -50,7 +50,6 @@
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
"game.apps.GameConfig",
"helpers.apps.GameConfig",
Expand Down Expand Up @@ -134,12 +133,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

Expand All @@ -163,8 +156,6 @@

AUTH_USER_MODEL = "game.User"

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

# Celery
# ------------------------------------------------------------------------------
# See: http://docs.celeryproject.org/en/latest/userguide/configuration.html
Expand Down
1 change: 0 additions & 1 deletion backend/dps_training_k/deployment/django/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if [ "${RUN_MIGRATIONS:-0}" = "1" ]; then

python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py import_actions
python manage.py import_patient_information
python manage.py loaddata patient_states.json
Expand Down
3 changes: 1 addition & 2 deletions backend/dps_training_k/deployment/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
RUN rm /etc/nginx/conf.d/default.conf
33 changes: 14 additions & 19 deletions backend/dps_training_k/deployment/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
upstream configuration {
server django:8000;
}

server {

listen 80;

location / {
proxy_pass http://configuration;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_redirect off;
}


location /static/ {
alias /app/staticfiles/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /media/ {
alias /app/mediafiles/;
location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

}
30 changes: 30 additions & 0 deletions backend/dps_training_k/deployment/nginx/nginx_deploy_dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
server {
listen 80;

location / {
Toni000 marked this conversation as resolved.
Show resolved Hide resolved
proxy_pass http://frontend:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
39 changes: 39 additions & 0 deletions backend/dps_training_k/deployment/nginx/nginx_deploy_prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
server {
listen 80;
server_name klinik-dps.de www.klinik-dps.de;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name klinik-dps.de www.klinik-dps.de;

ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;

location / {
proxy_pass http://frontend:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
7 changes: 4 additions & 3 deletions backend/dps_training_k/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ services:
volumes:
- static_volume:/app/staticfiles
- .:/app:z
expose:
- 8000
ports:
- 8000:8000
command: uvicorn configuration.asgi:application --host 0.0.0.0 --reload
stdin_open: true
tty: true
Expand Down Expand Up @@ -82,8 +82,9 @@ services:
container_name: K-dPS-nginx
volumes:
- static_volume:/app/staticfiles
- ./deployment/nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
ports:
- "8000:80"
- "80:80"
depends_on:
- django

Expand Down
4 changes: 2 additions & 2 deletions backend/dps_training_k/game/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from django.urls import path

urlpatterns = [
path("patient/access", PatientAccessView.as_view(), name="patient-access"),
path("trainer/login", TrainerLoginView.as_view(), name="trainer-login")
path("api/patient/access", PatientAccessView.as_view(), name="patient-access"),
Toni000 marked this conversation as resolved.
Show resolved Hide resolved
path("api/trainer/login", TrainerLoginView.as_view(), name="trainer-login")
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ def import_patients(file_path):

patient_information, _ = PatientInformation.objects.update_or_create(
code=row["Pat-Nr."].strip(),
personal_details=row["Personalien"].strip(),
blood_type=row["Blutgruppe"].strip(),
injury=row["Verletzungen"].strip(),
biometrics=biometrics,
triage=triage,
consecutive_unique_number=consecutiveUniqueNumber,
mobility=row["Mobilität"].strip(),
preexisting_illnesses=row["Vorerkrankungen"].strip(),
permanent_medication=row["Dauer-Medikation"].strip(),
current_case_history=row[
"Aktuelle Anamnese / Rettungsdienst-Übergabe"
].strip(),
pretreatment=row["Vorbehandlung"].strip(),
start_status=row["Start-Status"].strip(),
start_location=row["Start-Ort"].strip(),
op=row["OP / Interventions-Verlauf"].strip(),
defaults={
"personal_details": row["Personalien"].strip(),
"blood_type": row["Blutgruppe"].strip(),
"injury": row["Verletzungen"].strip(),
"biometrics": biometrics,
"triage": triage,
"consecutive_unique_number": consecutiveUniqueNumber,
"mobility": row["Mobilität"].strip(),
"preexisting_illnesses": row["Vorerkrankungen"].strip(),
"permanent_medication": row["Dauer-Medikation"].strip(),
"current_case_history": row[
"Aktuelle Anamnese / Rettungsdienst-Übergabe"
].strip(),
"pretreatment": row["Vorbehandlung"].strip(),
"pretreatment_action_templates": {},
"start_status": row["Start-Status"].strip(),
"start_location": row["Start-Ort"].strip(),
"op": row["OP / Interventions-Verlauf"].strip(),
}
)
pretreatments_list = [
pt.strip() for pt in patient_information.pretreatment.split(",")
Expand Down
Loading
Loading