Skip to content
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

Disable API Key Access for users, accounts and domains #9741

Merged
merged 54 commits into from
Dec 3, 2024

Conversation

abh1sar
Copy link
Collaborator

@abh1sar abh1sar commented Sep 27, 2024

Description

This PR implements the feature which give Root Admin the ability to Disable Api-key/Secret-key access at different granularities (User/Account/Domain/Global)
Spec : https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=323488155
Doc PR : apache/cloudstack-documentation#446

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Edit form :
Screenshot 2024-10-16 at 5 09 52 PM

User view :
Screenshot 2024-10-17 at 8 11 29 AM

Event logging :
Screenshot 2024-10-16 at 5 37 09 PM

Screenshot 2024-10-16 at 5 56 47 AM

How Has This Been Tested?

  1. Local value should always take precedence unless it is set to Inherit.
    Tested the following matrix. Result denotes if Api key access was allowed for the User or not.
User Account Domain Global Result
Inherit Inherit Inherit Enabled Enabled
Inherit Inherit Inherit Disabled Disabled
Inherit Inherit Enabled Disabled Enabled
Inherit Disabled Enabled Enabled Disabled
Disabled Enabled Enabled Enabled Disabled
Enabled Inherit Inherit Disabled Enabled
  1. Tested that apikeyaccess parameter in updateUser, updateAccount, listUsers and listAccounts is not shown to anyone else apart from the Root Admin.

  2. Tested that api.key.access configuration is not editable by the domain admin.

How did you try to break this feature and the system with this change?

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 35.65217% with 148 lines in your changes missing coverage. Please review.

Project coverage is 16.01%. Comparing base (58138f2) to head (564d2b4).
Report is 1 commits behind head on 4.20.

Files with missing lines Patch % Lines
...ava/com/cloud/upgrade/dao/Upgrade42000to42010.java 10.52% 34 Missing ⚠️
...c/main/java/com/cloud/user/dao/AccountDaoImpl.java 0.00% 14 Missing ⚠️
.../cloud/configuration/ConfigurationManagerImpl.java 0.00% 13 Missing ⚠️
...ain/java/com/cloud/api/query/QueryManagerImpl.java 57.14% 7 Missing and 5 partials ⚠️
...n/java/org/apache/cloudstack/api/ApiConstants.java 47.05% 9 Missing ⚠️
...c/main/java/com/cloud/user/AccountManagerImpl.java 80.00% 7 Missing and 1 partial ⚠️
...ne/schema/src/main/java/com/cloud/user/UserVO.java 0.00% 6 Missing ⚠️
...ck/api/command/admin/account/UpdateAccountCmd.java 0.00% 5 Missing ⚠️
...loudstack/api/command/admin/user/ListUsersCmd.java 0.00% 5 Missing ⚠️
...schema/src/main/java/com/cloud/user/AccountVO.java 16.66% 5 Missing ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20    #9741      +/-   ##
============================================
+ Coverage     15.98%   16.01%   +0.03%     
- Complexity    12753    12776      +23     
============================================
  Files          5631     5633       +2     
  Lines        492702   492958     +256     
  Branches      59737    59769      +32     
============================================
+ Hits          78755    78962     +207     
- Misses       405219   405230      +11     
- Partials       8728     8766      +38     
Flag Coverage Δ
uitests 4.03% <ø> (-0.01%) ⬇️
unittests 16.85% <35.65%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -955,6 +955,11 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
category = config.getCategory();
}

if ("System".equals(category) && !_accountMgr.isRootAdmin(caller.getId())) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe define a constant "System" somewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -70,6 +71,9 @@ public class UpdateAccountCmd extends BaseCmd {
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "Details for the account used to store specific parameters")
private Map details;

@Parameter(name = ApiConstants.API_KEY_ACCESS, type = CommandType.STRING, description = "Determines if Api key access for this user is enabled, disabled or inherits the value from its parent, the domain level setting \"api.key.access\"", since = "4.20.1.0", authorized = {RoleType.Admin})
Copy link
Member

Choose a reason for hiding this comment

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

is it targetted 4.20.1 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, is that ok?

@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 30, 2024

@blueorangutan package

@blueorangutan
Copy link

@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 11245

@abh1sar
Copy link
Collaborator Author

abh1sar commented Oct 1, 2024

@blueorangutan test

@blueorangutan
Copy link

@abh1sar a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

ADD COLUMN `api_key_access` boolean;

ALTER TABLE `cloud`.`account`
ADD COLUMN `api_key_access` boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

use IDEMPOTENT_ADD_COLUMN call to add columns

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -425,3 +425,9 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervi

CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" ');
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" ');

Copy link
Contributor

Choose a reason for hiding this comment

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

targeted for 4.20.1? add these changes in engine/schema/src/main/resources/META-INF/db/schema-42000to42010.sql

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will create the new schema file once 4.20.0 is cut. Keeping this PR in draft until then

@abh1sar
Copy link
Collaborator Author

abh1sar commented Dec 1, 2024

@blueorangutan package

@blueorangutan
Copy link

@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 11671

@abh1sar
Copy link
Collaborator Author

abh1sar commented Dec 1, 2024

@blueorangutan test matrix

@blueorangutan
Copy link

@abh1sar a [SL] Trillian-Jenkins matrix job (EL8 mgmt + EL8 KVM, Ubuntu22 mgmt + Ubuntu22 KVM, EL8 mgmt + VMware 7.0u3, EL9 mgmt + XCP-ng 8.2 ) has been kicked to run smoke tests

Copy link

github-actions bot commented Dec 2, 2024

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@abh1sar abh1sar marked this pull request as ready for review December 2, 2024 09:07
@abh1sar
Copy link
Collaborator Author

abh1sar commented Dec 2, 2024

Added Database upgrade path for 42000to42010.

@abh1sar abh1sar marked this pull request as draft December 2, 2024 10:39
@blueorangutan
Copy link

[SF] Trillian test result (tid-11828)
Environment: kvm-ubuntu22 (x2), Advanced Networking with Mgmt server u22
Total time taken: 54241 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr9741-t11828-kvm-ubuntu22.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@blueorangutan
Copy link

[SF] Trillian test result (tid-11827)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 54290 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr9741-t11827-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@rohityadavcloud rohityadavcloud marked this pull request as ready for review December 3, 2024 06:30
@rohityadavcloud rohityadavcloud merged commit d17de83 into apache:4.20 Dec 3, 2024
26 checks passed
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Dec 12, 2024
* cli changes to update user/account, list by apikeyaccess, domain level setting

* UI changes for updating user/account and searchfilter in listview

* make the api parameters and setting accessible only to root admin

* revert changes to ui/package-lock.json

* minor changes to description strings

* UT for ApiServer and AccountManagerImpl classes

* fix pre-commit failure

* Added a constant for the string System

* UT for searchForUsers and searchForAccounts

* Fix marvin test error

* Update schema to use idempotent add column

* Fix `updateTemplatePermission` when the UI is set to a language other than English (apache#9766)

* Fix updateTemplatePermission UI in non-english language

* Improve fix

---------

Co-authored-by: Lucas Martins <lucas.martins@scclouds.com.br>

* Added user name uuid to logging

* Add events when api key access is changed via api or config setting

* fix the userid for api key access update event

* Fix ut failure after event logging

* Convert drop down to radio-button in edit user and account

* Add ApiKeyAccess status in User InfoCard for Users if Api key is generated

* Return apiKeyAccess in user and account response only for Root Admin

* fixed noredist build failure

* Show apikeyaccess on the left panel in the user view for root admins as well

* don't show divider if apiKeyAccess is not shown to user

* Fix events generated to set Username, Account and Domain of the caller correctly

* cli changes to update user/account, list by apikeyaccess, domain level setting

* UI changes for updating user/account and searchfilter in listview

* make the api parameters and setting accessible only to root admin

* revert changes to ui/package-lock.json

* minor changes to description strings

* UT for ApiServer and AccountManagerImpl classes

* fix pre-commit failure

* Added a constant for the string System

* UT for searchForUsers and searchForAccounts

* Fix marvin test error

* Update schema to use idempotent add column

* Added user name uuid to logging

* Add events when api key access is changed via api or config setting

* fix the userid for api key access update event

* Fix ut failure after event logging

* Convert drop down to radio-button in edit user and account

* Add ApiKeyAccess status in User InfoCard for Users if Api key is generated

* Return apiKeyAccess in user and account response only for Root Admin

* fixed noredist build failure

* Show apikeyaccess on the left panel in the user view for root admins as well

* don't show divider if apiKeyAccess is not shown to user

* Fix events generated to set Username, Account and Domain of the caller correctly

* Added DB upgrade path from 42000 to 42010

---------

Co-authored-by: Daan Hoogland <daan@onecht.net>
Co-authored-by: Lucas Martins <56271185+lucas-a-martins@users.noreply.github.com>
Co-authored-by: Lucas Martins <lucas.martins@scclouds.com.br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants