Skip to content

fix(hugegraph-dist): gate init-store on a dedicated init_store.enabled option - #3119

Open
bitflicker64 wants to merge 12 commits into
apache:masterfrom
bitflicker64:fix/no-init
Open

fix(hugegraph-dist): gate init-store on a dedicated init_store.enabled option#3119
bitflicker64 wants to merge 12 commits into
apache:masterfrom
bitflicker64:fix/no-init

Conversation

@bitflicker64

@bitflicker64 bitflicker64 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #3118

Kept in sync with hugegraph#171

Problem

InitStore always performs local initialization: it scans conf/graphs,
initializes non-HStore backends, and bootstraps the built-in admin account. That
is correct for standalone and tarball deployments, but a PD/HStore deployment
already owns its metadata. Its Kubernetes pods also cannot rely on the
container-local docker/init_complete flag surviving a restart.

Solution

This adds a dedicated init_store.enabled option, defaulting to true.
Existing standalone and tarball configurations therefore keep the current full
initialization path. Distributed deployments can set it to false (or set
HG_SERVER_INIT_STORE_ENABLED=false in the server container) to make
InitStore return before backend registration, plugin registration, graph
scanning, or local admin initialization.

The disabled path validates authentication before returning successfully:

  • A local StandardAuthenticator or subclass requires usePD=true and an
    HStore-backed auth.graph_store, so the PD-created admin is visible to the
    authenticator.
  • Remote auth and custom authenticator implementations are exempt from the
    built-in admin requirement.
  • An unusable combination exits non-zero, including through the shipped
    bin/init-store.sh wrapper.

The Docker entrypoint now applies the same decision by invoking that Java
validation gate. It also:

  • canonicalizes Java-properties booleans and duplicate keys without rewriting
    an already complete mounted configuration;
  • completes REST, Gremlin, and HugeFactoryAuthProxy configuration for mounted
    auth configs, with or without PASSWORD;
  • writes PASSWORD to auth.admin_pa only in disabled mode, encoding all
    valid UTF-8 and Java-properties metacharacters without changing the value;
  • rejects a null or empty configured admin password when an account actually
    needs to be created, while always closing the auth graph;
  • restricts rest-server.properties to mode 0600 before persisting that
    secret while preserving a mounted file's inode;
  • fails explicitly on every auth-property write and uses an unpredictable,
    same-directory scratch file;
  • avoids writing docker/init_complete when no initialization occurred; and
  • records the non-secret auth topology so an existing no-auth installation is
    followed by one auth bootstrap when authentication is later mounted, using
    either PASSWORD or the configured auth.admin_pa.

auth.admin_pa is used only when the PD-backed admin is first created. Changing
PASSWORD on a later restart does not rotate an existing account.

Validation

  • Validated head: 906a3ef630294f8fad8e1d415aaa50d4af966a44.
  • Entrypoint lifecycle suite: 195 assertions passed, 0 failed.
  • Focused Java suite: 23 tests passed, 0 failed.
  • Full Java 11 unit suite: 615 tests, 0 failures/errors, 1 existing skip.
  • Java 11 clean compile: all 38 reactor modules passed.
  • Apache RAT: all 38 reactor modules passed with no unapproved licenses.
  • EditorConfig format/check and final diff check passed.

The entrypoint suite covers default and disabled initialization, mounted
properties, Boolean spelling and separators, duplicate-key normalization,
custom/remote/built-in auth, HStore eligibility, no-password mounted auth,
persisted no-auth-to-auth restarts, complete read-only mounts, helper no-op
behavior, wrapper exit propagation, secret file permissions, and exact Java
parsing of passwords containing backslashes, spaces, controls, non-ASCII
characters, embedded newlines, and a trailing newline.

Scope

This change does not alter graph.load_from_local_config, general
GraphManager behavior, Helm job structure, or shipped Compose usePD
defaults. Deployments opting out of init-store remain responsible for selecting
the PD/HStore metadata path described above.

…g is false

Honor the existing ServerOptions flag in InitStore so distributed/HStore
can opt out of local backend and admin init. Unset keeps full init for
standalone. Docker maps HG_SERVER_LOAD_FROM_LOCAL_CONFIG to
rest-server.properties.

Fixes apache#3118
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. tests Add or improve test cases labels Jul 26, 2026

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: Disabling local graph loading also bypasses the Docker password-based admin bootstrap, so the requested credential is never installed. Evidence: exact-head static trace through docker-entrypoint.sh, InitStore.java, and GraphManager.java; 3/3 focused tests passed; visible checks are green.

…d option

Replace the graph.load_from_local_config gate with a dedicated
init_store.enabled option defaulting to true. That property already means
whether GraphManager loads graph definitions from the local directory, and
existing configs may materialize its declared false default, so reusing it
made an explicit false skip backend and admin initialization for standalone
RocksDB/HBase installs.

The early return also skipped StandardAuthenticator.initAdminUserIfNeeded,
so a Docker PASSWORD was piped into init-store.sh and discarded without
creating the admin, leaving the server on the auth.admin_pa default. In skip
mode the entrypoint now writes PASSWORD to auth.admin_pa instead, and does
not create docker/init_complete since nothing was initialized. The gate is
read back from rest-server.properties so a config mounted without the env
var behaves the same way.

Cover the lifecycle with a main-level test whose graphs directory would fail
if the early exit were missed, and entrypoint smoke tests for default init,
PASSWORD, skip, skip with PASSWORD, mounted property, and false to true
restart. Run those in Docker CI and extend its path filter to the dist
docker directory.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 26, 2026
@bitflicker64 bitflicker64 changed the title fix(hugegraph-dist): skip init-store when graph.load_from_local_config is false fix(hugegraph-dist): gate init-store on a dedicated init_store.enabled option Jul 26, 2026
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 1.54%. Comparing base (f8e7abf) to head (4c9be3a).

Files with missing lines Patch % Lines
.../main/java/org/apache/hugegraph/cmd/InitStore.java 0.00% 24 Missing ⚠️
...ava/org/apache/hugegraph/config/ServerOptions.java 0.00% 3 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (f8e7abf) and HEAD (4c9be3a). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (f8e7abf) HEAD (4c9be3a)
3 1
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #3119       +/-   ##
============================================
- Coverage     39.13%   1.54%   -37.60%     
+ Complexity      264      21      -243     
============================================
  Files           770     748       -22     
  Lines         65772   63282     -2490     
  Branches       8725    8280      -445     
============================================
- Hits          25741     975    -24766     
- Misses        37272   62223    +24951     
+ Partials       2759      84     -2675     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: The skip path still fails admin bootstrap for the shipped HStore configuration and has inconsistent option/password handling; backend and plugin registration also occurs before the gate. Evidence: six independent review lanes, exact-head static traces, an uppercase FALSE regression test failing four assertions, and all visible latest-head checks passing.

Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
… is true

With init_store.enabled=false the built-in admin account is not created by
init-store, and the only other component that creates it is
GraphManager.initAdminUserIfNeeded(), reached from loadMetaFromPD() and so
gated on usePD. That option defaults to false and the shipped HStore compose
files do not set it, so enabling auth in skip mode would start a server that
enforces authentication with no account to authenticate against.

The entrypoint now refuses that combination and exits with an explanation,
and InitStore logs the same condition for non-Docker installs. Skipping
without auth is unaffected. usePD=true is already the documented pairing for
distributed deployments in the cluster-test rest-server.properties template.

Also align the shell with the server's boolean parsing, which is
case-insensitive, so HG_SERVER_INIT_STORE_ENABLED=FALSE no longer means skip
to Java and run to the entrypoint; read the property through the separators a
properties file allows; escape the password for properties serialization so a
backslash survives; and register backends and plugins only on the enabled
path, since plugin registration runs every plugin's register() and propagates
its failures.

Add entrypoint coverage for these plus a test that disabled mode leaves
backend options unregistered. Note a pre-existing arthas config key mismatch
found while checking the option table.
@bitflicker64

bitflicker64 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Unrelated to this change, but noticed while checking the ServerOptions table, so I left a TODO on it rather than silently fixing it here.

The arthas options are declared camelCase (arthas.telnetPort, arthas.httpPort, arthas.disabledCommands) while conf/rest-server.properties ships them snake_case (arthas.telnet_port, arthas.http_port, arthas.disabled_commands). Nothing normalizes between the two, so those keys never match and config.get() returns the declared default. Only arthas.ip works.

It is invisible today because each shipped value equals its default. It bites on any change, e.g. arthas.disabled_commands=jad,exec is dropped and exec stays enabled.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: The mounted-properties override path can create duplicate scalar keys and make init-store or server startup fail. Evidence: six independent review lanes, exact-head static tracing through docker-entrypoint.sh and HugeConfig.java, and all visible latest-head checks passing.

Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
get_prop was widened to read the `=`, `:` and whitespace separators a
properties file allows, but set_prop still matched only `key=value`. A mounted
`init_store.enabled:false` overridden by HG_SERVER_INIT_STORE_ENABLED therefore
gained a second definition instead of being replaced, and a key defined twice
collects both values into a list that fails the scalar type check while the
config is still loading. Both init-store and server startup would fail. The
same applied to a colon-form auth.admin_pa overridden by PASSWORD.

set_prop now matches the same separators and collapses every existing
definition into one canonical `key=value` line, leaving comments alone. It is
written in awk, so the key and value are matched and emitted literally and no
regex escaping is involved.

Cover colon-form and whitespace-form overrides asserting a single remaining
definition, a colon-form auth.admin_pa override, and that commented defaults
are not treated as definitions. Add a test loading a duplicated key through
HugeConfig to pin why the collapse is required.
@bitflicker64
bitflicker64 requested a review from imbajin July 27, 2026 15:19

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: The disabled init path can still report success for an unusable auth configuration, and two Docker config rewrite paths can fail or corrupt mounted/protected configs. Evidence: six independent exact-head review lanes; entrypoint smoke tests passed 57 assertions with 2 macOS-only skips; git diff --check passed; codecov/patch and codecov/project are failing.

Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
Comment thread hugegraph-server/hugegraph-dist/docker/test/test-docker-entrypoint.sh Outdated
…onf in place

Four fixes to the skip path.

InitStore returned zero for a configuration it had just reported as unusable:
init_store.enabled=false with an authenticator set and usePD false means no
component creates the built-in admin. Tarball and init-job callers see only the
exit status, so they continued into an auth-enabled server nobody could reach.
It now fails. Remote auth is exempt, since the auth manager is then an RPC
client and StandardAuthenticator only bootstraps a local one; the entrypoint
guard gains the same exemption, which it was missing.

set_prop replaced the config by rename. A single-file bind mount cannot be
replaced that way, so startup aborted under set -e, and the rename also
discarded the original mode, which matters where auth.admin_pa is written. It
now truncates and rewrites in place, and creates its scratch file under umask
077.

On the skip path enable-auth.sh ran unconditionally, and it appends its keys
without checking, so a mounted config that already enabled auth ended up with
auth.authenticator and auth.graph_store defined twice, which the config parser
rejects. It now runs only when auth is not configured yet, and both keys are
collapsed to single definitions afterwards.

The test guard that skipped two cases without GNU sed was stale once set_prop
moved to awk. Removed, so those cases run everywhere.

Cover the exit status and the remote-auth exemption in the CLI test, and add
entrypoint cases for a mounted auth config, the remote-auth exemption, inode
and mode preservation, and scratch file cleanup.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: The skip path can leave Gremlin authentication incomplete and rejects supported custom authenticators. Evidence: six independent exact-head review lanes, static traces through enable-auth.sh and HugeAuthenticator.loadAuthenticator(), 74/74 entrypoint assertions passing, git diff --check passing, and all visible latest-head workflows passing.

Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 28, 2026
…n check

