Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4527058873
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,359 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# How many logical definitions a key carries, `0` when it has none. Like
+# props_get, a nonzero status means the file could not be read rather than the
+# key being absent, so the status has to survive to the caller instead of
+# collapsing into an empty string that reads as "nothing there".
+props_count() {
+local status=0 value
+value=$(PROPS_MODE=count PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+return "${status}"
+fi
+printf '%s' "${value}"
+}
+
+# Whether a key's repeated definitions disagree on a non-empty value. `count`
+# cannot tell an older image's identical leftovers from two different classes,
+# and that difference decides between collapsing and refusing.
+props_conflict() {
+local status=0 value
+value=$(PROPS_MODE=conflict PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# Collapse a key to its first definition, dropping the rest, keeping the bytes
+# the server has already been reading. Going through props_set with a value
+# from props_get is not the same thing: props_get decodes, and a decoded value
+# containing `=`, `:` or a leading blank does not come back off the encoder
+# byte-identical.
+props_keep_first() {
+PROPS_MODE=set PROPS_KEEP_FIRST=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $2"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4453636610
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,334 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# How many logical definitions a key carries, `0` when it has none. Like
+# props_get, a nonzero status means the file could not be read rather than the
+# key being absent, so the status has to survive to the caller instead of
+# collapsing into an empty string that reads as "nothing there".
+props_count() {
+local status=0 value
+value=$(PROPS_MODE=count PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+return "${status}"
+fi
+printf '%s' "${value}"
+}
+
+# Collapse a key to its first definition, dropping the rest, keeping the bytes
+# the server has already been reading. Going through props_set with a value
+# from props_get is not the same thing: props_get decodes, and a decoded value
+# containing `=`, `:` or a leading blank does not come back off the encoder
+# byte-identical.
+props_keep_first() {
+PROPS_MODE=set PROPS_KEEP_FIRST=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $2"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding on the key being present and appending was not the same
+# question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so a presence check reported
+# them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides,
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-6627060087 `93e7a5b` fixes the blocking item: a repeated `auth.authenticator` with different values is now refused, not collapsed (`props.awk` `conflict` mode, consulted only for the key yaml reads). Your example exits 1 with the file untouched, identical duplicates still collapse, and `test-docker-entrypoint.sh` passes. The `Settings.read()` main is not in this commit. CI has not run: the PR is dirty against master. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4381624809
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,295 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding on the key being present and appending was not the same
+# question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so a presence check reported
+# them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+#
+# `$4` is the key's current value, read before the first write. Reading it
+# here instead -- `[[ -n "$(props_get "$1" "$3")" ]]` -- discarded the status
of
+# the command substitution, because `[[` only looks at the text, so props_get's
+# refusal of a file props.awk cannot read (an `include` directive) exited the
+# subshell, the guard saw an empty string, and props_set then tried to write
+# that same unreadable file.
+ensure_rest_prop() {
+[[ -n "$4" ]] && return 0
Review Comment:
Fixed in `51b4184`. `ensure_rest_prop` now counts the definitions
(`props.awk` gains a `count` mode) and, above one, rewrites the key
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4378798160
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,295 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding on the key being present and appending was not the same
+# question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so a presence check reported
+# them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+#
+# `$4` is the key's current value, read before the first write. Reading it
+# here instead -- `[[ -n "$(props_get "$1" "$3")" ]]` -- discarded the status
of
+# the command substitution, because `[[` only looks at the text, so props_get's
+# refusal of a file props.awk cannot read (an `include` directive) exited the
+# subshell, the guard saw an empty string, and props_set then tried to write
+# that same unreadable file.
+ensure_rest_prop() {
+[[ -n "$4" ]] && return 0
Review Comment:
Important: this skip keeps the extra `auth.authenticator` and
`auth.graph_store` lines that master's `enable-auth.sh` appended to a
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4234584336
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,794 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
Review Comment:
Important: should not exist. This file reimplements part of SnakeYAML so it
can guess what `Settings.read()` returns. Nearly every rule in the header (6b,
8b, 9, 10, 12, 13) says "Settings.read() loads X, so we must too", and each one
came from a review round finding another shape the awk read differently. The
codebase already has the real reader: `HugeGremlinServer.prepare()` calls
`Settings.read(conf)`, and `org.apache.hugegraph.cmd` already has small CLI
mains (`ConfDumper`, `InitStore`) that run off `lib/`. Something like this in
that package does the whole job:
```java
public class AuthConfState {
public static void main(String[] args) throws Exception {
Settings s = Settings.read(args[0]);
if (s.authentication == null) { System.out.println("none"); return; }
String a = s.authentication.authenticator;
System.out.println(a == null || a.trim().isEmpty() ? "nameless" :
"named");
}
}
```
Run it as `java -cp "lib/*" org.apache.hugegraph.cmd.AuthConfState
conf/gremlin-server.yaml`. It ships in the existing hugegraph-dist jar, so
there is no new build artifact. It works on the JRE base image and in the
tarball, and a document SnakeYAML rejects makes it exit nonzero, which is the
refusal you want. That lets you delete this file, its two Dockerfile COPYs, and
the 37 `yaml_case` shape cases in test-docker-entrypoint.sh, which then only
need one case per output.
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,295 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get()
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4223127529
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk:
##
@@ -0,0 +1,423 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition, in the on-disk
+# escaped form; with PROPS_DECODED=1 print it as java.util.Properties
+# would hand it to the server. Always exits 0.
+# PROPS_MODE=has PROPS_KEY=K PROPS_FILE=F
+# print nothing; exit 0 when K has any definition at all, empty
+# included, 1 when it has none, 2 on an error
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - physical lines end at \r\n, \n or a bare \r, as in java.util.Properties
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, where the whitespace Java counts is
+# space, tab and form feed, with whitespace then an optional single '=' or
+# ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+#
+# A file that carries commons-configuration's `include` directive is refused in
+# every mode, with exit status 2: the directive splices another file into this
+# one, so "this key is absent" is a question that cannot be answered from this
+# file alone, and writing into it could bury the definition the server reads.
+# Rewrites stage through two exclusively created 0600 files (`mktemp`) rather
+# than a predictable `.tmp` / `.bak`, which a writer in a mounted
+# conf directory could have arranged as a symlink before the entrypoint,
running
+# as root, opened either of them.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+# 2 for an error, so a caller that reads exit status 1 as "the key is not
+# there" (PROPS_MODE=has) cannot mistake an unreadable file for an absent
+# property and append a definition on top of one it failed to read.
+exit 2
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4173767663
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,299 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW = s
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4173766941
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# What the top-level authentication mapping of gremlin-server.yaml says about
+# authentication, as one of three states:
+#
+# none no such mapping
+# namedthe mapping carries an authenticator
+# nameless the mapping exists but names no authenticator
+#
+# Only presence is asked for, never the class: the entrypoint does not copy a
+# value between the two files any more, so quotes, inline comments and flow
+# mappings stay snakeyaml's business instead of becoming a parser here. The
+# key must start at column 0 — an `authentication:` nested under another
+# mapping belongs to that feature, not to the Gremlin server, and reading it as
+# the Gremlin one would let an unrelated class decide whether REST is
+# authenticated while Gremlin stayed on TinkerPop's AllowAllAuthenticator.
+yaml_auth_state() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || { echo "none"; return 0; }
+awk '
+/^authentication[ \t]*:/ {
+inblk = 1
+have = 1
+# A flow mapping keeps the authenticator on the same line as the
+# key, so it has to count there too; missing it would report a
+# configured mapping as nameless and refuse a valid deployment.
+if (match($0, /authenticator[ \t]*:/)) { named = 1; exit }
Review Comment:
No longer reproduces at head 0be7fde. The scanner strips an unquoted
trailing comment before any line can count as a child, so your shape prints
nameless, byte-identical to the comment-free control; SnakeYAML 1.27 on the
same bytes also says nameless. With REST holding that class the wrapper exits 1
instead of passing parity.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# What the top-level authentication mapping of gremlin-server.yaml says about
+# authentication, as one of three states:
+#
+# none no such mapping
+# namedthe mapping carries an authenticator
+# nameless the mapping exists but names no authenticator
+#
+# Only presence is asked for, never the class: the entrypoint does not copy a
+# value between the two files any more, so quotes, inline comments and flow
+# mappings stay snakeyaml's business instead of becoming a parser here. The
+# key must start at column 0 — an `authentication:` nested under another
+# mapping belongs to that feature, not to the Gremlin server, and reading it as
+# the Gremlin one would let an unrelated class decide whether REST is
+# authenticated while Gremlin stayed on TinkerPop's AllowAllAuthenticator.
+yaml_auth_state() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || { echo "none"; return 0; }
+awk '
+/^authentication[ \t]*:/ {
+inblk = 1
+have = 1
+# A flow mapping keeps the authenticator on the same line as the
+# key, so it has to count there too; missing it would report a
+# configured mapping as nameless and refuse a valid deployment.
+if (match($0, /authenticator[ \t]*:/)) { named = 1; exit }
+next
+}
+# Any other column-0 key ends the mapping. A blank or whitespace-only
+# line does not, because YAML does not close a mapping on an empty
line.
+inblk && /^[^ \t]/ { inblk = 0 }
Review Comment:
No longer reproduces at head 0be7fde. A comment-only line strips to empty
before the root-sibling test, so it does not close the mapping: your fixture
answers named, and with a matching REST authenticator check_auth_sides returns
0, so startup is not blocked. Measured on gawk 5.0.0 here.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4169945787 ## hugegraph-server/Dockerfile: ## @@ -70,6 +70,9 @@ RUN sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/ COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy ./scripts COPY hugegraph-server/hugegraph-dist/docker/scripts/detect-storage.groovy ./scripts COPY hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh . +# props.awk needs no COPY: it ships in the assembly bin/ above, which is also +# where bin/enable-auth.sh finds it. yamlscan.awk serves only the entrypoint. +COPY hugegraph-server/hugegraph-dist/docker/yamlscan.awk . Review Comment: At merge base `83ef9f3` this Dockerfile already had `WORKDIR /hugegraph-server/` (48), `COPY .../docker-entrypoint.sh .` (72), `VOLUME /hugegraph-server` (76) and `CMD ["./docker-entrypoint.sh"]` (82) - so the shadow predates this PR and already covers the entrypoint itself; my only new copy is `yamlscan.awk` (75). Relocating the payload outside the volume is a wider image-layout change; happy to do it here if maintainers want that. ## hugegraph-server/Dockerfile-hstore: ## @@ -72,6 +72,9 @@ RUN cd /hugegraph-server/conf/graphs \ COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy ./scripts #COPY hugegraph-server/hugegraph-dist/docker/scripts/detect-storage.groovy ./scripts COPY hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh . +# props.awk needs no COPY: it ships in the assembly bin/ above, which is also +# where bin/enable-auth.sh finds it. yamlscan.awk serves only the entrypoint. +COPY hugegraph-server/hugegraph-dist/docker/yamlscan.awk . Review Comment: Same for hstore: at merge base `83ef9f3` this file already had `WORKDIR /hugegraph-server/` (46), `COPY .../docker-entrypoint.sh .` (74), `VOLUME /hugegraph-server` (78) and `CMD ["./docker-entrypoint.sh"]` (84), so the entrypoint was already inside the declared volume before this PR added `COPY yamlscan.awk` (77). I can move these helpers under /opt in a follow-up if that is the preferred direction. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4167435748
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,405 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4137530422
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk:
##
@@ -0,0 +1,411 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition, in the on-disk
+# escaped form; with PROPS_DECODED=1 print it as java.util.Properties
+# would hand it to the server. Exits 0 when K has no definition, which
+# prints nothing, and 2 when the file cannot be read or uses an include
+# directive. The guards that append a default -- `check_auth_sides` and
+# `props_get` -- rely on that nonzero status to refuse rather than treat
+# an unreadable file as an absent key.
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - physical lines end at \r\n, \n or a bare \r, as in java.util.Properties
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, where the whitespace Java counts is
+# space, tab and form feed, with whitespace then an optional single '=' or
+# ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+#
+# A file that carries commons-configuration's `include` directive is refused in
+# every mode, with exit status 2: the directive splices another file into this
+# one, so "this key is absent" is a question that cannot be answered from this
+# file alone, and writing into it could bury the definition the server reads.
+# Rewrites stage through two exclusively created 0600 files (`mktemp`) rather
+# than a predictable `.tmp` / `.bak`, which a writer in a mounted
+# conf directory could have arranged as a symlink before the entrypoint,
running
+# as root, opened either of them.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+# 2 for an error. An absent key answers with empty output at exit 0, so an
+# error needs a status of its own: a caller that read any nonzero as "not
+# there" would append a definition on top of one it failed to read.
+exit 2
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4;
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4137077577
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk:
##
@@ -0,0 +1,411 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition, in the on-disk
+# escaped form; with PROPS_DECODED=1 print it as java.util.Properties
+# would hand it to the server. Exits 0 when K has no definition, which
+# prints nothing, and 2 when the file cannot be read or uses an include
+# directive. The guards that append a default -- `check_auth_sides` and
+# `props_get` -- rely on that nonzero status to refuse rather than treat
+# an unreadable file as an absent key.
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - physical lines end at \r\n, \n or a bare \r, as in java.util.Properties
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, where the whitespace Java counts is
+# space, tab and form feed, with whitespace then an optional single '=' or
+# ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+#
+# A file that carries commons-configuration's `include` directive is refused in
+# every mode, with exit status 2: the directive splices another file into this
+# one, so "this key is absent" is a question that cannot be answered from this
+# file alone, and writing into it could bury the definition the server reads.
+# Rewrites stage through two exclusively created 0600 files (`mktemp`) rather
+# than a predictable `.tmp` / `.bak`, which a writer in a mounted
+# conf directory could have arranged as a symlink before the entrypoint,
running
+# as root, opened either of them.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+# 2 for an error. An absent key answers with empty output at exit 0, so an
+# error needs a status of its own: a caller that read any nonzero as "not
+# there" would append a definition on top of one it failed to read.
+exit 2
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <=
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4132833104
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,244 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding on the key being present and appending was not the same
+# question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so a presence check reported
+# them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
+
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4132468807
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,244 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+# The character check for every class this script writes. Java class names
need
+# no properties escaping; anything else would have to go through the
entrypoint's
+# encoder first. It is one function rather than a pattern at each call site so
+# the early refusal below and the write cannot drift apart.
+check_class_name() {
+case "$1" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $1" ;;
+esac
+}
+
+props_set() {
+check_class_name "$2"
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding on the key being present and appending was not the same
+# question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so a presence check reported
+# them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4126083661 ## hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk: ## @@ -0,0 +1,423 @@ +# 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. +# +# props.awk — read and rewrite Java ".properties" files with the grammar +# HugeConfig (commons-configuration over JDK Properties) applies, so the +# entrypoint and the server agree on what a mounted file means. grep/sed +# rewrites do not: they see `\`-escaped keys, `:` separators, continuation +# lines and duplicate definitions differently, which is how a mounted +# config ends up with two definitions of one key. +# +# One invocation, selected with the `PROPS_MODE` environment variable: +# +# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F +# print the value of K's first logical definition, in the on-disk +# escaped form; with PROPS_DECODED=1 print it as java.util.Properties +# would hand it to the server. Always exits 0. Review Comment: Fixed in `9ae26c8`: `get` now states exit 0 when the key is absent, 2 when the file cannot be read or uses an include — both reproduced at `364d42f`. `has`, `props_has` and their tests are gone; nothing outside the suite called them. Its assertions became three `get` status checks, mutation-tested. Suite green here; CI has not run. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4125805319 ## hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk: ## @@ -0,0 +1,423 @@ +# 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. +# +# props.awk — read and rewrite Java ".properties" files with the grammar +# HugeConfig (commons-configuration over JDK Properties) applies, so the +# entrypoint and the server agree on what a mounted file means. grep/sed +# rewrites do not: they see `\`-escaped keys, `:` separators, continuation +# lines and duplicate definitions differently, which is how a mounted +# config ends up with two definitions of one key. +# +# One invocation, selected with the `PROPS_MODE` environment variable: +# +# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F +# print the value of K's first logical definition, in the on-disk +# escaped form; with PROPS_DECODED=1 print it as java.util.Properties +# would hand it to the server. Always exits 0. Review Comment: Minor: The header says `get` always exits 0, but it exits 2 whenever `props_load` calls `die`: for an unreadable file (line 237) and for a file with an `include` directive (line 288). `check_auth_sides` in docker-entrypoint.sh and `props_get` in enable-auth.sh both rely on that nonzero status to refuse instead of treating the key as absent, so a reader who trusts this header could remove those checks. Measured at 364d42f: `PROPS_MODE=get PROPS_KEY=a PROPS_FILE=/nonexistent awk -f props.awk /dev/null` prints `props.awk: cannot read /nonexistent` and exits 2. The same call on a file whose first line is `include=x.properties` also exits 2. Please change the sentence to say that `get` exits 0 when the key is absent and 2 when the file cannot be read or uses an include directive. ## hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk: ## @@ -0,0 +1,423 @@ +# 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. +# +# props.awk — read and rewrite Java ".properties" files with the grammar +# HugeConfig (commons-configuration over JDK Properties) applies, so the +# entrypoint and the server agree on what a mounted file means. grep/sed +# rewrites do not: they see `\`-escaped keys, `:` separators, continuation +# lines and duplicate definitions differently, which is how a mounted +# config ends up with two definitions of one key. +# +# One invocation, selected with the `PROPS_MODE` environment variable: +# +# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F +# print the value of K's first logical definition, in the on-disk +# escaped form; with PROPS_DECODED=1 print it as java.util.Properties +# would hand it to the server. Always exits 0. +# PROPS_MODE=has PROPS_KEY=K PROPS_FILE=F +# print nothing; exit 0 when K has any definition at all, empty +# included, 1 when it has none, 2 on an error +# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F +# replace K's first definition in place, drop every other +# definition of K, append one when the file has none. The new +# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment +# variable, so secrets never appear in `ps` output or in awk's +# argv), and -v is not used for it so awk cannot mangle its +# backslash escapes. +# +# Grammar implemented (java.util.Properties line reader + the +# first-definition-wins rule Configuration.getString applies): +# -
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4122935575
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,719 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the LAST one. The
+# answer therefore comes from the last mapping, which is the mapping the
+# server loads: the base enable-auth.sh appended a block every time
+# conf-bak/ was missing, so a bind-mounted conf/ carries two or three
+# identical ones (#3133, the bug this entrypoint fixes) and boots as an
+# authenticating server. Refusing that file would stop a container that
+# works, while an empty or class-less LAST mapping is still `nameless` and
+# still stops the boot, which is the direction that matters;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+# 8. a child value may open a flow collection or a quoted scalar that its own
+# line does not close, and flow content ignores indentation -- so every
+# line until it closes belongs to the nested node rather than to the
+# authentication mapping. Counting one of those continuation lines as a
+# direct child answered `named` for a file whose authenticator sits inside
+# `authentication.config`, which is the direction that leaves REST
+# enforcing beside a Gremlin on AllowAllAuthenticator;
+# 8b. the mapping itself may be a flow collection that opens behind an anchor
+# (`authentication: &auth {authenticator: X}`) or on its first child line
+# rather than on the key line. Settings.read() loads both, so answering
+# `nameless` for them stops a boot that works.
+# 9. a child
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4120087341
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,719 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the LAST one. The
+# answer therefore comes from the last mapping, which is the mapping the
+# server loads: the base enable-auth.sh appended a block every time
+# conf-bak/ was missing, so a bind-mounted conf/ carries two or three
+# identical ones (#3133, the bug this entrypoint fixes) and boots as an
+# authenticating server. Refusing that file would stop a container that
+# works, while an empty or class-less LAST mapping is still `nameless` and
+# still stops the boot, which is the direction that matters;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+# 8. a child value may open a flow collection or a quoted scalar that its own
+# line does not close, and flow content ignores indentation -- so every
+# line until it closes belongs to the nested node rather than to the
+# authentication mapping. Counting one of those continuation lines as a
+# direct child answered `named` for a file whose authenticator sits inside
+# `authentication.config`, which is the direction that leaves REST
+# enforcing beside a Gremlin on AllowAllAuthenticator;
+# 8b. the mapping itself may be a flow collection that opens behind an anchor
+# (`authentication: &auth {authenticator: X}`) or on its first child line
+# rather than on the key line. Settings.read() loads both, so answering
+# `nameless` for them stops a boot that works.
+# 9. a
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4115196963
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,654 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+# 8. a child value may open a flow collection or a quoted scalar that its own
+# line does not close, and flow content ignores indentation -- so every
+# line until it closes belongs to the nested node rather than to the
+# authentication mapping. Counting one of those continuation lines as a
+# direct child answered `named` for a file whose authenticator sits inside
+# `authentication.config`, which is the direction that leaves REST
+# enforcing beside a Gremlin on AllowAllAuthenticator;
+# 8b. the mapping itself may be a flow collection that opens behind an anchor
+# (`authentication: &auth {authenticator: X}`) or on its first child line
+# rather than on the key line. Settings.read() loads both, so answering
+# `nameless` for them stops a boot that works.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) {
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5855507639 All three fixed in 664dcac; both suites green here under gawk 5.0.0, and reverting just the scanner makes the new assertions fail. One asymmetry left deliberately: a duplicate `authenticator` inside one mapping still refuses, though the server takes the last of those too -- say if it should follow the root rule. CI is still action_required at this head. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4115027248
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,654 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+# 8. a child value may open a flow collection or a quoted scalar that its own
+# line does not close, and flow content ignores indentation -- so every
+# line until it closes belongs to the nested node rather than to the
+# authentication mapping. Counting one of those continuation lines as a
+# direct child answered `named` for a file whose authenticator sits inside
+# `authentication.config`, which is the direction that leaves REST
+# enforcing beside a Gremlin on AllowAllAuthenticator;
+# 8b. the mapping itself may be a flow collection that opens behind an anchor
+# (`authentication: &auth {authenticator: X}`) or on its first child line
+# rather than on the key line. Settings.read() loads both, so answering
+# `nameless` for them stops a boot that works.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) {
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4114312892
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,555 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4113856888
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,555 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4113277082
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,226 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+props_set() {
+# The only values written here are Java class names, whose characters need
+# no properties escaping; anything else would have to go through the
+# entrypoint's encoder first.
+case "$2" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $2" ;;
+esac
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding with props_has and appending was not the same question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so props_has reported them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
+cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" ||
+fail "cannot back up ${REST_SERVER_CONF}"
+cp "${CONF}/graphs/${GRAPH_CONF}"
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4113116473
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,226 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+props_set() {
+# The only values written here are Java class names, whose characters need
+# no properties escaping; anything else would have to go through the
+# entrypoint's encoder first.
+case "$2" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $2" ;;
+esac
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding with props_has and appending was not the same question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so props_has reported them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
+cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" ||
+fail "cannot back up ${REST_SERVER_CONF}"
+cp "${CONF}/graphs/${GRAPH_CONF}"
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4106563498
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,192 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+props_set() {
+# The only values written here are Java class names, whose characters need
+# no properties escaping; anything else would have to go through the
+# entrypoint's encoder first.
+case "$2" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $2" ;;
+esac
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding with props_has and appending was not the same question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so props_has reported them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
+cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" ||
+fail "cannot back up ${REST_SERVER_CONF}"
+cp "${CONF}/graphs/${GRAPH_CONF}"
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5827856143 Fixed in `c1dde5e` — spread-flow closing brace, CR/LF/CRLF records, escaped quoted keys, empty block scalars. Each input run against `5940fa5` and the new head; table in the commit. Both shell suites exit 0. Root flow mapping is refused, not parsed. Dockerfile volume-mount and class-name parity untouched — no Docker here. gawk only; snakeyaml not run. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4099872171
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,405 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 6b. the file is read to its end, not to the first mapping, because two
+# top-level `authentication` mappings resolve to the last one (or are
+# rejected outright). Answering from the first reported `named` for a
+# server left on AllowAllAuthenticator by the empty second mapping, so a
+# duplicate root mapping is refused rather than guessed at;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Copilot commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4099734960
##
hugegraph-server/Dockerfile:
##
@@ -70,6 +70,9 @@ RUN sed -i
"s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/
COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy
./scripts
COPY hugegraph-server/hugegraph-dist/docker/scripts/detect-storage.groovy
./scripts
COPY hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh .
+# props.awk needs no COPY: it ships in the assembly bin/ above, which is also
+# where bin/enable-auth.sh finds it. yamlscan.awk serves only the entrypoint.
+COPY hugegraph-server/hugegraph-dist/docker/yamlscan.awk .
Review Comment:
These helpers are copied inside `/hugegraph-server`, but the Dockerfile
declares that entire path as a volume (line 79). A user upgrading a container
with an existing named volume or bind-mounting the install directory will hide
the newly copied `bin/props.awk` and root `yamlscan.awk`; the new entrypoint
then exits at startup with “not found” before it can process the mounted
config. Keep the runtime helpers in a path outside the application volume (and
point both scripts there), or provide an equivalent upgrade-safe fallback.
##
hugegraph-server/Dockerfile-hstore:
##
@@ -72,6 +72,9 @@ RUN cd /hugegraph-server/conf/graphs \
COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy
./scripts
#COPY hugegraph-server/hugegraph-dist/docker/scripts/detect-storage.groovy
./scripts
COPY hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh .
+# props.awk needs no COPY: it ships in the assembly bin/ above, which is also
+# where bin/enable-auth.sh finds it. yamlscan.awk serves only the entrypoint.
+COPY hugegraph-server/hugegraph-dist/docker/yamlscan.awk .
Review Comment:
These helpers are copied inside `/hugegraph-server`, but the Dockerfile
declares that entire path as a volume (line 81). A user upgrading a container
with an existing named volume or bind-mounting the install directory will hide
the newly copied `bin/props.awk` and root `yamlscan.awk`; the new entrypoint
then exits at startup with “not found” before it can process the mounted
config. Keep the runtime helpers in a path outside the application volume (and
point both scripts there), or provide an equivalent upgrade-safe fallback.
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,405 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must sit at the indentation of the document root -- an
+# `authentication:` nested under some other key belongs to that feature,
+# not to the Gremlin server, while a root mapping written indented below a
+# document marker still counts because the server reads it as the root;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4096075020
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,355 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused;
+# 6. a mapping is read to its end before it is answered, because the server
+# sees the whole node: a direct `authenticator` defined twice is refused
+# rather than settled by whoever met it first;
+# 7. YAML ends a line at CR, LF or CRLF, so a CR that has survived the
+# comment being stripped is line noise, not part of a key or a value.
+# Reading `authentication:\r` as no key at all reported a Gremlin mapping
+# that names a class as absent, which is the direction that leaves REST
+# open while Gremlin authenticates.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4092697117
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -34,23 +36,179 @@ GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"
+fail() {
+echo "enable-auth.sh: $*" >&2
+exit 1
+}
+
+# Reading and writing .properties files goes through props.awk, the same helper
+# the docker entrypoint uses, because the keys below can be spelled in every
way
+# java.util.Properties accepts: `=`/`:`/bare-whitespace separators, a form feed
+# as whitespace, `\.` or `\u002e` for the dots, and LF, CRLF or CR line
+# terminators. grep and sed see a different file. A legal
+# `gremlin\u002egraph=org.apache.hugegraph.HugeFactory` matched no pattern at
+# all, so the factory was never wrapped for auth even though both servers were
+# told authentication was on -- and the CR byte that the previous pattern had
+# to be handed a carriage return for is now handled by the reader itself.
+#
+# props.awk is packaged in this same bin/ directory by the release assembly, so
+# it is present in the tarball and in the image. PROPS_AWK lets a caller point
+# at a different copy; the entrypoint reads that same variable for itself.
+for candidate in "${PROPS_AWK:-}" "${BIN}/props.awk" "${TOP}/props.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+PROPS_AWK="${candidate}"
+break
+fi
+done
+[[ -n "${PROPS_AWK:-}" ]] || fail "props.awk not found beside this script"
+
+# The Gremlin half of the decision below has to be made by the same reader the
+# entrypoint uses. yamlscan.awk is not in bin/: the Dockerfile places it in
the
+# install home, one above this script, which is where the image layout is
+# mirrored in the test tree; PROPS_AWK and YAMLSCAN_AWK cover a caller that
+# keeps it elsewhere. The release tarball carries no copy at all, so the
+# fallback below has to answer on its own.
+YAMLSCAN=""
+for candidate in "${YAMLSCAN_AWK:-}" "${TOP}/yamlscan.awk"
"${BIN}/yamlscan.awk"; do
+if [[ -n "${candidate}" && -f "${candidate}" ]]; then
+YAMLSCAN="${candidate}"
+break
+fi
+done
+
+# props_get is the only reader used here, and it treats any nonzero status from
+# props.awk as an error: 2 means the file could not be read at all, which must
+# not be mistaken for "the key is not there" and answered with a write.
+props_get() {
+local status=0 value
+value=$(PROPS_MODE=get PROPS_DECODED=1 PROPS_KEY="$1" PROPS_FILE="$2" \
+awk -f "${PROPS_AWK}" /dev/null) || status=$?
+if (( status > 0 )); then
+fail "cannot read $2"
+fi
+printf '%s' "${value}"
+}
+
+props_set() {
+# The only values written here are Java class names, whose characters need
+# no properties escaping; anything else would have to go through the
+# entrypoint's encoder first.
+case "$2" in
+*[!A-Za-z0-9_\.\$]*) fail "refusing to write an unescaped value: $2" ;;
+esac
+PROPS_MODE=set PROPS_KEY="$1" PROPS_VALUE_ENCODED="$2" PROPS_FILE="$3" \
+awk -f "${PROPS_AWK}" /dev/null || fail "cannot update $3"
+}
+
+# Give `$3` its default `$2` for key `$1`, in place, unless it already has a
+# value. Guarding with props_has and appending was not the same question:
+# `auth.authenticator=` and a bare `auth.authenticator` line both parse to the
+# empty string (measured against java.util.Properties, which also strips the
+# trailing blanks of `auth.authenticator= `), so props_has reported them as
+# answered and the append was skipped -- while the entrypoint's
+# check_auth_sides, which asks for the value rather than the key, counted the
+# same file as unconfigured. `loadAuthenticator("")` returns null, so REST
then
+# served without authentication next to a Gremlin that required it.
+#
+# props_set covers both shapes the guard had to split: with a definition
+# present it replaces the first one where it stands (no duplicate for
+# first-definition-wins to bury), with none present it appends.
+ensure_rest_prop() {
+[[ -n "$(props_get "$1" "$3")" ]] && return 0
+props_set "$1" "$2" "$3"
+}
+
# make a backup
BAK_CONF="$TOP/conf-bak"
if [ ! -d "$BAK_CONF" ]; then
-mkdir -p "$BAK_CONF"
-cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
-cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
-cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+mkdir -p "$BAK_CONF" || fail "cannot create ${BAK_CONF}"
+cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" ||
+fail "cannot back up ${GREMLIN_SERVER_CONF}"
+cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" ||
+fail "cannot back up ${REST_SERVER_CONF}"
+cp "${CONF}/graphs/${GRAPH_CONF}"
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4095554984
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint-test.sh:
##
@@ -324,4 +359,95 @@ done
)
assert_start_timeout 120
+# A mounted rest-server.properties that already carries auth.authenticator,
+# with no matching yaml mapping and no PASSWORD given, used to start without a
+# word: the parity check ran only inside the PASSWORD branch, so nothing ever
+# compared the two sides and the server came up with REST enforcing and Gremlin
+# on AllowAllAuthenticator. The check now runs on every start, and a refusal
+# has to come before anything touches the backend.
+printf '%s\n' 'host: 8182' > "${TEST_HOME}/conf/gremlin-server.yaml"
+grep -qx 'auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
+"${TEST_HOME}/conf/rest-server.properties" ||
+printf '%s\n' \
+'auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
+>> "${TEST_HOME}/conf/rest-server.properties"
+rm -f "${TEST_HOME}/docker/init_complete"
+before_calls="$(wc -l < "${TEST_HOME}/docker/init-store-calls")"
+before_auth="$(wc -l < "${TEST_HOME}/docker/enable-auth-calls")"
+status=0
+(
+cd "${TEST_HOME}"
+bash ./docker-entrypoint.sh
+) || status=$?
+if (( status == 0 )); then
+echo "entrypoint must refuse a mounted REST-only authenticator with no
PASSWORD" >&2
+exit 1
+fi
+if [[ "$(wc -l < "${TEST_HOME}/docker/init-store-calls")" != "${before_calls}"
]]; then
+echo "the refusal must happen before init-store runs" >&2
+exit 1
+fi
+if [[ "$(wc -l < "${TEST_HOME}/docker/enable-auth-calls")" != "${before_auth}"
]]; then
+echo "a refused start must not run enable-auth.sh" >&2
+exit 1
+fi
+
+# The same start is accepted once both sides agree, so the check above is a
+# parity decision and not a blanket refusal to run without PASSWORD.
+printf '%s\n' \
+'authentication: {' \
+' authenticator: org.apache.hugegraph.auth.StandardAuthenticator,' \
+' config: {tokens: conf/rest-server.properties}' \
+'}' > "${TEST_HOME}/conf/gremlin-server.yaml"
+rm -f "${TEST_HOME}/docker/init_complete"
+(
+cd "${TEST_HOME}"
+bash ./docker-entrypoint.sh
+)
+
+# ── The stabilization check follows the backend the JVM actually loaded ──
+# ACTUAL_BACKEND is compared against a literal, so it has to be the decoded
+# value. A mounted hugegraph.properties may spell the word with a unicode
+# escape for the s, which java.util.Properties hands the server as hstore;
+# reading the on-disk escaping instead compared something else to hstore,
+# skipped wait-partition.sh, and let startup continue before the partitions
+# were assigned. bs is the backslash, taken from its code point rather than
+# written here: printf '%c' 92 hands back the digit 9, which would have built a
+# fixture holding a different word than the one being decoded.
+bs=$(awk 'BEGIN { printf "%c", 92 }')
+if [[ "${#bs}" != 1 || "$(printf '%d' "'${bs}")" != 92 ]]; then
+echo "this host did not yield a backslash for code point 92" >&2
+exit 1
+fi
+touch "${TEST_HOME}/docker/init_complete"
+rm -f "${TEST_HOME}/docker/wait-partition-calls"
+printf '%s\n' "backend=h${bs}u0073tore" 'pd.peers=pd:8686' \
+> "${TEST_HOME}/conf/graphs/hugegraph.properties"
+if [[ "$(head -n 1 "${TEST_HOME}/conf/graphs/hugegraph.properties")" != \
+ "backend=h${bs}u0073tore" ]]; then
+echo "the fixture has to hold the escaped bytes, not the decoded word" >&2
+exit 1
+fi
+(
+cd "${TEST_HOME}"
+bash ./docker-entrypoint.sh
Review Comment:
⚠️ [P2] Isolate this config-driven invocation from the CI backend
environment. Server CI exports `BACKEND=rocksdb`; the entrypoint maps it to
`HG_SERVER_BACKEND` and overwrites this fixture's escaped `hstore`, so the
assertion at line 436 fails. This reproduces with `BACKEND=rocksdb` and passes
when `BACKEND` and `HG_SERVER_BACKEND` are unset. Clear inherited backend
variables for these config-driven cases rather than changing production
environment precedence.
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,355 @@
+# 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
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4095039962
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,297 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+}
+return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar. Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,i, n, c, q) {
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+continue
+}
+if (is_quote(c)) { q = c; continue }
+if (c != ":") continue
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4095042049
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/props.awk:
##
@@ -0,0 +1,374 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition, in the on-disk
+# escaped form; with PROPS_DECODED=1 print it as java.util.Properties
+# would hand it to the server. Always exits 0.
+# PROPS_MODE=has PROPS_KEY=K PROPS_FILE=F
+# print nothing; exit 0 when K has any definition at all, empty
+# included, 1 when it has none, 2 on an error
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - physical lines end at \r\n, \n or a bare \r, as in java.util.Properties
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, where the whitespace Java counts is
+# space, tab and form feed, with whitespace then an optional single '=' or
+# ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+# 2 for an error, so a caller that reads exit status 1 as "the key is not
+# there" (PROPS_MODE=has) cannot mistake an unreadable file for an absent
+# property and append a definition on top of one it failed to read.
+exit 2
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4092035686
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,297 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+}
+return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar. Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,i, n, c, q) {
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+continue
+}
+if (is_quote(c)) { q = c; continue }
+if (c != ":") continue
+
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4090080929
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,257 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+}
+return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar. Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,i, n, c, q) {
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+continue
+}
+if (is_quote(c)) { q = c; continue }
+if (c != ":") continue
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4090078907
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,257 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+}
+return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar. Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,i, n, c, q) {
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+continue
+}
+if (is_quote(c)) { q = c; continue }
+if (c != ":") continue
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r408173
##
hugegraph-server/hugegraph-dist/docker/yamlscan.awk:
##
@@ -0,0 +1,257 @@
+# 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.
+#
+# yamlscan.awk -- does the top-level `authentication` mapping of a Gremlin
+# server YAML file name an authenticator? Prints exactly one of:
+#
+# none there is no top-level authentication mapping
+# nameless the mapping exists but names no authenticator class
+# named the mapping names an authenticator class
+#
+# The entrypoint asks this one question to decide whether
+# rest-server.properties and gremlin-server.yaml configure authentication
+# together. Getting it wrong toward "named" is how REST ends up enforcing
+# StandardAuthenticator while Gremlin silently falls back to TinkerPop
+# AllowAllAuthenticator, so the answer has to follow the same structure
+# snakeyaml hands to the server, within the subset of YAML that shipped and
+# mounted configs use:
+#
+# 1. the mapping must start at column 0 -- an `authentication:` nested under
+# some other key belongs to that feature, not to the Gremlin server;
+# 2. only a direct child `authenticator` counts -- a class reached through
+# `authentication.config`, or through any other nested mapping, is not
+# the server authenticator, because TinkerPop keeps `config` as its own
+# map;
+# 3. `#` outside quotes starts a comment: text behind one is not content,
+# and a comment-only line is neither a child nor the end of the mapping;
+# 4. in a flow mapping the key must sit at depth one between the braces, so
+# `{authenticator: X}` names a class while `{config: {authenticator: X}}`
+# does not;
+# 5. a direct `authenticator` whose value is empty, `null` or `~` names no
+# class -- the server reads the key, gets nothing and leaves
+# authentication off, which is the nameless case that must be refused.
+#
+# Quote characters come from sprintf so this file holds no literal apostrophe:
+# an awk program written into a single-quoted shell string breaks on one, and
+# that has cost this repo twice already.
+
+function apos() { return sprintf("%c", 39) }
+function dquo() { return sprintf("%c", 34) }
+
+function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
+function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
+function trim(s) { return rtrim(ltrim(s)) }
+
+function is_quote(c) { return c == apos() || c == dquo() }
+
+# Remove an unquoted trailing comment together with the whitespace that has to
+# precede the `#` for it to be a comment rather than part of a scalar.
+function strip_comment(s,i, n, c, q, prev) {
+q = ""
+prev = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+} else if (is_quote(c)) {
+q = c
+} else if (c == "#" && (prev == "" || prev == " " || prev == "\t")) {
+return rtrim(substr(s, 1, i - 1))
+}
+prev = c
+}
+return s
+}
+
+# How many whitespace characters open the line, i.e. its block nesting level.
+function indent_of(s,i, n, c) {
+n = length(s)
+i = 1
+while (i <= n) {
+c = substr(s, i, 1)
+if (c != " " && c != "\t") break
+i++
+}
+return i - 1
+}
+
+# One layer of matching quotes off a key or scalar.
+function unquote(s,f) {
+s = trim(s)
+if (length(s) >= 2) {
+f = substr(s, 1, 1)
+if ((f == apos() || f == dquo()) && substr(s, length(s), 1) == f)
+return substr(s, 2, length(s) - 2)
+}
+return s
+}
+
+# Split `name: value` at the first colon outside quotes that is followed by end
+# of line or a space, which is what makes a colon inside `http://host` part of
+# the scalar. Results go to K_TXT / V_TXT because awk returns one value.
+function split_pair(s,i, n, c, q) {
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+continue
+}
+if (is_quote(c)) { q = c; continue }
+if (c != ":") continue
+
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4085381605
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,61 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# The guards accept every spelling java.util.Properties reads as the key —
+# '=' or ':' or bare-whitespace separators, leading whitespace and
+# backslash-escaped dots — and the gremlin.graph flip tolerates CRLF
+# endings, which a mounted config saved on Windows carries. Appending
+# unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+
+# Appended with `>>` rather than `sed -i '$a\...'`: GNU sed's `$` address
+# never matches when the file has no lines, so on an empty mounted config
+# every append below silently did nothing. Neither the REST
+# `auth.authenticator` nor the yaml `authentication:` block was written,
+# while the entrypoint had already applied PASSWORD and init-store had run
+# in auth mode — the servers then came up unauthenticated with no error.
+# `sed -i '$a'` also closed the previous last line for us, which `>>` does
+# not, so a file without a trailing newline gets one first.
+append_lines() {
+local file="$1"
+shift
+if [[ -s "${file}" && -n "$(tail -c 1 "${file}")" ]]; then
+printf '\n' >> "${file}"
+fi
+printf '%s\n' "$@" >> "${file}"
+}
+AUTHENTICATOR_CLASS="${AUTHENTICATOR_CLASS:-org.apache.hugegraph.auth.StandardAuthenticator}"
-sed -i -e '$a\authentication: {' \
--e '$a\ authenticator:
org.apache.hugegraph.auth.StandardAuthenticator,' \
--e '$a\ authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \
--e '$a\ config: {tokens: conf/rest-server.properties}' \
--e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF}
+if ! grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:'
"${CONF}/${GREMLIN_SERVER_CONF}"; then
Review Comment:
Confirmed, and still live at `53a5edb` — this one was not covered by the
16:10Z push. Reproduced against the real `enable-auth.sh`:
```
before: state=none check_auth_sides=PASS | after: gremlin=none
rest=[...StandardAuthenticator] => ONE-SIDED
```
Guard anchored to column 0 in 2c9ebaf so the two files answer the same
question:
```sh
if ! grep -Eq '^authentication[[:blank:]]*:'
"${CONF}/${GREMLIN_SERVER_CONF}"; then
```
Test added at `docker/test/test-docker-entrypoint.sh:1066`, on your layout,
running the real script: it first asserts `check_auth_sides` *accepts* the tree
(a case the entrypoint refuses no longer tests anything), then requires
`yaml_auth_state` to come back `named`, the REST class to read back through
props.awk, exactly one `auth.authenticator` definition, and `check_auth_sides`
to still hold afterwards. `someFeature:`'s own block is asserted
byte-identical, so the fix cannot "resolve" this by rewriting the nested
mapping.
Red before the change, green after: `nested authentication mapping:
gremlin-server.yaml is none, not named`.
I did not check a CR-only or CRLF `gremlin-server.yaml` here — MSYS text
mode hides CR bytes, so `^authentication` against those shapes is CI's to
confirm, not mine.
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,61 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# The guards accept every spelling java.util.Properties reads as the key —
+# '=' or ':' or bare-whitespace separators, leading whitespace and
+# backslash-escaped dots — and the gremlin.graph flip tolerates CRLF
+# endings, which a mounted config saved on Windows carries. Appending
+# unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+#
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5798638213
All eight reproduced before touching anything, and every fix was reverted to
confirm its own test goes red. Pushed in 5afbb4a; master merged in 53a5edb
(`mergeable: true` again -- #3194 and the startup-timeout change had landed in
the same files).
You were right on all eight. Table of what each one was, measured against
`java.util.Properties` where the question was properties grammar:
| thread | what it was | at b8801a6 | now |
|---|---|---|---|
|
[`r4083528783`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528783)
| `authentication: {} # authenticator: X` counted as named because the scanner
matched the comment text | `named` | `nameless` |
|
[`r4083528796`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528796)
| a column-zero comment line ended the mapping, refusing a valid deployment |
`nameless` | `named` |
|
[`r4083528809`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528809)
| authenticator accepted at any depth, so
`authentication.config.authenticator` counted | `named` | `nameless` |
|
[`r4083528814`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528814)
| `check_auth_sides` only ran inside the `PASSWORD` branch | exit 0, server
starts | exit 1, refused before init-store |
|
[`r4083528824`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528824)
| `gremlin\u002egraph` matched no grep pattern, factory left unwrapped |
`org.apache.hugegraph.HugeFactory` | `HugeFactoryAuthProxy` |
|
[`r4083528831`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528831)
| a failed yaml append on a writable REST file still exited 0 | exit 0,
half-configured | exit 1 |
|
[`r4083528843`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528843)
| bare-CR file read as one record; rewriting its first key dropped every later
one | `auth.authenticator` gone | read and survives |
|
[`r4083528855`](https://github.com/apache/hugegraph/pull/3192#discussion_r4083528855)
| form feed not treated as separator whitespace | key invisible | parsed as
Java sees it |
The first, second and third were the same root cause and the worst of them:
two of the three produced a false `named`, which is a passed parity check with
Gremlin on `AllowAllAuthenticator`.
**properties/yaml readers**
- `props.awk` now splits records on `\r\n`, `\n` and `\r` and remembers each
line's terminator, so a rewrite replays untouched bytes. Your `r4083528843`
description was exactly right, and the rewrite is worse than "drop every later
key" in one respect worth naming: `auth.authenticator` is usually the later
key, so the surviving file is the unauthenticated one.
- `\f` is now separator whitespace on both sides of the separator, in the
leading-whitespace strip and in the comment/blank-line test.
- The yaml reader moved out of the shell into `yamlscan.awk`. It answers
about the mapping, not the text: column-zero mapping only, direct child only,
in block and flow form alike (a flow key counts at depth one, so `{config:
{authenticator: X}}` does not), comments stripped outside quotes, and a direct
`authenticator` with an empty/`null`/`~` value treated as nameless rather than
named. The last one is not in your list -- it is the same fail-open shape as
`r4083528783`, so I closed it while I was in there.
- `enable-auth.sh` reads and writes through `props.awk` instead of grep/sed.
The embedded-`CR` workaround the old pattern needed goes with it, since the
reader now handles terminators.
**One packaging change to look at:** `props.awk` moved from `docker/` to
`src/assembly/static/bin/`, because `bin/enable-auth.sh` now needs it and the
tarball does not ship `docker/`. That directory's assembly fileSet
(`*`) picks it up with no descriptor change, and the image
gets it from the same place it gets every other `bin/` file, so the `COPY
.../props.awk .` line added earlier in this PR is gone. `yamlscan.awk` stays in
`docker/` with an explicit COPY -- only the entrypoint uses it.
**Two smaller changes the review pushed me into:** `PROPS_MODE=has`, which
answers "is this key defined" without confusing `auth.authenticator=` (present,
empty) with absent -- appending a default on top of an empty first definition
would have left the empty one in force; and exit status 2 now means an error
while 1 means absent, so a caller wearing `errexit` cannot read an unreadable
file as "not there".
**Verification**
- `props.awk` against real `java.util.Properties` (javac/java 17) over 15
file shapes -- LF, CRLF, CR-only, mixed, no-final-newline, `\f` on either side
of the separator, `\u002e` and `\.` in keys, continuations, indentation,
`:`/whitespace separators. Two assertions per shape: every property Java sees
must be
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4084165117
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# What the top-level authentication mapping of gremlin-server.yaml says about
+# authentication, as one of three states:
+#
+# none no such mapping
+# namedthe mapping carries an authenticator
+# nameless the mapping exists but names no authenticator
+#
+# Only presence is asked for, never the class: the entrypoint does not copy a
+# value between the two files any more, so quotes, inline comments and flow
+# mappings stay snakeyaml's business instead of becoming a parser here. The
+# key must start at column 0 — an `authentication:` nested under another
+# mapping belongs to that feature, not to the Gremlin server, and reading it as
+# the Gremlin one would let an unrelated class decide whether REST is
+# authenticated while Gremlin stayed on TinkerPop's AllowAllAuthenticator.
+yaml_auth_state() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || { echo "none"; return 0; }
+awk '
+/^authentication[ \t]*:/ {
+inblk = 1
+have = 1
+# A flow mapping keeps the authenticator on the same line as the
+# key, so it has to count there too; missing it would report a
+# configured mapping as nameless and refuse a valid deployment.
+if (match($0, /authenticator[ \t]*:/)) { named = 1; exit }
+next
+}
+# Any other column-0 key ends the mapping. A blank or whitespace-only
+# line does not, because YAML does not close a mapping on an empty
line.
+inblk && /^[^ \t]/ { inblk = 0 }
+inblk && /^[ \t]+authenticator[ \t]*:/ { named = 1; exit }
Review Comment:
Important: `^[ \t]+authenticator[ \t]*:` matches at any depth inside the
block, and the same-line `match()` on line 107 matches anywhere on the line. An
authenticator that sits under `config` therefore counts as the Gremlin one.
Reproduced at b8801a6: both `authentication:` / ` authenticationHandler:
...` / ` config:` / `authenticator: com.example.X` and `authentication:
{config: {authenticator: X}}` make `yaml_auth_state` print `named`. With a REST
`auth.authenticator` present, `check_auth_sides` passes. TinkerPop reads
`authentication.authenticator` only, so Gremlin falls back to
AllowAllAuthenticator while REST authenticates.
Please count only a direct child. Record the indentation of the first key
inside the block and accept `authenticator:` only at that indentation, and for
the flow form only at the top level of the braces. Add both layouts to the
`want_state` cases as `nameless`.
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,61 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# The guards accept every spelling java.util.Properties reads as the key —
+# '=' or ':' or bare-whitespace separators, leading whitespace and
+# backslash-escaped dots — and the gremlin.graph flip tolerates CRLF
+# endings, which a mounted config saved on Windows carries. Appending
+# unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+
+# Appended with `>>` rather than `sed -i '$a\...'`: GNU sed's `$` address
+# never matches when the file has no lines, so on an empty mounted config
+# every append below silently did nothing. Neither the REST
+# `auth.authenticator` nor the yaml `authentication:` block was written,
+# while the entrypoint had already applied PASSWORD and init-store had run
+# in auth mode — the servers then came up unauthenticated with no error.
+# `sed -i '$a'` also closed the previous last line for us, which `>>` does
+# not, so a file without a trailing newline gets one first.
+append_lines() {
+local file="$1"
+shift
+if [[ -s "${file}" && -n
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4083528783
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# What the top-level authentication mapping of gremlin-server.yaml says about
+# authentication, as one of three states:
+#
+# none no such mapping
+# namedthe mapping carries an authenticator
+# nameless the mapping exists but names no authenticator
+#
+# Only presence is asked for, never the class: the entrypoint does not copy a
+# value between the two files any more, so quotes, inline comments and flow
+# mappings stay snakeyaml's business instead of becoming a parser here. The
+# key must start at column 0 — an `authentication:` nested under another
+# mapping belongs to that feature, not to the Gremlin server, and reading it as
+# the Gremlin one would let an unrelated class decide whether REST is
+# authenticated while Gremlin stayed on TinkerPop's AllowAllAuthenticator.
+yaml_auth_state() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || { echo "none"; return 0; }
+awk '
+/^authentication[ \t]*:/ {
+inblk = 1
+have = 1
+# A flow mapping keeps the authenticator on the same line as the
+# key, so it has to count there too; missing it would report a
+# configured mapping as nameless and refuse a valid deployment.
+if (match($0, /authenticator[ \t]*:/)) { named = 1; exit }
Review Comment:
‼️ Blocking: yes. Summary: This match also counts YAML comment text, so
authentication: {} # authenticator: com.example.Fake is reported as named while
Gremlin has no authenticator. Evidence: yaml_auth_state finds the comment text
and enable-auth.sh skips appending because the line starts with
authentication:. Please ignore comments and scalar text and count only a real
direct authenticator key.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,82 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# What the top-level authentication mapping of gremlin-server.yaml says about
+# authentication, as one of three states:
+#
+# none no such mapping
+# namedthe mapping carries an authenticator
+# nameless the mapping exists but names no authenticator
+#
+# Only presence is asked for, never the class: the entrypoint does not copy a
+# value between the two files any more, so quotes, inline comments and flow
+# mappings stay snakeyaml's business instead of becoming a parser here. The
+# key must start at column 0 — an `authentication:` nested under another
+# mapping belongs to that feature, not to the Gremlin server, and reading it as
+# the Gremlin one would let an unrelated class decide whether REST is
+# authenticated while Gremlin stayed on TinkerPop's AllowAllAuthenticator.
+yaml_auth_state() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || { echo "none"; return 0; }
+awk '
+/^authentication[ \t]*:/ {
+inblk = 1
+have = 1
+# A flow mapping keeps the authenticator on the same line as the
+# key, so it has to count there too; missing it would report a
+# configured mapping as nameless and refuse a valid deployment.
+if (match($0, /authenticator[ \t]*:/)) { named = 1; exit }
+next
+}
+# Any other column-0 key ends the mapping. A blank or whitespace-only
+# line does not, because YAML does not close a mapping on an empty
line.
+inblk && /^[^ \t]/ { inblk = 0 }
Review Comment:
⚠️ Blocking: no. Summary: A column-zero YAML comment ends this mapping scan,
so authentication: followed by # note and an indented authenticator is reported
as nameless and blocks startup when PASSWORD is set. Evidence: this condition
clears inblk on any first nonblank byte, including #. Please ignore comment
lines when detecting the end of the mapping.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -147,6 +221,9 @@ elif [[ -n "${AUTH_TOKEN_SECRET_ENCODED}" ]]; then
fi
if [[ -n
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5791789511 `b8801a6` takes @bitflicker64's simplification and answers all five threads. Short version: | finding | change | what fails without it | | --- | --- | --- | | `props_set` can write a value ending in an odd number of backslashes, which then swallows the next line | refuse it; the file is left byte-for-byte untouched | reverting the guard alone turns the suite red | | `authentication:` matched at any indentation, so a nested mapping decided the REST side | key must start at column 0; the indented-`authentication:` test is dropped and the nested case asserted instead | same | | `get-decoded` did not trim, so a trailing space produced a wrong `WARN` | the mode is deleted — nothing compares the two classes any more | n/a | | the post-startup backend read accepted only `=` | goes through `props.awk` and trims in bash, so `backend : hstore` reaches the partition-wait check | n/a (behaviour asserted in the suite) | | parse which authenticator the yaml names | don't: `check_auth_sides` decides by presence and refuses one-sided layouts | making the check always pass turns the suite red | Two things worth flagging rather than leaving in the diff: **The proposal as sketched reopened the fail-open.** `has_yaml_authentication_block` is true for any mapping that exists, so a mounted file with an `authentication:` block that names no authenticator plus `auth.authenticator` set in the REST file reads as `rest=1, yaml=1` → passes → snakeyaml resolves no authenticator → Gremlin on `AllowAllAuthenticator`, REST enforcing. The read is therefore three-valued (`none` / `named` / `nameless`) and `nameless` is refused by itself, before the comparison — still without ever reading the class. **Column 0 costs a test that used to pass.** The old suite asserted ` authentication:` opened the block; that and rejecting a nested mapping are the same bytes, so they cannot both hold. I dropped the permissive one: the shipped config puts the key at column 0 and TinkerPop resolves it as a top-level key, so the indented form was this script being more generous than what it models. Say so if you would rather keep the lenient reading and reject only the nested case by tracking the parent path. Honest state of the run, same caveat as before: this host is Git Bash, so the four assertions that need a real CR byte, a working `chmod`, or a symlink cannot execute here — the suite passes with exactly those four neutralised in a scratch copy, and the committed file is unchanged. Production delta is net **-56** lines of shell and awk; tests net **+105**, so the overall diff is not the ~250-line reduction the thread estimated. CI on `b8801a6` is `action_required` like every previous head on this fork PR, so nothing has executed it yet — could someone with write access approve the workflows, and take a look at the auth decision above? -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4080559102
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,300 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW = s
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4075569806
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,141 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
Review Comment:
⚠️ This reader, and the propagation it feeds in `align_auth_config`, can go.
Keep the guarantee (REST and Gremlin never end up on different authenticators)
and drop the YAML parsing.
The PR already refuses one case, a yaml block with no readable
authenticator, because carrying on would leave auth half-applied. Refuse every
one-sided case the same way and the entrypoint no longer needs to know *which*
class the yaml names, only *whether* each side names one. Both inputs already
exist in this diff:
```bash
check_auth_sides() {
local rest=0 yaml=0
[[ -n "$(get_prop_encoded auth.authenticator "${REST_SERVER_CONF}")" ]]
&& rest=1
has_yaml_authentication_block && yaml=1
if (( rest != yaml )); then
log "ERROR: authentication is configured in only one of" \
"rest-server.properties and gremlin-server.yaml;" \
"configure both or neither, then restart."
return 1
fi
}
```
Neither side: `enable-auth.sh` appends both, with its own
`AUTHENTICATOR_CLASS` default. Both sides: its per-file guards make it a no-op.
One side: stop.
That deletes `get_yaml_authenticator` (quotes, flow mappings, inline
comments, indent scoping), `get_prop` and the `get-decoded` mode in props.awk,
most of `align_auth_config`, and the test blocks for yaml scalars, sibling
scope, escaped authenticators and the `AUTHENTICATOR_CLASS` default: roughly
250 lines. The trailing-space thread on props.awk line 279 goes away with
`get-decoded`.
What you give up: an operator with a one-sided mounted config gets an error
telling them to finish it, instead of the entrypoint finishing it for them, and
two sides naming different classes are left alone without the WARN, as they
were before this PR. Checked with the head helpers: neither and both (including
`auth\.authenticator : A` next to a quoted yaml scalar) pass; REST-only,
yaml-only and a block without an authenticator all refuse.
--
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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4075342961
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,141 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c == "\"" || c == "\047") { q = c; continue }
+if (c == "#" &&
+(out == "" || substr(out, length(out), 1) ~ /[ \t]/))
+break
+if (c == "," || c == "}" || c == "]") break
+out = out c
+}
+sub(/^[ \t\r]+/, "", out)
+sub(/[ \t\r]+$/, "", out)
+return out
+}
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ {
Review Comment:
⚠️ `authentication:` is matched at any indentation, so a mapping nested
under another key is taken as the Gremlin server's authentication block.
Line 166 has the same loose match. Run against the extracted helpers at this
head:
```yaml
someFeature:
authentication:
authenticator: com.example.Nested
```
```
get_yaml_authenticator -> com.example.Nested
rest-server.properties after align_auth_config:
restserver.url=http://0.0.0.0:8080
auth.authenticator=com.example.Nested
```
A class the operator only ever gave to an unrelated nested mapping now
authenticates REST, while Gremlin stays on TinkerPop's `AllowAllAuthenticator`
default. The same nested mapping without a readable `authenticator:` reaches
`has_yaml_authentication_block` and fires the new refusal, so the container
fails to start:
```
ERROR: gremlin-server.yaml carries an authentication block without a
readable authenticator ...
(rc=1, entrypoint exits under set -e)
```
This is the sibling of the thread the `inblk` indent tracking fixed: that
change scopes the block once it is open, but never checks that the key itself
is top level. The test at `test/test-docker-entrypoint.sh` deliberately accepts
an indented ` authentication:`, so the two requirements conflict and need a
decision.
Requested change: either require the key at column 0 (dropping the
indented-block case), or track the parent path so an `authentication:` under
another key is not treated as the Gremlin one.
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,300 @@
+# 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
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5779577228 One correction to what I wrote in the empty-fixture thread: I said `docker-build (hugegraph-server/Dockerfile)` "should go green", and it cannot tell us anything yet — CI has not run on either new commit. Every workflow on `b93b52e` and `bf83032` is sitting at `action_required`, i.e. GitHub is holding the runs for this fork PR until a committer approves them ([Docker Build CI on `bf83032`](https://github.com/apache/hugegraph/actions/runs/35748205479)). Could someone with write access approve the workflows? The last approved run is [35101931936](https://github.com/apache/hugegraph/actions/runs/35101931936), which failed at `test-docker-entrypoint.sh:221` and never reached anything after it. Where the four open findings landed: | finding | fix | case that fails without it | | --- | --- | --- | | copy-back is not failure-safe (`props.awk:240`) | `b93b52e` — 0600 snapshot before the copy, restore on failure, staging files removed only on success | injected `cat` fails the copy; `cmp` against a pristine copy | | `inblk` never cleared (`docker-entrypoint.sh:139`) | `b93b52e` — block closes at the next key at or left of `authentication:`'s column | sibling mapping after the block must return nothing; also checked against the shipped `conf-raft1` yaml | | `AUTHENTICATOR_CLASS` overwritten (`docker-entrypoint.sh:190`) | `b93b52e` — default fills in only when unset | operator value survives / unset still defaults | | empty fixture reds the build (`test-docker-entrypoint.sh:207`) | `b93b52e` — the appends move off `sed -i '$a\...'`, which cannot match an empty file; the fixture is kept because the empty config is a real input | the empty-config case, plus the original line-221 assertion | What I could not execute here, so the approved run is the first real signal for it: my host is Git Bash, and MSYS stdio is text mode (`awk`/`grep` never see a CR byte), `chmod` is a no-op (`stat -c %a` says 644 for a 600 file) and `ln -s` writes a copy instead of linking. The CRLF case, the mode-preservation case and the symlink case therefore had to be neutralised to run the file locally — they exit 0 with those four assertions removed. Everything else, including all four cases added for the findings above, runs and passes locally, three times in a row. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4073491311
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,127 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c == "\"" || c == "\047") { q = c; continue }
+if (c == "#" &&
+(out == "" || substr(out, length(out), 1) ~ /[ \t]/))
+break
+if (c == "," || c == "}" || c == "]") break
+out = out c
+}
+sub(/^[ \t\r]+/, "", out)
+sub(/[ \t\r]+$/, "", out)
+return out
+}
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ {
+inblk = 1
+line = $0
+sub(/^[ \t]*authentication[ \t]*:[ \t]*/, "", line)
+if (match(line, /authenticator[ \t]*:/)) {
+print scalar(substr(line, RSTART + RLENGTH))
+exit
+}
+next
+}
+inblk && /^[ \t]+authenticator[ \t]*:/ {
Review Comment:
Fixed in `b93b52e`. Reproduced exactly as described: with the block open,
the first `authenticator:` below `authentication:` wins no matter which mapping
it belongs to, and `align_auth_config` then writes that class into
`rest-server.properties` — so a class only ever mentioned to an unrelated
mapping ends up authenticating REST.
The block now tracks the key's own column and closes on the next key at or
left of it:
```awk
/^[ \t]*authentication[ \t]*:/ {
inblk = 1
indent = match($0, /[^ \t]/)
...
}
# A blank line does not close a YAML mapping.
/^[ \t\r]*$/ { next }
inblk && match($0, /[^ \t]/) <= indent { inblk = 0 }
inblk && /^[ \t]+authenticator[ \t]*:/ { ... }
```
The blank-line rule has to precede the closing rule, otherwise a CR-only
"blank" line in a CRLF-saved yaml (column 1) would end the block early. Comment
lines were already skipped by the existing `/^[ \t]*#/` rule, and that rule
stays ahead of the closer so a commented-out `authentication:` cannot close the
block either.
Four cases added: sibling mapping after the block returns nothing; the
block's own authenticator is still found when a sibling follows it; a blank
line and a commented authenticator inside the block don't break it; and a block
that is itself indented (` authentication:` / `authenticator:`) still
resolves, because the comparison is against the key's column rather than zero.
Against the two real layouts in the tree rather than fixtures — the
entrypoint function sourced and run on the actual files:
```
conf-raft1 -> 'org.apache.hugegraph.auth.StandardAuthenticator'
conf -> ''
```
`conf-raft1` is the case worth checking: its block is the last thing in the
file, line 122 inside it is a commented-out `#authenticationHandler:` (so the
comment rule has to stay ahead of the closer), and the authenticator is on line
121 — it still resolves.
Deleting only the `inblk = 0` rule
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4073487299
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,280 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW = s
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4031349001
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,127 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c == "\"" || c == "\047") { q = c; continue }
+if (c == "#" &&
+(out == "" || substr(out, length(out), 1) ~ /[ \t]/))
+break
+if (c == "," || c == "}" || c == "]") break
+out = out c
+}
+sub(/^[ \t\r]+/, "", out)
+sub(/[ \t\r]+$/, "", out)
+return out
+}
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ {
+inblk = 1
+line = $0
+sub(/^[ \t]*authentication[ \t]*:[ \t]*/, "", line)
+if (match(line, /authenticator[ \t]*:/)) {
+print scalar(substr(line, RSTART + RLENGTH))
+exit
+}
+next
+}
+inblk && /^[ \t]+authenticator[ \t]*:/ {
+line = $0
+sub(/^[ \t]*authenticator[ \t]*:[ \t]*/, "", line)
+print scalar(line)
+exit
+}
+' "${yaml}"
+}
+
+# A mounted yaml can carry an authentication block whose authenticator
+# cannot be read (an empty or unparseable one). That is not the
+# both-empty case: exporting the default would override an explicit
+# choice that snakeyaml does resolve, so callers treat it as a mismatch.
+has_yaml_authentication_block() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 1
+grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:' "${yaml}"
+}
+
+# enable-auth.sh appends definitions to files it did not write. On a
+# mounted config those appended definitions are duplicates the two parsers
+# resolve in opposite directions — HugeConfig (commons-configuration) takes
+# the first, snakeyaml takes the last — so Gremlin and REST can land on
+# different authenticators with no error from either. Normalize both sides
+# to one definition of the same authenticator here; enable-auth.sh's
+# per-file guards then make its appends no-ops on anything already set.
+align_auth_config() {
+local rest_auth yaml_auth
+
+rest_auth=$(get_prop "auth.authenticator" "${REST_SERVER_CONF}")
+yaml_auth=$(get_yaml_authenticator)
+if [[ -z "${yaml_auth}" ]] && has_yaml_authentication_block; then
+# Refuse instead of bootstrapping one side: enable-auth.sh runs right
+# after align and only touches the REST side, so continuing would put
+# REST on StandardAuthenticator while Gremlin stays on TinkerPop's
+# AllowAllAuthenticator default. Failing fast (rather than skipping
+# enable-auth.sh) keeps a PASSWORD deployment from starting with
+# authentication silently half-applied.
+log "ERROR: gremlin-server.yaml carries an authentication block" \
+"without a readable authenticator; refusing to bootstrap" \
+"authentication one-sided. Add an
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4030331496
##
hugegraph-server/hugegraph-dist/docker/test/test-docker-entrypoint.sh:
##
@@ -66,3 +76,218 @@ assert_line_count 1 \
"${duplicate_file}"
assert_line_count 1 '^init_store\.enabled=true$' "${duplicate_file}"
grep -q '^unrelated=true$' "${duplicate_file}"
+
+# An escaped key is one logical definition of that key, not a key with
+# backslashes in its name: setting the plain key must rewrite it in place
+# rather than appending a second definition whose only resolution is
+# parser-dependent (and which HugeConfig then reports as a list).
+escaped_file="${test_dir}/config-escaped-key"
+printf '%s\n' \
+'auth\.admin_pa=old' \
+'unrelated=true' > "${escaped_file}"
+set_prop "auth.admin_pa" "new" "${escaped_file}"
+assert_line_count 1 '^auth\.admin_pa=new$' "${escaped_file}"
+assert_line_count 1 '^unrelated=true$' "${escaped_file}"
+
+# A value continued onto the next line is part of the same definition:
+# setting the key must remove the continuation, not leave it behind as a
+# stray property of its own.
+continued_file="${test_dir}/config-continuation"
+printf '%s\n' \
+'pd.peers 127.0.0.1:8686,\' \
+' 127.0.0.2:8686' \
+'unrelated=true' > "${continued_file}"
+set_prop "pd.peers" "10.0.0.1:8686" "${continued_file}"
+assert_line_count 1 '^pd\.peers=10\.0\.0\.1:8686$' "${continued_file}"
+assert_line_count 1 '^unrelated=true$' "${continued_file}"
+[[ "$(grep -c '127\.0\.0\.2' "${continued_file}")" -eq 0 ]]
+
+# get_prop_encoded reads through the same grammar: separators, escapes,
+# continuations, and first-definition-wins duplicates.
+get_file="${test_dir}/config-get"
+printf '%s\n' \
+'#comment' \
+'a\=b : colon value' \
+'multiline first \' \
+'second' \
+'dup : one' \
+'dup=two' > "${get_file}"
+[[ "$(get_prop_encoded 'a=b' "${get_file}")" == "colon value" ]]
+[[ "$(get_prop_encoded 'multiline' "${get_file}")" == "first second" ]]
+[[ "$(get_prop_encoded 'dup' "${get_file}")" == "one" ]]
+
+# Appends must still happen when the file has no definition of the key,
+# including when the only occurrences are inside comments.
+append_file="${test_dir}/config-append"
+printf '%s\n' \
+'#init_store.enabled=false' \
+'unrelated=true' > "${append_file}"
+set_prop "init_store.enabled" "true" "${append_file}"
+assert_line_count 1 '^init_store\.enabled=true$' "${append_file}"
+assert_line_count 1 '^#init_store\.enabled=false$' "${append_file}"
+
+# A key indented with leading whitespace is still one definition of the
+# key: java.util.Properties ignores whitespace before a key, so an
+# indented key must be read and rewritten in place rather than duplicated.
+indented_file="${test_dir}/config-indented-key"
+printf '%s\n' \
+' auth.token_secret: old-secret' \
+'unrelated=true' > "${indented_file}"
+[[ "$(get_prop_encoded 'auth.token_secret' "${indented_file}")" ==
"old-secret" ]]
+set_prop_encoded 'auth.token_secret' 'new-secret' "${indented_file}"
+assert_line_count 1 'auth\.token_secret' "${indented_file}"
+assert_line_count 1 '^unrelated=true$' "${indented_file}"
+
+# get_yaml_authenticator must agree with snakeyaml on what a mounted
+# gremlin-server.yaml says: the authenticator inside the authentication
+# block — quoted scalars and inline comments cleaned the way snakeyaml
+# strips them — and a flow mapping on the authentication line itself.
+# align_auth_config refuses an authentication block without a readable
+# authenticator instead of treating it as "no yaml side": exporting the
+# default there would override an explicit choice, and continuing would let
+# enable-auth.sh write the REST side alone.
+yaml_dir="${test_dir}/yaml"
+mkdir -p "${yaml_dir}/conf"
+(
+cd "${yaml_dir}" || exit 1
+REST_SERVER_CONF="./conf/rest-server.properties"
+: > "${REST_SERVER_CONF}"
+
+printf '%s\n' \
+'authentication:' \
+' authenticator: "com.example.MyAuth" # custom' \
+' authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler' \
+> conf/gremlin-server.yaml
+[[ "$(get_yaml_authenticator)" == "com.example.MyAuth" ]]
+
+printf '%s\n' \
+'authentication: {authenticator: com.example.FlowAuth,
authenticationHandler: org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,
config: {tokens: conf/rest-server.properties}}' \
+> conf/gremlin-server.yaml
+[[ "$(get_yaml_authenticator)" == "com.example.FlowAuth" ]]
+
+# align_auth_config must refuse an authentication block without a readable
+# authenticator: continuing would let enable-auth.sh write the REST side
+# alone (REST on StandardAuthenticator, Gremlin on TinkerPop's
+# AllowAllAuthenticator default), so the entrypoint stops here instead.
+printf '%s\n' \
+'authentication:' \
+' authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler' \
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r4026552978
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,119 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c == "\"" || c == "\047") { q = c; continue }
+if (c == "#" &&
+(out == "" || substr(out, length(out), 1) ~ /[ \t]/))
+break
+if (c == "," || c == "}" || c == "]") break
+out = out c
+}
+sub(/^[ \t\r]+/, "", out)
+sub(/[ \t\r]+$/, "", out)
+return out
+}
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ {
+inblk = 1
+line = $0
+sub(/^[ \t]*authentication[ \t]*:[ \t]*/, "", line)
+if (match(line, /authenticator[ \t]*:/)) {
+print scalar(substr(line, RSTART + RLENGTH))
+exit
+}
+next
+}
+inblk && /^[ \t]+authenticator[ \t]*:/ {
+line = $0
+sub(/^[ \t]*authenticator[ \t]*:[ \t]*/, "", line)
+print scalar(line)
+exit
+}
+' "${yaml}"
+}
+
+# A mounted yaml can carry an authentication block whose authenticator
+# cannot be read (an empty or unparseable one). That is not the
+# both-empty case: exporting the default would override an explicit
+# choice that snakeyaml does resolve, so callers treat it as a mismatch.
+has_yaml_authentication_block() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 1
+grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:' "${yaml}"
+}
+
+# enable-auth.sh appends definitions to files it did not write. On a
+# mounted config those appended definitions are duplicates the two parsers
+# resolve in opposite directions — HugeConfig (commons-configuration) takes
+# the first, snakeyaml takes the last — so Gremlin and REST can land on
+# different authenticators with no error from either. Normalize both sides
+# to one definition of the same authenticator here; enable-auth.sh's
+# per-file guards then make its appends no-ops on anything already set.
+align_auth_config() {
+local rest_auth yaml_auth
+
+rest_auth=$(get_prop "auth.authenticator" "${REST_SERVER_CONF}")
+yaml_auth=$(get_yaml_authenticator)
+if [[ -z "${yaml_auth}" ]] && has_yaml_authentication_block; then
Review Comment:
Fixed in bf2718f: the branch now fails the entrypoint (ERROR + nonzero exit
under set -e) instead of warning while enable-auth.sh writes REST alone. Chose
fail-fast over skip/add-to-yaml: skipping would start a PASSWORD deployment
with auth silently half-applied, and appending an authenticator line into YAML
by shell surgery risks corrupting the user's block. The unit test now asserts
the refusal and runs enable-auth.sh against the same layout to prove it would
write only REST (yaml untouched) — i.e. what the refusal prevents. Both shell
suites pass locally.
##
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3999406016
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,119 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# Decoded read: unescapes the on-disk value the way java.util.Properties
+# does, so it compares equal with the snakeyaml-decoded scalar from
+# get_yaml_authenticator. The raw get_prop_encoded mode stays for the
+# secret round trip, which must replay backslashes byte-for-byte.
+get_prop() {
+local key="$1" file="$2"
+
+PROPS_MODE=get-decoded PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c == "\"" || c == "\047") { q = c; continue }
+if (c == "#" &&
+(out == "" || substr(out, length(out), 1) ~ /[ \t]/))
+break
+if (c == "," || c == "}" || c == "]") break
+out = out c
+}
+sub(/^[ \t\r]+/, "", out)
+sub(/[ \t\r]+$/, "", out)
+return out
+}
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ {
+inblk = 1
+line = $0
+sub(/^[ \t]*authentication[ \t]*:[ \t]*/, "", line)
+if (match(line, /authenticator[ \t]*:/)) {
+print scalar(substr(line, RSTART + RLENGTH))
+exit
+}
+next
+}
+inblk && /^[ \t]+authenticator[ \t]*:/ {
+line = $0
+sub(/^[ \t]*authenticator[ \t]*:[ \t]*/, "", line)
+print scalar(line)
+exit
+}
+' "${yaml}"
+}
+
+# A mounted yaml can carry an authentication block whose authenticator
+# cannot be read (an empty or unparseable one). That is not the
+# both-empty case: exporting the default would override an explicit
+# choice that snakeyaml does resolve, so callers treat it as a mismatch.
+has_yaml_authentication_block() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 1
+grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:' "${yaml}"
+}
+
+# enable-auth.sh appends definitions to files it did not write. On a
+# mounted config those appended definitions are duplicates the two parsers
+# resolve in opposite directions — HugeConfig (commons-configuration) takes
+# the first, snakeyaml takes the last — so Gremlin and REST can land on
+# different authenticators with no error from either. Normalize both sides
+# to one definition of the same authenticator here; enable-auth.sh's
+# per-file guards then make its appends no-ops on anything already set.
+align_auth_config() {
+local rest_auth yaml_auth
+
+rest_auth=$(get_prop "auth.authenticator" "${REST_SERVER_CONF}")
+yaml_auth=$(get_yaml_authenticator)
+if [[ -z "${yaml_auth}" ]] && has_yaml_authentication_block; then
Review Comment:
⚠️ This branch logs "leaving both sides untouched", but `enable-auth.sh`
runs right after it and only touches the REST side.
At bedc21e, with a yaml block that has no authenticator and a
rest-server.properties without `auth.authenticator`:
```
gremlin-server.yaml:
authentication:
authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler
config: {tokens: conf/rest-server.properties}
align_auth_config -> WARN ... leaving both sides untouched
(AUTHENTICATOR_CLASS unset)
./bin/enable-auth.sh
rest:
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3998925615
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,263 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW = s
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3997764805
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,263 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5644922524 All 4 inline threads of review 5185689081 addressed in 5f5051130d29089e34fec1d611d52efa5ba566b6 (branch fix-entrypoint-auth-bootstrap): (A) CRLF stripped while assembling logical lines, RAW replay untouched + regression test; (B) die on getline -1 plus atomic sibling-temp rewrite with quoted rename; (C) gremlin.graph guard and sed widened together (colon/equals/bare-whitespace, leading blank, escaped dot, optional CR), proxied/commented still skipped, CR preserved; (D) decoded authenticator comparison via new get-decoded mode with encoding setter on write. Verification: bash test-docker-entrypoint.sh passes (exit 0), bash -n clean on all three shell files, guard/sed exercised against 8 spellings + CRLF/proxied/commented cases. shellcheck not installed on this host, so that step was skipped. No Docker daemon here, so image build/mawk paths remain for CI (docker-build-ci.yml). -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3995734426
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,43 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# The guards accept every spelling java.util.Properties reads as the key —
+# '=' or ':' or bare-whitespace separators, leading whitespace and
+# backslash-escaped dots — and the gremlin.graph flip tolerates CRLF
+# endings, which a mounted config saved on Windows carries. Appending
+# unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+AUTHENTICATOR_CLASS="${AUTHENTICATOR_CLASS:-org.apache.hugegraph.auth.StandardAuthenticator}"
+if ! grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:'
"${CONF}/${GREMLIN_SERVER_CONF}"; then
sed -i -e '$a\authentication: {' \
--e '$a\ authenticator:
org.apache.hugegraph.auth.StandardAuthenticator,' \
+-e "\$a\\ authenticator: ${AUTHENTICATOR_CLASS}," \
-e '$a\ authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \
-e '$a\ config: {tokens: conf/rest-server.properties}' \
-e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF}
+fi
-sed -i -e
'$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
--e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+if ! grep -Eq
'^[[:blank:]]*auth[\\]?\.authenticator[[:blank:]]*([:=]|[[:blank:]])'
"${CONF}/${REST_SERVER_CONF}"; then
+sed -i -e "\$a\\auth.authenticator=${AUTHENTICATOR_CLASS}"
${CONF}/${REST_SERVER_CONF}
+fi
+
+if ! grep -Eq
'^[[:blank:]]*auth[\\]?\.graph_store[[:blank:]]*([:=]|[[:blank:]])'
"${CONF}/${REST_SERVER_CONF}"; then
+sed -i -e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+fi
-sed -i
's/gremlin.graph=org.apache.hugegraph.HugeFactory/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/g'
${CONF}/graphs/${GRAPH_CONF}
+# GNU grep reads \r in a pattern as the letter r, so the carriage return a
+# CRLF line ends with is embedded as a byte: without it the anchored guard
+# misses a mounted CRLF config and the factory is never wrapped for auth
+# although both servers already believe authentication is on.
+CR=$'\r'
+if grep -Eq
"^gremlin\\.graph[[:blank:]]*=org\\.apache\\.hugegraph\\.HugeFactory[[:blank:]]*${CR}?\$"
"${CONF}/graphs/${GRAPH_CONF}"; then
Review Comment:
Fixed in 5f5051130d29089e34fec1d611d52efa5ba566b6. Guard and sed widened
together: leading blanks, escaped dot, colon/equals/bare-whitespace separators,
optional CR via the $CR byte variable. Verified against 8 spellings plus CRLF
(all rewrite), already-proxied and commented lines (both skipped), CR preserved
by the prefix-only sed. Suite passes.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,108 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block, or on the `authentication:` line itself (a flow
+# mapping). snakeyaml resolves duplicate top-level keys to the last one,
+# but a mounted file carrying two authentication blocks is pathological;
+# report the first and let the mismatch WARN handle it. The scalar is
+# cleaned the way snakeyaml reads it — an inline comment (a '#' preceded
+# by whitespace), surrounding quotes and padding are stripped — because
+# java.util.Properties keeps all of those in the class name.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+function scalar(s,out, i, n, c, q) {
+out = ""
+q = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (q != "") {
+if (c == q) q = ""
+else out = out c
+continue
+}
+if (c
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3995733065
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,232 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `PROPS_MODE` environment variable:
+#
+# PROPS_MODE=get PROPS_KEY=K PROPS_FILE=F
+# print the value of K's first logical definition
+# PROPS_MODE=set PROPS_KEY=K PROPS_FILE=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROPS_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
+}
+if (sep_at == 0) {
+K_RAW = s
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3995473971
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,43 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# The guards accept every spelling java.util.Properties reads as the key —
+# '=' or ':' or bare-whitespace separators, leading whitespace and
+# backslash-escaped dots — and the gremlin.graph flip tolerates CRLF
+# endings, which a mounted config saved on Windows carries. Appending
+# unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+AUTHENTICATOR_CLASS="${AUTHENTICATOR_CLASS:-org.apache.hugegraph.auth.StandardAuthenticator}"
+if ! grep -Eq '^[[:blank:]]*authentication[[:blank:]]*:'
"${CONF}/${GREMLIN_SERVER_CONF}"; then
sed -i -e '$a\authentication: {' \
--e '$a\ authenticator:
org.apache.hugegraph.auth.StandardAuthenticator,' \
+-e "\$a\\ authenticator: ${AUTHENTICATOR_CLASS}," \
-e '$a\ authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \
-e '$a\ config: {tokens: conf/rest-server.properties}' \
-e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF}
+fi
-sed -i -e
'$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
--e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+if ! grep -Eq
'^[[:blank:]]*auth[\\]?\.authenticator[[:blank:]]*([:=]|[[:blank:]])'
"${CONF}/${REST_SERVER_CONF}"; then
+sed -i -e "\$a\\auth.authenticator=${AUTHENTICATOR_CLASS}"
${CONF}/${REST_SERVER_CONF}
+fi
+
+if ! grep -Eq
'^[[:blank:]]*auth[\\]?\.graph_store[[:blank:]]*([:=]|[[:blank:]])'
"${CONF}/${REST_SERVER_CONF}"; then
+sed -i -e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+fi
-sed -i
's/gremlin.graph=org.apache.hugegraph.HugeFactory/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/g'
${CONF}/graphs/${GRAPH_CONF}
+# GNU grep reads \r in a pattern as the letter r, so the carriage return a
+# CRLF line ends with is embedded as a byte: without it the anchored guard
+# misses a mounted CRLF config and the factory is never wrapped for auth
+# although both servers already believe authentication is on.
+CR=$'\r'
+if grep -Eq
"^gremlin\\.graph[[:blank:]]*=org\\.apache\\.hugegraph\\.HugeFactory[[:blank:]]*${CR}?\$"
"${CONF}/graphs/${GRAPH_CONF}"; then
Review Comment:
⚠️ This guard is stricter than the `sed` it guards, so part of that `sed`'s
own pattern can never fire. The guard needs `HugeFactory` immediately after
`graph[[:blank:]]*=`, while the replacement on line 82 allows `[[:blank:]]*`
there:
```
gremlin.graph=org.apache.hugegraph.HugeFactory guard=MATCH
gremlin.graph = org.apache.hugegraph.HugeFactoryguard=miss, the sed
would have rewritten it
gremlin.graph= org.apache.hugegraph.HugeFactoryguard=miss, the sed
would have rewritten it
gremlin.graph=org.apache.hugegraph.HugeFactoryguard=miss
```
End to end at this head with `gremlin.graph =
org.apache.hugegraph.HugeFactory` in a mounted `hugegraph.properties`: REST and
the yaml both come out on `StandardAuthenticator` while `gremlin.graph` stays
on the unwrapped `HugeFactory`. `java.util.Properties` reads that spelling
identically to the unspaced one. The guard shape came from the CRLF thread on
the previous head, and the `auth.authenticator` and `auth.graph_store` guards
above were widened to `[:=]`, bare whitespace and escaped keys in that same
round; this one was not.
Requested change: widen the guard and the `sed` together, since relaxing
only the guard just lets the `sed` no-op. Verified against all four spellings
above plus `:`, bare-whitespace and escaped-key forms, and it still skips an
already-proxied line, a commented line, and preserves a trailing CR:
```sh
if grep -Eq
"^[[:blank:]]*gremlin[]?\\.graph[[:blank:]]*([:=]|[[:blank:]])[[:blank:]]*org\\.apache\\.hugegraph\\.HugeFactory[[:blank:]]*${CR}?\$"
"${CONF}/graphs/${GRAPH_CONF}"; then
sed -i -E
"s#^([[:blank:]]*gremlin[]?\\.graph[[:blank:]]*([:=]|[[:blank:]])[[:blank:]]*)org\\.apache\\.hugegraph\\.HugeFactory#\\1org.apache.hugegraph.auth.HugeFactoryAuthProxy#"
"${CONF}/graphs/${GRAPH_CONF}"
fi
```
##
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3991589459
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,58 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block. snakeyaml resolves duplicate top-level keys to the
+# last one, but a mounted file carrying two authentication blocks is
+# pathological; report the first and let the mismatch WARN handle it.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ { inblk = 1; next }
+inblk && /^[ \t]+authenticator[ \t]*:/ {
+line = $0
+sub(/^[ \t]*authenticator[ \t]*:[ \t]*/, "", line)
+sub(/[,:].*$/, "", line)
Review Comment:
Fixed in f5e368c: the extracted scalar now goes through a snakeyaml-shaped
cleanup before landing in rest-server.properties — an inline `#` comment (only
when the `#` is preceded by whitespace, so `#` inside a quoted scalar
survives), surrounding single/double quotes, and trailing padding are stripped.
Covered by a regression test with `authenticator: "com.example.MyAuth" #
custom`.
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,58 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block. snakeyaml resolves duplicate top-level keys to the
+# last one, but a mounted file carrying two authentication blocks is
+# pathological; report the first and let the mismatch WARN handle it.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ { inblk = 1; next }
Review Comment:
Fixed in f5e368c: `authenticator:` is now also matched on the
`authentication:` line itself, so a single-line flow mapping is read instead of
silently falling back to the default. And when an `authentication` block is
present but no authenticator can be read, `align_auth_config` now takes the
WARN branch and leaves both sides untouched rather than the both-empty branch
that exported `StandardAuthenticator`. Both cases are covered in the suite.
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,34 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# Appending unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+AUTHENTICATOR_CLASS="${AUTHENTICATOR_CLASS:-org.apache.hugegraph.auth.StandardAuthenticator}"
+if ! grep -Eq '^[ \t]*authentication[ \t]*:' "${CONF}/${GREMLIN_SERVER_CONF}";
then
sed -i -e '$a\authentication: {' \
--e '$a\ authenticator:
org.apache.hugegraph.auth.StandardAuthenticator,' \
+-e "\$a\\ authenticator: ${AUTHENTICATOR_CLASS}," \
-e '$a\ authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \
-e '$a\ config: {tokens: conf/rest-server.properties}' \
-e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF}
+fi
-sed -i -e
'$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
--e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+if ! grep -Eq '^[ \t]*auth\.authenticator[ \t]*='
"${CONF}/${REST_SERVER_CONF}"; then
Review Comment:
Fixed in f5e368c: the guards use `[[:blank:]]`, accept `[:=]` and the
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
Adarsh-Me commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3991591311
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,227 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `mode` environment variable:
+#
+# mode=get key=K file=F
+# print the value of K's first logical definition
+# mode=set key=K file=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROP_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
Review Comment:
Fixed in f5e368c: props.awk now strips leading whitespace before the key
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
codecov[bot] commented on PR #3192: URL: https://github.com/apache/hugegraph/pull/3192#issuecomment-5542817831 ## [Codecov](https://app.codecov.io/gh/apache/hugegraph/pull/3192?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 93.25%. Comparing base ([`3681148`](https://app.codecov.io/gh/apache/hugegraph/commit/36811483a2040f70ca6923a288a8c28cad0086c0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`698b0c3`](https://app.codecov.io/gh/apache/hugegraph/commit/698b0c35f1451a93f18bc2618075ee301b454816?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)). Additional details and impacted files ```diff @@ Coverage Diff @@ ## master#3192 +/- ## = + Coverage 37.77% 93.25% +55.48% + Complexity 6560 65 -6495 = Files 8009 -791 Lines 68960 267-68693 Branches 9166 22 -9144 = - Hits 26052 249-25803 + Misses398418-39833 + Partials 3067 10 -3057 ``` [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/hugegraph/pull/3192?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache). :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache). :rocket: New features to boost your workflow: - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems. -- 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]
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
imbajin commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3929618342
##
hugegraph-server/hugegraph-dist/docker/props.awk:
##
@@ -0,0 +1,227 @@
+# 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.
+#
+# props.awk — read and rewrite Java ".properties" files with the grammar
+# HugeConfig (commons-configuration over JDK Properties) applies, so the
+# entrypoint and the server agree on what a mounted file means. grep/sed
+# rewrites do not: they see `\`-escaped keys, `:` separators, continuation
+# lines and duplicate definitions differently, which is how a mounted
+# config ends up with two definitions of one key.
+#
+# One invocation, selected with the `mode` environment variable:
+#
+# mode=get key=K file=F
+# print the value of K's first logical definition
+# mode=set key=K file=F
+# replace K's first definition in place, drop every other
+# definition of K, append one when the file has none. The new
+# value arrives pre-encoded in PROP_VALUE_ENCODED (an environment
+# variable, so secrets never appear in `ps` output or in awk's
+# argv), and -v is not used for it so awk cannot mangle its
+# backslash escapes.
+#
+# Grammar implemented (java.util.Properties line reader + the
+# first-definition-wins rule Configuration.getString applies):
+# - '#' / '!' comments and blank lines
+# - '=' / ':' / whitespace separators, with whitespace then an optional
+# single '=' or ':' accepted as one separator
+# - continuations: a physical line ending in an odd number of
+# backslashes joins the next line (its leading whitespace stripped)
+# - backslash escapes in keys and values, including \u
+# - duplicate logical keys resolve to the first definition
+#
+# Rewrites keep every untouched line byte-for-byte (comments, blank
+# lines, unrelated entries), and replace the first definition where it
+# stands, so mounted configs stay reviewable in git diffs.
+
+function die(msg) {
+printf "props.awk: %s\n", msg > "/dev/stderr"
+exit 1
+}
+
+function hex_digit(c) {
+return index("0123456789abcdef", tolower(c)) - 1
+}
+
+# \u is a UTF-16 code unit in Java. Values here are effectively
+# ISO-8859-1, so codes above 0xFF are kept as their literal escape text
+# rather than being mangled through a single-byte sprintf.
+function unescape(s,out, i, n, c, code, j, d, ok) {
+out = ""
+n = length(s)
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (c != "\\") { out = out c; continue }
+if (i == n) break
+i++
+c = substr(s, i, 1)
+if (c == "u" && i + 4 <= n) {
+code = 0
+ok = 1
+for (j = 1; j <= 4; j++) {
+d = hex_digit(substr(s, i + j, 1))
+if (d < 0) { ok = 0; break }
+code = code * 16 + d
+}
+if (ok) {
+i += 4
+if (code <= 255) out = out sprintf("%c", code)
+else out = out substr(s, i - 5, 6)
+continue
+}
+}
+if (c == "t") out = out "\t"
+else if (c == "n") out = out "\n"
+else if (c == "r") out = out "\r"
+else if (c == "f") out = out "\f"
+else out = out c
+}
+return out
+}
+
+# A physical line is continued when it ends in an odd number of
+# backslashes (an even count escapes itself).
+function trailing_backslashes(s,n, k) {
+n = length(s)
+k = 0
+while (k < n && substr(s, n - k, 1) == "\\") k++
+return k
+}
+
+function is_skipped(raw) {
+return raw ~ /^[ \t]*([#!]|$)/
+}
+
+# Split a logical line into its raw (still-escaped) key and value parts.
+# Results land in K_RAW / V_RAW because awk returns one value.
+function split_kv(s,n, i, c, esc, sep_at, rest) {
+n = length(s)
+esc = 0
+sep_at = 0
+for (i = 1; i <= n; i++) {
+c = substr(s, i, 1)
+if (esc) { esc = 0; continue }
+if (c == "\\") { esc = 1; continue }
+if (c == "=" || c == ":" || c == " " || c == "\t") { sep_at = i; break
}
Review Comment:
⚠️ Blocking: yes. `java.util.Properties` ignores leading spaces before a
Re: [PR] fix(docker): make auth bootstrap safe for mounted and upgraded configs [hugegraph]
bitflicker64 commented on code in PR #3192:
URL: https://github.com/apache/hugegraph/pull/3192#discussion_r3928440554
##
hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh:
##
@@ -70,12 +74,58 @@ set_prop() {
get_prop_encoded() {
local key="$1" file="$2"
-local esc_key
-esc_key=$(printf '%s' "$key" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')
-sed -nE \
-
"s~^[[:space:]]*${esc_key}([[:space:]]*[:=][[:space:]]*|[[:space:]]+)(.*)$~\\2~p"
\
-"${file}" | head -n 1
+PROPS_MODE=get PROPS_KEY="${key}" PROPS_FILE="${file}" \
+awk -f "${PROPS_AWK}" /dev/null
+}
+
+# First uncommented `authenticator:` inside the gremlin-server.yaml
+# authentication block. snakeyaml resolves duplicate top-level keys to the
+# last one, but a mounted file carrying two authentication blocks is
+# pathological; report the first and let the mismatch WARN handle it.
+get_yaml_authenticator() {
+local yaml="./conf/gremlin-server.yaml"
+
+[[ -f "${yaml}" ]] || return 0
+awk '
+/^[ \t]*#/ { next }
+/^[ \t]*authentication[ \t]*:/ { inblk = 1; next }
+inblk && /^[ \t]+authenticator[ \t]*:/ {
+line = $0
+sub(/^[ \t]*authenticator[ \t]*:[ \t]*/, "", line)
+sub(/[,:].*$/, "", line)
Review Comment:
⚠️ The yaml scalar goes into rest-server.properties as-is, so quotes and
inline comments become part of the class name.
`sub(/[,:].*$/, "", line)` strips a trailing comma and nothing else, and
line 123 hands the result straight to `set_prop_encoded`. snakeyaml strips
quotes, comments and padding; `java.util.Properties` strips none of them.
Measured at 698b0c3 on `ubuntu:22.04`:
```
yaml authenticator: "com.example.MyAuth" ->
auth.authenticator="com.example.MyAuth"
yaml authenticator: com.example.MyAuth␣␣␣->
auth.authenticator=com.example.MyAuth␣␣␣
yaml authenticator: com.example.MyAuth # custom ->
auth.authenticator=com.example.MyAuth # custom
```
Gremlin resolves `com.example.MyAuth` in all three rows. REST gets a
different string in all three, which is the split `align_auth_config` exists to
prevent, and a quoted scalar is ordinary yaml.
Requested change: before returning, strip an inline `#` comment, then
surrounding single or double quotes, then trailing blanks.
##
hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh:
##
@@ -41,16 +41,34 @@ if [ ! -d "$BAK_CONF" ]; then
cp "${CONF}/${GREMLIN_SERVER_CONF}"
"${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak"
+fi
+
+# The appends below are guarded per file and match only an absent or still
+# commented-out definition, so they are no-ops on any config that already
+# carries authentication (e.g. a mounted one, or a re-run of this script).
+# Appending unconditionally used to create duplicate definitions that the
+# properties parser (first definition wins) and the yaml parser (last wins)
+# resolved in opposite directions, leaving Gremlin and REST on different
+# authenticators.
+AUTHENTICATOR_CLASS="${AUTHENTICATOR_CLASS:-org.apache.hugegraph.auth.StandardAuthenticator}"
+if ! grep -Eq '^[ \t]*authentication[ \t]*:' "${CONF}/${GREMLIN_SERVER_CONF}";
then
sed -i -e '$a\authentication: {' \
--e '$a\ authenticator:
org.apache.hugegraph.auth.StandardAuthenticator,' \
+-e "\$a\\ authenticator: ${AUTHENTICATOR_CLASS}," \
-e '$a\ authenticationHandler:
org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \
-e '$a\ config: {tokens: conf/rest-server.properties}' \
-e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF}
+fi
-sed -i -e
'$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \
--e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF}
+if ! grep -Eq '^[ \t]*auth\.authenticator[ \t]*='
"${CONF}/${REST_SERVER_CONF}"; then
Review Comment:
⚠️ These guards accept only the `key=` spelling, so the forms `props.awk`
was added for still get a duplicate appended.
`^[ \t]*auth\.authenticator[ \t]*=` matches none of `auth.authenticator :
X`, `auth.authenticator X`, `auth\.authenticator=X`, and `java.util.Properties`
reads all three as a definition of `auth.authenticator`. Line 68 has the same
shape. Note also that `[ \t]` in a GNU grep `-E` bracket is the set {space,
backslash, `t`}, not a tab: under GNU grep 3.7 a tab-indented
`auth.authenticator=X` fails this guard too.
Docker path at 698b0c3, mounted config using `:`, after `align_auth_config
&& ./bin/enable-auth.sh`:
```
auth.authenticator : com.example.MyAuth
auth.authenticator=com.example.MyAuth
```
Two definitions of one key, which the unit test you add at
`docker/test/test-docker-entrypoint.sh:76-79` names as the thing to
