Repository navigation
CLOUDSTACK-9099: SecretKey is returned from the APIs - Fixed #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
|
||
| 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 |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default should be false! this is a security issue.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
There was a problem hiding this comment.
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.