Skip to content

Fix/docker setup #206

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ only and should not be used in production.
```

- run `docker compose up`
- After Keycloak is up, open a second terminal window and run
`docker compose up keycloak-cli` to import a realm with all the users
and roles already set up.
- To set up our CouchDB server open `http://127.0.0.1:5984/_utils/#/setup`
and run the [Single Node Setup](https://docs.couchdb.org/en/stable/setup/single-node.html). This creates databases like **_users** and stops CouchDB from spamming our logs (Admin credentials from .env)
- Create a database in CouchDB with the name specified in `CSAF_COUCHDB_DBNAME`
Expand Down
97 changes: 67 additions & 30 deletions compose.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change the command in keycloak to get the real import to work

command:
  - start-dev
  - --import-realm
  - --verbose

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

services:
cms-couchdb:
image: couchdb:3.3
image: couchdb:3.4
hostname: couchdb.csaf.internal
#container_name: cms-couchdb
restart: on-failure
Expand All @@ -16,13 +16,18 @@ services:
- csaf-couchdb-data:/opt/couchdb/data
ports:
- "${CSAF_COUCHDB_PORT}:5984"
healthcheck:
test: ["CMD-SHELL", "curl http://127.0.0.1:5984/_up || exit 1"]
interval: 10s
timeout: 10s
retries: 10
networks:
default:
aliases:
- "couchdb.csaf.internal"

keycloak-db:
image: postgres:14
image: postgres:17
hostname: keycloak-db.csaf.internal
#container_name: keycloak-db
volumes:
Expand All @@ -35,31 +40,51 @@ services:
restart: on-failure
ports:
- "${CSAF_KEYCLOAK_DATABASE_PORT}:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${CSAF_KEYCLOAK_DATABASE_USER}"]
interval: 10s
timeout: 10s
retries: 10
networks:
default:
aliases:
- "keycloak-db.csaf.internal"

keycloak:
image: quay.io/keycloak/keycloak:20.0
image: quay.io/keycloak/keycloak:26.2
hostname: keycloak.csaf.internal
#container_name: keycloak
env_file: .env
environment:
# https://www.keycloak.org/server/all-config
KC_HEALTH_ENABLED: "true"
KC_METRICS_ENABLED: "true"
KC_DB: postgres
KC_DB_SCHEMA: public

KC_DB_URL_HOST: keycloak-db.csaf.internal
KC_DB_URL_PORT: 5432
KC_DB_URL_DATABASE: ${CSAF_KEYCLOAK_DATABASE_NAME}

KC_DB_USERNAME: ${CSAF_KEYCLOAK_DATABASE_USER}
KC_DB_PASSWORD: ${CSAF_KEYCLOAK_DATABASE_PASSWORD}
KC_DB_SCHEMA: public

KEYCLOAK_ADMIN: ${CSAF_KEYCLOAK_ADMIN_USER}
KEYCLOAK_ADMIN_PASSWORD: ${CSAF_KEYCLOAK_ADMIN_PASSWORD}

KEYCLOAK_EXTRA_ARGS: --import-realm
volumes:
- ./keycloak:/opt/bitnami/keycloak/data/import
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this entry to get the import work

volumes:
  - ./keycloak/csaf-realm.json:/opt/keycloak/data/import/realm.json:ro

healthcheck:
start_period: 120s
test:
["CMD-SHELL", "timeout 1 bash -c 'cat < /dev/null > /dev/tcp/localhost/8080'", ]
interval: 10s
timeout: 10s
retries: 10
depends_on:
- keycloak-db
keycloak-db:
condition: service_healthy
restart: true
restart: on-failure
ports:
- "${CSAF_KEYCLOAK_PORT}:8080"
Expand All @@ -68,22 +93,6 @@ services:
default:
aliases:
- "keycloak.csaf.internal"

# Run this manually to import the default keycloak config since 'depends_on' is currently broken.
keycloak-cli:
image: adorsys/keycloak-config-cli:latest-20.0.1
#container_name: keycloak-cli
profiles: [ "run_manually" ]
env_file: .env
environment:
KEYCLOAK_URL: "http://keycloak.csaf.internal:8080/"
KEYCLOAK_USER: ${CSAF_KEYCLOAK_ADMIN_USER}
KEYCLOAK_PASSWORD: ${CSAF_KEYCLOAK_ADMIN_PASSWORD}
IMPORT_FILES_LOCATIONS: "/config/csaf-realm.json"
volumes:
- ./keycloak:/config:z
depends_on:
- keycloak

oauth2-proxy:
image: bitnami/oauth2-proxy:7.4.0
Expand All @@ -95,7 +104,9 @@ services:
# listening address and proxy target
OAUTH2_PROXY_HTTP_ADDRESS: "0.0.0.0:4180"
OAUTH2_PROXY_UPSTREAMS: "http://host.docker.internal:${CSAF_CMS_BACKEND_PORT}/api/v1/"


OAUTH2_PROXY_REVERSE_PROXY: "true"

