incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Bug] Docker entrypoint auth bootstrap is unsafe for mounted and upgraded configs

Open bitflicker64 opened this issue 4 months ago • 7 comments

Problem

The Docker entrypoint bootstraps authentication with grep/sed against conf/rest-server.properties. That works for the shipped defaults it was written for, but not for mounted configs, upgraded volumes, or any value whose encoding differs between shell and HugeConfig.

Concrete cases, most of them raised during review of #3119:

  • Gremlin and REST can end up on different auth providers. The check is a presence-only grep for auth.authenticator, so a config that already has the REST property but not the Gremlin side is treated as fully configured.
  • A pre-existing authenticated volume can fail its first startup after upgrade. A legacy volume can carry docker/init_complete while the bootstrap state the entrypoint now expects is absent.
  • PASSWORD is observable. It is currently handed to Java as a command-line argument, which puts it in ps output for every process in the container.
  • sed rewriting does not implement the Java properties grammar. Escaped keys, : and whitespace separators, continuations, and duplicate logical definitions are all read differently by HugeConfig than by the entrypoint. Concretely, set_prop detects only key=, so a mounted config using : gets a second logical definition appended and HugeConfig then rejects the file as a list. This affects backend and pd.peers as well as init_store.enabled, so the fix should cover all of them together.
  • PASSWORD silently does nothing when init-store is skipped. init-store reads it from stdin, and the disabled path returns before that, so the admin is created on the PD startup path from auth.admin_pa — public default pa. #3119 documents this and warns at runtime; it does not fix it.

The first case, as it stands on master 98477f0f5: the entrypoint no longer greps for auth.authenticator itself, it calls bin/enable-auth.sh whenever PASSWORD is set, and that script gates only on whether conf-bak/ exists. On a config it did not write, it appends a second definition to both files, and the two parsers disagree about which one wins.

A mounted authenticator plus the one enable-auth.sh appends: REST resolves to the first, Gremlin to the last

Proposal

Move property reading and writing off grep/sed and onto the same Commons Configuration path HugeConfig uses, so both sides agree on encoding, and let the entrypoint delegate auth classification to it.

Rough shape:

  • a small ConfigTool CLI for typed get/set against a properties file, preserving comments, file mode, and inode for mounted configs;
  • entrypoint uses it instead of grep/sed, and stops passing secrets as process arguments;
  • auth bootstrap becomes explicit about mounted, upgraded, and custom authenticator cases rather than inferring from one key's presence;
  • a shell test suite covering the entrypoint contract, wired into docker-build-ci.yml.

Scope

In scope: docker-entrypoint.sh, the new config CLI and its wrapper, the entrypoint test suite, and the workflow path filters that run it.

