Skip to content

Limit listRoles API visibility#8639

Merged
DaanHoogland merged 2 commits intoapache:mainfrom
scclouds:fix-role-visibility
May 7, 2024
Merged

Limit listRoles API visibility#8639
DaanHoogland merged 2 commits intoapache:mainfrom
scclouds:fix-role-visibility

Conversation

@hsato03
Copy link
Copy Markdown
Member

@hsato03 hsato03 commented Feb 9, 2024

Description

When calling the listRoles API, users can see roles with more permissions than theirs.

Therefore, the behavior of the listRoles API was changed so that users can only see roles that their role has permission to access (roles with same and less permissions).

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

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  1. I created a custom role based on User role and added the listRoles API to it.
  2. I created an account using the role from step 1 and logged into it.
  3. I called the listRoles API via CloudMonkey and verfied that the roles with more permissions than mine were not listed, such as default admin roles.

Copy link
Copy Markdown
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm and unit-test included, but i think some monkey testing is still in order

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (49cecae) 30.37% compared to head (3dd46d3) 30.78%.
Report is 30 commits behind head on main.

Files Patch % Lines
...ava/org/apache/cloudstack/acl/RoleManagerImpl.java 89.47% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8639      +/-   ##
============================================
+ Coverage     30.37%   30.78%   +0.41%     
- Complexity    32633    33113     +480     
============================================
  Files          5352     5353       +1     
  Lines        374419   374635     +216     
  Branches      54609    54645      +36     
============================================
+ Hits         113719   115348    +1629     
+ Misses       245523   243994    -1529     
- Partials      15177    15293     +116     
Flag Coverage Δ
simulator-marvin-tests 24.66% <69.23%> (+0.51%) ⬆️
uitests 4.38% <ø> (-0.01%) ⬇️
unit-tests 16.44% <64.10%> (+0.02%) ⬆️

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.

Comment on lines +425 to +427
* @param rolePermissions the permissions of the caller role.
* @param roleToAccess the role that the caller role wants to access.
* @return True if the role can be accessed with the given permissions; false otherwise.
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.

@hsato03, what do you think about naming these parameters as sourceRolePermissions and targetRole? IMO, it seems more intuitive. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I agree.

@DaanHoogland DaanHoogland added this to the 20.0.0 milestone Feb 16, 2024
Copy link
Copy Markdown
Contributor

@GutoVeronezi GutoVeronezi left a comment

Choose a reason for hiding this comment

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

CLGTM

@JoaoJandre
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@JoaoJandre 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
Copy Markdown

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

@JoaoJandre
Copy link
Copy Markdown
Contributor

@DaanHoogland @sureshanaparti @rohityadavcloud @shwstppr could we run the CI here?

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

@blueorangutan
Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-9857)

@BryanMLima
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@BryanMLima 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
Copy Markdown

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

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

@blueorangutan
Copy link
Copy Markdown

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

Test Result Time (s) Test File
test_01_events_resource Error 434.56 test_events_resource.py

Copy link
Copy Markdown
Member

@bernardodemarco bernardodemarco left a comment

Choose a reason for hiding this comment

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

LGTM, I manually tested the PR in a local environment.

  1. I created a role called list-roles-test based on the User role.
  2. I added the listRoles API to the created role.
  3. I created an account called list-roles-test-account with the custom role.
  4. Through CloudMonkey, I created a profile for the account and I executed the sync command.
  5. I called the listRoles API and I got the following output:
(test-roles-api) 🐱 > listRoles
{
  "count": 2,
  "role": [
    {
      "description": "Default user role",
      "id": "8cead084-771e-11ee-8e59-5254003754dc",
      "isdefault": true,
      "ispublic": true,
      "name": "User",
      "type": "User"
    },
    {
      "id": "ca565c1b-8589-4a78-b7eb-531d5505cadd",
      "isdefault": false,
      "ispublic": true,
      "name": "list-roles-test",
      "type": "User"
    }
  ]
}
  1. As it can be noticed, default admin roles and the ones with more permission than the list-roles-test role do not appear in the API's response.

@DaanHoogland DaanHoogland merged commit 0d1bc7d into apache:main May 7, 2024
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request May 17, 2024
Co-authored-by: Henrique Sato <henrique.sato@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.

7 participants