Skip to content

Commit aa08286

Browse files
committed
Add Kong section
1 parent 75ef788 commit aa08286

9 files changed

Lines changed: 874 additions & 394 deletions

File tree

.env

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ KEYROCK_HTTPS_PORT=3443
2727
MYSQL_DB_VERSION=8.0
2828
MYSQL_DB_PORT=3306
2929

30-
# PEP Proxy variables
30+
# Wilma PEP Proxy variables
3131
WILMA_VERSION=8.3.0-distroless
32-
ORION_PROXY_PORT=1027
32+
ORION_PROXY_PORT=1027
33+
34+
# Kong PEP Proxy variables
35+
KONG_VERSION=0.4.0

README.md

Lines changed: 571 additions & 382 deletions
Large diffs are not rendered by default.

docker-compose/orion-kong.yml

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# WARNING: Do not deploy this tutorial configuration directly to a production environment
2+
#
3+
# The tutorial docker-compose files have not been written for production deployment and will not
4+
# scale. A proper architecture has been sacrificed to keep the narrative focused on the learning
5+
# goals, they are just used to deploy everything onto a single Docker machine. All FIWARE components
6+
# are running at full debug and extra ports have been exposed to allow for direct calls to services.
7+
# They also contain various obvious security flaws - passwords in plain text, no load balancing,
8+
# no use of HTTPS and so on.
9+
#
10+
# This is all to avoid the need of multiple machines, generating certificates, encrypting secrets
11+
# and so on, purely so that a single docker-compose file can be read as an example to build on,
12+
# not use directly.
13+
#
14+
# When deploying to a production environment, please refer to the Helm Repository
15+
# for FIWARE Components in order to scale up to a proper architecture:
16+
#
17+
# see: https://github.com/FIWARE/helm-charts/
18+
#
19+
version: "3.8"
20+
services:
21+
# Orion is the context broker
22+
orion:
23+
labels:
24+
org.fiware: 'tutorial'
25+
image: fiware/orion:${ORION_VERSION}
26+
hostname: orion
27+
container_name: fiware-orion
28+
depends_on:
29+
- mongo-db
30+
networks:
31+
default:
32+
ipv4_address: 172.18.1.9
33+
expose:
34+
- "${ORION_PORT}"
35+
ports:
36+
- "${ORION_PORT}:${ORION_PORT}" # localhost:1026
37+
command: -dbhost mongo-db -logLevel DEBUG
38+
healthcheck:
39+
test: curl --fail -s http://orion:${ORION_PORT}/version || exit 1
40+
interval: 15s
41+
42+
# IoT-Agent is configured for the UltraLight Protocol
43+
iot-agent:
44+
labels:
45+
org.fiware: 'tutorial'
46+
image: fiware/iotagent-ul:${ULTRALIGHT_VERSION}
47+
hostname: iot-agent
48+
container_name: fiware-iot-agent
49+
depends_on:
50+
- mongo-db
51+
- orion
52+
networks:
53+
- default
54+
ports:
55+
- "${IOTA_NORTH_PORT}:${IOTA_NORTH_PORT}" # localhost:4041
56+
- "${IOTA_SOUTH_PORT}:${IOTA_SOUTH_PORT}" # localhost:7896
57+
environment:
58+
- IOTA_CB_HOST=orion # name of the context broker to update context
59+
- IOTA_CB_PORT=${ORION_PORT} # port the context broker listens on to update context
60+
- IOTA_NORTH_PORT=${IOTA_NORTH_PORT}
61+
- IOTA_REGISTRY_TYPE=mongodb #Whether to hold IoT device info in memory or in a database
62+
- IOTA_LOG_LEVEL=DEBUG # The log level of the IoT Agent
63+
- IOTA_TIMESTAMP=true # Supply timestamp information with each measurement
64+
- IOTA_CB_NGSI_VERSION=v2 # use NGSIv2 when sending updates for active attributes
65+
- IOTA_AUTOCAST=true # Ensure Ultralight number values are read as numbers not strings
66+
- IOTA_MONGO_HOST=mongo-db # The host name of MongoDB
67+
- IOTA_MONGO_PORT=${MONGO_DB_PORT} # The port mongoDB is listening on
68+
- IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
69+
- IOTA_HTTP_PORT=${IOTA_SOUTH_PORT} # The port used for device traffic over HTTP
70+
- IOTA_PROVIDER_URL=http://iot-agent:${IOTA_NORTH_PORT}
71+
healthcheck:
72+
interval: 15s
73+
74+
75+
# Keyrock is an Identity Management Front-End
76+
keyrock:
77+
labels:
78+
org.fiware: 'tutorial'
79+
image: fiware/idm:${KEYROCK_VERSION}
80+
container_name: fiware-keyrock
81+
hostname: keyrock
82+
networks:
83+
default:
84+
ipv4_address: 172.18.1.5
85+
depends_on:
86+
- mysql-db
87+
ports:
88+
- "${KEYROCK_PORT}:${KEYROCK_PORT}" # localhost:3005
89+
environment:
90+
- DEBUG=idm:*
91+
- IDM_DB_HOST=mysql-db
92+
- IDM_DB_PASS_FILE=/run/secrets/my_secret_data
93+
- IDM_DB_USER=root
94+
- IDM_HOST=http://localhost:${KEYROCK_PORT}
95+
- IDM_PORT=${KEYROCK_PORT}
96+
- IDM_HTTPS_ENABLED=${IDM_HTTPS_ENABLED}
97+
- IDM_HTTPS_PORT=${KEYROCK_HTTPS_PORT}
98+
- IDM_ADMIN_USER=alice
99+
- IDM_ADMIN_EMAIL=alice-the-admin@test.com
100+
- IDM_ADMIN_PASS=test
101+
- IDM_CSP_FORM_ACTION=*
102+
secrets:
103+
- my_secret_data
104+
healthcheck:
105+
interval: 5s
106+
107+
108+
# PEP Proxy for Orion
109+
kong-api-gateway:
110+
labels:
111+
org.fiware: 'tutorial'
112+
image: quay.io/fiware/kong:${KONG_VERSION}
113+
container_name: fiware-orion-kong
114+
hostname: orion-proxy
115+
networks:
116+
default:
117+
ipv4_address: 172.18.1.10
118+
depends_on:
119+
keyrock:
120+
condition: service_started
121+
deploy:
122+
restart_policy:
123+
condition: on-failure
124+
ports:
125+
- "8000:8000/tcp"
126+
environment:
127+
- KONG_DATABASE=off
128+
- KONG_DECLARATIVE_CONFIG=/etc/kong/kong.yaml
129+
- KONG_PLUGINS=bundled,pep-plugin
130+
- KONG_PLUGINSERVER_NAMES= pep-plugin
131+
- "KONG_PLUGINSERVER_PEP_PLUGIN_QUERY_CMD=/go-plugins/pep-plugin -dump"
132+
- "KONG_PLUGINSERVER_PEP_PLUGIN_START_CMD=/go-plugins/pep-plugin"
133+
- KONG_LOG_LEVEL=debug
134+
135+
volumes:
136+
- ../kong/kong.yaml:/etc/kong/kong.yaml
137+
138+
139+
# Tutorial acts as a series of dummy IoT Sensors over HTTP
140+
tutorial:
141+
labels:
142+
org.fiware: 'tutorial'
143+
image: fiware/tutorials.context-provider
144+
hostname: iot-sensors
145+
container_name: fiware-tutorial
146+
depends_on:
147+
iot-agent:
148+
condition: service_started
149+
keyrock:
150+
condition: service_started
151+
networks:
152+
default:
153+
ipv4_address: 172.18.1.7
154+
aliases:
155+
- tutorial
156+
- context-provider
157+
expose:
158+
- "${TUTORIAL_APP_PORT}"
159+
- "${TUTORIAL_DUMMY_DEVICE_PORT}"
160+
ports:
161+
- "${TUTORIAL_APP_PORT}:${TUTORIAL_APP_PORT}" # localhost:3000
162+
- "${TUTORIAL_DUMMY_DEVICE_PORT}:${TUTORIAL_DUMMY_DEVICE_PORT}" # localhost:3001
163+
environment:
164+
- "MONGO_URL=mongodb://mongo-db:27017"
165+
- "DEBUG=tutorial:*"
166+
- "WEB_APP_PORT=${TUTORIAL_APP_PORT}" # Port used by the content provider proxy and web-app for viewing data
167+
- "IOTA_HTTP_HOST=iot-agent"
168+
- "IOTA_HTTP_PORT=${IOTA_SOUTH_PORT}"
169+
- "IOTA_DEFAULT_RESOURCE=/iot/d"
170+
- "DUMMY_DEVICES_PORT=${TUTORIAL_DUMMY_DEVICE_PORT}" # Port used by the dummy IOT devices to receive commands
171+
- "DUMMY_DEVICES_TRANSPORT=HTTP" # Default transport used by dummy Io devices
172+
- "CONTEXT_BROKER=http://orion-proxy:${ORION_PROXY_PORT}/v2" # URL of the PEP Proxy to update context
173+
- "OPENWEATHERMAP_KEY_ID=<ADD_YOUR_KEY_ID>"
174+
- "TWITTER_CONSUMER_KEY=<ADD_YOUR_CONSUMER_KEY>"
175+
- "TWITTER_CONSUMER_SECRET=<ADD_YOUR_CONSUMER_SECRET>"
176+
- "NGSI_LD_PREFIX="
177+
- "SECURE_ENDPOINTS=true"
178+
- "KEYROCK_URL=http://localhost"
179+
- "KEYROCK_IP_ADDRESS=http://172.18.1.5"
180+
- "KEYROCK_PORT=${KEYROCK_PORT}"
181+
- "KEYROCK_CLIENT_ID=tutorial-dckr-site-0000-xpresswebapp"
182+
- "KEYROCK_CLIENT_SECRET=tutorial-dckr-site-0000-clientsecret"
183+
- "CALLBACK_URL=http://localhost:${TUTORIAL_APP_PORT}/login"
184+
185+
186+
187+
# Databases
188+
mongo-db:
189+
labels:
190+
org.fiware: 'tutorial'
191+
image: mongo:${MONGO_DB_VERSION}
192+
hostname: mongo-db
193+
container_name: db-mongo
194+
expose:
195+
- "${MONGO_DB_PORT}"
196+
ports:
197+
- "${MONGO_DB_PORT}:${MONGO_DB_PORT}" # localhost:27017
198+
networks:
199+
- default
200+
volumes:
201+
- mongo-db:/data
202+
healthcheck:
203+
test: |
204+
host=`hostname --ip-address || echo '127.0.0.1'`;
205+
mongo --quiet $host/test --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' && echo 0 || echo 1
206+
interval: 5s
207+
208+
209+
mysql-db:
210+
restart: always
211+
labels:
212+
org.fiware: 'tutorial'
213+
image: mysql:${MYSQL_DB_VERSION}
214+
hostname: mysql-db
215+
container_name: db-mysql
216+
expose:
217+
- "${MYSQL_DB_PORT}"
218+
ports:
219+
- "${MYSQL_DB_PORT}:${MYSQL_DB_PORT}" # localhost:3306
220+
networks:
221+
default:
222+
ipv4_address: 172.18.1.6
223+
environment:
224+
- "MYSQL_ROOT_PASSWORD_FILE=/run/secrets/my_secret_data"
225+
- "MYSQL_ROOT_HOST=172.18.1.5" # Allow Keyrock to access this database
226+
volumes:
227+
- mysql-db:/var/lib/mysql
228+
- ../mysql-data:/docker-entrypoint-initdb.d/:ro
229+
secrets:
230+
- my_secret_data
231+
networks:
232+
default:
233+
labels:
234+
org.fiware: 'tutorial'
235+
ipam:
236+
config:
237+
- subnet: 172.18.1.0/24
238+
volumes:
239+
mysql-db: ~
240+
mongo-db: ~
241+
242+
secrets:
243+
my_secret_data:
244+
file: ../secrets.txt
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ services:
107107

