arshilkxwork commented on code in PR #3334:
URL: https://github.com/apache/hugegraph/pull/3334#discussion_r4262409197
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java:
##########
@@ -202,8 +226,67 @@ public static void initAdminUserIfNeeded(String confFile)
throws Exception {
config.addProperty(INITING_STORE, true);
auth.setup(config);
if (auth.graph().backendStoreFeatures().supportsPersistence()) {
- auth.initAdminUser();
+ auth.initAdminUser(config);
+ }
+ }
+
+ /**
+ * The initial admin password for the bootstrap paths that cannot prompt.
+ * auth.admin_pa goes through the properties grammar, which trims it,
+ * processes backslash escapes and decodes it as ISO-8859-1, so
+ * auth.admin_pa_file takes precedence when both are set.
+ */
+ public static String initialAdminPassword(HugeConfig config) {
+ String file = config.get(ServerOptions.ADMIN_PA_FILE);
+ if (!file.isEmpty()) {
+ return readAdminPasswordFile(file);
+ }
+ return config.get(ServerOptions.ADMIN_PA);
+ }
+
+ private static String readAdminPasswordFile(String file) {
+ String option = ServerOptions.ADMIN_PA_FILE.name();
+ byte[] bytes;
+ // Bounded, so a path that points at a log or a device fails quickly
+ try (InputStream in = Files.newInputStream(Paths.get(file))) {
Review Comment:
Fixed in 7ba00bd. `readAdminPasswordFile` now calls
`Files.readAttributes(path, BasicFileAttributes.class)` first and refuses the
path with a `ConfigException` ("is not a regular file") unless it is a regular
file. `readAttributes` follows symlinks by default, so a Secret mounted through
Kubernetes' `..data` links still passes. The 4096-byte bounded read happens
after that check. New tests: `testDirectoryFails`,
`testSymlinkToRegularFileIsFollowed`, and `testFifoFailsWithoutBlocking`, which
creates a FIFO with `mkfifo` and runs under a 10 second timeout. I checked the
FIFO test by removing the attribute check: it then times out and fails instead
of hanging the build.
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java:
##########
@@ -43,12 +52,27 @@
public class StandardAuthenticator implements HugeAuthenticator {
private static final String INITING_STORE = "initing_store";
+ private static final int MAX_ADMIN_PA_FILE_BYTES = 4096;
Review Comment:
Thanks for checking this against jbcrypt. I went with the first option in
7ba00bd: `readAdminPasswordFile` now refuses a password longer than 72 bytes in
UTF-8 (counted after the BOM and trailing line break are dropped) with a
`ConfigException` that names the option. `auth.admin_pa_file` is new, so nobody
depends on longer values yet. `testOversizedFileFails` no longer accepts a
4096-byte password; it only checks that a 4097-byte file is refused by the read
limit, and `testPasswordOverBcryptLimitFails` covers 72 and 73 bytes for ASCII
and for a two-byte character. The option description, `docker/README.md` and
`rest-server.properties` state the limit. `auth.admin_pa` keeps its current
behaviour.
--
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]