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

explore: non-root user for docker #1589

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1c922bf
Update Dockerfile
eric-intuitem Mar 1, 2025
75bffc8
Delete readme.txt
eric-intuitem Mar 1, 2025
812de5e
restrict user for frontend
eric-intuitem Mar 1, 2025
c31aafb
Update Dockerfile
eric-intuitem Mar 1, 2025
e1299a5
Create readme.txt
eric-intuitem Mar 1, 2025
313e420
Update Dockerfile
eric-intuitem Mar 2, 2025
1c3e023
Update startup-tests.yml
eric-intuitem Mar 2, 2025
868380e
Update startup-tests.yml
eric-intuitem Mar 2, 2025
23033a4
another test
eric-intuitem Mar 2, 2025
3afce1d
Update startup-tests.yml
eric-intuitem Mar 2, 2025
de85136
Update Dockerfile
eric-intuitem Mar 2, 2025
282b343
Update Dockerfile
eric-intuitem Mar 2, 2025
7b6c64b
Update startup.sh
eric-intuitem Mar 2, 2025
8730446
Update startup.sh
eric-intuitem Mar 2, 2025
63493b1
Update startup-tests.yml
eric-intuitem Mar 2, 2025
7bd6bad
Update startup.sh
eric-intuitem Mar 2, 2025
f10016e
WIP
eric-intuitem Mar 2, 2025
5be9ca7
Update Dockerfile
eric-intuitem Mar 2, 2025
a9a824e
Update startup.sh
eric-intuitem Mar 2, 2025
1e0dd04
Update startup-tests.yml
eric-intuitem Mar 2, 2025
fda2d80
Update startup-tests.yml
eric-intuitem Mar 2, 2025
0cbd9b0
Update startup-tests.yml
eric-intuitem Mar 2, 2025
8448ac9
Update docker-compose-build.yml
eric-intuitem Mar 2, 2025
310df30
WIP
eric-intuitem Mar 2, 2025
fea748d
Update docker-compose-build.yml
eric-intuitem Mar 2, 2025
a010250
Update docker-compose-build.yml
eric-intuitem Mar 2, 2025
1c56c24
Update startup-tests.yml
eric-intuitem Mar 2, 2025
ddd432a
Update startup-tests.yml
eric-intuitem Mar 2, 2025
da79fb6
Update startup-tests.yml
eric-intuitem Mar 2, 2025
80bc579
WIP
eric-intuitem Mar 2, 2025
8399c9b
WIP
eric-intuitem Mar 2, 2025
0122617
Update startup-tests.yml
eric-intuitem Mar 2, 2025
7238cd7
Update Dockerfile
eric-intuitem Mar 2, 2025
f73b87e
Update startup-tests.yml
eric-intuitem Mar 2, 2025
3cf8ef0
WIP
eric-intuitem Mar 2, 2025
0b2bdb5
Update startup-tests.yml
eric-intuitem Mar 2, 2025
2cf5602
Update startup-tests.yml
eric-intuitem Mar 2, 2025
e2f0af6
Update Dockerfile
eric-intuitem Mar 2, 2025
233503d
WIP
eric-intuitem Mar 2, 2025
f7eab93
Update Dockerfile
eric-intuitem Mar 2, 2025
eebfb33
Update docker-compose-build.yml
eric-intuitem Mar 2, 2025
edbded1
WIP
eric-intuitem Mar 2, 2025
fe24b8a
Update Dockerfile
eric-intuitem Mar 2, 2025
4eb4255
Update startup-tests.yml
eric-intuitem Mar 2, 2025
ae131bb
Update startup-tests.yml
eric-intuitem Mar 2, 2025
aa2c37d
Update startup-tests.yml
eric-intuitem Mar 2, 2025
c9b7d56
Update docker-compose-build.yml
eric-intuitem Mar 2, 2025
de2ddb7
Update Dockerfile
eric-intuitem Mar 3, 2025
95cc9a8
use docker named volume instead of mount-dir
eric-intuitem Mar 3, 2025
b9dc1e9
WIP
eric-intuitem Mar 3, 2025
5afd278
Update startup-tests.yml
eric-intuitem Mar 3, 2025
10df56d
Update docker-compose-build.yml
eric-intuitem Mar 3, 2025
0776d4a
use volume for EE
eric-intuitem Mar 3, 2025
e64123e
fix EE test
eric-intuitem Mar 3, 2025
feb3bf0
use volume for docker-compose.sh
eric-intuitem Mar 3, 2025
8df65e3
use volume for docker-compose.sh
eric-intuitem Mar 4, 2025
944634d
Update docker-compose-build.yml
eric-intuitem Mar 4, 2025
9dfae46
add sudo and update doc
eric-intuitem Mar 4, 2025
62bb591
WIP
eric-intuitem Mar 4, 2025
22be866
WIP
eric-intuitem Mar 4, 2025
ebbb275
Update docker-compose-build.yml
eric-intuitem Mar 4, 2025
df74261
WIP
eric-intuitem Mar 4, 2025
443c449
Merge branch 'main' into fix/docker-app-user
eric-intuitem Mar 4, 2025
c5ca2a0
WIP
eric-intuitem Mar 4, 2025
6ac2f2c
fix codefactor-detected error
eric-intuitem Mar 4, 2025
f9f2b2c
fix EE
eric-intuitem Mar 4, 2025
4e03efd
Update README.md
eric-intuitem Mar 5, 2025
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
15 changes: 10 additions & 5 deletions .github/workflows/startup-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ jobs:
run: pnpm exec playwright install
- name: Build the Docker app
run: |
rm -rf db
mkdir db
docker compose -f docker-compose-build.yml up -d
- name: Create backend environment variables file
working-directory: ${{ env.backend-directory }}
Expand All @@ -143,7 +141,10 @@ jobs:
export $(grep -v '^#' .env | xargs)
- name: Config the Docker app
run: |
sleep 120 # give the migrations time to finish (included in the up on the previous step)
until docker compose -f docker-compose-build.yml exec -T backend curl -f http://localhost:8000/api/build >/dev/null 2>&1; do
echo "Backend is not ready - waiting 10s..."
sleep 10
done
docker compose -f docker-compose-build.yml exec backend /bin/bash -c "[email protected] DJANGO_SUPERUSER_PASSWORD=1234 poetry run python manage.py createsuperuser --noinput && exit 0"
- name: Run tests
working-directory: ${{ env.frontend-directory }}
Expand Down Expand Up @@ -270,15 +271,19 @@ jobs:
working-directory: ${{ env.enterprise-frontend-build-directory }}
run: pnpm exec playwright install
- name: Build the Docker app
run: docker compose -f enterprise/docker-compose-build.yml up -d
run: |
docker compose -f enterprise/docker-compose-build.yml up -d
- name: Create backend environment variables file
working-directory: ${{ env.backend-directory }}
run: |
touch .env
export $(grep -v '^#' .env | xargs)
- name: Config the Docker app
run: |
sleep 120 # give the migrations time to finish (included in the up on the previous step)
until docker compose -f enterprise/docker-compose-build.yml exec -T backend curl -f http://localhost:8000/api/build >/dev/null 2>&1; do
echo "Backend is not ready - waiting 10s..."
sleep 10
done
docker compose -f enterprise/docker-compose-build.yml exec backend /bin/bash -c "[email protected] DJANGO_SUPERUSER_PASSWORD=1234 poetry run python manage.py createsuperuser --noinput --settings=${{ env.enterprise-backend-settings-module }} && exit 0"
- name: Run tests
working-directory: ${{ env.frontend-directory }}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ For the following executions, use "docker compose up" directly.
> [!TIP]
> If you want a fresh install, simply delete the `db` directory, (default: backend/db) where the database is stored.