# Security related config
OAUTH2_PROXY_COOKIE_SECURE: "false"
OAUTH2_PROXY_COOKIE_HTTPONLY: "true"
Expand All @@ -108,9 +119,15 @@ services:
OAUTH2_PROXY_PROVIDER_DISPLAY_NAME: "CSAF OIDC Provider"
# You need to set your keycloak "Frontend URL", in our case "http://localhost:9000/auth/"
# If you don't want to use autodiscovery, you have to set all urls by hand (login-url, oidc-jwks-url, redeem-url, ...)

OAUTH2_PROXY_SKIP_OIDC_DISCOVERY: "true"
OAUTH2_PROXY_OIDC_ISSUER_URL: "http://keycloak.csaf.internal:8080/realms/${CSAF_REALM}"
OAUTH2_PROXY_LOGIN_URL: "http://localhost/realms/csaf/protocol/openid-connect/auth"
OAUTH2_PROXY_REDEEM_URL: "http://keycloak.csaf.internal:8080/realms/csaf/protocol/openid-connect/token"
OAUTH2_PROXY_OIDC_JWKS_URL: http://keycloak.csaf.internal:8080/realms/csaf/protocol/openid-connect/certs
OAUTH2_PROXY_INSECURE_OIDC_SKIP_ISSUER_VERIFICATION: "true"
OAUTH2_PROXY_WHITELIST_DOMAINS: "localhost:4180,localhost:8080"

OAUTH2_PROXY_WHITELIST_DOMAINS: "localhost:4180,localhost:8080,localhost,locahost:80"

# Client credentials
OAUTH2_PROXY_CLIENT_ID: ${CSAF_CLIENT_ID}
Expand All @@ -131,7 +148,8 @@ services:
- "host.docker.internal:host-gateway"
restart: on-failure
depends_on:
- keycloak
keycloak:
condition: service_healthy
networks:
default:
aliases:
Expand All @@ -145,6 +163,11 @@ services:
env_file: .env
ports:
- "$CSAF_VALIDATOR_PORT:8082"
healthcheck:
test: ["CMD-SHELL", "wget -O /dev/null http://127.0.0.1:8082/api/v1/tests || exit 1"]
interval: 10s
timeout: 10s
retries: 10
networks:
default:
aliases:
Expand All @@ -157,25 +180,39 @@ services:
hostname: secvisogram.csaf.internal
volumes:
- "./docker/secvisogram/appspecific:/usr/share/nginx/html/.well-known/appspecific"
healthcheck:
test: ["CMD-SHELL", "wget -O /dev/null http://127.0.0.1 || exit 1"]
interval: 10s
timeout: 10s
retries: 10
networks:
default:
aliases:
- "secvisogram.csaf.internal"


reverse-proxy:
image: nginx:1.23-alpine
image: nginx:1.27-alpine
hostname: "reverseproxy.csaf.internal"
restart: on-failure
ports:
- "80:80"
volumes:
- "./docker/reverseproxy/nginx.conf:/etc/nginx/nginx.conf"
healthcheck:
test: ["CMD-SHELL", "wget -O /dev/null http://127.0.0.1 || exit 1"]
interval: 10s
timeout: 10s
retries: 10
depends_on:
- secvisogram
- keycloak
- oauth2-proxy
- validator
secvisogram:
condition: service_healthy
keycloak:
condition: service_healthy
oauth2-proxy:
condition: service_started
validator:
condition: service_healthy

volumes:
csaf-couchdb-data:
Expand Down
2 changes: 1 addition & 1 deletion docker/secvisogram/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ RUN apk add git; \
# This build takes the production build from staging build
#

FROM nginx:1.23-alpine
FROM nginx:1.27-alpine
COPY --from=build /usr/src/secvisogram/app/dist /usr/share/nginx/html
EXPOSE 80
4 changes: 4 additions & 0 deletions keycloak/csaf-realm.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty "validator": [] entries lead to an error when initializing keycloack

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"adminUrl": "http://localhost",
"bearerOnly": false,
"clientAuthenticatorType": "client-secret",
"secret": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my environment (Rancher Desktop on Windows) this leads to an error :

keycloak-1 | 2025-05-19 07:36:52,523 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to run import
keycloak-1 | 2025-05-19 07:36:52,524 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT)
keycloak-1 | at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 7, column: 17] (through reference chain: org.keycloak.representations.idm.RealmRepresentation["clients"]->java.util.ArrayList[0]->org.keycloak.representations.idm.ClientRepresentation["secret"])
keycloak-1 | 2025-05-19 07:36:52,524 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.
Gracefully stopping... (press Ctrl+C again to force)
dependency failed to start: container csaf-cms-backend-keycloak-1 is unhealthy

"type": "password",
"value": "mDmZiwDL814MCTHJwySSiECRwcncIuHu"
},
"clientId": "secvisogram",
"consentRequired": false,
"directAccessGrantsEnabled": false,
Expand Down