From 071fa1a215ec1f0411bd1c54681548e02fa81a0b Mon Sep 17 00:00:00 2001 From: "F.D.Castel" Date: Sat, 26 Sep 2026 21:00:20 +0000 Subject: [PATCH 1/2] feat: support running as a non-root user (issue #46) The image still runs as root by default, but it now also runs as the 'firebird' user (UID 84) or as any UID with GID 0, which is how OpenShift's restricted SCC runs containers. - Dockerfile: runtime-writable paths (/opt/firebird itself, firebird.conf, SYSDBA.password, firebird.log, fb_guard, replication.log, security*.fdb, /tmp/firebird and the data directory) are owned by firebird:0 with g=u. Binaries, libraries and plugins stay owned by root. The installer's stale lock files in /tmp/firebird are removed. - entrypoint: every local isql connection names its user explicitly. Local connections otherwise take the OS user name, which is SYSDBA only for root: UID 84 became 'FIREBIRD' and a random UID failed to create FIREBIRD_USER. - entrypoint: warn on startup when a non-root user cannot write to /opt/firebird or the data directory. - tests: test tmpfs mirrors the image's data directory ownership; new tests for file ownership, full initialization as 84:84 and 12345:0, database ownership without FIREBIRD_USER, and the warning. - README: new "Running as a non-root user" section. - DECISIONS.md: D-020. --- DECISIONS.md | 6 ++ README.md | 21 +++++ generated/3.0.10/bookworm/Dockerfile | 17 +++- generated/3.0.10/bookworm/entrypoint.sh | 27 +++++- generated/3.0.10/jammy/Dockerfile | 17 +++- generated/3.0.10/jammy/entrypoint.sh | 27 +++++- generated/3.0.10/noble/Dockerfile | 17 +++- generated/3.0.10/noble/entrypoint.sh | 27 +++++- generated/3.0.10/trixie/Dockerfile | 17 +++- generated/3.0.10/trixie/entrypoint.sh | 27 +++++- generated/3.0.11/bookworm/Dockerfile | 17 +++- generated/3.0.11/bookworm/entrypoint.sh | 27 +++++- generated/3.0.11/jammy/Dockerfile | 17 +++- generated/3.0.11/jammy/entrypoint.sh | 27 +++++- generated/3.0.11/noble/Dockerfile | 17 +++- generated/3.0.11/noble/entrypoint.sh | 27 +++++- generated/3.0.11/trixie/Dockerfile | 17 +++- generated/3.0.11/trixie/entrypoint.sh | 27 +++++- generated/3.0.12/bookworm/Dockerfile | 17 +++- generated/3.0.12/bookworm/entrypoint.sh | 27 +++++- generated/3.0.12/jammy/Dockerfile | 17 +++- generated/3.0.12/jammy/entrypoint.sh | 27 +++++- generated/3.0.12/noble/Dockerfile | 17 +++- generated/3.0.12/noble/entrypoint.sh | 27 +++++- generated/3.0.12/trixie/Dockerfile | 17 +++- generated/3.0.12/trixie/entrypoint.sh | 27 +++++- generated/3.0.13/bookworm/Dockerfile | 17 +++- generated/3.0.13/bookworm/entrypoint.sh | 27 +++++- generated/3.0.13/jammy/Dockerfile | 17 +++- generated/3.0.13/jammy/entrypoint.sh | 27 +++++- generated/3.0.13/noble/Dockerfile | 17 +++- generated/3.0.13/noble/entrypoint.sh | 27 +++++- generated/3.0.13/trixie/Dockerfile | 17 +++- generated/3.0.13/trixie/entrypoint.sh | 27 +++++- generated/3.0.14/bookworm/Dockerfile | 17 +++- generated/3.0.14/bookworm/entrypoint.sh | 27 +++++- generated/3.0.14/jammy/Dockerfile | 17 +++- generated/3.0.14/jammy/entrypoint.sh | 27 +++++- generated/3.0.14/noble/Dockerfile | 17 +++- generated/3.0.14/noble/entrypoint.sh | 27 +++++- generated/3.0.14/trixie/Dockerfile | 17 +++- generated/3.0.14/trixie/entrypoint.sh | 27 +++++- generated/3.0.9/bookworm/Dockerfile | 17 +++- generated/3.0.9/bookworm/entrypoint.sh | 27 +++++- generated/3.0.9/jammy/Dockerfile | 17 +++- generated/3.0.9/jammy/entrypoint.sh | 27 +++++- generated/3.0.9/noble/Dockerfile | 17 +++- generated/3.0.9/noble/entrypoint.sh | 27 +++++- generated/3.0.9/trixie/Dockerfile | 17 +++- generated/3.0.9/trixie/entrypoint.sh | 27 +++++- generated/4.0.0/bookworm/Dockerfile | 17 +++- generated/4.0.0/bookworm/entrypoint.sh | 27 +++++- generated/4.0.0/jammy/Dockerfile | 17 +++- generated/4.0.0/jammy/entrypoint.sh | 27 +++++- generated/4.0.0/noble/Dockerfile | 17 +++- generated/4.0.0/noble/entrypoint.sh | 27 +++++- generated/4.0.0/trixie/Dockerfile | 17 +++- generated/4.0.0/trixie/entrypoint.sh | 27 +++++- generated/4.0.1/bookworm/Dockerfile | 17 +++- generated/4.0.1/bookworm/entrypoint.sh | 27 +++++- generated/4.0.1/jammy/Dockerfile | 17 +++- generated/4.0.1/jammy/entrypoint.sh | 27 +++++- generated/4.0.1/noble/Dockerfile | 17 +++- generated/4.0.1/noble/entrypoint.sh | 27 +++++- generated/4.0.1/trixie/Dockerfile | 17 +++- generated/4.0.1/trixie/entrypoint.sh | 27 +++++- generated/4.0.2/bookworm/Dockerfile | 17 +++- generated/4.0.2/bookworm/entrypoint.sh | 27 +++++- generated/4.0.2/jammy/Dockerfile | 17 +++- generated/4.0.2/jammy/entrypoint.sh | 27 +++++- generated/4.0.2/noble/Dockerfile | 17 +++- generated/4.0.2/noble/entrypoint.sh | 27 +++++- generated/4.0.2/trixie/Dockerfile | 17 +++- generated/4.0.2/trixie/entrypoint.sh | 27 +++++- generated/4.0.3/bookworm/Dockerfile | 17 +++- generated/4.0.3/bookworm/entrypoint.sh | 27 +++++- generated/4.0.3/jammy/Dockerfile | 17 +++- generated/4.0.3/jammy/entrypoint.sh | 27 +++++- generated/4.0.3/noble/Dockerfile | 17 +++- generated/4.0.3/noble/entrypoint.sh | 27 +++++- generated/4.0.3/trixie/Dockerfile | 17 +++- generated/4.0.3/trixie/entrypoint.sh | 27 +++++- generated/4.0.4/bookworm/Dockerfile | 17 +++- generated/4.0.4/bookworm/entrypoint.sh | 27 +++++- generated/4.0.4/jammy/Dockerfile | 17 +++- generated/4.0.4/jammy/entrypoint.sh | 27 +++++- generated/4.0.4/noble/Dockerfile | 17 +++- generated/4.0.4/noble/entrypoint.sh | 27 +++++- generated/4.0.4/trixie/Dockerfile | 17 +++- generated/4.0.4/trixie/entrypoint.sh | 27 +++++- generated/4.0.5/bookworm/Dockerfile | 17 +++- generated/4.0.5/bookworm/entrypoint.sh | 27 +++++- generated/4.0.5/jammy/Dockerfile | 17 +++- generated/4.0.5/jammy/entrypoint.sh | 27 +++++- generated/4.0.5/noble/Dockerfile | 17 +++- generated/4.0.5/noble/entrypoint.sh | 27 +++++- generated/4.0.5/trixie/Dockerfile | 17 +++- generated/4.0.5/trixie/entrypoint.sh | 27 +++++- generated/4.0.6/bookworm/Dockerfile | 17 +++- generated/4.0.6/bookworm/entrypoint.sh | 27 +++++- generated/4.0.6/jammy/Dockerfile | 17 +++- generated/4.0.6/jammy/entrypoint.sh | 27 +++++- generated/4.0.6/noble/Dockerfile | 17 +++- generated/4.0.6/noble/entrypoint.sh | 27 +++++- generated/4.0.6/trixie/Dockerfile | 17 +++- generated/4.0.6/trixie/entrypoint.sh | 27 +++++- generated/4.0.7/bookworm/Dockerfile | 17 +++- generated/4.0.7/bookworm/entrypoint.sh | 27 +++++- generated/4.0.7/jammy/Dockerfile | 17 +++- generated/4.0.7/jammy/entrypoint.sh | 27 +++++- generated/4.0.7/noble/Dockerfile | 17 +++- generated/4.0.7/noble/entrypoint.sh | 27 +++++- generated/4.0.7/trixie/Dockerfile | 17 +++- generated/4.0.7/trixie/entrypoint.sh | 27 +++++- generated/5.0.0/bookworm/Dockerfile | 17 +++- generated/5.0.0/bookworm/entrypoint.sh | 27 +++++- generated/5.0.0/jammy/Dockerfile | 17 +++- generated/5.0.0/jammy/entrypoint.sh | 27 +++++- generated/5.0.0/noble/Dockerfile | 17 +++- generated/5.0.0/noble/entrypoint.sh | 27 +++++- generated/5.0.0/trixie/Dockerfile | 17 +++- generated/5.0.0/trixie/entrypoint.sh | 27 +++++- generated/5.0.1/bookworm/Dockerfile | 17 +++- generated/5.0.1/bookworm/entrypoint.sh | 27 +++++- generated/5.0.1/jammy/Dockerfile | 17 +++- generated/5.0.1/jammy/entrypoint.sh | 27 +++++- generated/5.0.1/noble/Dockerfile | 17 +++- generated/5.0.1/noble/entrypoint.sh | 27 +++++- generated/5.0.1/trixie/Dockerfile | 17 +++- generated/5.0.1/trixie/entrypoint.sh | 27 +++++- generated/5.0.2/bookworm/Dockerfile | 17 +++- generated/5.0.2/bookworm/entrypoint.sh | 27 +++++- generated/5.0.2/jammy/Dockerfile | 17 +++- generated/5.0.2/jammy/entrypoint.sh | 27 +++++- generated/5.0.2/noble/Dockerfile | 17 +++- generated/5.0.2/noble/entrypoint.sh | 27 +++++- generated/5.0.2/trixie/Dockerfile | 17 +++- generated/5.0.2/trixie/entrypoint.sh | 27 +++++- generated/5.0.3/bookworm/Dockerfile | 17 +++- generated/5.0.3/bookworm/entrypoint.sh | 27 +++++- generated/5.0.3/jammy/Dockerfile | 17 +++- generated/5.0.3/jammy/entrypoint.sh | 27 +++++- generated/5.0.3/noble/Dockerfile | 17 +++- generated/5.0.3/noble/entrypoint.sh | 27 +++++- generated/5.0.3/trixie/Dockerfile | 17 +++- generated/5.0.3/trixie/entrypoint.sh | 27 +++++- generated/5.0.4/bookworm/Dockerfile | 17 +++- generated/5.0.4/bookworm/entrypoint.sh | 27 +++++- generated/5.0.4/jammy/Dockerfile | 17 +++- generated/5.0.4/jammy/entrypoint.sh | 27 +++++- generated/5.0.4/noble/Dockerfile | 17 +++- generated/5.0.4/noble/entrypoint.sh | 27 +++++- generated/5.0.4/trixie/Dockerfile | 17 +++- generated/5.0.4/trixie/entrypoint.sh | 27 +++++- src/Dockerfile.template | 17 +++- src/README.md.template | 21 +++++ src/entrypoint.sh | 27 +++++- src/image.tests.ps1 | 106 +++++++++++++++++++++++- 158 files changed, 3231 insertions(+), 311 deletions(-) diff --git a/DECISIONS.md b/DECISIONS.md index a7e67e9..c1a797c 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -122,6 +122,12 @@ Also adds `tzdata` to Noble's distro `extraPackages` (matching Jammy). FB3 relie **Rationale:** `publish-fork.yaml` passes `-Registry 'ghcr.io/'` to `Update-Readme`, which substitutes the fork's registry into the README table header. The previous unguarded auto-commit pushed that fork-specific README back to whatever branch was dispatched, including branches with open upstream PRs — directly polluting the PR diff with content that must not land upstream, and breaking GitHub's linear rebase when the upstream master had its own concurrent `README.md` changes (observed during PR #43, which required a force-pushed clean rebase to unblock). Branch-gating preserves D-014's "generated/ tracked in git" invariant on the fork's default branch while keeping PR/feature branches diff-clean against upstream. Confines the `-Registry` rewrite to the only place the fork wants it (its own showcased README on `master`). +## D-020: Non-root capable image, root remains the default user + +**Decision:** The image keeps running as `root` by default (no `USER` directive), but also supports running as `firebird` (UID 84) or as any UID with GID 0. Runtime-writable paths — `/opt/firebird` itself, `firebird.conf`, `SYSDBA.password`, `firebird.log`, `fb_guard`, `replication.log`, `security*.fdb`, `/tmp/firebird` and `$FIREBIRD_DATA` — are owned by `firebird:0` with group permissions equal to owner permissions (`g=u`). Binaries, libraries and plugins stay owned by `root`. The installer's leftover lock and shared memory files in `/tmp/firebird` are removed at build time. Every local `isql` connection in the entrypoint names its user explicitly (`-user SYSDBA`, or `FIREBIRD_USER` in `process_sql`). A non-root user without write access gets a warning on startup. + +**Rationale:** Requested in [issue #46](https://github.com/FirebirdSQL/firebird-docker/issues/46) (security policies requiring non-root containers; OpenShift). OpenShift's `restricted` SCC ignores the image's `USER` and injects a random UID with GID 0, so group-0 ownership is what makes it work, not a `USER` line; owner `firebird` keeps `--user firebird` working with GID 84. Local (embedded) connections take the OS user name as the Firebird user: `root` is mapped to SYSDBA, but UID 84 becomes `FIREBIRD` and a random UID has no name at all, which made `CREATE USER` fail and changed database/object ownership. `$FIREBIRD_DATA` is a `VOLUME`, so its ownership must be set in the image layer. Changing the default to `USER firebird` was rejected for now: existing volumes and bind mounts contain root-owned databases which a non-root container cannot open, so it would break deployments on upgrade. It belongs in a major release with explicit release notes. + ## D-022: Bullseye images are no longer built **Decision:** Debian 11 `bullseye` is removed from `config.distros` in `assets.json`, so no `*-bullseye` image is built, tested or published, and its `generated/` folders are deleted. The `*-bullseye` tags already on Docker Hub are kept as they are (no deletion). The README lists bullseye under "Discontinued distributions" and points to `trixie` (default) or `bookworm`. diff --git a/README.md b/README.md index e276256..e9b39fe 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,27 @@ Alternatively, you can use the same time zone as your host system by mapping the +## Running as a non-root user + +The container runs as `root` by default. It can also run as a non-root user, without any change in behavior: + +- as the `firebird` user (UID `84`), e.g. `docker run --user firebird ...`; or +- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. This is how OpenShift runs containers under its default `restricted` security context constraint, which assigns a random UID. + +```yaml +# Kubernetes + securityContext: + runAsNonRoot: true + runAsUser: 84 # or any UID... + runAsGroup: 0 # ...as long as the group is 0 +``` + +Other UID/GID combinations are not supported: the entrypoint shows a warning and Firebird cannot write its runtime files. + +> **IMPORTANT:** When using a bind mount or a pre-existing volume for `/var/lib/firebird/data`, it must be writable by the chosen user. Databases created while running as `root` are owned by `root`, and a non-root container cannot open them until you change their ownership (e.g. `chown -R 84:0` on the data directory). + + + ## Backup and Restore ### For online databases diff --git a/generated/3.0.10/bookworm/Dockerfile b/generated/3.0.10/bookworm/Dockerfile index debed50..e60611d 100644 --- a/generated/3.0.10/bookworm/Dockerfile +++ b/generated/3.0.10/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.10/bookworm/entrypoint.sh b/generated/3.0.10/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.10/bookworm/entrypoint.sh +++ b/generated/3.0.10/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.10/jammy/Dockerfile b/generated/3.0.10/jammy/Dockerfile index de1c6a4..63c6190 100644 --- a/generated/3.0.10/jammy/Dockerfile +++ b/generated/3.0.10/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.10/jammy/entrypoint.sh b/generated/3.0.10/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.10/jammy/entrypoint.sh +++ b/generated/3.0.10/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.10/noble/Dockerfile b/generated/3.0.10/noble/Dockerfile index 83efdd0..bf2c58e 100644 --- a/generated/3.0.10/noble/Dockerfile +++ b/generated/3.0.10/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.10/noble/entrypoint.sh b/generated/3.0.10/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.10/noble/entrypoint.sh +++ b/generated/3.0.10/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.10/trixie/Dockerfile b/generated/3.0.10/trixie/Dockerfile index bacf9c3..96dbfc8 100644 --- a/generated/3.0.10/trixie/Dockerfile +++ b/generated/3.0.10/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.10/trixie/entrypoint.sh b/generated/3.0.10/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.10/trixie/entrypoint.sh +++ b/generated/3.0.10/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.11/bookworm/Dockerfile b/generated/3.0.11/bookworm/Dockerfile index 616f54c..f5b2796 100644 --- a/generated/3.0.11/bookworm/Dockerfile +++ b/generated/3.0.11/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.11/bookworm/entrypoint.sh b/generated/3.0.11/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.11/bookworm/entrypoint.sh +++ b/generated/3.0.11/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.11/jammy/Dockerfile b/generated/3.0.11/jammy/Dockerfile index 1bbab84..96e3354 100644 --- a/generated/3.0.11/jammy/Dockerfile +++ b/generated/3.0.11/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.11/jammy/entrypoint.sh b/generated/3.0.11/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.11/jammy/entrypoint.sh +++ b/generated/3.0.11/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.11/noble/Dockerfile b/generated/3.0.11/noble/Dockerfile index e60ba6b..81c7504 100644 --- a/generated/3.0.11/noble/Dockerfile +++ b/generated/3.0.11/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.11/noble/entrypoint.sh b/generated/3.0.11/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.11/noble/entrypoint.sh +++ b/generated/3.0.11/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.11/trixie/Dockerfile b/generated/3.0.11/trixie/Dockerfile index 5546419..cf44380 100644 --- a/generated/3.0.11/trixie/Dockerfile +++ b/generated/3.0.11/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.11/trixie/entrypoint.sh b/generated/3.0.11/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.11/trixie/entrypoint.sh +++ b/generated/3.0.11/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.12/bookworm/Dockerfile b/generated/3.0.12/bookworm/Dockerfile index a2fe8cb..82167fb 100644 --- a/generated/3.0.12/bookworm/Dockerfile +++ b/generated/3.0.12/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.12/bookworm/entrypoint.sh b/generated/3.0.12/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.12/bookworm/entrypoint.sh +++ b/generated/3.0.12/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.12/jammy/Dockerfile b/generated/3.0.12/jammy/Dockerfile index efa77c1..4a216a3 100644 --- a/generated/3.0.12/jammy/Dockerfile +++ b/generated/3.0.12/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.12/jammy/entrypoint.sh b/generated/3.0.12/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.12/jammy/entrypoint.sh +++ b/generated/3.0.12/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.12/noble/Dockerfile b/generated/3.0.12/noble/Dockerfile index 03bdfe7..c6c0b30 100644 --- a/generated/3.0.12/noble/Dockerfile +++ b/generated/3.0.12/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.12/noble/entrypoint.sh b/generated/3.0.12/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.12/noble/entrypoint.sh +++ b/generated/3.0.12/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.12/trixie/Dockerfile b/generated/3.0.12/trixie/Dockerfile index 07c8228..cc79064 100644 --- a/generated/3.0.12/trixie/Dockerfile +++ b/generated/3.0.12/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.12/trixie/entrypoint.sh b/generated/3.0.12/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.12/trixie/entrypoint.sh +++ b/generated/3.0.12/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.13/bookworm/Dockerfile b/generated/3.0.13/bookworm/Dockerfile index eefe52c..3d641df 100644 --- a/generated/3.0.13/bookworm/Dockerfile +++ b/generated/3.0.13/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.13/bookworm/entrypoint.sh b/generated/3.0.13/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.13/bookworm/entrypoint.sh +++ b/generated/3.0.13/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.13/jammy/Dockerfile b/generated/3.0.13/jammy/Dockerfile index 2ed78e5..949c6bc 100644 --- a/generated/3.0.13/jammy/Dockerfile +++ b/generated/3.0.13/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.13/jammy/entrypoint.sh b/generated/3.0.13/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.13/jammy/entrypoint.sh +++ b/generated/3.0.13/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.13/noble/Dockerfile b/generated/3.0.13/noble/Dockerfile index 78ed260..5326c3c 100644 --- a/generated/3.0.13/noble/Dockerfile +++ b/generated/3.0.13/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.13/noble/entrypoint.sh b/generated/3.0.13/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.13/noble/entrypoint.sh +++ b/generated/3.0.13/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.13/trixie/Dockerfile b/generated/3.0.13/trixie/Dockerfile index 5908fea..f16f47d 100644 --- a/generated/3.0.13/trixie/Dockerfile +++ b/generated/3.0.13/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.13/trixie/entrypoint.sh b/generated/3.0.13/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.13/trixie/entrypoint.sh +++ b/generated/3.0.13/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.14/bookworm/Dockerfile b/generated/3.0.14/bookworm/Dockerfile index 441a427..b330b33 100644 --- a/generated/3.0.14/bookworm/Dockerfile +++ b/generated/3.0.14/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.14/bookworm/entrypoint.sh b/generated/3.0.14/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.14/bookworm/entrypoint.sh +++ b/generated/3.0.14/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.14/jammy/Dockerfile b/generated/3.0.14/jammy/Dockerfile index c42f496..3584ab4 100644 --- a/generated/3.0.14/jammy/Dockerfile +++ b/generated/3.0.14/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.14/jammy/entrypoint.sh b/generated/3.0.14/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.14/jammy/entrypoint.sh +++ b/generated/3.0.14/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.14/noble/Dockerfile b/generated/3.0.14/noble/Dockerfile index b886b5c..d301b24 100644 --- a/generated/3.0.14/noble/Dockerfile +++ b/generated/3.0.14/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.14/noble/entrypoint.sh b/generated/3.0.14/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.14/noble/entrypoint.sh +++ b/generated/3.0.14/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.14/trixie/Dockerfile b/generated/3.0.14/trixie/Dockerfile index 724857b..1b369dc 100644 --- a/generated/3.0.14/trixie/Dockerfile +++ b/generated/3.0.14/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.14/trixie/entrypoint.sh b/generated/3.0.14/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.14/trixie/entrypoint.sh +++ b/generated/3.0.14/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.9/bookworm/Dockerfile b/generated/3.0.9/bookworm/Dockerfile index 5afcddb..1716a58 100644 --- a/generated/3.0.9/bookworm/Dockerfile +++ b/generated/3.0.9/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.9/bookworm/entrypoint.sh b/generated/3.0.9/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.9/bookworm/entrypoint.sh +++ b/generated/3.0.9/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.9/jammy/Dockerfile b/generated/3.0.9/jammy/Dockerfile index 62e366c..cfa25cf 100644 --- a/generated/3.0.9/jammy/Dockerfile +++ b/generated/3.0.9/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.9/jammy/entrypoint.sh b/generated/3.0.9/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.9/jammy/entrypoint.sh +++ b/generated/3.0.9/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.9/noble/Dockerfile b/generated/3.0.9/noble/Dockerfile index 77b7c33..add1c8f 100644 --- a/generated/3.0.9/noble/Dockerfile +++ b/generated/3.0.9/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.9/noble/entrypoint.sh b/generated/3.0.9/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.9/noble/entrypoint.sh +++ b/generated/3.0.9/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/3.0.9/trixie/Dockerfile b/generated/3.0.9/trixie/Dockerfile index c529bf4..ecf585b 100644 --- a/generated/3.0.9/trixie/Dockerfile +++ b/generated/3.0.9/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/3.0.9/trixie/entrypoint.sh b/generated/3.0.9/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/3.0.9/trixie/entrypoint.sh +++ b/generated/3.0.9/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.0/bookworm/Dockerfile b/generated/4.0.0/bookworm/Dockerfile index 6507138..c59d153 100644 --- a/generated/4.0.0/bookworm/Dockerfile +++ b/generated/4.0.0/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.0/bookworm/entrypoint.sh b/generated/4.0.0/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.0/bookworm/entrypoint.sh +++ b/generated/4.0.0/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.0/jammy/Dockerfile b/generated/4.0.0/jammy/Dockerfile index 40bcf88..b7e5888 100644 --- a/generated/4.0.0/jammy/Dockerfile +++ b/generated/4.0.0/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.0/jammy/entrypoint.sh b/generated/4.0.0/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.0/jammy/entrypoint.sh +++ b/generated/4.0.0/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.0/noble/Dockerfile b/generated/4.0.0/noble/Dockerfile index 0c0fdc2..5b9880f 100644 --- a/generated/4.0.0/noble/Dockerfile +++ b/generated/4.0.0/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.0/noble/entrypoint.sh b/generated/4.0.0/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.0/noble/entrypoint.sh +++ b/generated/4.0.0/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.0/trixie/Dockerfile b/generated/4.0.0/trixie/Dockerfile index 6ff0a32..b9982fd 100644 --- a/generated/4.0.0/trixie/Dockerfile +++ b/generated/4.0.0/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.0/trixie/entrypoint.sh b/generated/4.0.0/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.0/trixie/entrypoint.sh +++ b/generated/4.0.0/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.1/bookworm/Dockerfile b/generated/4.0.1/bookworm/Dockerfile index 33a137a..7cda5ba 100644 --- a/generated/4.0.1/bookworm/Dockerfile +++ b/generated/4.0.1/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.1/bookworm/entrypoint.sh b/generated/4.0.1/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.1/bookworm/entrypoint.sh +++ b/generated/4.0.1/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.1/jammy/Dockerfile b/generated/4.0.1/jammy/Dockerfile index 18c0a54..0aec71d 100644 --- a/generated/4.0.1/jammy/Dockerfile +++ b/generated/4.0.1/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.1/jammy/entrypoint.sh b/generated/4.0.1/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.1/jammy/entrypoint.sh +++ b/generated/4.0.1/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.1/noble/Dockerfile b/generated/4.0.1/noble/Dockerfile index de2bd95..d2a1567 100644 --- a/generated/4.0.1/noble/Dockerfile +++ b/generated/4.0.1/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.1/noble/entrypoint.sh b/generated/4.0.1/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.1/noble/entrypoint.sh +++ b/generated/4.0.1/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.1/trixie/Dockerfile b/generated/4.0.1/trixie/Dockerfile index 3751566..4250dad 100644 --- a/generated/4.0.1/trixie/Dockerfile +++ b/generated/4.0.1/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.1/trixie/entrypoint.sh b/generated/4.0.1/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.1/trixie/entrypoint.sh +++ b/generated/4.0.1/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.2/bookworm/Dockerfile b/generated/4.0.2/bookworm/Dockerfile index 1d2b091..6695f36 100644 --- a/generated/4.0.2/bookworm/Dockerfile +++ b/generated/4.0.2/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.2/bookworm/entrypoint.sh b/generated/4.0.2/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.2/bookworm/entrypoint.sh +++ b/generated/4.0.2/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.2/jammy/Dockerfile b/generated/4.0.2/jammy/Dockerfile index 9b4c0bf..446a48a 100644 --- a/generated/4.0.2/jammy/Dockerfile +++ b/generated/4.0.2/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.2/jammy/entrypoint.sh b/generated/4.0.2/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.2/jammy/entrypoint.sh +++ b/generated/4.0.2/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.2/noble/Dockerfile b/generated/4.0.2/noble/Dockerfile index c155216..1f22ca3 100644 --- a/generated/4.0.2/noble/Dockerfile +++ b/generated/4.0.2/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.2/noble/entrypoint.sh b/generated/4.0.2/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.2/noble/entrypoint.sh +++ b/generated/4.0.2/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.2/trixie/Dockerfile b/generated/4.0.2/trixie/Dockerfile index dce38af..1e6cd23 100644 --- a/generated/4.0.2/trixie/Dockerfile +++ b/generated/4.0.2/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.2/trixie/entrypoint.sh b/generated/4.0.2/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.2/trixie/entrypoint.sh +++ b/generated/4.0.2/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.3/bookworm/Dockerfile b/generated/4.0.3/bookworm/Dockerfile index 86476f8..871fea1 100644 --- a/generated/4.0.3/bookworm/Dockerfile +++ b/generated/4.0.3/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.3/bookworm/entrypoint.sh b/generated/4.0.3/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.3/bookworm/entrypoint.sh +++ b/generated/4.0.3/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.3/jammy/Dockerfile b/generated/4.0.3/jammy/Dockerfile index 6d73b2c..e9978cb 100644 --- a/generated/4.0.3/jammy/Dockerfile +++ b/generated/4.0.3/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.3/jammy/entrypoint.sh b/generated/4.0.3/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.3/jammy/entrypoint.sh +++ b/generated/4.0.3/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.3/noble/Dockerfile b/generated/4.0.3/noble/Dockerfile index 39805a6..5023722 100644 --- a/generated/4.0.3/noble/Dockerfile +++ b/generated/4.0.3/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.3/noble/entrypoint.sh b/generated/4.0.3/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.3/noble/entrypoint.sh +++ b/generated/4.0.3/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.3/trixie/Dockerfile b/generated/4.0.3/trixie/Dockerfile index 9ba3f97..e118b5e 100644 --- a/generated/4.0.3/trixie/Dockerfile +++ b/generated/4.0.3/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.3/trixie/entrypoint.sh b/generated/4.0.3/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.3/trixie/entrypoint.sh +++ b/generated/4.0.3/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.4/bookworm/Dockerfile b/generated/4.0.4/bookworm/Dockerfile index 3ea1e5e..54a1255 100644 --- a/generated/4.0.4/bookworm/Dockerfile +++ b/generated/4.0.4/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.4/bookworm/entrypoint.sh b/generated/4.0.4/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.4/bookworm/entrypoint.sh +++ b/generated/4.0.4/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.4/jammy/Dockerfile b/generated/4.0.4/jammy/Dockerfile index 70eff63..ff38a0c 100644 --- a/generated/4.0.4/jammy/Dockerfile +++ b/generated/4.0.4/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.4/jammy/entrypoint.sh b/generated/4.0.4/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.4/jammy/entrypoint.sh +++ b/generated/4.0.4/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.4/noble/Dockerfile b/generated/4.0.4/noble/Dockerfile index 2313fc4..43da8e7 100644 --- a/generated/4.0.4/noble/Dockerfile +++ b/generated/4.0.4/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.4/noble/entrypoint.sh b/generated/4.0.4/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.4/noble/entrypoint.sh +++ b/generated/4.0.4/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.4/trixie/Dockerfile b/generated/4.0.4/trixie/Dockerfile index 1681e5b..2453632 100644 --- a/generated/4.0.4/trixie/Dockerfile +++ b/generated/4.0.4/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.4/trixie/entrypoint.sh b/generated/4.0.4/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.4/trixie/entrypoint.sh +++ b/generated/4.0.4/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.5/bookworm/Dockerfile b/generated/4.0.5/bookworm/Dockerfile index aefdc2d..20f21b1 100644 --- a/generated/4.0.5/bookworm/Dockerfile +++ b/generated/4.0.5/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.5/bookworm/entrypoint.sh b/generated/4.0.5/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.5/bookworm/entrypoint.sh +++ b/generated/4.0.5/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.5/jammy/Dockerfile b/generated/4.0.5/jammy/Dockerfile index 4633414..e9606d8 100644 --- a/generated/4.0.5/jammy/Dockerfile +++ b/generated/4.0.5/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.5/jammy/entrypoint.sh b/generated/4.0.5/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.5/jammy/entrypoint.sh +++ b/generated/4.0.5/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.5/noble/Dockerfile b/generated/4.0.5/noble/Dockerfile index b8d6d87..aaa24ff 100644 --- a/generated/4.0.5/noble/Dockerfile +++ b/generated/4.0.5/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.5/noble/entrypoint.sh b/generated/4.0.5/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.5/noble/entrypoint.sh +++ b/generated/4.0.5/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.5/trixie/Dockerfile b/generated/4.0.5/trixie/Dockerfile index d63c1b6..c28c8b6 100644 --- a/generated/4.0.5/trixie/Dockerfile +++ b/generated/4.0.5/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.5/trixie/entrypoint.sh b/generated/4.0.5/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.5/trixie/entrypoint.sh +++ b/generated/4.0.5/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.6/bookworm/Dockerfile b/generated/4.0.6/bookworm/Dockerfile index f980acd..b1b8a0a 100644 --- a/generated/4.0.6/bookworm/Dockerfile +++ b/generated/4.0.6/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.6/bookworm/entrypoint.sh b/generated/4.0.6/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.6/bookworm/entrypoint.sh +++ b/generated/4.0.6/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.6/jammy/Dockerfile b/generated/4.0.6/jammy/Dockerfile index 694c60f..612ea67 100644 --- a/generated/4.0.6/jammy/Dockerfile +++ b/generated/4.0.6/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.6/jammy/entrypoint.sh b/generated/4.0.6/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.6/jammy/entrypoint.sh +++ b/generated/4.0.6/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.6/noble/Dockerfile b/generated/4.0.6/noble/Dockerfile index 98d59da..ed0cb9f 100644 --- a/generated/4.0.6/noble/Dockerfile +++ b/generated/4.0.6/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.6/noble/entrypoint.sh b/generated/4.0.6/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.6/noble/entrypoint.sh +++ b/generated/4.0.6/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.6/trixie/Dockerfile b/generated/4.0.6/trixie/Dockerfile index 8be7c3a..42f4555 100644 --- a/generated/4.0.6/trixie/Dockerfile +++ b/generated/4.0.6/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.6/trixie/entrypoint.sh b/generated/4.0.6/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.6/trixie/entrypoint.sh +++ b/generated/4.0.6/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.7/bookworm/Dockerfile b/generated/4.0.7/bookworm/Dockerfile index be62c24..adf74ab 100644 --- a/generated/4.0.7/bookworm/Dockerfile +++ b/generated/4.0.7/bookworm/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.7/bookworm/entrypoint.sh b/generated/4.0.7/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.7/bookworm/entrypoint.sh +++ b/generated/4.0.7/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.7/jammy/Dockerfile b/generated/4.0.7/jammy/Dockerfile index 59d0580..a590f08 100644 --- a/generated/4.0.7/jammy/Dockerfile +++ b/generated/4.0.7/jammy/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.7/jammy/entrypoint.sh b/generated/4.0.7/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.7/jammy/entrypoint.sh +++ b/generated/4.0.7/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.7/noble/Dockerfile b/generated/4.0.7/noble/Dockerfile index 09e4a9c..8042a43 100644 --- a/generated/4.0.7/noble/Dockerfile +++ b/generated/4.0.7/noble/Dockerfile @@ -121,10 +121,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.7/noble/entrypoint.sh b/generated/4.0.7/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.7/noble/entrypoint.sh +++ b/generated/4.0.7/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/4.0.7/trixie/Dockerfile b/generated/4.0.7/trixie/Dockerfile index b419346..2c99185 100644 --- a/generated/4.0.7/trixie/Dockerfile +++ b/generated/4.0.7/trixie/Dockerfile @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/4.0.7/trixie/entrypoint.sh b/generated/4.0.7/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/4.0.7/trixie/entrypoint.sh +++ b/generated/4.0.7/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.0/bookworm/Dockerfile b/generated/5.0.0/bookworm/Dockerfile index 798e7f9..a8ccbba 100644 --- a/generated/5.0.0/bookworm/Dockerfile +++ b/generated/5.0.0/bookworm/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.0/bookworm/entrypoint.sh b/generated/5.0.0/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.0/bookworm/entrypoint.sh +++ b/generated/5.0.0/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.0/jammy/Dockerfile b/generated/5.0.0/jammy/Dockerfile index 8ce97b7..249c102 100644 --- a/generated/5.0.0/jammy/Dockerfile +++ b/generated/5.0.0/jammy/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.0/jammy/entrypoint.sh b/generated/5.0.0/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.0/jammy/entrypoint.sh +++ b/generated/5.0.0/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.0/noble/Dockerfile b/generated/5.0.0/noble/Dockerfile index 07fcadf..b8c180e 100644 --- a/generated/5.0.0/noble/Dockerfile +++ b/generated/5.0.0/noble/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.0/noble/entrypoint.sh b/generated/5.0.0/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.0/noble/entrypoint.sh +++ b/generated/5.0.0/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.0/trixie/Dockerfile b/generated/5.0.0/trixie/Dockerfile index 8295896..58f2164 100644 --- a/generated/5.0.0/trixie/Dockerfile +++ b/generated/5.0.0/trixie/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.0/trixie/entrypoint.sh b/generated/5.0.0/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.0/trixie/entrypoint.sh +++ b/generated/5.0.0/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.1/bookworm/Dockerfile b/generated/5.0.1/bookworm/Dockerfile index 8996ced..c00a0ea 100644 --- a/generated/5.0.1/bookworm/Dockerfile +++ b/generated/5.0.1/bookworm/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.1/bookworm/entrypoint.sh b/generated/5.0.1/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.1/bookworm/entrypoint.sh +++ b/generated/5.0.1/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.1/jammy/Dockerfile b/generated/5.0.1/jammy/Dockerfile index 9a9e3c5..5a9ca75 100644 --- a/generated/5.0.1/jammy/Dockerfile +++ b/generated/5.0.1/jammy/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.1/jammy/entrypoint.sh b/generated/5.0.1/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.1/jammy/entrypoint.sh +++ b/generated/5.0.1/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.1/noble/Dockerfile b/generated/5.0.1/noble/Dockerfile index 0ad54bc..5cbe056 100644 --- a/generated/5.0.1/noble/Dockerfile +++ b/generated/5.0.1/noble/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.1/noble/entrypoint.sh b/generated/5.0.1/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.1/noble/entrypoint.sh +++ b/generated/5.0.1/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.1/trixie/Dockerfile b/generated/5.0.1/trixie/Dockerfile index 48ddb36..98588ef 100644 --- a/generated/5.0.1/trixie/Dockerfile +++ b/generated/5.0.1/trixie/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.1/trixie/entrypoint.sh b/generated/5.0.1/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.1/trixie/entrypoint.sh +++ b/generated/5.0.1/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.2/bookworm/Dockerfile b/generated/5.0.2/bookworm/Dockerfile index 5db46db..4a8ab3f 100644 --- a/generated/5.0.2/bookworm/Dockerfile +++ b/generated/5.0.2/bookworm/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.2/bookworm/entrypoint.sh b/generated/5.0.2/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.2/bookworm/entrypoint.sh +++ b/generated/5.0.2/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.2/jammy/Dockerfile b/generated/5.0.2/jammy/Dockerfile index dd8aa46..618f10b 100644 --- a/generated/5.0.2/jammy/Dockerfile +++ b/generated/5.0.2/jammy/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.2/jammy/entrypoint.sh b/generated/5.0.2/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.2/jammy/entrypoint.sh +++ b/generated/5.0.2/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.2/noble/Dockerfile b/generated/5.0.2/noble/Dockerfile index 3ac468b..acf4f59 100644 --- a/generated/5.0.2/noble/Dockerfile +++ b/generated/5.0.2/noble/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.2/noble/entrypoint.sh b/generated/5.0.2/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.2/noble/entrypoint.sh +++ b/generated/5.0.2/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.2/trixie/Dockerfile b/generated/5.0.2/trixie/Dockerfile index d507828..c39f5a3 100644 --- a/generated/5.0.2/trixie/Dockerfile +++ b/generated/5.0.2/trixie/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.2/trixie/entrypoint.sh b/generated/5.0.2/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.2/trixie/entrypoint.sh +++ b/generated/5.0.2/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.3/bookworm/Dockerfile b/generated/5.0.3/bookworm/Dockerfile index 855f0c1..e9d1186 100644 --- a/generated/5.0.3/bookworm/Dockerfile +++ b/generated/5.0.3/bookworm/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.3/bookworm/entrypoint.sh b/generated/5.0.3/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.3/bookworm/entrypoint.sh +++ b/generated/5.0.3/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.3/jammy/Dockerfile b/generated/5.0.3/jammy/Dockerfile index 26c4fc8..d1b4ac7 100644 --- a/generated/5.0.3/jammy/Dockerfile +++ b/generated/5.0.3/jammy/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.3/jammy/entrypoint.sh b/generated/5.0.3/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.3/jammy/entrypoint.sh +++ b/generated/5.0.3/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.3/noble/Dockerfile b/generated/5.0.3/noble/Dockerfile index 7738844..9784260 100644 --- a/generated/5.0.3/noble/Dockerfile +++ b/generated/5.0.3/noble/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.3/noble/entrypoint.sh b/generated/5.0.3/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.3/noble/entrypoint.sh +++ b/generated/5.0.3/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.3/trixie/Dockerfile b/generated/5.0.3/trixie/Dockerfile index ef6dd71..904e0f8 100644 --- a/generated/5.0.3/trixie/Dockerfile +++ b/generated/5.0.3/trixie/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.3/trixie/entrypoint.sh b/generated/5.0.3/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.3/trixie/entrypoint.sh +++ b/generated/5.0.3/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.4/bookworm/Dockerfile b/generated/5.0.4/bookworm/Dockerfile index 23121b8..fb9bfd6 100644 --- a/generated/5.0.4/bookworm/Dockerfile +++ b/generated/5.0.4/bookworm/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.4/bookworm/entrypoint.sh b/generated/5.0.4/bookworm/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.4/bookworm/entrypoint.sh +++ b/generated/5.0.4/bookworm/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.4/jammy/Dockerfile b/generated/5.0.4/jammy/Dockerfile index 50d4885..d66658c 100644 --- a/generated/5.0.4/jammy/Dockerfile +++ b/generated/5.0.4/jammy/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.4/jammy/entrypoint.sh b/generated/5.0.4/jammy/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.4/jammy/entrypoint.sh +++ b/generated/5.0.4/jammy/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.4/noble/Dockerfile b/generated/5.0.4/noble/Dockerfile index a6afdf0..e14fff2 100644 --- a/generated/5.0.4/noble/Dockerfile +++ b/generated/5.0.4/noble/Dockerfile @@ -125,10 +125,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.4/noble/entrypoint.sh b/generated/5.0.4/noble/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.4/noble/entrypoint.sh +++ b/generated/5.0.4/noble/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/generated/5.0.4/trixie/Dockerfile b/generated/5.0.4/trixie/Dockerfile index 5d6810a..26bddea 100644 --- a/generated/5.0.4/trixie/Dockerfile +++ b/generated/5.0.4/trixie/Dockerfile @@ -124,10 +124,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/generated/5.0.4/trixie/entrypoint.sh b/generated/5.0.4/trixie/entrypoint.sh index 21a0cfa..311b947 100644 --- a/generated/5.0.4/trixie/entrypoint.sh +++ b/generated/5.0.4/trixie/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/src/Dockerfile.template b/src/Dockerfile.template index 45c3495..266dc2d 100644 --- a/src/Dockerfile.template +++ b/src/Dockerfile.template @@ -120,10 +120,23 @@ ENV PATH=/opt/firebird/bin:$PATH # Data directory ENV FIREBIRD_DATA=/var/lib/firebird/data + +# Non-root support: runtime-writable paths are owned by 'firebird' with group 0 (root), and group permissions equal +# owner permissions. The image still runs as root by default, but it also runs as 'firebird' (--user firebird) or as +# an arbitrary UID with GID 0 (OpenShift restricted SCC). Binaries, libraries and plugins stay owned by root. +# The data directory is a VOLUME: its ownership must be set here, in the image layer. +# Lock and shared memory files left in /tmp/firebird by the installer are removed (Firebird recreates them at runtime). +# See DECISIONS.md D-020 and https://github.com/FirebirdSQL/firebird-docker/issues/46 RUN set -eux; \ mkdir -p "$FIREBIRD_DATA"; \ - chown -R firebird:firebird "$FIREBIRD_DATA"; \ - chmod 755 "$FIREBIRD_DATA" + rm -rf /tmp/firebird/*; \ + cd /opt/firebird; \ + for f in . SYSDBA.password firebird.conf firebird.log fb_guard replication.log security*.fdb /tmp/firebird "$FIREBIRD_DATA"; do \ + if [ -e "$f" ]; then \ + chown firebird:0 "$f"; \ + chmod g=u,o-w "$f"; \ + fi; \ + done VOLUME $FIREBIRD_DATA # Entrypoint diff --git a/src/README.md.template b/src/README.md.template index 688971b..f9afbea 100644 --- a/src/README.md.template +++ b/src/README.md.template @@ -267,6 +267,27 @@ Alternatively, you can use the same time zone as your host system by mapping the +## Running as a non-root user + +The container runs as `root` by default. It can also run as a non-root user, without any change in behavior: + +- as the `firebird` user (UID `84`), e.g. `docker run --user firebird ...`; or +- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. This is how OpenShift runs containers under its default `restricted` security context constraint, which assigns a random UID. + +```yaml +# Kubernetes + securityContext: + runAsNonRoot: true + runAsUser: 84 # or any UID... + runAsGroup: 0 # ...as long as the group is 0 +``` + +Other UID/GID combinations are not supported: the entrypoint shows a warning and Firebird cannot write its runtime files. + +> **IMPORTANT:** When using a bind mount or a pre-existing volume for `/var/lib/firebird/data`, it must be writable by the chosen user. Databases created while running as `root` are owned by `root`, and a non-root container cannot open them until you change their ownership (e.g. `chown -R 84:0` on the data directory). + + + ## Backup and Restore ### For online databases diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 21a0cfa..311b947 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -107,6 +107,25 @@ indent() { sed 's/^/ /'; } +# Warns when a non-root user cannot write to Firebird runtime files. +# Supported non-root users are 'firebird' and any UID with GID 0 (e.g. OpenShift restricted SCC). +check_permissions() { + if [ "$(id -u)" = '0' ]; then + return + fi + + if [ ! -w /opt/firebird ] || [ ! -w "$FIREBIRD_DATA" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + WARNING: Running as UID $(id -u) / GID $(id -g), which cannot write to /opt/firebird or $FIREBIRD_DATA. + + Run the container as root, as user 'firebird' (UID 84), or as any UID with GID 0. + ----- + EOL + fi +} + # Set Firebird configuration parameters from environment variables. set_config() { read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' @@ -203,7 +222,7 @@ create_user() { escaped_password=$(escape_sql_string "$FIREBIRD_PASSWORD") # [Tabs ahead] - /opt/firebird/bin/isql -b security.db <<-EOL + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL CREATE OR ALTER USER ${quoted_user} PASSWORD '${escaped_password}' GRANT ADMIN ROLE; @@ -221,6 +240,9 @@ process_sql() { # authentication, and the server then normalizes the name exactly like it # normalized the database owner name, so DDL permissions work in init scripts. isql_command+=( -u "$(unquote_sql_identifier "$(quote_sql_identifier "$FIREBIRD_USER")")" -p "$FIREBIRD_PASSWORD" ) + else + # Local connections otherwise take the OS user name, which is SYSDBA only for root. + isql_command+=( -u SYSDBA ) fi if [ -n "$FIREBIRD_DATABASE" ]; then @@ -302,7 +324,7 @@ create_db() { [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" # [Tabs ahead] - /opt/firebird/bin/isql -b -q <<-EOL + /opt/firebird/bin/isql -b -q -user SYSDBA <<-EOL CREATE DATABASE '${escaped_database}' $user_and_password $page_size @@ -345,6 +367,7 @@ run_daemon_and_wait() { # main() # if [ "$1" = 'firebird' ]; then + check_permissions set_config set_sysdba diff --git a/src/image.tests.ps1 b/src/image.tests.ps1 index 3689c07..5d7d6b5 100644 --- a/src/image.tests.ps1 +++ b/src/image.tests.ps1 @@ -2,11 +2,14 @@ # Functions # +# Data directory for test containers. Same ownership and mode as in the image layer (firebird:0, 0775). +$dataTmpfs = '/var/lib/firebird/data:uid=84,gid=0,mode=0775' + # Run commands in a container and return. function Invoke-Container([string[]]$DockerParameters, [string[]]$ImageParameters) { assert $env:FULL_IMAGE_NAME "'FULL_IMAGE_NAME' environment variable must be set to the image name to test." - $allParameters = @('run', '--tmpfs', '/var/lib/firebird/data', '--rm'; $DockerParameters; $env:FULL_IMAGE_NAME) + $allParameters = @('run', '--tmpfs', $dataTmpfs, '--rm'; $DockerParameters; $env:FULL_IMAGE_NAME) if ($ImageParameters) { # Do not append a $null as last parameter if $ImageParameters is empty $allParameters += $ImageParameters @@ -21,7 +24,7 @@ function Invoke-Container([string[]]$DockerParameters, [string[]]$ImageParameter function Use-Container([string[]]$Parameters, [Parameter(Mandatory)][ScriptBlock]$ScriptBlock) { assert $env:FULL_IMAGE_NAME "'FULL_IMAGE_NAME' environment variable must be set to the image name to test." - $allParameters = @('run'; $Parameters; '--tmpfs', '/var/lib/firebird/data', '--detach', $env:FULL_IMAGE_NAME) + $allParameters = @('run'; $Parameters; '--tmpfs', $dataTmpfs, '--detach', $env:FULL_IMAGE_NAME) Write-Verbose 'Starting container... Command line is' Write-Verbose " docker $allParameters" @@ -594,4 +597,101 @@ task Tag_correctness_via_docker_inspect { assert ($null -ne $version) "Expected 'org.opencontainers.image.version' label to be set." # Accept either a semver release (e.g. '5.0.3') or a snapshot tag (e.g. '5-snapshot', '6-snapshot') assert ($version -match '^\d+\.\d+\.\d+$' -or $version -match '^\d+-snapshot$') "Expected version label '$version' to be semver or snapshot format." -} \ No newline at end of file +} + +# +# Non-root support -- https://github.com/FirebirdSQL/firebird-docker/issues/46 +# + +task Runtime_paths_are_owned_by_firebird_and_group_root { + # Runs 'stat' directly (not via Invoke-Container) to see the data directory as shipped in the image layer, not a tmpfs. + $paths = '/opt/firebird', '/opt/firebird/firebird.conf', '/opt/firebird/firebird.log', '/opt/firebird/fb_guard', '/tmp/firebird', '/var/lib/firebird/data' + $stats = docker run --rm --entrypoint stat $env:FULL_IMAGE_NAME -c '%U %g %A %n' @paths + assert ($LastExitCode -eq 0) "Expected 'stat' to succeed on all runtime paths." + + $stats | ForEach-Object { + $owner, $gid, $mode, $path = $_ -split ' ' + assert ($owner -eq 'firebird') "Expected '$path' to be owned by 'firebird', got '$owner'." + assert ($gid -eq '0') "Expected '$path' to have group 0 (root), got '$gid'." + assert ($mode.Substring(1, 3) -eq $mode.Substring(4, 3)) "Expected '$path' to have group permissions equal to owner permissions, got '$mode'." + } + + # Binaries must stay owned by root. + docker run --rm --entrypoint stat $env:FULL_IMAGE_NAME -c '%U' /opt/firebird/bin/firebird | + Contains -Pattern '^root$' -ErrorMessage "Expected Firebird binaries to stay owned by root." +} + +# Runs the whole initialization path (config, SYSDBA password, user, database, init scripts) as the given user. +function Test-NonRootInitialization([Parameter(Mandatory)][string]$User) { + $initDbFolder = New-TemporaryDirectory + try { + @' + CREATE TABLE init_check (id INTEGER NOT NULL PRIMARY KEY); +'@ | Out-File "$initDbFolder/10-init.sql" + + Use-Container -Parameters '--user', $User, '-e', 'FIREBIRD_CONF_WireCrypt=Enabled', '-e', 'FIREBIRD_ROOT_PASSWORD=passw0rd', '-e', 'FIREBIRD_USER=alice', '-e', 'FIREBIRD_PASSWORD=bird', '-e', 'FIREBIRD_DATABASE=test.fdb', '-v', "$($initDbFolder):/docker-entrypoint-initdb.d/" { + param($cId) + + $expectedUid = ($User -split ':')[0] + $serverUid = docker exec $cId ps -o uid= -C firebird + assert ($serverUid.Trim() -eq $expectedUid) "Expected Firebird server to run as UID $expectedUid, got '$serverUid'." + + $logs = docker logs $cId 2>&1 + $logs | Contains -Pattern 'WireCrypt = Enabled' -ErrorMessage "Expected FIREBIRD_CONF_WireCrypt to be applied when running as '$User'." + $logs | ContainsExactly -Pattern 'WARNING' -ExpectedCount 0 -ErrorMessage "Expected no permission warning when running as '$User'." + + 'SELECT 1 FROM rdb$database;' | + docker exec -i $cId isql -b -q -u SYSDBA -p passw0rd inet:///var/lib/firebird/data/test.fdb | + ExitCodeIs -ExpectedValue 0 -ErrorMessage "Expected successful login with new SYSDBA password when running as '$User'." + + docker exec $cId test -f /opt/firebird/SYSDBA.password | + ExitCodeIs -ExpectedValue 1 -ErrorMessage "Expected SYSDBA.password file to be removed when running as '$User'." + + # Init script must have been executed as 'alice' + 'SET LIST ON; SELECT rdb$owner_name AS table_owner FROM rdb$relations WHERE rdb$relation_name = ''INIT_CHECK'';' | + docker exec -i $cId isql -b -q -u alice -p bird inet:///var/lib/firebird/data/test.fdb | + Contains -Pattern 'TABLE_OWNER(\s+)ALICE' -ErrorMessage "Expected init script to create table 'init_check' owned by 'alice' when running as '$User'." + } + } + finally { + Remove-Item $initDbFolder -Force -Recurse + } +} + +task Can_run_as_firebird_user { + Test-NonRootInitialization -User '84:84' +} + +task Can_run_as_arbitrary_uid_with_group_root { + # OpenShift restricted SCC: random UID, no /etc/passwd entry, GID 0. + Test-NonRootInitialization -User '12345:0' +} + +task Without_FIREBIRD_USER_database_is_owned_by_SYSDBA_for_any_user { + # Local connections would otherwise take the OS user name (e.g. 'FIREBIRD' for UID 84), not SYSDBA. + $initDbFolder = New-TemporaryDirectory + try { + @' + CREATE TABLE init_check (id INTEGER NOT NULL PRIMARY KEY); +'@ | Out-File "$initDbFolder/10-init.sql" + + foreach ($user in '0:0', '84:84', '12345:0') { + Use-Container -Parameters '--user', $user, '-e', 'FIREBIRD_DATABASE=test.fdb', '-v', "$($initDbFolder):/docker-entrypoint-initdb.d/" { + param($cId) + + 'SET LIST ON; SELECT rdb$owner_name AS table_owner FROM rdb$relations WHERE rdb$relation_name = ''INIT_CHECK'';' | + docker exec -i $cId isql -b -q -u SYSDBA /var/lib/firebird/data/test.fdb | + Contains -Pattern 'TABLE_OWNER(\s+)SYSDBA' -ErrorMessage "Expected init script to create table 'init_check' owned by SYSDBA when running as '$user'." + } + } + } + finally { + Remove-Item $initDbFolder -Force -Recurse + } +} + +task Unsupported_user_shows_permission_warning { + # A UID which is neither 'firebird' nor in group 0 cannot write runtime files. + $($stdout = Invoke-Container -DockerParameters '--user', '1000:1000', '-e', 'FIREBIRD_CONF_WireCrypt=Enabled') 2>&1 | + Contains -Pattern 'WARNING: Running as UID 1000 / GID 1000' -ErrorMessage "Expected permission warning when running as an unsupported user." +} From e7a794f44f85c1fd74715713cb92ad6cd374b828 Mon Sep 17 00:00:00 2001 From: "F.D.Castel" Date: Mon, 23 Nov 2026 18:29:29 +0000 Subject: [PATCH 2/2] docs(readme): explain how to run under OpenShift's restricted-v2 SCC (issue #46) --- DECISIONS.md | 2 +- README.md | 4 +++- src/README.md.template | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DECISIONS.md b/DECISIONS.md index c1a797c..80dcb55 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -126,7 +126,7 @@ Also adds `tzdata` to Noble's distro `extraPackages` (matching Jammy). FB3 relie **Decision:** The image keeps running as `root` by default (no `USER` directive), but also supports running as `firebird` (UID 84) or as any UID with GID 0. Runtime-writable paths — `/opt/firebird` itself, `firebird.conf`, `SYSDBA.password`, `firebird.log`, `fb_guard`, `replication.log`, `security*.fdb`, `/tmp/firebird` and `$FIREBIRD_DATA` — are owned by `firebird:0` with group permissions equal to owner permissions (`g=u`). Binaries, libraries and plugins stay owned by `root`. The installer's leftover lock and shared memory files in `/tmp/firebird` are removed at build time. Every local `isql` connection in the entrypoint names its user explicitly (`-user SYSDBA`, or `FIREBIRD_USER` in `process_sql`). A non-root user without write access gets a warning on startup. -**Rationale:** Requested in [issue #46](https://github.com/FirebirdSQL/firebird-docker/issues/46) (security policies requiring non-root containers; OpenShift). OpenShift's `restricted` SCC ignores the image's `USER` and injects a random UID with GID 0, so group-0 ownership is what makes it work, not a `USER` line; owner `firebird` keeps `--user firebird` working with GID 84. Local (embedded) connections take the OS user name as the Firebird user: `root` is mapped to SYSDBA, but UID 84 becomes `FIREBIRD` and a random UID has no name at all, which made `CREATE USER` fail and changed database/object ownership. `$FIREBIRD_DATA` is a `VOLUME`, so its ownership must be set in the image layer. Changing the default to `USER firebird` was rejected for now: existing volumes and bind mounts contain root-owned databases which a non-root container cannot open, so it would break deployments on upgrade. It belongs in a major release with explicit release notes. +**Rationale:** Requested in [issue #46](https://github.com/FirebirdSQL/firebird-docker/issues/46) (security policies requiring non-root containers; OpenShift). OpenShift's `restricted` SCC ignores the image's `USER` and injects a random UID with GID 0, so group-0 ownership is what makes it work, not a `USER` line (validated by the issue reporter on OKD 4.17 under `restricted-v2`, with Firebird 3, 4 and 5); owner `firebird` keeps `--user firebird` working with GID 84. Local (embedded) connections take the OS user name as the Firebird user: `root` is mapped to SYSDBA, but UID 84 becomes `FIREBIRD` and a random UID has no name at all, which made `CREATE USER` fail and changed database/object ownership. `$FIREBIRD_DATA` is a `VOLUME`, so its ownership must be set in the image layer. Changing the default to `USER firebird` was rejected for now: existing volumes and bind mounts contain root-owned databases which a non-root container cannot open, so it would break deployments on upgrade. It belongs in a major release with explicit release notes. ## D-022: Bullseye images are no longer built diff --git a/README.md b/README.md index e9b39fe..182157d 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,7 @@ Alternatively, you can use the same time zone as your host system by mapping the The container runs as `root` by default. It can also run as a non-root user, without any change in behavior: - as the `firebird` user (UID `84`), e.g. `docker run --user firebird ...`; or -- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. This is how OpenShift runs containers under its default `restricted` security context constraint, which assigns a random UID. +- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. ```yaml # Kubernetes @@ -361,6 +361,8 @@ The container runs as `root` by default. It can also run as a non-root user, wit runAsGroup: 0 # ...as long as the group is 0 ``` +**OpenShift:** under the default `restricted-v2` (or `restricted`) security context constraint, leave `runAsUser` and `runAsGroup` unset. OpenShift assigns a UID from the project's range and runs the container with GID `0`, which this image supports. A UID outside that range, such as `runAsUser: 84`, is rejected by the security context constraint (`must be in the ranges: [...]`). + Other UID/GID combinations are not supported: the entrypoint shows a warning and Firebird cannot write its runtime files. > **IMPORTANT:** When using a bind mount or a pre-existing volume for `/var/lib/firebird/data`, it must be writable by the chosen user. Databases created while running as `root` are owned by `root`, and a non-root container cannot open them until you change their ownership (e.g. `chown -R 84:0` on the data directory). diff --git a/src/README.md.template b/src/README.md.template index f9afbea..1f4f94c 100644 --- a/src/README.md.template +++ b/src/README.md.template @@ -272,7 +272,7 @@ Alternatively, you can use the same time zone as your host system by mapping the The container runs as `root` by default. It can also run as a non-root user, without any change in behavior: - as the `firebird` user (UID `84`), e.g. `docker run --user firebird ...`; or -- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. This is how OpenShift runs containers under its default `restricted` security context constraint, which assigns a random UID. +- as **any** UID with GID `0` (`root` group), e.g. `docker run --user 12345:0 ...`. ```yaml # Kubernetes @@ -282,6 +282,8 @@ The container runs as `root` by default. It can also run as a non-root user, wit runAsGroup: 0 # ...as long as the group is 0 ``` +**OpenShift:** under the default `restricted-v2` (or `restricted`) security context constraint, leave `runAsUser` and `runAsGroup` unset. OpenShift assigns a UID from the project's range and runs the container with GID `0`, which this image supports. A UID outside that range, such as `runAsUser: 84`, is rejected by the security context constraint (`must be in the ranges: [...]`). + Other UID/GID combinations are not supported: the entrypoint shows a warning and Firebird cannot write its runtime files. > **IMPORTANT:** When using a bind mount or a pre-existing volume for `/var/lib/firebird/data`, it must be writable by the chosen user. Databases created while running as `root` are owned by `root`, and a non-root container cannot open them until you change their ownership (e.g. `chown -R 84:0` on the data directory).