Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/en/docs/admin-manual/config/fe-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ Is it a configuration item unique to the Master FE node: true

Whether to enable the multi-tags function of a single BE

#### `initial_root_password`

Set root user initial 2-staged SHA-1 encrypted password, default as '', means no root password. Subsequent `set password` operations for root user will overwrite the initial root password.

Example: If you want to configure a plaintext password `root@123`. You can execute Doris SQL `select password('root@123')` to generate encrypted password `*A00C34073A26B40AB4307650BFB9309D6BFA6999`.

Default: empty string

Is it possible to dynamically configure: false

Is it a configuration item unique to the Master FE node: true

### Service

#### `query_port`
Expand Down
12 changes: 12 additions & 0 deletions docs/zh-CN/docs/admin-manual/config/fe-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ heartbeat_mgr 中处理心跳事件的线程数。

是否开启单BE的多标签功能

#### `initial_root_password`

设置 root 用户初始化2阶段 SHA-1 加密密码,默认为'',即不设置 root 密码。后续 root 用户的 `set password` 操作会将 root 初始化密码覆盖。

示例:如要配置密码的明文是 `root@123`,可在Doris执行SQL `select password('root@123')` 获取加密密码 `*A00C34073A26B40AB4307650BFB9309D6BFA6999`。

默认值:空字符串

是否可以动态配置:false

是否为 Master FE 节点独有的配置项:true

### 服务

#### `query_port`
Expand Down
12 changes: 12 additions & 0 deletions fe/fe-common/src/main/java/org/apache/doris/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,18 @@ public class Config extends ConfigBase {
})
public static double diagnose_balance_max_tablet_num_ratio = 1.1;

@ConfField(masterOnly = true, description = {
"设置 root 用户初始化2阶段 SHA-1 加密密码,默认为'',即不设置 root 密码。"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以多加一句,说明下如何获取 SHA-1 加密后的密码值

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已加

+ "后续 root 用户的 `set password` 操作会将 root 初始化密码覆盖。"
+ "示例:如要配置密码的明文是 `root@123`,可在Doris执行SQL `select password('root@123')` "
+ "获取加密密码 `*A00C34073A26B40AB4307650BFB9309D6BFA6999`",
"Set root user initial 2-staged SHA-1 encrypted password, default as '', means no root password. "
+ "Subsequent `set password` operations for root user will overwrite the initial root password. "
+ "Example: If you want to configure a plaintext password `root@123`."
+ "You can execute Doris SQL `select password('root@123')` to generate encrypted "
+ "password `*A00C34073A26B40AB4307650BFB9309D6BFA6999`"})
public static String initial_root_password = "";

@ConfField(description = {"nereids trace文件的存放路径。",
"The path of the nereids trace file."})
public static String nereids_trace_log_dir = System.getenv("DORIS_HOME") + "/log/nereids_trace";
Expand Down
2 changes: 2 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,8 @@ private void transferToMaster() {
editLog.logAddFirstFrontend(self);

initLowerCaseTableNames();
// Set initial root password if master FE first time launch.
auth.setInitialRootPassword(Config.initial_root_password);
} else {
if (journalVersion <= FeMetaVersion.VERSION_114) {
// if journal version is less than 114, which means it is upgraded from version before 2.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.doris.ldap.LdapManager;
import org.apache.doris.ldap.LdapUserInfo;
import org.apache.doris.load.DppConfig;
import org.apache.doris.mysql.MysqlPassword;
import org.apache.doris.persist.AlterUserOperationLog;
import org.apache.doris.persist.LdapInfo;
import org.apache.doris.persist.PrivInfo;
Expand All @@ -70,6 +71,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -1349,6 +1351,29 @@ private void initUser() {
}
}

public void setInitialRootPassword(String initialRootPassword) {
// Skip set root password if `initial_root_password` set to empty string
if (StringUtils.isEmpty(initialRootPassword)) {
return;
}
byte[] scramble;
try {
scramble = MysqlPassword.checkPassword(initialRootPassword);
} catch (AnalysisException e) {
// Skip set root password if `initial_root_password` is not valid 2-staged SHA-1 encrypted
LOG.warn("initial_root_password [{}] is not valid 2-staged SHA-1 encrypted, ignore it",
initialRootPassword);
return;
}
UserIdentity rootUser = new UserIdentity(ROOT_USER, "%");
rootUser.setIsAnalyzed();
try {
setPasswordInternal(rootUser, scramble, null, false, false, false);
} catch (DdlException e) {
LOG.warn("Fail to set initial root password, ignore it", e);
}
}

public List<List<String>> getRoleInfo() {
readLock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.doris.common.ExceptionChecker;
import org.apache.doris.common.UserException;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.mysql.MysqlPassword;
import org.apache.doris.persist.EditLog;
import org.apache.doris.persist.PrivInfo;
import org.apache.doris.qe.ConnectContext;
Expand Down Expand Up @@ -2335,4 +2336,21 @@ public void testShowViewPriv() throws UserException {
Lists.newArrayList(new AccessPrivilegeWithCols(AccessPrivilege.DROP_PRIV)));
revoke(revokeStmt);
}

@Test
public void testSetInitialRootPassword() {
// Skip set root password if `initial_root_password` set to empty string
auth.setInitialRootPassword("");
Assert.assertTrue(
auth.checkPlainPasswordForTest("root", "192.168.0.1", null, null));
// Skip set root password if `initial_root_password` is not valid 2-staged SHA-1 encrypted
auth.setInitialRootPassword("invalidRootPassword");
Assert.assertTrue(
auth.checkPlainPasswordForTest("root", "192.168.0.1", null, null));
// Set initial root password
byte[] scrambled = MysqlPassword.makeScrambledPassword("validRootPassword");
auth.setInitialRootPassword(new String(scrambled));
Assert.assertTrue(
auth.checkPlainPasswordForTest("root", "192.168.0.1", "validRootPassword", null));
}
}