From 705183ce05e8fddee3c88facefee8fc03b167e8d Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Tue, 19 Dec 2023 23:56:48 +0100 Subject: [PATCH] feat: add server setting for providing root password --- .../java/com/arcadedb/GlobalConfiguration.java | 4 ++++ .../arcadedb/server/security/ServerSecurity.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/engine/src/main/java/com/arcadedb/GlobalConfiguration.java b/engine/src/main/java/com/arcadedb/GlobalConfiguration.java index ce3d6b50a5d..dca4c78ab32 100644 --- a/engine/src/main/java/com/arcadedb/GlobalConfiguration.java +++ b/engine/src/main/java/com/arcadedb/GlobalConfiguration.java @@ -285,6 +285,10 @@ public Object call(final Object value) { "Password for root user to use at first startup of the server. Set this to avoid asking the password to the user", String.class, null), + SERVER_ROOT_PASSWORD_PATH("arcadedb.server.rootPasswordPath", SCOPE.SERVER, + "Path to file with password for root user to use at first startup of the server. Set this to avoid asking the password to the user", + String.class, null), + SERVER_MODE("arcadedb.server.mode", SCOPE.SERVER, "Server mode between 'development', 'test' and 'production'", String.class, "development", Set.of((Object[]) new String[] { "development", "test", "production" })), diff --git a/server/src/main/java/com/arcadedb/server/security/ServerSecurity.java b/server/src/main/java/com/arcadedb/server/security/ServerSecurity.java index d88c30483b1..6137525d523 100644 --- a/server/src/main/java/com/arcadedb/server/security/ServerSecurity.java +++ b/server/src/main/java/com/arcadedb/server/security/ServerSecurity.java @@ -39,6 +39,7 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import java.io.*; +import java.nio.file.*; import java.nio.charset.*; import java.security.*; import java.security.spec.*; @@ -332,6 +333,19 @@ protected void askForRootPassword() throws IOException { server.getConfiguration().getValueAsString(GlobalConfiguration.SERVER_ROOT_PASSWORD) : GlobalConfiguration.SERVER_ROOT_PASSWORD.getValueAsString(); + if (rootPassword == null) { + final String rootPasswordPath = server != null ? + server.getConfiguration().getValueAsString(GlobalConfiguration.SERVER_ROOT_PASSWORD_PATH) : + GlobalConfiguration.SERVER_ROOT_PASSWORD_PATH.getValueAsString(); + + if (rootPasswordPath != null) { + if (Files.isReadable(Paths.get(rootPasswordPath))) + rootPassword = Files.readString(Paths.get(rootPasswordPath)); + else + throw new ServerSecurityException("Error reading password file at path '" + rootPasswordPath + "'"); + } + } + if (rootPassword == null) { if (server != null ? server.getConfiguration().getValueAsBoolean(GlobalConfiguration.HA_K8S) :