Out of scope: the init_store.enabled option and its gate (#3118 / #3119), Helm chart structure, and GraphManager behavior.

Context

This work originally shared a branch with #3119. That made a ~2,900-line diff covering two unrelated ideas, so it was split out to keep each reviewable on its own. #3119 now carries only the option, the gate, the env mapping, and the init-flag guard.

Visual summary

Docker auth bootstrap

bitflicker64 avatar Aug 01 '26 17:08 bitflicker64

Hi! bitflicker64 suggested this one in #3188 as still unclaimed — I'd like to take it. Could a maintainer assign it to me? My plan is to reproduce the breakage with a mounted rest-server.properties and an upgraded config (the concrete cases listed in the issue), make the entrypoint's auth bootstrap idempotent and non-destructive (match exact keys, quote values, avoid rewriting user-provided files in place), and add CI coverage for mounted-config and upgrade paths. Thanks!

Adarsh-Me avatar Sep 03 '26 06:09 Adarsh-Me

Go ahead, it is yours as far as I am concerned. I opened this one but I am not a committer here, so I cannot set the assignee; a maintainer will have to do that.

Worth knowing before you start: #3119 landed after this was filed and fixed a good part of it. On master 98477f0f5:

  • The : and whitespace separator case is done. set_prop handles both separators now and collapses duplicate definitions, and CI covers it in docker/test/test-docker-entrypoint.sh.
  • PASSWORD reaches init-store on stdin, not as a process argument.
  • PASSWORD no longer no-ops when init-store is disabled, and enable-auth.sh runs outside the init-flag guard, so the upgraded-volume case is covered.

What is still open:

  • The Gremlin/REST split, though the mechanism moved. See the diagram I just added to the description: enable-auth.sh appends a second definition to a config it did not write, commons-configuration2 2.8.0 takes the first of the duplicate pair and snakeyaml 2.2 takes the last, so the two sides land on different authenticators with no error from either.
  • Escaped keys and continuation lines still confuse set_prop. A mounted auth\.admin_pa=pa plus the appended auth.admin_pa=<password> is two definitions of one key, and getString returns pa, so the env var is silently dropped. A pd.peers value continued onto a second line leaves the continuation behind as a stray property.
  • set_prop interpolates the value into the sed command, so when the key already exists the password ends up in sed's argv and is visible in ps. The shipped conf has auth.admin_pa commented out, so a default first boot takes the append branch and is clean; a mounted or persisted conf hits it.

Your plan lines up with the parts that are left. I would reproduce against master first so you are not fixing the ones that are already gone.

bitflicker64 avatar Sep 03 '26 09:09 bitflicker64

@imbajin — @bitflicker64 has confirmed this issue is mine to work on (see above), but as he's not a committer he can't set the assignee field. Could you please assign this to me? FYI, my plan is to reproduce the remaining cases against current master first (per the updated description diagram): the Gremlin/REST authenticator split via the commons-configuration2 first-definition vs snakeyaml last-definition mismatch, then the escaped-key/continuation handling in set_prop, and the password-in-sed-argv visibility when the key already exists.

Adarsh-Me avatar Sep 03 '26 13:09 Adarsh-Me

@imbajin — @bitflicker64 has confirmed this issue is mine to work on (see above), but as he's not a committer he can't set the assignee field.

Feel free to continue working on it; you don’t need to be assigned to an issue, to be honest

bitflicker64 avatar Sep 03 '26 15:09 bitflicker64

Opened PR #3192 with the fixes for the parts still open on master:

  • Gremlin/REST authenticator split — enable-auth.sh appends are now guarded per file (only an absent or commented-out definition triggers an append), re-runs are idempotent, and the entrypoint aligns both sides first: a yaml authenticator is propagated into rest-server.properties and vice versa, so the default StandardAuthenticator can no longer split the pair. Genuine mismatches get a loud WARN instead of silent divergence.
  • Escaped keys and continuations — property rewriting moved to props.awk, which implements the java.util.Properties line grammar (escapes, ':'/whitespace separators, continuations, first-definition-wins duplicates) and rewrites the first definition in place, so mounted configs like one carrying auth\.admin_pa=pa no longer grow duplicate definitions that HugeConfig resolves to pa.
  • PASSWORD in ps — the value no longer interpolates into a sed command line; it travels via environment variable into awk, so argv stays clean.

Both test suites pass locally (the extended unit suite and the full entrypoint harness, including the complex-secret round-trips). @bitflicker64 your updated diagram and 'what is still open' list were exactly the roadmap — I followed the reproduce-on-master-first advice and skipped what #3119 already fixed. @imbajin could you take a look when you get a chance?

Adarsh-Me avatar Sep 03 '26 15:09 Adarsh-Me

@imbajin @bitflicker64 #3133 has no assignee while #3192 (the fix for it) is 37 days old and actively reviewed here. Could one of you assign #3133 to me, so it is clear the work is taken? Happy to also fold in whatever you want from the tracker on that issue.

Adarsh-Me avatar Oct 10 '26 11:10 Adarsh-Me

15. @imbajin @bitflicker64 #3133 has no assignee while #3192 (the fix for it) is 37 days old and actively reviewed here. Could one of you assign #3133 to me, so it is clear the work is taken? Happy to also fold in whatever you want from the tracker on that issue.

Don't worry about assigning; as you can see, other issues and PRs have no one assigned, which is the norm.

bitflicker64 avatar Oct 10 '26 11:10 bitflicker64