Skip to content

Hash digest ACL ids with the platform charset, as in branch-3.6 - #192

Draft
bellatrix007 wants to merge 1 commit into
li-dev/base-3.8.7from
adbansal/zk-387-p15-digest-platform-charset
Draft

bellatrix007 wants to merge 1 commit into
li-dev/base-3.8.7from
adbansal/zk-387-p15-digest-platform-charset

Conversation

@bellatrix007

Copy link
Copy Markdown

Hash digest ACL ids with the platform charset, as in branch-3.6

Based on li-dev/base-3.8.7 (P01 to P14 are already merged there).

Problem

DigestAuthenticationProvider.digest() hashes with UTF-8 since ZOOKEEPER-3342, but handleAuthentication() still
decodes the auth bytes with the platform charset. On a host whose default charset is not UTF-8, a digest ACL persisted by
3.6.3-35 with a non-ASCII user or password no longer matches after the upgrade, and access to the znode is lost.
Setting file.encoding=UTF-8 does not bring the old hash back, because the stored ids were already built from the
charset-mangled string.

Prod is affected: zk.sandbox-rain prod-ltx1 reports file.encoding=ANSI_X3.4-1968 (US-ASCII), and so does every
sandbox-blr node. ASCII-only credentials are unaffected.

Change

digest() calls idPassword.getBytes() again (platform default charset), as in branch-3.6, and the unused UTF_8 import is
removed. One production line, no new configuration.

  • UTF-8 host: identical to 3.8.7-0 (UTF-8 is the platform charset).
  • Any other host: identical to 3.6.3-35.

Trade-offs

  • The hash depends on the host charset again, as it did on 3.6. This is a deliberate fork-only deviation from upstream.
  • DigestAuthenticationProvider.generateDigest is also what the client tools use, so on a non-UTF-8 host
    java ... DigestAuthenticationProvider user:pw prints the 3.6 value again.
  • Without this patch the alternative is to find and re-create the affected ACLs after the upgrade.

Testing

  • New DigestAuthenticationProviderCharsetTest runs the real handleAuthentication path in a child JVM started with
    -Dfile.encoding=US-ASCII (a UTF-8 JVM cannot tell the two behaviours apart).

    • Without the change: fails, expected: iluzynxkwbZ1KS/W7MV6IQ4Rts4= but was: F2E4i782FsuPaGBSfsCS6MLGvYM=.
    • With the change: passes.
  • AuthTest, AuthSHA2Test, AuthSHA3Test, EnsembleAuthenticationProviderTest pass. Checkstyle: 0 violations.

  • End to end on real standalone servers (server file.encoding=US-ASCII, UTF-8 client, throwaway credential ü:pw),
    in-place restart on the data written by 3.6.3-35:

    Restart on get /dig-u with ü:pw get /dig-a with u:pw
    3.6.3-35 (control) dd (access kept) dd
    3.8.7-0 Insufficient permission : /dig-u dd
    3.8.7-0 + this PR dd (access kept) dd
  • Fresh server with this PR: the stored ids are byte-identical to 3.6.3-35 under US-ASCII, and identical to both versions
    under UTF-8.

Script and output: run13_digest_patched.sh.
The end-to-end runs used the 3.8.7-0 distribution with only DigestAuthenticationProvider.class replaced; that class is
identical in li-dev/base-3.8.7. The unit tests and checkstyle were re-run on this branch after rebasing onto the base.

Not covered

  • Whether any prod digest ACL actually uses a non-ASCII id (needs a prod ACL scan). If none does, this PR is optional.
  • Only one prod ensemble's charset was read; the others are expected to match.
  • Non-digest schemes (x509, sasl, ip) are not affected.

ZOOKEEPER-3342 changed DigestAuthenticationProvider.digest() to hash with
UTF-8, while handleAuthentication() still decodes the auth bytes with the
platform charset. On a host whose default charset is not UTF-8 (prod and
sandbox-blr run US-ASCII), a digest ACL persisted by 3.6.3-35 with a
non-ASCII user or password no longer matches after the upgrade, so access
to the znode is lost. Setting file.encoding=UTF-8 does not restore the old
hash.

Hash with the platform default charset again. This is identical to 3.8.7 on
UTF-8 hosts and identical to 3.6.3-35 on every other host.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant