Skip to content

Commit cfd2091

Browse files
author
Alena Prokharchyk
committed
Fixed CLOUDSTACK-287
1) Always fail to authenticate system user. 2) DB - always create system user with RANDOM not null password 3) Don't allow modifying (setting api/secretKeys, etc) system user via API Conflicts: server/src/com/cloud/user/AccountManagerImpl.java setup/db/db/schema-305to306.sql
1 parent 098a78a commit cfd2091

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎server/src/com/cloud/server/ConfigurationServerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ protected void saveUser() {
333333
} catch (SQLException ex) {
334334
}
335335
// insert system user
336-
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created) VALUES (1, 'system', '', 1, 'system', 'cloud', now())";
336+
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created)" +
337+
" VALUES (1, 'system', RAND(), 1, 'system', 'cloud', now())";
337338
txn = Transaction.currentTxn();
338339
try {
339340
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);

‎server/src/com/cloud/test/DatabaseConfig.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,8 @@ protected void saveUser() {
10901090
}
10911091

10921092
// insert system user
1093-
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created) VALUES (1, 'system', '', 1, 'system', 'cloud', now())";
1093+
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created)" +
1094+
" VALUES (1, 'system', RAND(), 1, 'system', 'cloud', now())";
10941095
txn = Transaction.currentTxn();
10951096
try {
10961097
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,10 @@
7474
import com.cloud.network.NetworkManager;
7575
import com.cloud.network.NetworkVO;
7676
import com.cloud.network.RemoteAccessVpnVO;
77-
import com.cloud.network.Site2SiteCustomerGatewayVO;
78-
import com.cloud.network.Site2SiteVpnConnectionVO;
7977
import com.cloud.network.VpnUserVO;
8078
import com.cloud.network.dao.IPAddressDao;
8179
import com.cloud.network.dao.NetworkDao;
8280
import com.cloud.network.dao.RemoteAccessVpnDao;
83-
import com.cloud.network.dao.Site2SiteCustomerGatewayDao;
84-
import com.cloud.network.dao.Site2SiteVpnConnectionDao;
85-
import com.cloud.network.dao.Site2SiteVpnGatewayDao;
8681
import com.cloud.network.dao.VpnUserDao;
8782
import com.cloud.network.security.SecurityGroupManager;
8883
import com.cloud.network.security.dao.SecurityGroupDao;
@@ -881,6 +876,7 @@ public UserAccount updateUser(UpdateUserCmd cmd) {
881876
throw new InvalidParameterValueException("unable to find user by id");
882877
}
883878

879+
//don't allow updating system account
884880
if (account != null && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
885881
throw new PermissionDeniedException("user id : " + id + " is system account, update is not allowed");
886882
}
@@ -1713,7 +1709,7 @@ public UserAccount authenticateUser(String username, String password, Long domai
17131709
String singleSignOnTolerance = _configDao.getValue("security.singlesignon.tolerance.millis");
17141710
if (singleSignOnTolerance == null) {
17151711
// the SSO tolerance is gone (how much time before/after system time we'll allow the login request to be
1716-
// valid),
1712+
// valid),
17171713
// don't authenticate
17181714
return null;
17191715
}
@@ -1798,6 +1794,12 @@ public UserAccount authenticateUser(String username, String password, Long domai
17981794
}
17991795

18001796
if (user != null) {
1797+
//don't allow to authenticate system user
1798+
if (user.getId() == User.UID_SYSTEM) {
1799+
s_logger.error("Failed to authenticate user: " + username + " in domain " + domainId);
1800+
return null;
1801+
}
1802+
18011803
if (s_logger.isDebugEnabled()) {
18021804
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
18031805
}
@@ -1895,8 +1897,14 @@ public Pair<User, Account> findUserByApiKey(String apiKey) {
18951897
public String[] createApiKeyAndSecretKey(RegisterCmd cmd) {
18961898
Long userId = cmd.getId();
18971899

1898-
if (getUserIncludingRemoved(userId) == null) {
1899-
throw new InvalidParameterValueException("unable to find user for id : " + userId);
1900+
User user = getUserIncludingRemoved(userId);
1901+
if (user == null) {
1902+
throw new InvalidParameterValueException("unable to find user by id");
1903+
}
1904+
1905+
//don't allow updating system user
1906+
if (user.getId() == User.UID_SYSTEM) {
1907+
throw new PermissionDeniedException("user id : " + user.getId() + " is system account, update is not allowed");
19001908
}
19011909

19021910
// generate both an api key and a secret key, update the user table with the keys, return the keys to the user

0 commit comments

Comments
 (0)