Skip to content

Commit 83553de

Browse files
authored
Merge pull request #195 from secvisogram/fix/hostdockerinternal
Fix/hostdockerinternal
2 parents 24144fb + 24373f8 commit 83553de

File tree

7 files changed

+231
-27
lines changed

7 files changed

+231
-27
lines changed

README.md

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,94 @@ If you want different passwords, database names or ports you can change them
8787
in that file. Please note that the following setup is for development purposes
8888
only and should not be used in production.
8989

90+
```mermaid
91+
C4Component
92+
title Component diagram for CSAF CMS Backend
93+
94+
Person(user,"User")
95+
Container(reverseproxy, "Reverse-Proxy", "nginx")
96+
97+
Container_Boundary(c4, "Internal") {
98+
Container(secvisogram, "Secvisogram", "nginx + javascript", "Provides secvisogramm via their web browser.")
99+
100+
Container_Boundary(c2, "Keycloak") {
101+
Container(keycloak, "Keycloak", "keycloak")
102+
ContainerDb(keycloak-db, "PostGreSQL", "Keycloak-Database")
103+
}
104+
105+
Container_Boundary(c3, "Oauth") {
106+
Container(oauth, "OAuth2-Proxy", "Authentication for REST-API")
107+
Container(validator, "CSAF validator service", "node")
108+
109+
Container_Boundary(c1, "Backend") {
110+
Container(backend, "CSAF-CMS-Backend", "Spring Boot")
111+
ContainerDb(backend-db, "CouchDB", "CMS-Backend-Database")
112+
}
113+
}
114+
}
115+
116+
Rel(user, reverseproxy,"","HTTPS")
117+
Rel(reverseproxy, secvisogram,"/")
118+
Rel(reverseproxy, oauth,"/api/*")
119+
Rel(reverseproxy, keycloak,"/realm/csaf/")
120+
Rel(oauth, validator, "/api/v1/test")
121+
Rel(oauth, validator, "/api/v1/validate")
122+
Rel(oauth, backend, "/api/v1/advisories/*")
123+
Rel(backend, backend-db,"")
124+
Rel(backend, keycloak,"")
125+
Rel(keycloak, keycloak-db,"")
126+
127+
128+
```
129+
90130
- run `docker compose up`
91131
- After Keycloak is up, open a second terminal window and run
92132
`docker compose up csaf-keycloak-cli` to import a realm with all the users
93133
and roles already set up.
94134
- To set up our CouchDB server open `http://127.0.0.1:5984/_utils/#/setup`
95-
and run the [Single Node Setup](https://docs.couchdb.org/en/stable/setup/single-node.html). This creates databases like **_users** and
96-
stops CouchDB from spamming our logs
135+
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)
136+
- Create a database in CouchDB with the name specified in `CSAF_COUCHDB_DBNAME`
97137
- Open `http://localhost:9000/` and log in with the admin user.
98138
- The port is defined in .env - CSAF_KEYCLOAK_PORT, default 9000
139+
- Select `CSAF`-Realm
99140
- On the left side, navigate to "Clients" and select the Secvisogram client.
100141
- Select the **Credentials** tab and copy the Secret. This is our
101142
`CSAF_CLIENT_SECRET` environment variable.
102143
- [Generate a cookie secret](https://oauth2-proxy.github.io/oauth2-proxy/docs/configuration/overview/#generating-a-cookie-secret)
103144
and paste it in `CSAF_COOKIE_SECRET`.
104-
- Create a database in CouchDB with the name specified in `CSAF_COUCHDB_DBNAME`
105145
- restart compose
106146
- (required for exports) install [pandoc (tested with version 2.18)](https://pandoc.org/installing.html)
107147
as well as [weasyprint (tested with version 56.0)](https://weasyprint.org/) and make sure both are in
108148
your PATH
109149
- (optional for exports) define the path to a company logo that should be used in the exports through the environment variable `CSAF_COMPANY_LOGO_PATH`. The path can either be relative to the project root or absolute. See .env.example file for an example.
110150

111151
You should now be able to start the spring boot application, navigate to
112-
`localhost:4180/api/v1/about`, log in with one of the users and get a
152+
`http://localhost/api/v1/about`, log in with one of the users and get a
113153
response from the server.
114-
The port is defined in .env - CSAF_APP_EXTERNAL_PORT, default 4180
154+
155+
You should now be able to access Secvisogram, navigate to `http://localhost/`.
156+
There are the following default users:
157+
|User |Password |Roles |
158+
|----- |-------- |----- |
159+
|registered |registered |**registered** |
160+
|author |author |registered, editor, **author** |
161+
|editor |editor |registered, **editor** |
162+
|publisher |publisher |registered, editor, **publisher** |
163+
|reviewer |reviewer |registered, **reviewer** |
164+
|auditor |auditor |**auditor** |
165+
|all |all |**auditor, reviewer, publisher, editor, author, registred** |
166+
|none |none | |
167+
168+
### Login & Logout in combination with Secvisogram
169+
170+
Some explantion on the logoutUrl configured in `.well-known/appspecific/de.bsi.secvisogram.json` for Secvisogram
171+
172+
```
173+
"logoutUrl": "/oauth2/sign_out?rd=http://localhost/realms/csaf/protocol/openid-connect/logout?post_logout_redirect_uri=http%3A%2F%2Flocalhost&client_id=secvisogram",
174+
```
175+
176+
`/oauth2/sign_out` is the logout URI from the OAUTH-Proxy. This will invalidate the session on the proxy. Then, a redirect to Keycloak (`http://localhost/realms/csaf/protocol/openid-connect/logout?post_logout_redirect_uri=http%3A%2F%2Flocalhost&client_id=secvisogram`) is necessary to log out from the session on Keyloak. Subsequently, there is a redirect back to Secvisogram (`localhost`).
177+
When hostnames are changed, this has to adapted.
115178

116179
### build and execute tests
117180

compose.yaml

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
###############################################################################
44

55
services:
6-
csaf-couchdb:
6+
cms-couchdb:
77
image: couchdb:3.3
8-
container_name: csaf-couchdb
8+
hostname: couchdb.csaf.internal
9+
#container_name: cms-couchdb
910
restart: on-failure
1011
env_file: .env
1112
environment:
@@ -15,10 +16,15 @@ services:
1516
- csaf-couchdb-data:/opt/couchdb/data
1617
ports:
1718
- "${CSAF_COUCHDB_PORT}:5984"
19+
networks:
20+
default:
21+
aliases:
22+
- "couchdb.csaf.internal"
1823

19-
csaf-keycloak-db:
24+
keycloak-db:
2025
image: postgres:14
21-
container_name: csaf-keycloak-db
26+
hostname: keycloak-db.csaf.internal
27+
#container_name: keycloak-db
2228
volumes:
2329
- csaf-keycloak-db-data:/var/lib/postgresql/data
2430
env_file: .env
@@ -29,17 +35,22 @@ services:
2935
restart: on-failure
3036
ports:
3137
- "${CSAF_KEYCLOAK_DATABASE_PORT}:5432"
38+
networks:
39+
default:
40+
aliases:
41+
- "keycloak-db.csaf.internal"
3242

33-
csaf-keycloak:
43+
keycloak:
3444
image: quay.io/keycloak/keycloak:20.0
35-
container_name: csaf-keycloak
45+
hostname: keycloak.csaf.internal
46+
#container_name: keycloak
3647
env_file: .env
3748
environment:
3849
# https://www.keycloak.org/server/all-config
3950
KC_HEALTH_ENABLED: "true"
4051
KC_METRICS_ENABLED: "true"
4152
KC_DB: postgres
42-
KC_DB_URL_HOST: csaf-keycloak-db
53+
KC_DB_URL_HOST: keycloak-db.csaf.internal
4354
KC_DB_URL_PORT: 5432
4455
KC_DB_URL_DATABASE: ${CSAF_KEYCLOAK_DATABASE_NAME}
4556
KC_DB_USERNAME: ${CSAF_KEYCLOAK_DATABASE_USER}
@@ -48,36 +59,42 @@ services:
4859
KEYCLOAK_ADMIN: ${CSAF_KEYCLOAK_ADMIN_USER}
4960
KEYCLOAK_ADMIN_PASSWORD: ${CSAF_KEYCLOAK_ADMIN_PASSWORD}
5061
depends_on:
51-
- csaf-keycloak-db
62+
- keycloak-db
5263
restart: on-failure
5364
ports:
5465
- "${CSAF_KEYCLOAK_PORT}:8080"
5566
command: ["start-dev"] # https://www.keycloak.org/server/configuration#_starting_keycloak_in_production_mode
56-
67+
networks:
68+
default:
69+
aliases:
70+
- "keycloak.csaf.internal"
71+
5772
# Run this manually to import the default keycloak config since 'depends_on' is currently broken.
58-
csaf-keycloak-cli:
73+
keycloak-cli:
5974
image: adorsys/keycloak-config-cli:latest-20.0.1
60-
container_name: csaf-keycloak-cli
75+
#container_name: keycloak-cli
6176
profiles: [ "run_manually" ]
6277
env_file: .env
6378
environment:
64-
KEYCLOAK_URL: "http://csaf-keycloak:8080/"
79+
KEYCLOAK_URL: "http://keycloak.csaf.internal:8080/"
6580
KEYCLOAK_USER: ${CSAF_KEYCLOAK_ADMIN_USER}
6681
KEYCLOAK_PASSWORD: ${CSAF_KEYCLOAK_ADMIN_PASSWORD}
6782
IMPORT_FILES_LOCATIONS: "/config/csaf-realm.json"
6883
volumes:
6984
- ./keycloak:/config:z
70-
restart: on-failure
85+
depends_on:
86+
- keycloak
7187

72-
csaf-oauth2-proxy:
88+
oauth2-proxy:
7389
image: bitnami/oauth2-proxy:7.4.0
74-
container_name: csaf-oauth2-proxy
90+
hostname: oauth2.csaf.internal
91+
#container_name: oauth2-proxy
7592
command: [""]
7693
env_file: .env
7794
environment:
7895
# listening address and proxy target
7996
OAUTH2_PROXY_HTTP_ADDRESS: "0.0.0.0:4180"
80-
OAUTH2_PROXY_UPSTREAMS: "http://host.docker.internal:${CSAF_VALIDATOR_PORT}/api/v1/validate,http://host.docker.internal:${CSAF_VALIDATOR_PORT}/api/v1/tests,http://host.docker.internal:${CSAF_CMS_BACKEND_PORT}/api/v1/"
97+
OAUTH2_PROXY_UPSTREAMS: "http://host.docker.internal:${CSAF_CMS_BACKEND_PORT}/api/v1/"
8198

8299
# Security related config
83100
OAUTH2_PROXY_COOKIE_SECURE: "false"
@@ -91,7 +108,7 @@ services:
91108
OAUTH2_PROXY_PROVIDER_DISPLAY_NAME: "CSAF OIDC Provider"
92109
# You need to set your keycloak "Frontend URL", in our case "http://localhost:9000/auth/"
93110
# If you don't want to use autodiscovery, you have to set all urls by hand (login-url, oidc-jwks-url, redeem-url, ...)
94-
OAUTH2_PROXY_OIDC_ISSUER_URL: "http://csaf-keycloak:8080/realms/${CSAF_REALM}"
111+
OAUTH2_PROXY_OIDC_ISSUER_URL: "http://keycloak.csaf.internal:8080/realms/${CSAF_REALM}"
95112
OAUTH2_PROXY_INSECURE_OIDC_SKIP_ISSUER_VERIFICATION: "true"
96113
OAUTH2_PROXY_WHITELIST_DOMAINS: "localhost:4180,localhost:8080"
97114

@@ -113,16 +130,53 @@ services:
113130
extra_hosts:
114131
- "host.docker.internal:host-gateway"
115132
restart: on-failure
116-
117-
csaf-validation-server:
133+
depends_on:
134+
- keycloak
135+
networks:
136+
default:
137+
aliases:
138+
- "oauth2.csaf.internal"
139+
140+
validator:
118141
build:
119142
context: https://github.com/secvisogram/csaf-validator-service.git#main
120-
container_name: csaf-validation-server
143+
#container_name: validator
144+
hostname: validator.csaf.internal
121145
env_file: .env
122146
ports:
123147
- "$CSAF_VALIDATOR_PORT:8082"
148+
networks:
149+
default:
150+
aliases:
151+
- "validator.csaf.internal"
124152

153+
secvisogram:
154+
build:
155+
context: ./docker/secvisogram
156+
dockerfile: Dockerfile
157+
hostname: secvisogram.csaf.internal
158+
volumes:
159+
- "./docker/secvisogram/appspecific:/usr/share/nginx/html/.well-known/appspecific"
160+
networks:
161+
default:
162+
aliases:
163+
- "secvisogram.csaf.internal"
164+
125165

166+
reverse-proxy:
167+
image: nginx:1.23-alpine
168+
hostname: "reverseproxy.csaf.internal"
169+
restart: on-failure
170+
ports:
171+
- "80:80"
172+
volumes:
173+
- "./docker/reverseproxy/nginx.conf:/etc/nginx/nginx.conf"
174+
depends_on:
175+
- secvisogram
176+
- keycloak
177+
- oauth2-proxy
178+
- validator
179+
126180
volumes:
127181
csaf-couchdb-data:
128182
driver: local

docker/reverseproxy/nginx.conf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
worker_processes 1;
2+
3+
events { worker_connections 1024; }
4+
5+
http {
6+
sendfile on;
7+
8+
proxy_set_header Host $host;
9+
proxy_set_header X-Real-IP $remote_addr;
10+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11+
proxy_set_header X-Forwarded-Host $server_name;
12+
13+
14+
#https://www.getpagespeed.com/server-setup/nginx/tuning-proxy_buffer_size-in-nginx
15+
proxy_buffer_size 16k; # should be enough for most PHP websites, or adjust as above
16+
proxy_busy_buffers_size 24k; # essentially, proxy_buffer_size + 2 small buffers of 4k
17+
proxy_buffers 64 4k; # should be enough for most PHP websites, adjust as above to get an accurate value
18+
19+
server {
20+
listen 80;
21+
22+
location /realms {
23+
proxy_pass http://keycloak.csaf.internal:8080/realms;
24+
proxy_redirect off;
25+
}
26+
27+
location /resources{
28+
proxy_pass http://keycloak.csaf.internal:8080/resources;
29+
proxy_redirect off;
30+
}
31+
32+
location /validate/api/v1/tests {
33+
proxy_pass http://validator.csaf.internal:8082/api/v1/tests;
34+
proxy_redirect off;
35+
}
36+
37+
location /validate/api/v1/validate {
38+
proxy_pass http://validator.csaf.internal:8082/api/v1/validate;
39+
proxy_redirect off;
40+
}
41+
42+
location /api/ {
43+
proxy_pass http://oauth2.csaf.internal:4180;
44+
proxy_redirect off;
45+
}
46+
47+
location /oauth2 {
48+
proxy_pass http://oauth2.csaf.internal:4180/oauth2;
49+
proxy_redirect off;
50+
}
51+
52+
location /.well-known/appspecific/de.bsi.secvisogram.json {
53+
proxy_pass http://secvisogram.csaf.internal/.well-known/appspecific/de.bsi.secvisogram.json;
54+
proxy_redirect off;
55+
}
56+
57+
location / {
58+
proxy_pass http://secvisogram.csaf.internal/;
59+
proxy_redirect off;
60+
}
61+
}
62+
}

docker/secvisogram/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build Stage 1
2+
# This build created a staging docker image
3+
#
4+
FROM node:20-alpine AS build
5+
WORKDIR /usr/src
6+
RUN apk add git; \
7+
git clone https://github.com/secvisogram/secvisogram.git; \
8+
cd secvisogram; \
9+
npm ci; \
10+
npm run build
11+
12+
# Build Stage 2
13+
# This build takes the production build from staging build
14+
#
15+
16+
FROM nginx:1.23-alpine
17+
COPY --from=build /usr/src/secvisogram/app/dist /usr/share/nginx/html
18+
EXPOSE 80
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"loginAvailable": true,
3+
"loginUrl": "/oauth2/sign_in?rd=http%3A%2F%2Flocalhost",
4+
"logoutUrl": "/oauth2/sign_out?rd=http://localhost/realms/csaf/protocol/openid-connect/logout?post_logout_redirect_uri=http%3A%2F%2Flocalhost&client_id=secvisogram",
5+
"userInfoUrl": "/oauth2/userinfo",
6+
"validatorUrl": "/validate"
7+
}

keycloak/csaf-realm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"registrationAllowed": false,
4343
"verifyEmail": false,
4444
"attributes" : {
45-
"frontendUrl": "http://localhost:9000/"
45+
"frontendUrl": "http://localhost/"
4646
},
4747
"roles": {
4848
"client": {

src/main/java/de/bsi/secvisogram/csaf_cms_backend/rest/MainController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class MainController {
5353
)
5454
public String about() {
5555
LOG.info("about");
56-
return "{version:\"" + buildProperties.getVersion() + "\"}";
56+
return "{\"version\":\"" + buildProperties.getVersion() + "\"}";
5757
}
5858

5959
}

0 commit comments

Comments
 (0)