Skip to content

Commit 9d468ec

Browse files
committed
Update example to use nginx setup instead of keycloak plugin
1 parent fd84f66 commit 9d468ec

11 files changed

Lines changed: 105 additions & 311 deletions

File tree

examples/BaSyxSecured/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,33 @@
33
All BaSyx components support role-based access control by using Keycloak as identity provider.
44
Access rules are defined based on roles. Roles are defined in the Keycloak server.
55

6+
In this setup, an nginx proxy is used to expose the different BaSyx services under dedicated subdomains.
7+
The main URLs are:
8+
9+
AAS Web UI: http://aasgui.basyx.localhost
10+
11+
Keycloak: http://keycloak.basyx.localhost
12+
13+
Additional service URLs can be found in the docker-compose file.
14+
15+
Modern browsers like Google Chrome, Firefox, and others automatically resolve any URL ending with .localhost to the local address 127.0.0.1.
16+
This means requests to these URLs are directly routed to your own machine, where the nginx instance running inside Docker forwards the requests to the corresponding BaSyx service.
17+
As an alternative for setups where .localhost handling might not work correctly, you could manually map the required domains to 127.0.0.1 by editing your /etc/hosts file.
18+
619
To start the secure setup execute the following command
720

821
```bash
922
docker-compose up -d
1023
```
1124

12-
This will start the BaSyx components and the Keycloak server. The Keycloak server can be found at http://localhost:9097.
25+
This will start the BaSyx components and the Keycloak server. The Keycloak server can be found at http://keycloak.basyx.localhost.
1326
There you can login as admin with username `admin` and password `keycloak-admin`.
1427
![BaSyx Realm User Overview](users.png)
1528

1629
The example comes with an already configured realm `BaSyx` and a user `john.doe` with password `johndoe`.
1730
This user has the `admin` role and can access all BaSyx components and all information about each component.
1831

19-
The entry point for accessing the Asset Administration Shells and their Submodels is the AAS Web UI running at http://localhost:3000.
32+
The entry point for accessing the Asset Administration Shells and their Submodels is the AAS Web UI running at http://aasgui.basyx.localhost.
2033
After opening the page you will be redirected to the Keycloak login page. Use the credentials of user `john.doe` to log in.
2134
![Login to BaSyx using Keycloak](login.png)
2235

@@ -25,7 +38,7 @@ The UI shows the login status in the top right corner.
2538
To end your session click on the logout button in the top right corner.
2639
![Logout button in the AAS UI](logout.png)
2740