enable-auth.sh also adds the authentication block to gremlin-server.yaml and
switches hugegraph.properties to the auth proxy. Skipping it whenever
auth.authenticator already existed left both undone, so a mounted config that
set only that key could start with REST auth on and Gremlin open. Apply each of
the three changes only where it is missing instead, and point the Gremlin block
at whichever authenticator the REST config names.

The admin-account requirement now applies only to the built-in authenticator
and its subclasses. auth.authenticator takes any implementation class, and a
custom LDAP/OIDC/plugin one manages identities elsewhere, so requiring usePD
for it rejected a deployment that works.

get_prop no longer deletes whitespace inside a value, only around it, as the
properties parser does.
- get_prop uses `sed -E` rather than `-r`, which only GNU sed documents
- the appended gremlin-server.yaml block no longer glues itself onto a last
  line that has no trailing newline
- the option description, the InitStore comment and docker/README no longer
  claim every authenticator needs the built-in admin account, which stopped
  being true when the check was narrowed
- InitStoreConfigTest is imported in suite order in UnitTestSuite
- a test asserts the entrypoint's inlined auth block still names everything
  bin/enable-auth.sh does, so the two cannot drift unnoticed
@bitflicker64

Copy link
Copy Markdown
Contributor Author

Did a self-review pass over the whole diff and pushed 090763a with the follow-ups, no behaviour change beyond the two fixes below:

  • get_prop now uses sed -E rather than -r, which only GNU sed documents.
  • The gremlin-server.yaml block is no longer appended onto a last line that has no trailing newline.

The rest is text and hygiene: the option description, the InitStore comment and docker/README.md still said every auth.authenticator needs the built-in admin account, which stopped being true when the check was narrowed; InitStoreConfigTest is now imported in suite order.

Since the entrypoint reapplies what bin/enable-auth.sh does when it cannot run the script itself, there is now a test asserting the entrypoint still names every class and key that script does, so the two cannot drift silently. Happy to move that logic into enable-auth.sh instead if you would rather have one source of truth there, it just reaches outside the docker path.

Local run: 106 assertions across 30 entrypoint cases, unit suite 626 tests green on JDK 11, rat and editorconfig clean.

# Conflicts:
#	hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: yes. Summary: The skip path still has inconsistent admin-bootstrap decisions across Docker and Java, and several auth configurations can start unusable or incompletely protected. Evidence: six independent exact-head review lanes, static traces through docker-entrypoint.sh, InitStore, GraphManager, and StandardHugeGraph; 106/106 entrypoint assertions and the focused Java test passed; git diff --check passed; visible Actions passed but Codecov statuses failed.

Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
Comment thread hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh Outdated
Comment thread .github/workflows/docker-build-ci.yml
Comment thread hugegraph-server/hugegraph-dist/docker/test/test-docker-entrypoint.sh Outdated
Comment thread PR_DESCRIPTION.md Outdated
@bitflicker64

Copy link
Copy Markdown
Contributor Author

Coverage infrastructure note for final head 4b298bf2477685e886516acb54de880904a57ff5:

Both completed Linux server jobs generated and discovered four coverage XML reports, then reached the repository coverage upload step. The tokenless POST was rejected by Codecov with HTTP 429 in both jobs:

  • rocksdb job: Rate limit reached, expected availability 3366 seconds
  • memory job: Rate limit reached, expected availability 3169 seconds

The uploader explicitly exited with status 0 after those errors, so GitHub shows the jobs as successful but Codecov has not produced final-head project or patch statuses. This reproduces the repository-level tokenless-upload failure seen on the baseline; it is not a test or coverage-generation failure. The focused suite has 17 passing tests and the full Java 11 unit profile has 609 passing tests with one existing skip.

Could a maintainer retry coverage after the rate-limit window with the repository upload token, or explicitly waive the Codecov gate for this head?

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files. tests Add or improve test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InitStore should skip local init when graph.load_from_local_config is explicitly false

2 participants