> [!Note]
> For docker compose under Linux, using a bind-mount, it is necessary to do `chown 1001:1001 db`.

## Docker-compose on remote

For docker setup on a remote server or hypervisor, checkout the [specific instructions here](https://intuitem.gitbook.io/ciso-assistant/deployment/remote-virtualization)
Expand Down
6 changes: 5 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ENV PYTHONUNBUFFERED=1 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
POETRY_CACHE_DIR=/tmp/poetry_cache \
HOME=/tmp/

WORKDIR /code

Expand Down Expand Up @@ -47,6 +48,9 @@ RUN poetry install --no-root \

#watch out for local files during dev and maintenance of .dockerignore
COPY . .
RUN groupadd --gid 1001 app && useradd --uid 1001 --gid 1001 app && mkdir -p /code/db && chown 1001:1001 /code/db
USER app
VOLUME /code/db

EXPOSE 8000
ENTRYPOINT ["poetry", "run", "bash", "startup.sh"]
38 changes: 17 additions & 21 deletions docker-compose-build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

DOCKER_COMPOSE_FILE=docker-compose-build.yml
DOCKER_COMPOSE_FILE="${1:-docker-compose-build.yml}"

prepare_meta_file() {
VERSION=$(git describe --tags --always)
Expand All @@ -16,28 +16,24 @@ prepare_meta_file() {
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1

# Check if database already exists
if [ -f db/ciso-assistant.sqlite3 ]; then
echo "The database seems already created."
echo "For successive runs, you can now use 'docker compose up'."
else
prepare_meta_file
prepare_meta_file

# Build and start the containers
echo "Building containers..."
docker compose -f "${DOCKER_COMPOSE_FILE}" build --pull
# Build and start the containers
echo "Building containers..."
docker compose -f "${DOCKER_COMPOSE_FILE}" build --pull

echo "Starting services..."
docker compose -f "${DOCKER_COMPOSE_FILE}" up -d
echo "Starting services..."
docker compose -f "${DOCKER_COMPOSE_FILE}" up -d

# Simple wait for database migrations
echo "Giving some time for the database to be ready, please wait ..."
sleep 50
echo "Waiting for CISO Assistant backend to be ready..."
until docker compose -f "${DOCKER_COMPOSE_FILE}" exec -T backend curl -f http://localhost:8000/api/build >/dev/null 2>&1; do
echo "Backend is not ready - waiting 10s..."
sleep 10
done

echo "Initialize your superuser account..."
docker compose exec backend poetry run python manage.py createsuperuser
echo "Initialize your superuser account..."
docker compose -f "${DOCKER_COMPOSE_FILE}" exec backend poetry run python manage.py createsuperuser

echo "🚀 CISO Assistant is ready!"
echo "Connect to CISO Assistant on https://localhost:8443"
echo "For successive runs, you can now use 'docker compose up'."
fi
echo "🚀 CISO Assistant is ready!"
echo "Connect to CISO Assistant on https://localhost:8443"
echo "For successive runs, you can now use 'docker compose -f ${DOCKER_COMPOSE_FILE} up -d'."
9 changes: 6 additions & 3 deletions docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
volumes:
db:
caddy_data:
services:
backend:
container_name: backend
Expand All @@ -10,7 +13,7 @@ services:
- CISO_ASSISTANT_URL=https://localhost:8443
- DJANGO_DEBUG=True
volumes:
- ./db:/code/db
- db:/code/db

huey:
container_name: huey
Expand All @@ -25,7 +28,7 @@ services:
- CISO_ASSISTANT_URL=https://localhost:8443
- DJANGO_DEBUG=False
volumes:
- ./db:/code/db
- db:/code/db
entrypoint:
- /bin/sh
- -c
Expand Down Expand Up @@ -55,7 +58,7 @@ services:
ports:
- 8443:8443
volumes:
- ./db:/data
- caddy_data:/data
command: |
sh -c 'echo $$CISO_ASSISTANT_URL "{
reverse_proxy /api/* backend:8000
Expand Down
7 changes: 1 addition & 6 deletions docker-compose.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#! /bin/bash
set -euo pipefail

DOCKER_COMPOSE_FILE=docker-compose.yml
if [ -d ./db ]; then
echo "The database seems already created. You should launch 'docker compose up -d' instead."
echo "For a clean start, you can remove the db folder, and then run 'docker compose rm -fs' and start over"
exit 1
fi
echo "Starting CISO Assistant services..."
docker compose pull
echo "Initializing the database. This can take up to 2 minutes, please wait.."
Expand All @@ -24,3 +18,4 @@ docker compose exec backend poetry run python manage.py createsuperuser

echo -e "Initialization complete!"
echo "You can now access CISO Assistant at https://localhost:8443 (or the host:port you've specified)"

9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
volumes:
db:
caddy_data:
services:
backend:
container_name: backend
Expand All @@ -11,7 +14,7 @@ services:
- AUTH_TOKEN_TTL=7200

volumes:
- ./db:/code/db
- db:/code/db
healthcheck:
test: ["CMD-SHELL", "curl -f http://backend:8000/api/build || exit 1"]
interval: 10s
Expand All @@ -34,7 +37,7 @@ services:
- AUTH_TOKEN_TTL=7200

volumes:
- ./db:/code/db
- db:/code/db
entrypoint:
- /bin/sh
- -c
Expand Down Expand Up @@ -66,7 +69,7 @@ services:
ports:
- 8443:8443
volumes:
- ./caddy_data:/data
- caddy_data:/data
command: |
sh -c 'echo $$CISO_ASSISTANT_URL "{
reverse_proxy /api/* backend:8000
Expand Down
4 changes: 2 additions & 2 deletions enterprise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ New: use the config builder on the `config` folder.

To run CISO Assistant Enterprise locally in a straightforward way, you can use Docker compose.

1. Make sure you are located in the enterprise directory of the repository
1. Make sure you are located in the top directory of the repository

2. Launch docker-compose script with enterprise docker-compose.yml file:

```sh
./docker-compose-build.sh -f enterprise/docker-compose-build.yml
docker compose-build.sh enterprise/docker-compose-build.yml
```

When asked for, enter your email and password for your superuser.
Expand Down
7 changes: 6 additions & 1 deletion enterprise/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ENV PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
DJANGO_SETTINGS_MODULE=enterprise_core.settings
DJANGO_SETTINGS_MODULE=enterprise_core.settings \
HOME=/tmp

WORKDIR /code

Expand Down Expand Up @@ -53,5 +54,9 @@ COPY backend /code/
COPY enterprise/backend/enterprise_core /code/enterprise_core
COPY backend/startup.sh /code/

RUN groupadd --gid 1001 app && useradd --uid 1001 --gid 1001 app && mkdir -p /code/db && chown 1001:1001 /code/db
USER app
VOLUME /code/db

EXPOSE 8000
ENTRYPOINT ["poetry", "run", "bash", "startup.sh"]
11 changes: 8 additions & 3 deletions enterprise/docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
volumes:
db:
caddy_data:
services:
backend:
container_name: backend
Expand All @@ -13,21 +16,23 @@ services:
- LICENSE_EXPIRATION=2025-12-21
- DJANGO_SETTINGS_MODULE=enterprise_core.settings
volumes:
- ./db:/code/db
- db:/code/db

huey:
container_name: huey
build:
context: ../
dockerfile: ./enterprise/backend/Dockerfile
depends_on:
- backend
restart: always
environment:
- ALLOWED_HOSTS=backend,localhost
- DJANGO_DEBUG=True
- LICENSE_SEATS=5
- LICENSE_EXPIRATION=2025-12-21
volumes:
- ./db:/code/db
- db:/code/db
entrypoint:
- /bin/sh
- -c
Expand Down Expand Up @@ -57,7 +62,7 @@ services:
ports:
- 8443:8443
volumes:
- ./db:/data
- caddy_data:/data
command: |
sh -c 'echo $$CISO_ASSISTANT_URL "{
reverse_proxy /api/* backend:8000
Expand Down
4 changes: 4 additions & 0 deletions enterprise/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ COPY frontend/package.json .
EXPOSE 3000
ENV NODE_ENV=production
ENV BODY_SIZE_LIMIT=20000000

RUN addgroup -g 1001 app && adduser -u 1001 -G app -D app
USER app

CMD [ "node", "server" ]
3 changes: 2 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ COPY package.json .
EXPOSE 3000
ENV NODE_ENV=production
ENV BODY_SIZE_LIMIT=20000000

RUN addgroup -g 1001 app && adduser -u 1001 -G app -D app
USER app

CMD [ "node", "server" ]
Loading