28-
There are several other user accounts available, each with different roles. You can use them to test the different levels of access. The password for these users is their username without the dots. You can find them in the [Users](http://localhost:9097/admin/master/console/#/BaSyx/users) tab of the BaSyx realm in Keycloak.
41+
There are several other user accounts available, each with different roles. You can use them to test the different levels of access. The password for these users is their username without the dots. You can find them in the [Users](http://keycloak.basyx.localhost/admin/master/console/#/BaSyx/users) tab of the BaSyx realm in Keycloak.
2942

3043
## Upload AAS Environment files (AASX/JSON/XML) with RBAC
3144

examples/BaSyxSecured/basyx/aas-discovery.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ basyx.feature.authorization.enabled = true
99
basyx.feature.authorization.type = rbac
1010
basyx.feature.authorization.jwtBearerTokenProvider = keycloak
1111
basyx.feature.authorization.rbac.file = file:/application/rbac_rules.json
12-
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://keycloak:9097/realms/BaSyx
12+
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://keycloak.basyx.localhost/realms/BaSyx

examples/BaSyxSecured/basyx/aas-env.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ basyx.cors.allowed-origins=*
55
basyx.cors.allowed-methods=GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
66
basyx.aasrepository.feature.registryintegration=http://aas-registry:8080
77
basyx.submodelrepository.feature.registryintegration=http://sm-registry:8080
8-
basyx.externalurl=http://localhost:8081
8+
basyx.externalurl=http://aasenv.basyx.localhost
99

1010
basyx.feature.authorization.enabled = true
1111
basyx.feature.authorization.type = rbac
1212
basyx.feature.authorization.jwtBearerTokenProvider = keycloak
1313
basyx.feature.authorization.rbac.file = file:/application/rbac_rules.json
14-
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://keycloak-rbac:8080/realms/BaSyx
15-
basyx.aasenvironment.authorization.preconfiguration.token-endpoint=http://keycloak-rbac:8080/realms/BaSyx/protocol/openid-connect/token
14+
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://keycloak.basyx.localhost/realms/BaSyx
15+
basyx.aasenvironment.authorization.preconfiguration.token-endpoint=http://keycloak.basyx.localhost/realms/BaSyx/protocol/openid-connect/token
1616
basyx.aasenvironment.authorization.preconfiguration.grant-type = CLIENT_CREDENTIALS
1717
basyx.aasenvironment.authorization.preconfiguration.client-id=workstation-1
1818
basyx.aasenvironment.authorization.preconfiguration.client-secret=nY0mjyECF60DGzNmQUjL81XurSl8etom
@@ -23,12 +23,12 @@ spring.servlet.multipart.max-request-size=128MB
2323
spring.servlet.multipart.max-file-size=128MB
2424

2525
basyx.aasrepository.feature.registryintegration.authorization.enabled=true
26-
basyx.aasrepository.feature.registryintegration.authorization.token-endpoint=http://keycloak-rbac:8080/realms/BaSyx/protocol/openid-connect/token
26+
basyx.aasrepository.feature.registryintegration.authorization.token-endpoint=http://keycloak.basyx.localhost/realms/BaSyx/protocol/openid-connect/token
2727
basyx.aasrepository.feature.registryintegration.authorization.grant-type = CLIENT_CREDENTIALS
2828
basyx.aasrepository.feature.registryintegration.authorization.client-id = workstation-1
2929
basyx.aasrepository.feature.registryintegration.authorization.client-secret = nY0mjyECF60DGzNmQUjL81XurSl8etom
3030
basyx.submodelrepository.feature.registryintegration.authorization.enabled=true
31-
basyx.submodelrepository.feature.registryintegration.authorization.token-endpoint=http://keycloak-rbac:8080/realms/BaSyx/protocol/openid-connect/token
31+
basyx.submodelrepository.feature.registryintegration.authorization.token-endpoint=http://keycloak.basyx.localhost/realms/BaSyx/protocol/openid-connect/token
3232
basyx.submodelrepository.feature.registryintegration.authorization.grant-type = CLIENT_CREDENTIALS
3333
basyx.submodelrepository.feature.registryintegration.authorization.client-id=workstation-1
3434
basyx.submodelrepository.feature.registryintegration.authorization.client-secret=nY0mjyECF60DGzNmQUjL81XurSl8etom

examples/BaSyxSecured/docker-compose.yaml

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
services:
2+
3+
# nginx reverse proxy to support dns lookup
4+
# nginx-proxy:
5+
# image: nginxproxy/nginx-proxy:1.6.0-alpine
6+
# container_name: proxy
7+
# restart: always
8+
# ports:
9+
# - "80:80"
10+
# volumes:
11+
# - /var/run/docker.sock:/tmp/docker.sock:ro
12+
# environment:
13+
# DEFAULT_HOST: aasgui.basyx.localhost
14+
# networks:
15+
# - basyx-java-server-sdk
16+
217
# AAS Environment
318
aas-env:
419
image: eclipsebasyx/aas-environment:$BASYX_VERSION
520
container_name: aas-env-rbac
21+
extra_hosts:
22+
- "keycloak.basyx.localhost:host-gateway"
623
volumes:
724
- ./aas:/application/aas
825
- ./basyx/aas-env.properties:/application/application.properties
926
- ./basyx/rules/aas_env_rbac_rules.json:/application/rbac_rules.json
1027
ports:
1128
- '8081:8081'
1229
restart: always
30+
environment:
31+
VIRTUAL_HOST: aasenv.basyx.localhost
32+
VIRTUAL_PORT: "8081"
1333
depends_on:
1434
aas-registry:
1535
condition: service_healthy
@@ -22,54 +42,76 @@ services:
2242
aas-registry:
2343
image: eclipsebasyx/aas-registry-log-mem:$BASYX_VERSION
2444
container_name: secured-aas-registry-log-mem-rbac
45+
extra_hosts:
46+
- "keycloak.basyx.localhost:host-gateway"
2547
ports:
2648
- "8082:8080"
2749
environment:
50+
VIRTUAL_HOST: aasreg.basyx.localhost
51+
VIRTUAL_PORT: "8080"
2852
SERVER_SERVLET_CONTEXT_PATH: /
2953
BASYX_CORS_ALLOWED_ORIGINS: '*'
3054
BASYX_CORS_ALLOWED_METHODS: GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
3155
BASYX_FEATURE_AUTHORIZATION_ENABLED: true
3256
BASYX_FEATURE_AUTHORIZATION_TYPE: rbac
3357
BASYX_FEATURE_AUTHORIZATION_JWTBEARERTOKENPROVIDER: keycloak
34-
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak-rbac:8080/realms/BaSyx
58+
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak.basyx.localhost/realms/BaSyx
3559
BASYX_FEATURE_AUTHORIZATION_RBAC_FILE: file:/workspace/config/rbac_rules.json
3660
volumes:
3761
- ./basyx/rules/aas_registry_rbac_rules.json:/workspace/config/rbac_rules.json
3862
restart: always
63+
depends_on:
64+
keycloak-healthcheck:
65+
condition: service_completed_successfully
3966
networks:
4067
- basyx-java-server-sdk
4168

4269
# Submodel Registry
4370
sm-registry:
4471
image: eclipsebasyx/submodel-registry-log-mem:$BASYX_VERSION
4572
container_name: secured-sm-registry-log-mem-rbac
73+
extra_hosts:
74+
- "keycloak.basyx.localhost:host-gateway"
4675
environment:
76+
VIRTUAL_HOST: smreg.basyx.localhost
77+
VIRTUAL_PORT: "8080"
4778
SERVER_SERVLET_CONTEXT_PATH: /
4879
BASYX_CORS_ALLOWED_ORIGINS: '*'
4980
BASYX_CORS_ALLOWED_METHODS: GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
5081
BASYX_FEATURE_AUTHORIZATION_ENABLED: true
5182
BASYX_FEATURE_AUTHORIZATION_TYPE: rbac
5283
BASYX_FEATURE_AUTHORIZATION_JWTBEARERTOKENPROVIDER: keycloak
53-
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak-rbac:8080/realms/BaSyx
84+
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak.basyx.localhost/realms/BaSyx
5485
BASYX_FEATURE_AUTHORIZATION_RBAC_FILE: file:/workspace/config/rbac_rules.json
5586
ports:
5687
- "8083:8080"
5788
volumes:
5889
- ./basyx/rules/sm_registry_rbac_rules.json:/workspace/config/rbac_rules.json
5990
restart: always
91+
depends_on:
92+
keycloak-healthcheck:
93+
condition: service_completed_successfully
6094
networks:
6195
- basyx-java-server-sdk
6296

6397
# AAS Discovery
6498
aas-discovery:
6599
image: eclipsebasyx/aas-discovery:$BASYX_VERSION
66100
container_name: aas-discovery
101+
extra_hosts:
102+
- "keycloak.basyx.localhost:host-gateway"
103+
environment:
104+
VIRTUAL_HOST: discovery.basyx.localhost
105+
VIRTUAL_PORT: "8081"
67106
volumes:
68107
- ./basyx/aas-discovery.properties:/application/application.properties
69108
- ./basyx/rules/aas_discovery_rbac_rules.json:/application/rbac_rules.json
70109
ports:
71110
- '8084:8081'
72111
restart: always
112+
depends_on:
113+
keycloak-healthcheck:
114+
condition: service_completed_successfully
73115
networks:
74116
- basyx-java-server-sdk
75117

@@ -78,17 +120,19 @@ services:
78120
image: eclipsebasyx/aas-gui:$AAS_WEBUI_VERSION
79121
container_name: aas-web-gui
80122
extra_hosts:
81-
- "keycloak:127.0.0.1"
123+
- "keycloak.basyx.localhost:host-gateway"
82124
ports:
83125
- '3000:3000'
84126
environment:
85-
AAS_REGISTRY_PATH: http://localhost:8082/shell-descriptors
86-
SUBMODEL_REGISTRY_PATH: http://localhost:8083/submodel-descriptors
87-
AAS_REPO_PATH: http://localhost:8081/shells
88-
SUBMODEL_REPO_PATH: http://localhost:8081/submodels
89-
CD_REPO_PATH: http://localhost:8081/concept-descriptions
90-
AAS_DISCOVERY_PATH: http://localhost:8084/lookup/shells
91-
KEYCLOAK_URL: http://localhost:9097
127+
VIRTUAL_HOST: aasgui.basyx.localhost
128+
VIRTUAL_PORT: "3000"
129+
AAS_REGISTRY_PATH: http://aasreg.basyx.localhost/shell-descriptors
130+
SUBMODEL_REGISTRY_PATH: http://smreg.basyx.localhost/submodel-descriptors
131+
AAS_REPO_PATH: http://aasenv.basyx.localhost/shells
132+
SUBMODEL_REPO_PATH: http://aasenv.basyx.localhost/submodels
133+
CD_REPO_PATH: http://aasenv.basyx.localhost/concept-descriptions
134+
AAS_DISCOVERY_PATH: http://discovery.basyx.localhost/lookup/shells
135+
KEYCLOAK_URL: http://keycloak.basyx.localhost
92136
KEYCLOAK_REALM: BaSyx
93137
KEYCLOAK_CLIENT_ID: basyx-web-ui
94138
restart: always
@@ -98,24 +142,42 @@ services:
98142
networks:
99143
- basyx-java-server-sdk
100144

145+
101146
keycloak:
102-
image: eclipsebasyx/keycloak:0.0.1
103-
build:
104-
context: ./keycloak
105-
dockerfile: Dockerfile
147+
image: keycloak/keycloak:24.0.4
106148
container_name: keycloak-rbac
107149
environment:
108-
KC_HOSTNAME: localhost
109-
KC_SPI_INITIALIZER_ISSUER_BASE_URI: http://keycloak-rbac:8080
150+
VIRTUAL_HOST: keycloak.basyx.localhost
151+
VIRTUAL_PORT: "8080"
152+
KC_HOSTNAME: keycloak.basyx.localhost
110153
KEYCLOAK_ADMIN: admin
111154
KEYCLOAK_ADMIN_PASSWORD: keycloak-admin
155+
KC_HTTP_ENABLED: "true"
156+
KC_HTTPS_ENABLED: "false"
157+
KC_HEALTH_ENABLED: "true"
158+
KC_IMPORT: /opt/keycloak/data/import/
112159
command: ["start-dev", "--import-realm"]
113160
ports:
114161
- 9097:8080
115162
volumes:
116163
- ./keycloak/realm:/opt/keycloak/data/import
117164
networks:
118165
- basyx-java-server-sdk
166+
167+
keycloak-healthcheck:
168+
image: curlimages/curl:latest
169+
container_name: keycloak-healthcheck
170+
command: >
171+
sh -c "
172+
echo 'Waiting for Keycloak to become ready...';
173+
until curl -sf http://keycloak-rbac:8080/health/ready; do
174+
sleep 5;
175+
done;
176+
echo 'Keycloak is ready!'"
177+
depends_on:
178+
- keycloak
179+
networks:
180+
- basyx-java-server-sdk
119181

120182
networks:
121183
basyx-java-server-sdk:

examples/BaSyxSecured/keycloak/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)