Skip to content

[documentdb-local] Secure-by-default gaps in the container image #758

Open

Description

@guanzhousongmicrosoft

The container's defaults are looser than its docs and warnings suggest. Each item is small on its own; together they mean a no-flags container accepts a well-known password over plaintext, and the runtime user has passwordless root.

Items

  • documentdb-local starts with the well-known default password (Admin100) when none is supplied; --help says it is REQUIRED
  • documentdb-local: default TLS_MODE=allowTLS silently accepts plaintext authentication
  • documentdb-local: TLS_MODE=disabled still accepts TLS, behaves like allowTLS (won't fix, see comments)
  • documentdb-local: empty TLS_MODE env var silently becomes allowTLS and accepts plaintext
  • documentdb-local: runtime user documentdb has passwordless root (NOPASSWD: ALL)

1. documentdb-local starts with the well-known default password (Admin100) when none is supplied; --help says it is REQUIRED

Starting documentdb-local without --password/PASSWORD does not fail. The container comes up healthy and accepts Admin100 for whatever username is in effect (default_user, or a custom --username).

Why

  • documentdb_local_settings.sh:27 gives PASSWORD a table default of Admin100; the pass at emulator_entrypoint.sh:343-351 applies it to any unset setting.
  • The PASSWORD is required check (emulator_entrypoint.sh:490-493) can therefore never fire.
  • USING_DEFAULT_CREDS (:342-345) only drives a warning (:503-531), and DOCUMENTDB_ALLOW_DEFAULT_PASSWORD=true suppresses it entirely, so the riskiest configuration is the quietest.
  • --help still says --password ... REQUIRED. (:165-166), so docs and behavior disagree.
  • The warning banner prints both the username and password lines unconditionally (:510-511), so it claims --username was not set even when it was. In the image USERNAME is always set anyway (Dockerfile_documentdb_local:136), so that line is never accurate.

Repro

docker run -d IMG --username myadmin     # no password
#### mongosh with myadmin / Admin100 succeeds

Suggested fix

  1. If PASSWORD is not explicit, exit 1; keep DOCUMENTDB_ALLOW_DEFAULT_PASSWORD=true as the only way to get Admin100, and still print a one-line warning.
  2. Make the banner list only what actually defaulted.
  3. Keep --help saying REQUIRED; mention the opt-in there.
  4. Update scripts that rely on the default (e.g. documentdb-local/functional-tests/scripts/run-functional-tests.sh) and add a test under documentdb-local/scripts/documentdb_local_tests/.

The entrypoint comment at :323 already says a future major version will refuse to start; this is a request to schedule that. It's a breaking change for anyone relying on the defaults, so a release-note callout is warranted. Related: #236 (closed, same ask, no fix landed), #685.

2. documentdb-local: default TLS_MODE=allowTLS silently accepts plaintext authentication

The image defaults to TLS_MODE=allowTLS (packaging/gateway/docker/Dockerfile_documentdb_local:143, documentdb-local/scripts/documentdb_local_settings.sh:37). The entrypoint maps every mode except requireTLS to EnforceTls=false (emulator_entrypoint.sh:1226-1232), and the gateway then accepts non-TLS clients (runtime/v2/listener.rs:125-127, runtime/v1.rs:308-311). So a client that omits --tls authenticates over SCRAM in cleartext, with no log line about it. test_image.py:608 and run_documentdb_local_tls_tests.sh:86 assert this behaviour.

Not claiming a bug, since allowTLS does what it says. But the entrypoint already warns loudly for built-in default credentials (emulator_entrypoint.sh:503-531) and for disabled (line 1231), and nothing warns about plaintext acceptance in the default mode. A no-flags container with the published port accepts the well-known Admin100 credential over an unencrypted connection.

Options:

  1. Default to requireTLS (breaking: tests, healthcheck, banner, quickstart).
  2. Keep allowTLS, print a one-time stderr warning at startup when enforceTls=false, pointing to TLS_MODE=requireTLS.
  3. Keep as-is and document it in the quickstart.

Option 2 is the cheap one; a test next to test_emulator_entrypoint.py:2303 would cover it. Related: #688.

3. documentdb-local: TLS_MODE=disabled still accepts TLS, behaves like allowTLS

--tlsMode disabled / TLS_MODE=disabled doesn't turn TLS off. The entrypoint only writes EnforceTls=false (documentdb-local/scripts/emulator_entrypoint.sh:1226-1232), and with that set the gateway sniffs each connection and accepts both TLS and plaintext (pg_documentdb_gw/documentdb_gateway_core/src/runtime/v2/listener.rs:126-127, runtime/v1.rs:308-311). There is no plain-only path, so disabled is the same as allowTLS. Only requireTLS is distinct.

Main already prints a stderr warning (emulator_entrypoint.sh:1231) and --help says so (:246), but the enum still lists disabled (documentdb_local_settings.sh:37), the container starts and reports ready, and the TLS port stays open. Anyone using disabled to terminate TLS at a sidecar or satisfy a no-in-process-TLS policy doesn't get it.

Suggested fix: reject disabled at startup (non-zero exit, name allowTLS/requireTLS), drop it from the enum and --help, and update the entrypoint test that pins the current behaviour. Or add a real plain-only listener in the gateway, which is a bigger change.

A wrong mode that starts and gets ignored is worse than refusing to start.

4. documentdb-local: empty TLS_MODE env var silently becomes allowTLS and accepts plaintext

An empty TLS_MODE (e.g. -e TLS_MODE=, or a compose/env-file variable that expands to nothing) is treated as unset and replaced with the table default allowTLS. The container starts, exits 0, logs Setting TLS mode to 'allowTLS'..., and accepts plaintext clients. An operator who meant requireTLS gets no signal.

The CLI path is fine: --tlsMode with a missing or empty value fails fast (documentdb-local/scripts/emulator_entrypoint.sh:308-309).

The env path is not:

  • emulator_entrypoint.sh:327 tests [ -n "${!_setting_var:-}" ], so empty falls to the elif and exports the default allowTLS (documentdb_local_settings.sh:37).
  • The enum validator skips empty values (:371-372) and would see a valid allowTLS anyway.
  • docker run -e TLS_MODE= overrides the Dockerfile ENV TLS_MODE="allowTLS" (packaging/gateway/docker/Dockerfile_documentdb_local:143) with empty.

Repro: docker run -e TLS_MODE= ... <image> --username u --password p, then connect with tls=false: it connects.

Fix: before the default pass, reject a set-but-empty TLS_MODE:

if [ "${TLS_MODE+set}" = set ] && [ -z "$TLS_MODE" ]; then
  echo "TLS_MODE must not be empty: disabled, allowTLS, or requireTLS." >&2; exit 1
fi

Only for TLS_MODE: INIT_DATA, CERT_PATH and KEY_FILE are legitimately empty. Add a test next to the --toast-compression missing-value test in test_emulator_entrypoint.py.

5. documentdb-local: runtime user documentdb has passwordless root (NOPASSWD: ALL)

The documentdb-local image adds documentdb to group sudo and ships %sudo ALL=(ALL:ALL) NOPASSWD: ALL, and the final stage runs as USER documentdb. Anything running as that user is container-root with no password.

Defense-in-depth, not a container escape. It matters because the image can't honestly be called unprivileged, and RCE in the gateway or a mounted --init-data-path script gets root for free.

Code (main):

  • packaging/gateway/docker/Dockerfile_documentdb_local:88-89 creates the user and writes the sudoers rule; :182 USER documentdb
  • Build steps use it after USER (:183-250, e.g. sudo chown, sudo tee /version.txt)
  • Runtime: documentdb-local/scripts/emulator_entrypoint.sh:472-474 (log dir), :577 (mkdir data dir), :603/:607 (recursive chown/chmod of DATA_PATH), :611
  • scripts/start_oss_server.sh:393-394 (/var/run/postgresql)

Repro: docker exec -u documentdb <container> sudo -n id returns uid=0(root).

Fix: a targeted sudoers rule only helps if it wraps a fixed root-owned helper. Allowing raw chown/chmod/bash is still root-equivalent. The cleaner route is the official postgres image pattern: start as root, let the entrypoint do the ownership fix-ups, then exec gosu/runuser to documentdb. Move the build-time RUN sudo ... steps ahead of USER documentdb. Add a test asserting sudo -n id fails as documentdb, and update the entrypoint tests that stub sudo.

Related: #688 (security-posture coverage gaps for the image defaults).

Activity

  1. added
    documentdb-local
    documentdb-1.0
    on Oct 5, 2026
  2. added this to the 1.0-RC2 milestone on Oct 5, 2026
  3. guanzhousongmicrosoft commented on Oct 5, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Plan: items 1, 3 and 4 go in 1.0-RC2. Items 2 (warn about the default allowTLS; needs a decision) and 5 (drop passwordless sudo; needs an entrypoint rework) go in 1.0.

  4. guanzhousongmicrosoft commented on Oct 5, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Closing item 3 as won't fix. disabled is MongoDB's no-TLS mode and documentdb-local has accepted it since v0.114-0. Plain clients already connect under it; the only difference from MongoDB is that TLS clients get in too. Rejecting it would break working configs without making anything safer, so it stays, with its startup warning and --help note.

    A real plain-only mode (for TLS terminated at a sidecar) would be a gateway listener change. Open a separate issue if someone needs it.

  5. added
    1.0-blocker
    on Oct 6, 2026
  6. guanzhousongmicrosoft commented on Oct 6, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    1.0 blockers: items 1 and 4. The fix is in review. Items 2 and 5 don't block 1.0.

  7. documentdb-triage-tool commented on Oct 28, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 22 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  8. documentdb-triage-tool commented on Nov 11, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  9. guanzhousongmicrosoft commented on Nov 23, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Items 1 and 4 are fixed on main (cf53d26): documentdb-local refuses to start without a password unless DOCUMENTDB_ALLOW_DEFAULT_PASSWORD=true, and rejects an empty TLS_MODE. Items 2 and 5 are still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

1.0-blockerbugdocumentdb-1.0documentdb-local

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions