bitflicker64 commented on code in PR #3189:
URL: https://github.com/apache/hugegraph/pull/3189#discussion_r3957229133


##########
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:
   Fixed in ae2a39a5f. deployment-guide.md now opens with the same credential 
note operations-guide.md carries, and the PD `/v1` examples take `-u 
hg:"${PD_SECRET}"`: `members` and `stores` in the deployment steps, the two you 
named, plus `members`, `stores`, `partitions` and `graphs` under "Verification 
and Testing", which had the same problem. The expected-output blocks below the 
first two are truthful as shown now rather than needing a rewrite.
   
   hugegraph-store/README.md line 263 takes the credential and a comment saying 
what a missing one returns. `/v1/health` and `/actuator/health` stay bare in 
both files, since those are the anonymous probes.
   



##########
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:
   Fixed in b98db4188. set-hubble-pd-password.sh now rejects a secret outside 
`\x20-\x7e` with your message, and the usage header states printable ASCII and 
the reason.
   
   One change from your snippet: the range check runs under `local LC_ALL=C` 
inside a small function. A `case` range is collated as well, so under the 
caller's locale a non-ASCII character can sort inside `\x20-\x7e` and slip 
through, which is the same hazard as the json_escape thread on the PD 
entrypoint.
   
   Covered in hubble_password_helper_check: `set-hubble-pd-password.sh hstore 
'pässwörd'` must exit non-zero. `bash docker/test-compose.sh render` passes, 
rc=0.
   



##########
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:
   Fixed in ae2a39a5f. Both health probes assert `!= 401` now, with a comment 
recording why: a 503 from a DOWN indicator is not an authentication regression. 
`/actuator/metrics/jvm.memory.used` keeps `== 200`, as you suggested, since a 
200 there is the real evidence that nested actuator paths stay open.
   
   Verified by building: `mvn -pl 
hugegraph-pd/hg-pd-service,hugegraph-pd/hg-pd-test -am -DskipTests compile` on 
JDK 11 exits 0. The suite itself needs a running PD, so it runs in CI rather 
than locally.
   



##########
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:
   Taken in ae2a39a5f, close to your sketch. `HG_PD_ACTUATOR_EXPOSURE` defaults 
to `health,metrics,prometheus` and feeds MANAGEMENT_JSON through json_escape, 
and the effective value is logged with the rest of the config.
   
   One addition: a value containing `*` is refused with exit 2. That is the 
exact hole the pin closed, since `/actuator/env` returns the 
SPRING_APPLICATION_JSON entry verbatim.
   
   test-pd-docker-entrypoint.sh gained three cases: the override reaches the 
JSON as `health,metrics,prometheus,loggers`, and `*` and `health,*` are both 
refused. 15 passed, 0 failed. configuration.md and the Store deployment guide 
document the variable now instead of recording the loss.
   



-- 
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]

Reply via email to