108108
# PEP Proxy for Orion
109109
orion-proxy:
110-
#image: pep-slim
111110
labels:
112111
org.fiware: 'tutorial'
113112
image: fiware/pep-proxy:${WILMA_VERSION}

kong/kong.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
_format_version: "2.1"
2+
_transform: true
3+
4+
services:
5+
- host: "orion"
6+
name: "orion-oidc"
7+
port: 1026
8+
protocol: http
9+
routes:
10+
- name: orion-oidc
11+
paths:
12+
- /orion
13+
strip_path: true
14+
plugins:
15+
- name: pep-plugin
16+
config:
17+
authorizationendpointtype: Keyrock
18+
authorizationendpointaddress: http://keyrock:3005/user/
19+
keyrockappid: tutorial-dckr-site-0000-xpresswebapp
20+
pathprefix: /orion

mysql-data/backup.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ INSERT INTO `oauth_client` VALUES
319319
('tutorial-dckr-site-0000-xpresswebapp','FIWARE Tutorial',
320320
'FIWARE Application protected by OAuth2 and Keyrock', 'tutorial-dckr-site-0000-clientsecret',
321321
'http://localhost:3000','http://localhost:3000/login',NULL,'default',
322-
'authorization_code,implicit,password,client_credentials,refresh_token','code',NULL,NULL,NULL,'bearer,permanent', NULL),
322+
'authorization_code,implicit,password,client_credentials,refresh_token','code',NULL,NULL,NULL,'bearer,jwt,permanent', '51129f085f3e1a80'),
323323
('trusted-dckr-app-0000-000000000000','Trusted Application',
324324
'Second application protected by OAuth2 and Keyrock','trusted-dckr-app-0000-clientsecret',
325325
'','',NULL,'default',
@@ -491,7 +491,8 @@ INSERT INTO `permission` VALUES
491491
('increase-stck-0000-0000-000000000000','Order Stock','Increase Stock Count',0,'GET','/app/order-stock',NULL,'tutorial-dckr-site-0000-xpresswebapp',0,NULL,0,NULL,NULL,NULL),
492492
('entrance-open-0000-0000-000000000000','Unlock','Unlock main entrance',0,'POST','/door/unlock',NULL,'tutorial-dckr-site-0000-xpresswebapp',0,NULL,0,NULL,NULL,NULL),
493493
('alrmbell-ring-0000-0000-000000000000','Ring Alarm Bell',NULL,0,'POST','/bell/ring',NULL,'tutorial-dckr-site-0000-xpresswebapp',0,NULL,0,NULL,NULL,NULL),
494-
('pricechg-stck-0000-0000-000000000000','Access Price Changes',NULL,0,'GET','/app/price-change',NULL,'tutorial-dckr-site-0000-xpresswebapp',0,NULL,0,NULL,NULL,NULL);
494+
('pricechg-stck-0000-0000-000000000000','Access Price Changes',NULL,0,'GET','/app/price-change',NULL,'tutorial-dckr-site-0000-xpresswebapp',0,NULL,0,NULL,NULL,NULL),
495+
('orion-context-0000-0000-000000000000','Access Context Broker',NULL,0,'GET','\/v2\/entities(\/|$).*',NULL,'tutorial-dckr-site-0000-xpresswebapp',1,NULL,0,NULL,NULL,NULL);
495496
/*!40000 ALTER TABLE `permission` ENABLE KEYS */;
496497
UNLOCK TABLES;
497498

@@ -605,7 +606,9 @@ INSERT INTO `role_permission` VALUES
605606
(9,'security-role-0000-0000-000000000000','entrance-open-0000-0000-000000000000'),
606607
(10,'managers-role-0000-0000-000000000000','alrmbell-ring-0000-0000-000000000000'),
607608
(11,'managers-role-0000-0000-000000000000','increase-stck-0000-0000-000000000000'),
608-
(12,'managers-role-0000-0000-000000000000','pricechg-stck-0000-0000-000000000000');
609+
(12,'managers-role-0000-0000-000000000000','pricechg-stck-0000-0000-000000000000'),
610+
(13,'security-role-0000-0000-000000000000','orion-context-0000-0000-000000000000'),
611+
(14,'managers-role-0000-0000-000000000000','orion-context-0000-0000-000000000000');
609612

610613

611614

services

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ startContainers () {
133133
stoppingContainers () {
134134
export $(cat .env | grep "#" -v)
135135
echo "Stopping running containers"
136-
${dockerCmd} -f docker-compose/southport.yml down -v --remove-orphans
136+
${dockerCmd} -f docker-compose/southport-wilma.yml down -v --remove-orphans
137137
}
138138

139139
command="$1"
140140
case "${command}" in
141141
"help")
142-
echo "usage: services [create|orion|northport]"
142+
echo "usage: services [create|orion|orion-wilma|orion-kong|northport]"
143143
;;
144144
"orion")
145145
stoppingContainers
@@ -149,7 +149,25 @@ case "${command}" in
149149
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
150150
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
151151
echo -e "- \033[1;31mWilma\033[0m is a PEP Proxy around \033[1;34mOrion\033[0m"
152-
startContainers false orion.yml
152+
startContainers false orion-wilma.yml
153+
waitForKeyrock
154+
export ORION_URL="http://orion:1026"
155+
waitForMongo
156+
addDatabaseIndex
157+
waitForOrion
158+
loadData
159+
displayServices
160+
echo -e "Now open \033[4mhttp://localhost:3000\033[0m"
161+
;;
162+
"orion-kong")
163+
stoppingContainers
164+
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1;31mKeyrock\033[0m, \033[1;31mKong\033[0m, \033[1mTutorial\033[0m and \033[1mMongoDB\033[0m and \033[1mMySQL\033[0m databases."
165+
echo -e "- \033[1;34mOrion\033[0m is the context broker"
166+
echo -e "- \033[1;36mIoT-Agent\033[0m is configured for the UltraLight Protocol"
167+
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
168+
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
169+
echo -e "- \033[1;31mKong\033[0m is a PEP Proxy around \033[1;34mOrion\033[0m"
170+
startContainers false orion-kong.yml
153171
waitForKeyrock
154172
export ORION_URL="http://orion:1026"
155173
waitForMongo
@@ -167,7 +185,7 @@ case "${command}" in
167185
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
168186
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
169187
echo -e "- 2 instances of \033[1;31mWilma\033[0m as a PEP Proxy around \033[1;34mOrion\033[0m and between the Devices and \033[1;36mIoT-Agent\033[0m Southport"
170-
startContainers false southport.yml
188+
startContainers false southport-wilma.yml
171189
waitForKeyrock
172190
waitForMongo
173191
addDatabaseIndex
@@ -184,7 +202,7 @@ case "${command}" in
184202
echo -e "- \033[1mTutorial\033[0m acts as a series of dummy IoT Sensors over HTTP"
185203
echo -e "- \033[1;31mKeyrock\033[0m is an Identity Management Front-End"
186204
echo -e "- \033[1;31mWilma\033[0m as a PEP Proxy between \033[1;34mOrion\033[0m and the \033[1;36mIoT-Agent\033[0m"
187-
startContainers false northport.yml
205+
startContainers false northport-wilma.yml
188206
waitForKeyrock
189207
export ORION_URL="http://orion-proxy:1027"
190208
waitForMongo
@@ -206,15 +224,19 @@ case "${command}" in
206224
"start")
207225
./services orion $2
208226
;;
227+
"orion-wilma")
228+
./services orion $2
229+
;;
209230
"create")
210231
export $(cat .env | grep "#" -v)
211232
echo "Pulling Docker images"
212233
docker pull curlimages/curl
213234
${dockerCmd} -f docker-compose/orion.yml pull
235+
${dockerCmd} -f docker-compose/kong.yml pull
214236
;;
215237
*)
216238
echo "Command not Found."
217-
echo "usage: services [create|orion|southport|northport|stop]"
239+
echo "usage: services [create|orion-wilma|orion-kong|southport|northport|stop]"
218240
exit 127;
219241
;;
220242
esac

0 commit comments

Comments
 (0)