Skip to content

create_user silently truncates user names longer than PostgreSQL's 63-byte identifier limit #730

Closed

Description

@GuanzhouSong

Summary

documentdb_api.create_user() accepts user names longer than PostgreSQL's 63-byte identifier limit. PostgreSQL silently truncates the backing role name, while DocumentDB continues to report setup or user creation as successful.

As a result, authentication with the requested full user name fails, while authentication with the first 63 bytes succeeds.

This focused backend issue is also needed as the OSS changelog reference for the fix.

Tested revision and environment

  • Commit: 9765074529b9f09ba05fc86a3cf7c5bb5caaa6eb
  • Architecture: AMD64
  • OS: Ubuntu 24.04
  • PostgreSQL: 18
  • DocumentDB package version used by the E2E environment: 0.116.0
  • Reproduced through the native installer and the authoritative documentdb_api.create_user() path

Reproduction

Create a 64-byte ASCII user directly through the backend API:

user64="$(printf 'a%.0s' $(seq 1 64))"

psql -d postgres -v user64="$user64" <<'SQL'
SELECT documentdb_api.create_user(
  format(
    '{"createUser":"%s","pwd":"test_password","roles":[{"role":"readAnyDatabase","db":"admin"}],"$db":"admin"}',
    :'user64'
  )::documentdb_core.bson
);
SQL

Inspect the resulting PostgreSQL role:

SELECT rolname, octet_length(rolname)
FROM pg_roles
WHERE rolname LIKE 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%';

The same result can be observed through the native installer by supplying 64- or 100-byte alphabetic values as --admin-user.

Actual behavior

  • create_user() reports success.
  • Setup completes and services are reported healthy.
  • The underlying PostgreSQL role contains only the first 63 bytes.
  • Authentication with the requested 64-byte value fails with AuthenticationFailed.
  • Authentication with the first 63 bytes succeeds.
  • No error or warning identifies the truncation.

Expected behavior

create_user() should reject user names whose UTF-8 byte length is greater than 63 before attempting PostgreSQL role creation.

A rejected request must not leave a truncated role or other partial user state.

Impact

This is silent identity corruption:

  • successful setup produces credentials that do not work as displayed;
  • a different, truncated identity unexpectedly becomes valid;
  • all callers are affected, including direct SQL/API callers and administrative scripts;
  • shell-only validation cannot protect callers that invoke create_user() directly.

Acceptance criteria

  • A 63-byte ASCII user name remains accepted.
  • A 64-byte or longer user name is rejected by documentdb_api.create_user() with a stable bad-value/invalid-name error.
  • The check uses UTF-8 byte length, matching PostgreSQL identifier semantics.
  • Rejection occurs before CREATE ROLE or other persistent mutation.
  • No truncated PostgreSQL role remains after rejection.
  • Direct API callers and all shell entry points receive consistent behavior.
  • Backend regression coverage verifies 63-byte acceptance, 64-byte rejection, and absence of the truncated role.
  • The regression is validated on supported PostgreSQL 15, 16, 17, and 18 builds.

Activity

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

    @documentdb-triage-tool

    🤖 Auto-triaged by documentdb-triage-tool.

    Applied: write-operations, bug, performance
    Project fields suggested: Component commands · Priority P0 · Effort S · Status Triage
    Confidence: 0.85 (mixed)

    Reasoning

    P0 keyword "corruption" in body; LLM: Silent identity corruption in create_user when names exceed PostgreSQL's 63-byte limit — a functional bug with security/auth impact, but no data loss or service crash; fix is a straightforward input-validation guard in one command handler.

    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. DeepakSPemmaraju commented on Oct 29, 2026

    @DeepakSPemmaraju
    Collaborator

    Fix was checked in 217648a

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions