From 43a300fba7264ef9ed1fa5dae1c50233e44bacf9 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 27 Feb 2024 13:28:44 +0100 Subject: [PATCH] Initial version --- bundles.yml | 4 + cloudbeaver.nomad.hcl | 112 ++++++ .../config/service-defaults/cloudbeaver.hcl | 3 + .../config/service-intentions/cloudbeaver.hcl | 15 + example/LICENSE | 9 + example/README.md | 3 + example/cloudbeaver.nomad.hcl | 320 ++++++++++++++++++ .../config/service-defaults/cloudbeaver.hcl | 3 + .../config/service-intentions/cloudbeaver.hcl | 15 + example/images/cloudbeaver/Dockerfile | 27 ++ .../cloudbeaver/root/entrypoint.d/10-mkdir.sh | 6 + .../root/usr/local/bin/cloudbeaver | 41 +++ example/init/cloudbeaver-vault-database | 12 + example/prep.d/10-cloudbeaver-rand-secrets.sh | 22 ++ example/vault/policies/cloudbeaver.hcl | 7 + images/cloudbeaver/Dockerfile | 27 ++ .../cloudbeaver/root/entrypoint.d/10-mkdir.sh | 6 + .../root/usr/local/bin/cloudbeaver | 41 +++ init/cloudbeaver-vault-database | 5 + prep.d/10-cloudbeaver-rand-secrets.sh | 5 + templates/cloudbeaver.conf | 81 +++++ templates/initial-data.conf | 18 + templates/logback.xml | 19 ++ variables.yml | 75 ++++ vault/policies/cloudbeaver.hcl | 7 + 25 files changed, 883 insertions(+) create mode 100644 bundles.yml create mode 100644 cloudbeaver.nomad.hcl create mode 100644 consul/config/service-defaults/cloudbeaver.hcl create mode 100644 consul/config/service-intentions/cloudbeaver.hcl create mode 100644 example/LICENSE create mode 100644 example/README.md create mode 100644 example/cloudbeaver.nomad.hcl create mode 100644 example/consul/config/service-defaults/cloudbeaver.hcl create mode 100644 example/consul/config/service-intentions/cloudbeaver.hcl create mode 100644 example/images/cloudbeaver/Dockerfile create mode 100755 example/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh create mode 100755 example/images/cloudbeaver/root/usr/local/bin/cloudbeaver create mode 100755 example/init/cloudbeaver-vault-database create mode 100755 example/prep.d/10-cloudbeaver-rand-secrets.sh create mode 100644 example/vault/policies/cloudbeaver.hcl create mode 100644 images/cloudbeaver/Dockerfile create mode 100755 images/cloudbeaver/root/entrypoint.d/10-mkdir.sh create mode 100755 images/cloudbeaver/root/usr/local/bin/cloudbeaver create mode 100755 init/cloudbeaver-vault-database create mode 100755 prep.d/10-cloudbeaver-rand-secrets.sh create mode 100644 templates/cloudbeaver.conf create mode 100644 templates/initial-data.conf create mode 100644 templates/logback.xml create mode 100644 variables.yml create mode 100644 vault/policies/cloudbeaver.hcl diff --git a/bundles.yml b/bundles.yml new file mode 100644 index 0000000..5b9120e --- /dev/null +++ b/bundles.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - url: ../common.git diff --git a/cloudbeaver.nomad.hcl b/cloudbeaver.nomad.hcl new file mode 100644 index 0000000..a08d389 --- /dev/null +++ b/cloudbeaver.nomad.hcl @@ -0,0 +1,112 @@ +job "[[ .instance ]]" { + +[[- $c := merge .cloudbeaver . ]] +[[ template "common/job_start" $c ]] + + group "cloudbeaver" { + shutdown_delay = "6s" +[[ template "common/constraints" $c ]] + + network { + mode = "bridge" +[[- if $c.prometheus.enabled ]] + port "metrics" {} +[[- end ]] + } + +[[ template "common/volumes" $c ]] + + service { + name = "[[ .instance ]][[ .consul.suffix ]]" + port = 8978 +[[ template "common/service_meta" $c ]] +[[ template "common/connect" $c ]] + + tags = [ +[[ template "common/traefik_tags" $c ]] + ] + } + +[[ template "common/task.wait_for" $c ]] +[[ template "common/task.pgpooler" $c ]] + + task "cloudbeaver" { + driver = "[[ $c.nomad.driver ]]" + + config { + image = "[[ $c.image ]]" + pids_limit = 100 + readonly_rootfs = true +[[ template "common/tmpfs" "/tmp" ]] + } + +[[ template "common/vault.policies" $c ]] + + env { + CLOUDBEAVER_WEB_CONFIG = "/local/cloudbeaver.conf" + } + +[[ template "common/file_env" $c ]] + + # Postgres DB config + template { + data = <<_EOT +PGDATABASE=[[ $c.postgres.database ]] +[[- if ne $c.postgres.pooler.engine "none" ]] +PGHOST=127.0.0.1 +PGPORT=6432 +PGUSER=[[ .instance ]] +PGPASSWORD={{ env "NOMAD_ALLOC_ID" }} +[[- else ]] +PGHOST=[[ $c.postgres.host ]] +PGPORT=[[ $c.postgres.port ]] +PGUSER=[[ $c.postgres.user ]] +PGPASSWORD=[[ $c.postgres.password ]] +[[- end ]] +_EOT + destination = "secrets/.db.env" + perms = 0400 + env = true + } + + # Main cloudbeaver configuration + template { + data = <<_EOT +[[- if isKind "map" $c.config ]] +[[ (merge $c.config (tmpl.Exec "cloudbeaver/cloudbeaver.conf" $c | json)) | toJSONPretty " " | replaceAll "${" "$${" ]] +[[- else if isKind "string" $c.config ]] +[[ (merge ($c.config | yaml) (tmpl.Exec "cloudbeaver/cloudbeaver.conf" $c | json)) | toJSONPretty " " | replaceAll "${" "$${" ]] +[[- end ]] +_EOT + destination = "local/cloudbeaver.conf" + } + + # Logback config + template { + data = <<_EOT +[[ template "cloudbeaver/logback.xml" $c ]] +_EOT + destination = "local/logback.xml" + } + + # Initial config (admin user and teams) + template { + data = <<_EOT +[[ tmpl.Exec "cloudbeaver/initial-data.conf" $c | replaceAll "${" "$${" ]] +_EOT + destination = "secrets/initial-data.conf" + uid = 100000 + gid = 108978 + perms = 440 + } + + # Mount persistent volume in /data + volume_mount { + volume = "data" + destination = "/data" + } + +[[ template "common/resources" $c ]] + } + } +} diff --git a/consul/config/service-defaults/cloudbeaver.hcl b/consul/config/service-defaults/cloudbeaver.hcl new file mode 100644 index 0000000..f3ad32f --- /dev/null +++ b/consul/config/service-defaults/cloudbeaver.hcl @@ -0,0 +1,3 @@ +Kind = "service-defaults" +Name = "[[ .instance ]][[ .consul.suffix ]]" +Protocol = "http" diff --git a/consul/config/service-intentions/cloudbeaver.hcl b/consul/config/service-intentions/cloudbeaver.hcl new file mode 100644 index 0000000..a1cf204 --- /dev/null +++ b/consul/config/service-intentions/cloudbeaver.hcl @@ -0,0 +1,15 @@ +Kind = "service-intentions" +Name = "[[ .instance ]][[ .consul.suffix ]]" +Sources = [ + { + Name = "[[ (merge .cloudbeaver .).traefik.instance ]]" + Permissions = [ + { + Action = "allow" + HTTP { + PathPrefix = "/" + } + } + ] + } +] diff --git a/example/LICENSE b/example/LICENSE new file mode 100644 index 0000000..09c6323 --- /dev/null +++ b/example/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 nomad + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..115c7f4 --- /dev/null +++ b/example/README.md @@ -0,0 +1,3 @@ +# cloudbeaver + +Cloudbever Nomad job template \ No newline at end of file diff --git a/example/cloudbeaver.nomad.hcl b/example/cloudbeaver.nomad.hcl new file mode 100644 index 0000000..8ffc936 --- /dev/null +++ b/example/cloudbeaver.nomad.hcl @@ -0,0 +1,320 @@ +job "cloudbeaver" { + + datacenters = ["dc1"] + region = "global" + + + group "cloudbeaver" { + shutdown_delay = "6s" + + + + network { + mode = "bridge" + } + + + volume "data" { + source = "cloudbeaver-data" + type = "csi" + access_mode = "single-node-writer" + attachment_mode = "file-system" + } + + + service { + name = "cloudbeaver" + port = 8978 + meta { + alloc = "${NOMAD_ALLOC_INDEX}" + job = "${NOMAD_JOB_NAME}" + } + + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "postgres" + local_bind_port = 5432 + # Work arround, see https://github.com/hashicorp/nomad/issues/18538 + destination_type = "service" + } + } + } + sidecar_task { + config { + args = [ + "-c", + "${NOMAD_SECRETS_DIR}/envoy_bootstrap.json", + "-l", + "${meta.connect.log_level}", + "--concurrency", + "${meta.connect.proxy_concurrency}", + "--disable-hot-restart" + ] + } + + resources { + cpu = 50 + memory = 64 + } + + } + } + + + tags = [ + + "traefik.enable=true", + "traefik.http.routers.cloudbeaver.entrypoints=https", + "traefik.http.routers.cloudbeaver.rule=Host(`cloudbeaver.example.org`)", + "traefik.http.middlewares.csp-cloudbeaver.headers.contentsecuritypolicy=default-src 'self';font-src 'self' data:;img-src 'self' data:;script-src 'self' 'unsafe-inline' 'unsafe-eval';style-src 'self' 'unsafe-inline';", + "traefik.http.routers.cloudbeaver.middlewares=security-headers@file,rate-limit-std@file,forward-proto@file,inflight-std@file,hsts@file,compression@file,csp-cloudbeaver", + + ] + } + + # wait for required services tp be ready before starting the main task + task "wait-for" { + + driver = "docker" + user = 1053 + + config { + image = "danielberteaud/wait-for:24.2-1" + readonly_rootfs = true + pids_limit = 20 + } + + lifecycle { + hook = "prestart" + } + + env { + SERVICE_0 = "master.postgres.service.consul" + } + + resources { + cpu = 10 + memory = 10 + memory_max = 30 + } + } + + + + + + task "cloudbeaver" { + driver = "docker" + + config { + image = "danielberteaud/cloudbeaver:23.3.5" + pids_limit = 100 + readonly_rootfs = true + mount { + type = "tmpfs" + target = "/tmp" + tmpfs_options { + size = 3000000 + } + } + + } + + + vault { + policies = ["cloudbeaver"] + env = false + disable_file = true + change_mode = "noop" + } + + + env { + CLOUDBEAVER_WEB_CONFIG = "/local/cloudbeaver.conf" + } + + # Use a template block instead of env {} so we can fetch values from vault + template { + data = <<_EOT +LANG=fr_FR.utf8 +TZ=Europe/Paris +_EOT + destination = "secrets/.env" + perms = 400 + env = true + } + + + # Postgres DB config + template { + data = <<_EOT +PGDATABASE=cloudbeaver +PGHOST=127.0.0.1 +PGPORT=5432 +PGUSER={{ with secret "/database/creds/cloudbeaver" }}{{ .Data.username }}{{ end }} +PGPASSWORD={{ with secret "/database/creds/cloudbeaver" }}{{ .Data.password }}{{ end }} +_EOT + destination = "secrets/.db.env" + perms = 0400 + env = true + } + + # Main cloudbeaver configuration + template { + data = <<_EOT +{ + "app": { + "adminCredentialsSaveEnabled": false, + "anonymousAccessAllowed": false, + "anonymousUserTeam": "user", + "authenticationEnabled": true, + "defaultNavigatorSettings": { + "hideFolders": false, + "hideSchemas": false, + "mergeEntities": false, + "showOnlyEntities": false, + "showSystemObjects": true, + "showUtilityObjects": false + }, + "disabledDrivers": [ + "sqlite:sqlite_jdbc", + "h2:h2_embedded", + "h2:h2_embedded_v2" + ], + "enabledAuthProviders": [ + "local" + ], + "enabledDrivers": [], + "forwardProxy": true, + "plugins": {}, + "publicCredentialsSaveEnabled": false, + "resourceManagerEnabled": true, + "resourceQuotas": { + "dataExportFileSizeLimit": 1000000000, + "resourceManagerFileSizeLimit": 500000, + "sqlBinaryPreviewMaxLength": 261120, + "sqlMaxRunningQueries": 100, + "sqlResultSetMemoryLimit": 2000000, + "sqlResultSetRowsLimit": 100000, + "sqlTextPreviewMaxLength": 4096 + }, + "supportsCustomConnections": true + }, + "server": { + "contentRoot": "web", + "database": { + "driver": "postgres-jdbc", + "initialDataConfiguration": "/secrets/initial-data.conf", + "password": "$${PGPASSWORD}", + "pool": { + "maxConnections": 100, + "maxIdleConnections": 10, + "minIdleConnections": 4, + "validationQuery": "SELECT 1" + }, + "url": "jdbc:postgresql://$${PGHOST}:$${PGPORT}/$${PGDATABASE}", + "user": "$${PGUSER}" + }, + "develMode": false, + "driversLocation": "drivers", + "expireSessionAfterPeriod": 600000, + "productConfiguration": "conf/product.conf", + "rootURI": "/", + "serverHost": "127.0.0.1", + "serverName": "cloudbeaver", + "serverPort": 8978, + "serverURL": "https://cloudbeaver.example.org", + "serviceURI": "/api/", + "sm": { + "blockLoginPeriod": "$${CLOUDBEAVER_BLOCK_PERIOD:300}", + "enableBruteForceProtection": true, + "expiredAuthAttemptInfoTtl": 60, + "maxFailedLogin": "$${CLOUDBEAVER_MAX_FAILED_LOGINS:5}", + "minimumLoginTimeout": "$${CLOUDBEAVER_MINIMUM_LOGIN_TIMEOUT:1}", + "passwordPolicy": { + "minLength": "$${CLOUDBEAVER_POLICY_MIN_LENGTH:8}", + "minNumberCount": "$${CLOUDBEAVER_POLICY_MIN_NUMBER_COUNT:1}", + "minSymbolCount": "$${CLOUDBEAVER_POLICY_MIN_SYMBOL_COUNT:0}", + "requireMixedCase": "$${CLOUDBEAVER_POLICY_REQUIRE_MIXED_CASE:true}" + } + }, + "workspaceLocation": "/data" + } +} +_EOT + destination = "local/cloudbeaver.conf" + } + + # Logback config + template { + data = <<_EOT + + + + + + %d{dd-MM-yyyy HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + + + + + +_EOT + destination = "local/logback.xml" + } + + # Initial config (admin user and teams) + template { + data = <<_EOT +{ + adminName: "cloudbeaver", + adminPassword: "{{ with secret "/kv/service/cloudbeaver" }}{{ .Data.data.initial_admin_pwd }}{{ end }}", + teams: [ + { + subjectId: "admin", + teamName: "Admin", + description: "Administrative access. Has all permissions.", + permissions: [ "admin" ] + }, + { + subjectId: "user", + teamName: "User", + description: "All users, including anonymous.", + permissions: [ ] + } + ] +} + +_EOT + destination = "secrets/initial-data.conf" + uid = 100000 + gid = 108978 + perms = 440 + } + + # Mount persistent volume in /data + volume_mount { + volume = "data" + destination = "/data" + } + + + resources { + cpu = 100 + memory = 512 + } + + } + } +} diff --git a/example/consul/config/service-defaults/cloudbeaver.hcl b/example/consul/config/service-defaults/cloudbeaver.hcl new file mode 100644 index 0000000..d76dfce --- /dev/null +++ b/example/consul/config/service-defaults/cloudbeaver.hcl @@ -0,0 +1,3 @@ +Kind = "service-defaults" +Name = "cloudbeaver" +Protocol = "http" diff --git a/example/consul/config/service-intentions/cloudbeaver.hcl b/example/consul/config/service-intentions/cloudbeaver.hcl new file mode 100644 index 0000000..bdd1d26 --- /dev/null +++ b/example/consul/config/service-intentions/cloudbeaver.hcl @@ -0,0 +1,15 @@ +Kind = "service-intentions" +Name = "cloudbeaver" +Sources = [ + { + Name = "traefik" + Permissions = [ + { + Action = "allow" + HTTP { + PathPrefix = "/" + } + } + ] + } +] diff --git a/example/images/cloudbeaver/Dockerfile b/example/images/cloudbeaver/Dockerfile new file mode 100644 index 0000000..d0de0d6 --- /dev/null +++ b/example/images/cloudbeaver/Dockerfile @@ -0,0 +1,27 @@ +FROM danielberteaud/java:17.24.2-4 +MAINTAINER Daniel Berteaud + +ENV CLOUDBEAVER_WEB_CONFIG=/opt/cloudbeaver/conf/cloudbeaver.conf + +RUN set -euxo pipefail &&\ + apk --no-cache add \ + ca-certificates \ + bash \ + &&\ + addgroup --gid 8978 cloudbeaver &&\ + adduser --system --ingroup cloudbeaver --disabled-password --uid 8978 --home /opt/cloudbeaver --shell /sbin/nologin cloudbeaver &&\ + mkdir -p /data/workspace /data/.eclipse &&\ + chown -R cloudbeaver:cloudbeaver /data + +COPY --from=dbeaver/cloudbeaver:23.3.5 /opt/cloudbeaver /opt/cloudbeaver +COPY root/ / + +RUN set -euxo pipefail &&\ + cd /opt/cloudbeaver &&\ + ln -sf /data/.eclipse ./.eclipse + +WORKDIR /opt/cloudbeaver +VOLUME /data +USER cloudbeaver +EXPOSE 8978 +CMD ["cloudbeaver"] diff --git a/example/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh b/example/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh new file mode 100755 index 0000000..51cafaf --- /dev/null +++ b/example/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +mkdir -p /data/workspace/.metadata \ + /data/workspace/.data \ + /data/workspace/GlobalConfiguration/.dbeaver \ + /data/.eclipse diff --git a/example/images/cloudbeaver/root/usr/local/bin/cloudbeaver b/example/images/cloudbeaver/root/usr/local/bin/cloudbeaver new file mode 100755 index 0000000..6404e4b --- /dev/null +++ b/example/images/cloudbeaver/root/usr/local/bin/cloudbeaver @@ -0,0 +1,41 @@ +#!/bin/sh + +set -euo pipefail + +echo "Starting Cloudbeaver Server" + +if [ ! -f "/data/workspace/GlobalConfiguration/.dbeaver/data-sources.json" ]; then + cp conf/initial-data-sources.conf /data/workspace/GlobalConfiguration/.dbeaver/data-sources.json +fi + +java ${JAVA_OPTS} \ + -Dfile.encoding=UTF-8 \ + --add-modules=ALL-SYSTEM \ + --add-opens=java.base/java.io=ALL-UNNAMED \ + --add-opens=java.base/java.lang=ALL-UNNAMED \ + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ + --add-opens=java.base/java.net=ALL-UNNAMED \ + --add-opens=java.base/java.nio=ALL-UNNAMED \ + --add-opens=java.base/java.nio.charset=ALL-UNNAMED \ + --add-opens=java.base/java.text=ALL-UNNAMED \ + --add-opens=java.base/java.time=ALL-UNNAMED \ + --add-opens=java.base/java.util=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED \ + --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED \ + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED \ + --add-opens=java.base/sun.security.ssl=ALL-UNNAMED \ + --add-opens=java.base/sun.security.action=ALL-UNNAMED \ + --add-opens=java.base/sun.security.util=ALL-UNNAMED \ + --add-opens=java.security.jgss/sun.security.jgss=ALL-UNNAMED \ + --add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens=java.sql/java.sql=ALL-UNNAMED \ + -jar server/plugins/org.eclipse.equinox.launcher*.jar \ + -product io.cloudbeaver.product.ce.product \ + -web-config ${CLOUDBEAVER_WEB_CONFIG} \ + -data /data/.metadata \ + -configuration /data/.eclipse \ + -nl en \ + -registryMultiLanguage diff --git a/example/init/cloudbeaver-vault-database b/example/init/cloudbeaver-vault-database new file mode 100755 index 0000000..129f226 --- /dev/null +++ b/example/init/cloudbeaver-vault-database @@ -0,0 +1,12 @@ +#!/bin/sh + +set -euo pipefail + +vault write /database/roles/cloudbeaver \ + db_name="postgres" \ + creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \ + GRANT \"cloudbeaver\" TO \"{{name}}\"; \ + ALTER ROLE \"{{name}}\" SET role = \"cloudbeaver\"" \ + default_ttl="12h" \ + max_ttl="720h" + diff --git a/example/prep.d/10-cloudbeaver-rand-secrets.sh b/example/prep.d/10-cloudbeaver-rand-secrets.sh new file mode 100755 index 0000000..436be23 --- /dev/null +++ b/example/prep.d/10-cloudbeaver-rand-secrets.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -euo pipefail + +# vim: syntax=sh + +export LC_ALL=C +VAULT_KV_PATH=/kv/service/cloudbeaver +RAND_CMD="tr -dc A-Za-z0-9\-_\/=~\.+ < /dev/urandom | head -c 50" +if ! vault kv list $(dirname ${VAULT_KV_PATH}) 2>/dev/null | grep -q -E "^$(basename ${VAULT_KV_PATH})\$"; then + vault kv put ${VAULT_KV_PATH} \ + initial_admin_pwd="$(sh -c "${RAND_CMD}")" \ + +fi +for SECRET in initial_admin_pwd; do + if ! vault kv get -field ${SECRET} ${VAULT_KV_PATH} >/dev/null 2>&1; then + vault kv patch ${VAULT_KV_PATH} \ + ${SECRET}=$(sh -c "${RAND_CMD}") + fi +done + + diff --git a/example/vault/policies/cloudbeaver.hcl b/example/vault/policies/cloudbeaver.hcl new file mode 100644 index 0000000..a3f591d --- /dev/null +++ b/example/vault/policies/cloudbeaver.hcl @@ -0,0 +1,7 @@ +path "/kv/data/service/cloudbeaver" { + capabilities = ["read"] +} + +path "/database/creds/cloudbeaver" { + capabilities = ["read"] +} diff --git a/images/cloudbeaver/Dockerfile b/images/cloudbeaver/Dockerfile new file mode 100644 index 0000000..a54e73b --- /dev/null +++ b/images/cloudbeaver/Dockerfile @@ -0,0 +1,27 @@ +FROM [[ .docker.repo ]][[ .docker.base_images.java17.image ]] +MAINTAINER [[ .docker.maintainer ]] + +ENV CLOUDBEAVER_WEB_CONFIG=/opt/cloudbeaver/conf/cloudbeaver.conf + +RUN set -euxo pipefail &&\ + apk --no-cache add \ + ca-certificates \ + bash \ + &&\ + addgroup --gid 8978 cloudbeaver &&\ + adduser --system --ingroup cloudbeaver --disabled-password --uid 8978 --home /opt/cloudbeaver --shell /sbin/nologin cloudbeaver &&\ + mkdir -p /data/workspace /data/.eclipse &&\ + chown -R cloudbeaver:cloudbeaver /data + +COPY --from=dbeaver/cloudbeaver:[[ .cloudbeaver.version ]] /opt/cloudbeaver /opt/cloudbeaver +COPY root/ / + +RUN set -euxo pipefail &&\ + cd /opt/cloudbeaver &&\ + ln -sf /data/.eclipse ./.eclipse + +WORKDIR /opt/cloudbeaver +VOLUME /data +USER cloudbeaver +EXPOSE 8978 +CMD ["cloudbeaver"] diff --git a/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh b/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh new file mode 100755 index 0000000..51cafaf --- /dev/null +++ b/images/cloudbeaver/root/entrypoint.d/10-mkdir.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +mkdir -p /data/workspace/.metadata \ + /data/workspace/.data \ + /data/workspace/GlobalConfiguration/.dbeaver \ + /data/.eclipse diff --git a/images/cloudbeaver/root/usr/local/bin/cloudbeaver b/images/cloudbeaver/root/usr/local/bin/cloudbeaver new file mode 100755 index 0000000..6404e4b --- /dev/null +++ b/images/cloudbeaver/root/usr/local/bin/cloudbeaver @@ -0,0 +1,41 @@ +#!/bin/sh + +set -euo pipefail + +echo "Starting Cloudbeaver Server" + +if [ ! -f "/data/workspace/GlobalConfiguration/.dbeaver/data-sources.json" ]; then + cp conf/initial-data-sources.conf /data/workspace/GlobalConfiguration/.dbeaver/data-sources.json +fi + +java ${JAVA_OPTS} \ + -Dfile.encoding=UTF-8 \ + --add-modules=ALL-SYSTEM \ + --add-opens=java.base/java.io=ALL-UNNAMED \ + --add-opens=java.base/java.lang=ALL-UNNAMED \ + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ + --add-opens=java.base/java.net=ALL-UNNAMED \ + --add-opens=java.base/java.nio=ALL-UNNAMED \ + --add-opens=java.base/java.nio.charset=ALL-UNNAMED \ + --add-opens=java.base/java.text=ALL-UNNAMED \ + --add-opens=java.base/java.time=ALL-UNNAMED \ + --add-opens=java.base/java.util=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED \ + --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED \ + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED \ + --add-opens=java.base/sun.security.ssl=ALL-UNNAMED \ + --add-opens=java.base/sun.security.action=ALL-UNNAMED \ + --add-opens=java.base/sun.security.util=ALL-UNNAMED \ + --add-opens=java.security.jgss/sun.security.jgss=ALL-UNNAMED \ + --add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED \ + --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens=java.sql/java.sql=ALL-UNNAMED \ + -jar server/plugins/org.eclipse.equinox.launcher*.jar \ + -product io.cloudbeaver.product.ce.product \ + -web-config ${CLOUDBEAVER_WEB_CONFIG} \ + -data /data/.metadata \ + -configuration /data/.eclipse \ + -nl en \ + -registryMultiLanguage diff --git a/init/cloudbeaver-vault-database b/init/cloudbeaver-vault-database new file mode 100755 index 0000000..95db02a --- /dev/null +++ b/init/cloudbeaver-vault-database @@ -0,0 +1,5 @@ +#!/bin/sh + +set -euo pipefail + +[[ template "common/vault.mkpgrole.sh" merge .cloudbeaver . ]] diff --git a/prep.d/10-cloudbeaver-rand-secrets.sh b/prep.d/10-cloudbeaver-rand-secrets.sh new file mode 100755 index 0000000..19eb461 --- /dev/null +++ b/prep.d/10-cloudbeaver-rand-secrets.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -euo pipefail + +[[ template "common/vault.rand_secrets" merge .cloudbeaver . ]] diff --git a/templates/cloudbeaver.conf b/templates/cloudbeaver.conf new file mode 100644 index 0000000..50f5950 --- /dev/null +++ b/templates/cloudbeaver.conf @@ -0,0 +1,81 @@ +{ + server: { + serverPort: 8978, + serverHost: "127.0.0.1", + serverName: "[[ .instance ]]", + workspaceLocation: "/data", + contentRoot: "web", + driversLocation: "drivers", + serverURL: "[[ .public_url ]]", + rootURI: "[[ (urlParse .public_url).Path | regexp.Replace "/$" "" ]]/", + serviceURI: "[[ (urlParse .public_url).Path | regexp.Replace "/$" "" ]]/api/", + productConfiguration: "conf/product.conf", + expireSessionAfterPeriod: 600000, + develMode: false, + sm: { + enableBruteForceProtection: true, + expiredAuthAttemptInfoTtl: 60, + maxFailedLogin: "${CLOUDBEAVER_MAX_FAILED_LOGINS:5}", + minimumLoginTimeout: "${CLOUDBEAVER_MINIMUM_LOGIN_TIMEOUT:1}", + blockLoginPeriod: "${CLOUDBEAVER_BLOCK_PERIOD:300}", + passwordPolicy: { + minLength: "${CLOUDBEAVER_POLICY_MIN_LENGTH:8}", + requireMixedCase: "${CLOUDBEAVER_POLICY_REQUIRE_MIXED_CASE:true}", + minNumberCount: "${CLOUDBEAVER_POLICY_MIN_NUMBER_COUNT:1}", + minSymbolCount: "${CLOUDBEAVER_POLICY_MIN_SYMBOL_COUNT:0}" + } + }, + database: { + driver: "postgres-jdbc", + url: "jdbc:postgresql://${PGHOST}:${PGPORT}/${PGDATABASE}", + user: "${PGUSER}", + password: "${PGPASSWORD}", + initialDataConfiguration: "/secrets/initial-data.conf", + pool: { + minIdleConnections: 4, + maxIdleConnections: 10, + maxConnections: 100, + validationQuery: "SELECT 1" + } + } + }, + app: { + anonymousAccessAllowed: false, + anonymousUserTeam: "user", + authenticationEnabled: true, + supportsCustomConnections: true, + forwardProxy: true, + publicCredentialsSaveEnabled: false, + adminCredentialsSaveEnabled: false, + resourceManagerEnabled: true, + resourceQuotas: { + dataExportFileSizeLimit: 1000000000, + resourceManagerFileSizeLimit: 500000, + sqlMaxRunningQueries: 100, + sqlResultSetRowsLimit: 100000, + sqlResultSetMemoryLimit: 2000000, + sqlTextPreviewMaxLength: 4096, + sqlBinaryPreviewMaxLength: 261120 + }, + defaultNavigatorSettings: { + showSystemObjects: true, + showUtilityObjects: false, + showOnlyEntities: false, + mergeEntities: false, + hideFolders: false, + hideSchemas: false + }, + plugins: { + }, + enabledAuthProviders: [ + "local" + ], + enabledDrivers: [ + ], + disabledDrivers: [ + "sqlite:sqlite_jdbc", + "h2:h2_embedded", + "h2:h2_embedded_v2" + ] + } +} diff --git a/templates/initial-data.conf b/templates/initial-data.conf new file mode 100644 index 0000000..3ca0e55 --- /dev/null +++ b/templates/initial-data.conf @@ -0,0 +1,18 @@ +{ + adminName: "cloudbeaver", + adminPassword: "{{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}{{ .Data.data.initial_admin_pwd }}{{ end }}", + teams: [ + { + subjectId: "admin", + teamName: "Admin", + description: "Administrative access. Has all permissions.", + permissions: [ "admin" ] + }, + { + subjectId: "user", + teamName: "User", + description: "All users, including anonymous.", + permissions: [ ] + } + ] +} diff --git a/templates/logback.xml b/templates/logback.xml new file mode 100644 index 0000000..9d9ecb7 --- /dev/null +++ b/templates/logback.xml @@ -0,0 +1,19 @@ + + + + + + %d{dd-MM-yyyy HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + + + + diff --git a/variables.yml b/variables.yml new file mode 100644 index 0000000..45a8fa9 --- /dev/null +++ b/variables.yml @@ -0,0 +1,75 @@ +--- + +# Name of this instance +instance: cloudbeaver + + +cloudbeaver: + + # Version of cloudbeaver to deploy + version: 23.3.5 + + # Docker image to use + image: '[[ .docker.repo ]]cloudbeaver:[[ .cloudbeaver.version ]]' + + # Resources for the container + resources: + cpu: 100 + memory: 512 + + + vault: + # Vault policies to attach to the container + policies: + - '[[ .instance ]][[ .consul.suffix ]]' + # Random secrets to generate + rand_secrets: + fields: + - initial_admin_pwd + + consul: + connect: + # Connect to the postgres server + upstreams: + - destination_name: postgres[[ .consul.suffix ]] + local_bind_port: 5432 + + # Wait for postgres master to be ready before starting + wait_for: + - service: master.postgres[[ .consul.suffix ]] + + # Custom env var to set in the container + env: {} + + # Custom configuration which will be merged with the default template + # Eg + # config: + # app: + # enabledAuthProviders: + # - reverseProxy + # - local + # authConfigurations: + # - id: lemonldap + # provider: reverseProxy + # displayName: Lemonldap::NG + # parameters: + # user-header: X-SSO-User + # team-header: X-SSO-Groups + # team-delimiter: ',' + # first-name-header: X-SSO-Firstname + # last-name-header: X-SSO-Lastname + # Can be either a map, or a string which will be parsed as YAML before merging + config: {} + + # URL where cloudbeaver will be exposed + public_url: https://cloudbeaver.example.org + + # Traefik settings + traefik: {} + + # CSI volumes for data persistence + volumes: + data: + source: '[[ .instance ]]-data' + type: csi + diff --git a/vault/policies/cloudbeaver.hcl b/vault/policies/cloudbeaver.hcl new file mode 100644 index 0000000..4b45679 --- /dev/null +++ b/vault/policies/cloudbeaver.hcl @@ -0,0 +1,7 @@ +path "[[ .vault.root ]]kv/data/service/[[ .instance ]]" { + capabilities = ["read"] +} + +path "[[ .vault.root ]]database/creds/[[ .instance ]]" { + capabilities = ["read"] +}