Skip to content

Commit a99feae

Browse files
authored
Merge pull request #28 from Skejven/feature/secrets-support-for-karaf
Karaf support for docker secrets
2 parents a3568c7 + ae366b2 commit a99feae

7 files changed

Lines changed: 64 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Not released yet
2-
No new features so far...
2+
- [PR-28](https://github.com/Skejven/aet-docker/pull/28) - Before the start of a Karaf service, Docker secrets are exported to environment variables.
33

44
# 0.14.0
55
- [PR-27](https://github.com/Skejven/aet-docker/pull/27) - Karaf provisioned with all dependencies - offline mode provisioning support.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ You may find released versions of AET Docker images at [Docker Hub](https://clou
1919
* [Configuration](#configuration)
2020
+ [OSGi configs](#osgi-configs)
2121
+ [Throughput and scaling](#throughput-and-scaling)
22+
+ [Docker secrets](#docker-secrets)
2223
* [Updating instance](#updating-instance)
2324
* [Running AET Suite](#running-aet-suite)
2425
+ [Docker Client](#docker-client)
@@ -54,6 +55,7 @@ It contains all AET modules (bundles): Runner, Workers, Web-API, Datastorage, Ex
5455
with all their dependencies required (no internet access required to provision).
5556
[AET application core](https://github.com/Cognifide/aet) is located in the `/aet/core` directory.
5657
All custom AET extensions are kept in the `/aet/custom` directory.
58+
Before the start of a Karaf service, Docker secrets are exported to environment variables. Read more in [secrets](#docker-secrets) section.
5759
### AET Report
5860
Runs [Apache Server](https://httpd.apache.org/) that hosts [AET Report](https://github.com/Cognifide/aet/wiki/SuiteReport).
5961
The [AET report application](https://github.com/Cognifide/aet/tree/master/report) is placed under `/usr/local/apache2/htdocs`.
@@ -235,6 +237,13 @@ That number should be set for following configs:
235237
- `maxMessagesInCollectorQueue` in `com.cognifide.aet.runner.RunnerConfiguration.cfg`
236238
- `collectorInstancesNo` in `com.cognifide.aet.worker.listeners.WorkersListenersService.cfg`
237239

240+
#### Docker secrets
241+
AET Karaf image reads all files in the `/run/secrets/` directory matching `KARAF_*` pattern export them as environment variable.
242+
See the [Karaf entrypoint][/blob/master/karaf/entrypoint.sh] for details.
243+
244+
E.g.
245+
If the file `/run/secrets/KARAF_MY_SECRET` is found, its content will be exported to `MY_SECRET` environment variable.
246+
238247
### Updating instance
239248
You may update configuration files directly from your host
240249
(unless you use docker-machine, see the workaround below).

example-aet-swarm/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ AET stack defined in this example runs:
2424
│   └── com.github.skejven.collector.LighthouseCollectorFactory.cfg
2525
├── features
2626
│   └── custom-features.xml
27-
└── report
27+
├── report
28+
└── secrets
29+
└── KARAF_EXAMPLE_SECRET
2830
```
2931

3032
- `aet-swarm.yml` - this file contains configuration file to run AET [single-node swarm cluster](https://docs.docker.com/engine/swarm/key-concepts/)
3133
- `bundles` - directory mounted to the `/aet/custom/bundles` in the Karaf service, where Karaf search for custom [OSGi bundles](https://en.wikipedia.org/wiki/OSGi#Bundles), that's the place to put any extra AET extensions
3234
- `configs` - directory mounted to the `/aet/custom/configs` in the Karaf service, contains OSGi components in form of `.cfg` files
3335
- `features` - directory mounted to the `/aet/custom/features in the Karaf service`, contains [Karaf provisioning](https://karaf.apache.org/manual/latest/provisioning) configuration files - called features
3436
- `report` - directory that may contain custom AET report application, if mounted to `/usr/local/apache2/htdocs` volume in the Report service, it will override default [AET Report application](https://github.com/Cognifide/aet/tree/master/report)
37+
- `secrets` - directory contains example [Docker secret](https://docs.docker.com/engine/swarm/secrets/) files. They are scanned before Karaf starts and exported as environment variables. Read more in the [secrets configuration](https://github.com/Skejven/aet-docker#docker-secrets).
3538

3639
## Karaf healthcheck
3740
Karaf's service in this sample docker instance have [healthcheck](https://docs.docker.com/compose/compose-file/#healthcheck). It simply checks the dedicated service's endpoint `/health-check` that responses with `200` when everything is ready, with error code otherwise. If the healthcheck fails, swarm will automatically restart the service.

example-aet-swarm/aet-swarm.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ services:
106106
- ./configs:/aet/custom/configs
107107
- ./bundles:/aet/custom/bundles
108108
- ./features:/aet/custom/features
109+
secrets:
110+
- KARAF_EXAMPLE_SECRET
109111
ports:
110112
- '8181:8181'
111113
# - '5005:5005' # uncomment to be able to connect Karaf in debug mode
@@ -124,3 +126,7 @@ services:
124126
# - AET_WEB_API=http://my.karaf.com # uncomment to configure custom AET Web API endpoint
125127
networks:
126128
- private
129+
130+
secrets:
131+
KARAF_EXAMPLE_SECRET:
132+
file: secrets/KARAF_EXAMPLE_SECRET
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ex@mpl3-s3cret-v4lue

karaf/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ RUN mv /opt/karaf/deploy/aet-*.xml /aet/core/features \
102102

103103
RUN chown -R ${KARAF_USER}.${KARAF_USER} /opt/karaf
104104

105+
COPY entrypoint.sh /opt/karaf/entrypoint.sh
106+
RUN chmod a+x /opt/karaf/entrypoint.sh && chown -R ${KARAF_USER}.${KARAF_USER} /opt/karaf/entrypoint.sh
107+
105108
EXPOSE 1099 8101 8181 44444
106109

107110
USER ${KARAF_USER}
108111

109-
CMD ["/opt/karaf/bin/karaf", "run"]
112+
ENTRYPOINT ["/opt/karaf/entrypoint.sh"]
113+
CMD ["run"]

karaf/entrypoint.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# AET Docker
3+
#
4+
# Copyright (C) 2020 Maciej Laskowski
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
set -e
19+
20+
KARAF_COMMAND=$1
21+
22+
read_secrets() {
23+
echo "Exporting secrets to env..."
24+
for file in /run/secrets/KARAF_*; do
25+
envName=$(echo "$file" | awk -F"KARAF_" '{print $2}')
26+
envVal="$(<"${file}")"
27+
echo "Exporting: $envName"
28+
export "$envName"="$envVal"
29+
done
30+
}
31+
32+
if [ "$KARAF_COMMAND" = 'run' ]; then
33+
[ -d "/run/secrets" ] && read_secrets || echo "No secrets configured."
34+
echo "Running karaf"
35+
exec /opt/karaf/bin/karaf $KARAF_COMMAND "$@"
36+
fi
37+
38+
exec "$@"

0 commit comments

Comments
 (0)