Skip to content

Align native installer username and password-file validation with backend and client semantics #731

Open

Description

@GuanzhouSong

Summary

The native installer and companion administrative tools currently have several inconsistent input and credential semantics:

  1. public passes public username prevalidation but fails later during PostgreSQL role creation.
  2. Passwords containing characters prohibited by client SCRAM/SASL preparation are accepted during setup, producing unusable credentials.
  3. Password files have surprising and inconsistent line-ending behavior:
    • a final LF is silently removed;
    • CRLF leaves an unusable credential;
    • embedded newlines produce unusable credentials;
    • an LF-only file reaches setup and fails as an empty password.
  4. The reserved-role policy is not represented consistently across every public username validator.

Tested revision and environment

  • Commit: 9765074529b9f09ba05fc86a3cf7c5bb5caaa6eb
  • Architecture: AMD64
  • OS: Ubuntu 24.04
  • PostgreSQL: 18
  • Package manager: APT
  • Privileged systemd-as-PID-1 E2E environment
  • Authentication client: Python 3.12 with PyMongo

Reproduction

1. Reserved PostgreSQL role passes prevalidation

printf '%s' 'ValidPass123!' >/root/pw
chmod 0600 /root/pw

sh install.sh \
  --yes \
  --admin-user public \
  --admin-password-file /root/pw \
  --accept-external-listen

2. Client-prohibited password character

Create a password file containing a Unicode code point rejected by the client's SASLprep implementation, for example an emoji together with otherwise valid password characters:

printf '%s' 'Valid🧪Pass123!' >/root/pw
chmod 0600 /root/pw

sh install.sh \
  --yes \
  --admin-user admin \
  --admin-password-file /root/pw \
  --accept-external-listen

Then authenticate with PyMongo using the exact same Unicode string.

3. Password-file line endings

Run clean installations using these fixtures:

printf 'ValidPass123!\n'        >/root/trailing-lf
printf 'ValidPass123!\r\n'      >/root/crlf
printf 'ValidPass123!\nsecond'  >/root/multiline
printf '\n'                     >/root/lf-only
chmod 0600 /root/trailing-lf /root/crlf /root/multiline /root/lf-only

Actual behavior

  • public passes installer validation, proceeds through cluster initialization and extension creation, and then fails at:

    ERROR: role name "public" is reserved
    
  • A subsequent attempt with another user can conflict with the interrupted setup state.

  • The Unicode password installation completes successfully, but PyMongo authentication fails before reaching the server:

    ValueError: SASLprep: failed prohibited character check
    
  • A file ending in LF installs successfully, but the exact file bytes do not authenticate; authentication succeeds only after removing the LF.

  • CRLF and multi-line files install successfully but produce credentials unusable by the client.

  • An LF-only file proceeds to setup and then fails because the resulting password is empty.

Expected behavior

All public entry points should enforce one deterministic username and password-file contract before performing persistent setup work.

Recommended password-file contract:

  • one logical password line;
  • at most one optional terminal LF, which is removed;
  • CR characters and embedded LF characters are rejected;
  • an empty value after normalization is rejected;
  • passwords incompatible with the supported SCRAM/SASL preparation rules are rejected before user creation.

Impact

  • Invalid input can fail only after expensive and partially mutating setup.
  • Users can receive a successful installation with credentials that standard clients cannot use.
  • Password bytes may differ from what the operator supplied without an explicit contract.
  • Different entry points can accept and reject different reserved identities.
  • Recovery after late username failure is more complicated than a normal validation error.

Acceptance criteria

  • public and other PostgreSQL-reserved role names are rejected during prevalidation.
  • Dry-run and live setup apply the same side-effect-free username validation.
  • install.sh, documentdb-setup, documentdb-gateway-admin, and the container username validator use the same case-insensitive reserved-name/prefix policy.
  • Passwords that supported clients cannot pass through SCRAM/SASL preparation are rejected before mutation with an actionable error.
  • The password-file line-ending contract is explicitly documented.
  • A single optional terminal LF is handled consistently.
  • CRLF, embedded newlines, and LF-only/empty values are rejected before setup begins.
  • Regression tests cover every public username validator and every listed password fixture.
  • Failed validation leaves no cluster, user, listener, or misleading completed receipt state.

Activity

  1. documentdb-triage-tool commented on Sep 2, 2026

    @documentdb-triage-tool

    🤖 Auto-triaged by documentdb-triage-tool.

    Applied: packaging, bug
    Project fields suggested: Component packaging · Priority P2 · Effort M · Status Triage
    Confidence: 0.82 (llm)

    Reasoning

    LLM: Multiple input/credential validation inconsistencies in the native installer (reserved usernames, prohibited password characters, line-ending handling) that result in unusable credentials or failed setups, but no data loss or security exposure.

    If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

  2. guanzhousongmicrosoft commented on Oct 5, 2026

    @guanzhousongmicrosoft
    Member

    One more installer-side gap in the same area, not covered above:

    Problem. The interactive username prompt enforces ^[A-Za-z_][A-Za-z0-9_-]*$ (documentdb-local/scripts/documentdb-setup.sh:4440). The --admin-user flag path only runs the reserved-prefix check (documentdb-setup.sh:1908-1921, documentdb-gateway-admin.sh:551-556, documentdb-tools-lib.sh:775). No shape or length check, so:

    • A name over 63 bytes is truncated by PostgreSQL; setup reports ready, but the full name can't authenticate (backend side of this is create_user silently truncates user names longer than PostgreSQL's 63-byte identifier limit #730).
    • postgres, select, foo.bar, names with spaces, café and -rf are accepted as admin roles. A leading - is a footgun for any downstream cmd $USER.
    • --admin-user --yes takes --yes as the name (documentdb-setup.sh:3878-3881); --pg-version abc is only rejected late (:3914-3916) as "PostgreSQL abc not found".

    Fix. One shared helper in documentdb-tools-lib.sh: apply the prompt's regex plus a 63-byte cap (LC_ALL=C), call it from validate_required_arguments and create-user, before any dry-run early return. Reject option-lookalike values (leading -) for --admin-user/--pg-version and require digits for --pg-version at parse time. Add cases to documentdb_local_tests.

  3. added this to the 1.0-RC2 milestone on Oct 5, 2026
  4. guanzhousongmicrosoft commented on Oct 5, 2026

    @guanzhousongmicrosoft
    Member

    Follow-up from review: the built-in role names are now listed in four places. pg_documentdb/include/utils/role_utils.h (IS_NATIVE_BUILTIN_ROLE) is the source of truth; documentdb-local/scripts/documentdb-tools-lib.sh and packaging/install.sh carry copies kept in sync by a test; pg_documentdb_gw/documentdb_tests/src/utils/rbac_utils.rs has another.

    Longer term, generate them from one source instead: a shared definitions file that the C code includes, plus a build step that writes the shell lists. install.sh can embed the generated list, since it runs before any package exists. This touches the backend, the deb/rpm builds and the gateway tests, so it is not part of the packaging fix for this issue.

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

    @guanzhousongmicrosoft
    Member

    1.0 blocker. The fix is in review.

  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
    Member

    Most of this is on main: a92856b rejects reserved names such as public and applies the 63-byte, name-shape and one-line password-file rules, and d7637dd makes the backend reject passwords that fail SASLprep. #833 relaxes the tools' password rule to UTF-8 (#765). Still open: documentdb-register-gateway doesn't pre-validate the admin name, and the built-in role list lives in several places.

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.0packaging

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions