Skip to content
Closed
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
6 changes: 6 additions & 0 deletions api/src/com/cloud/user/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
// under the License.
package com.cloud.user;

import java.util.List;
import java.util.Map;

import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.user.GetUserKeysCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;

import com.cloud.domain.Domain;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;


public interface AccountService {

/**
Expand Down Expand Up @@ -124,6 +127,8 @@ User createUser(String userName, String password, String firstName, String lastN

void checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException;

void checkAccess(User user, ControlledEntity entity);

void checkAccess(Account account, AccessType accessType, boolean sameOwner, String apiName,
ControlledEntity... entities) throws PermissionDeniedException;

Expand All @@ -136,4 +141,5 @@ void checkAccess(Account account, AccessType accessType, boolean sameOwner, Stri
*/
UserAccount getUserAccountById(Long userId);

public List<String> getKeys(GetUserKeysCmd cmd);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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.

package org.apache.cloudstack.api.command.admin.user;


import com.cloud.user.Account;
import com.cloud.user.User;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.RegisterResponse;
import org.apache.cloudstack.api.response.UserResponse;

import java.util.List;
import java.util.logging.Logger;

@APICommand(name = "getUserKeys",
description = "This command allows the user to query the seceret and API keys for the account",
responseObject = RegisterResponse.class,
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = true)

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.

Please add the version annotation to indicate that this command was added for 4.9.


public class GetUserKeysCmd extends BaseCmd{

@Parameter(name= ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, required = true, description = "ID of the user whose keys are required")
private Long id;

public static final Logger s_logger = Logger.getLogger(RegisterCmd.class.getName());
public static final String s_name = "getuserkeysresponse";

public Long getID(){
return id;
}

public String getCommandName(){
return s_name;
}

public long getEntityOwnerId(){
User user = _entityMgr.findById(User.class, getID());
if(user != null){
return user.getAccountId();
}
else return Account.ACCOUNT_ID_SYSTEM;
}
public void execute(){
List<String> keys = _accountService.getKeys(this);
RegisterResponse response = new RegisterResponse();
if(keys != null){
response.setApiKey(keys.get(0));
response.setSecretKey(keys.get(1));
}

response.setObjectName("listkeys");
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class UserResponse extends BaseResponse {
@Param(description = "the api key of the user", isSensitive = true)
private String apiKey;

@Deprecated
@SerializedName("secretkey")
@Param(description = "the secret key of the user", isSensitive = true)
private String secretKey;
Expand Down Expand Up @@ -209,7 +210,6 @@ public void setApiKey(String apiKey) {
public String getSecretKey() {
return secretKey;
}

public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
Expand Down
1 change: 1 addition & 0 deletions client/tomcatconf/commands.properties.in
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ updateVolume=1
#### the userId...every request to the developer API should be
#### checked against the key
registerUserKeys=15
getUserKeys=15

### async-query command
queryAsyncJobResult=15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
"This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource. This is not to be enabled on production systems.",
true);


@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import org.apache.cloudstack.api.command.admin.user.GetUserKeysCmd;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.ControlledEntity;
Expand Down Expand Up @@ -432,4 +434,24 @@ public void checkAccess(Account account, ServiceOffering so) throws PermissionDe
public void checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException {
// TODO Auto-generated method stub
}

@Override
public List<String> getKeys(GetUserKeysCmd cmd){
return null;
}

@Override
public void checkAccess(User user, ControlledEntity entity)
throws PermissionDeniedException {

}
@Override
public String getConfigComponentName() {
return null;
}

@Override
public ConfigKey<?>[] getConfigKeys() {
return null;
}
}
8 changes: 8 additions & 0 deletions server/src/com/cloud/api/ApiDBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import com.cloud.user.AccountManager;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
Expand Down Expand Up @@ -427,6 +428,7 @@ public class ApiDBUtils {
static ResourceMetaDataService s_resourceDetailsService;
static HostGpuGroupsDao s_hostGpuGroupsDao;
static VGPUTypesDao s_vgpuTypesDao;
static AccountManager s_accountManager;

@Inject
private ManagementServer ms;
Expand Down Expand Up @@ -556,6 +558,8 @@ public class ApiDBUtils {
@Inject
private VpcManager vpcMgr;
@Inject
private AccountManager accountManager;
@Inject
private TaggedResourceService taggedResourceService;
@Inject
private UserVmDetailsDao userVmDetailsDao;
Expand Down Expand Up @@ -772,6 +776,7 @@ void init() {
s_resourceDetailsService = resourceDetailsService;
s_hostGpuGroupsDao = hostGpuGroupsDao;
s_vgpuTypesDao = vgpuTypesDao;
s_accountManager = accountManager;
}

// ///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1695,6 +1700,9 @@ public static UserResponse newUserResponse(UserAccountJoinVO usr) {

public static UserResponse newUserResponse(UserAccountJoinVO usr, Long domainId) {
UserResponse response = s_userAccountJoinDao.newUserResponse(usr);
if(!s_accountManager.UseSecretKeyInResponse.value()){
response.setSecretKey(" ");
}
if (domainId != null && usr.getDomainId() != domainId)
response.setIsCallerChildDomain(true);
else
Expand Down
2 changes: 2 additions & 0 deletions server/src/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
import org.apache.cloudstack.api.command.admin.user.DisableUserCmd;
import org.apache.cloudstack.api.command.admin.user.EnableUserCmd;
import org.apache.cloudstack.api.command.admin.user.GetUserCmd;
import org.apache.cloudstack.api.command.admin.user.GetUserKeysCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.admin.user.LockUserCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
Expand Down Expand Up @@ -3021,6 +3022,7 @@ public List<Class<?>> getCommands() {
cmdList.add(UpdateLBHealthCheckPolicyCmd.class);
cmdList.add(GetUploadParamsForTemplateCmd.class);
cmdList.add(GetUploadParamsForVolumeCmd.class);
cmdList.add(GetUserKeysCmd.class);
return cmdList;
}

Expand Down
11 changes: 10 additions & 1 deletion server/src/com/cloud/user/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
import com.cloud.utils.Ternary;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;

/**
* AccountManager includes logic that deals with accounts, domains, and users.
*
*/
public interface AccountManager extends AccountService {
public interface AccountManager extends AccountService, Configurable{
/**
* Disables an account by accountId
* @param accountId
Expand Down Expand Up @@ -198,4 +200,11 @@ void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEntity> s
public static final String MESSAGE_ADD_ACCOUNT_EVENT = "Message.AddAccount.Event";

public static final String MESSAGE_REMOVE_ACCOUNT_EVENT = "Message.RemoveAccount.Event";
public static final ConfigKey<Boolean> UseSecretKeyInResponse = new ConfigKey<Boolean>(
"Advanced",
Boolean.class,
"use.secret.key.in.response",
"true",

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.

default should be false! this is a security issue.

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.

Agree with @DaanHoogland, it is easy enough to enable again should people need it. Is this setting available to the user or does it need to be added to the database as well?

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.

@remibergsma It is a part of global config and the admin can change it.

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.

@kansal I agree with @DaanHoogland and @remibergsma -- it's about reasonable and secure defaults. We should not configure a management server insecurely by default.

"This parameter allows the users to enable or disable secret as a part of response for various APIs. By default it is allowed and value is set to true.",
true);
}
Loading