bitflicker64 commented on code in PR #3189: URL: https://github.com/apache/hugegraph/pull/3189#discussion_r3954361458
########## hugegraph-store/docs/deployment-guide.md: ########## @@ -678,6 +678,13 @@ For a production-like 3-node distributed deployment, use the compose file at `do ```bash cd docker +# The PD REST secret is required; the Compose file refuses to start without +# it. Generate it once and keep it, every PD node and PD client needs the +# same value (docker/README.md has the full .env recipe). Review Comment: 🧹 This file gets the credential for the Docker path, but its bare-metal path is left showing calls that will now be refused. Under "Verify PD cluster" (line ~475) `curl http://192.168.1.10:8620/v1/members` still omits `-u`, and the "Expected output" block right below it shows a `"message":"OK"` payload that will now be `{"status":-1,"error":"Unauthorized"}`; `curl http://192.168.1.10:8620/v1/stores` at line ~589 has the same problem, as does the quick-check block in `hugegraph-store/README.md` (line 263). `operations-guide.md` got a prominent credential note in this PR — this guide, which is the one an operator follows for a bare-metal install, did not. Requested change: add the same note here (and to the store README block), or put `-u hg:"${PD_SECRET}"` on those examples so the shown output stays truthful. ########## docker/set-hubble-pd-password.sh: ########## @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generate the Hubble properties file a Compose topology mounts, with PD's +# REST secret written in as operations.pd.password. +# +# usage: set-hubble-pd-password.sh <hstore|hstore-ha> [secret] +# +# Reads conf/hubble/<name>.properties.example (tracked) and writes +# conf/hubble/<name>.local.properties (ignored by git), so the secret never +# lands in a tracked file. The secret defaults to $HG_PD_AUTH_SECRET_KEY. The +# value never goes through a sed replacement, where & # and backslash are +# special, and backslashes are doubled for the .properties format. Run this +# before `docker compose up`: if the target is missing Docker creates an empty +# directory at the bind path and Hubble starts with no configuration. +set -euo pipefail + +name=${1:?usage: $0 <hstore|hstore-ha> [secret]} +secret=${2:-${HG_PD_AUTH_SECRET_KEY:-}} +dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/conf/hubble" +example="${dir}/${name}.properties.example" +out="${dir}/${name}.local.properties" + +[[ -f "$example" ]] || { echo "no such topology: ${name} (expected ${example})" >&2; exit 1; } +[[ -n "$secret" ]] || { echo "secret is empty; load .env first (set -a; . ./.env; set +a)" >&2; exit 1; } +case "$secret" in + *$'\n'*|*$'\r'*) echo "secret contains a line break, which a .properties value cannot hold" >&2; exit 1 ;; Review Comment: 🧹 This rejects CR/LF because a `.properties` value cannot hold one, but accepts any other byte — and the character set matters just as much here. PD compares the password as UTF-8 bytes (`Authentication.verifySecret` → `pwd.getBytes(StandardCharsets.UTF_8)`), while Hubble reads this file through `HugeConfig extends PropertiesConfiguration` (commons-configuration2, whose `DEFAULT_ENCODING` is ISO-8859-1). A non-ASCII secret is therefore written happily and decoded to different bytes on the Hubble side, giving a permanent 401 with no diagnostic anywhere. The README recipe generates hex so the documented path is safe, but the header comment explicitly invites a hand-chosen secret ("a hand-chosen one might"). Requested change: reject non-ASCII with a message, next to the line-break check: ```bash case "$secret" in *[!$'\x20'-$'\x7e']*) echo "secret must be printable ASCII: Hubble reads .properties as ISO-8859-1, PD compares as UTF-8" >&2; exit 1 ;; esac ``` or say ASCII-only in the usage comment. ########## hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh: ########## @@ -51,14 +72,31 @@ require_env "HG_PD_GRPC_HOST" require_env "HG_PD_RAFT_ADDRESS" require_env "HG_PD_RAFT_PEERS_LIST" require_env "HG_PD_INITIAL_STORE_LIST" +# The REST API refuses every authenticated request without this, and the image +# ships no default because a published secret is not a secret. +require_env "HG_PD_AUTH_SECRET_KEY" : "${HG_PD_GRPC_PORT:=8686}" : "${HG_PD_REST_PORT:=8620}" : "${HG_PD_DATA_PATH:=/hugegraph-pd/pd_data}" : "${HG_PD_INITIAL_STORE_COUNT:=1}" +# Secret for REST Basic authentication (auth.secret-key). Required above and +# never logged. +AUTH_JSON="\"auth\": { \"secret-key\": \"$(json_escape "${HG_PD_AUTH_SECRET_KEY}")\" }," + +# The secret above lands in SPRING_APPLICATION_JSON, and actuator's /env +# sanitizer keys off the property name: it redacts auth.secret-key but returns +# the SPRING_APPLICATION_JSON environment entry verbatim, secret included. The +# image's own conf/application.yml already narrows the exposure, but a +# bind-mounted pre-1.8 config brings back include: "*". SPRING_APPLICATION_JSON +# outranks the config file, so pin the allowlist here too. +MANAGEMENT_JSON="\"management\": { \"endpoints\": { \"web\": { \"exposure\": { \"include\": \"health,metrics,prometheus\" } } } }," Review Comment: 🧹 Pinning the allowlist here does close the pre-1.8 `include: "*"` hole for a bind-mounted config, and the reasoning above it is right. But because `SPRING_APPLICATION_JSON` outranks the config file, it also removes a knob Docker operators had: there is now no way to expose `/actuator/info`, `/actuator/loggers` or a custom endpoint from the image at all, and the docs added in this PR record that as a limitation rather than offering a way round it. Every other PD setting in this entrypoint is env-driven, so this one stands out. Requested change: keep the hardened value as the default but let it be overridden, e.g. ```bash : "${HG_PD_ACTUATOR_EXPOSURE:=health,metrics,prometheus}" MANAGEMENT_JSON="\"management\": { \"endpoints\": { \"web\": { \"exposure\": { \"include\": \"$(json_escape "${HG_PD_ACTUATOR_EXPOSURE}")\" } } } }," ``` so an operator who needs `/actuator/loggers` opts into it deliberately instead of losing the endpoint. ########## hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java: ########## @@ -137,11 +137,89 @@ public void testQueryShards() throws URISyntaxException, IOException, Interrupte String url = pdRestAddr + "/v1/shards"; HttpRequest request = HttpRequest.newBuilder() .uri(new URI(url)) - .header("Authorization", "Basic c3RvcmU6MTIz") + .header(AUTH_HEADER, VALID_AUTH) .GET() .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); JSONObject obj = new JSONObject(response.body()); assert obj.getInt("status") == 0; } + + @Test + public void testMissingCredentialGets401() throws URISyntaxException, IOException, + InterruptedException { + String url = pdRestAddr + "/v1/members"; + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(url)) + .GET() + .build(); + HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assert response.statusCode() == 401; + } + + @Test + public void testWrongPasswordGets401() throws URISyntaxException, IOException, + InterruptedException { + String url = pdRestAddr + "/v1/members"; + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(url)) + .header(AUTH_HEADER, basicAuth("store", "wrong-password")) + .GET() + .build(); + HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assert response.statusCode() == 401; + } + + @Test + public void testEmptyPasswordGets401() throws URISyntaxException, IOException, + InterruptedException { + String url = pdRestAddr + "/v1/members"; + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(url)) + .header(AUTH_HEADER, basicAuth("hg", "")) + .GET() + .build(); + HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assert response.statusCode() == 401; + } + + private int statusWithoutCredential(String path) throws URISyntaxException, IOException, + InterruptedException { + HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(pdRestAddr + path)) + .GET() + .build(); + return client.send(request, HttpResponse.BodyHandlers.ofString()).statusCode(); + } + + @Test + public void testProbePathsNeedNoCredential() throws URISyntaxException, IOException, + InterruptedException { + assert statusWithoutCredential("/v1/health") == 200; + assert statusWithoutCredential("/actuator/health") == 200; Review Comment: 🧹 The claim this test makes is "these paths need no credential", but `== 200` also fails when PD is simply unhealthy: `/actuator/health` answers 503 whenever any health indicator is DOWN (low disk space is the usual one on a CI runner), and `/v1/health` reflects cluster state. In a suite where every other case is about authentication, a transient unhealthy PD will read as an auth regression and send someone hunting in the wrong file. Requested change: assert what the test is actually about — `assert statusWithoutCredential("/v1/health") != 401;` and the same for `/actuator/health`. The `/actuator/metrics/jvm.memory.used` case can keep `== 200`, since a 200 there is the real evidence that nested actuator paths stay open. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
