Skip to content

Bypass empty string check for username and password#5337

Merged
yadvr merged 5 commits into
apache:mainfrom
shapeblue:bypass-empty-string-check
Aug 24, 2021
Merged

Bypass empty string check for username and password#5337
yadvr merged 5 commits into
apache:mainfrom
shapeblue:bypass-empty-string-check

Conversation

@Pearl1594
Copy link
Copy Markdown
Contributor

@Pearl1594 Pearl1594 commented Aug 19, 2021

Description

Fixes: #5332
This PR attempts to bypass the empty string check added in ParamProcessorValidator - for username and password, so that in case of vmware, it doesn't fail during addition of hosts (where username and password is obtained from cluster details)

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)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Added a host to a VMware cluster via UI without any issues.

@yadvr yadvr added this to the 4.16.0.0 milestone Aug 19, 2021
@yadvr
Copy link
Copy Markdown
Member

yadvr commented Aug 19, 2021

I think we had fixed the issue in Trillian to work-around that @Pearl1594 cc @nvazquez

Copy link
Copy Markdown
Member

@harikrishna-patnala harikrishna-patnala left a comment

Choose a reason for hiding this comment

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

LGTM. the old UI behaves the same as this PR.

@yadvr
Copy link
Copy Markdown
Member

yadvr commented Aug 19, 2021

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian. SL-JID 930

@Pearl1594
Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

private static final Logger s_logger = Logger.getLogger(ParamProcessWorker.class.getName());
public final DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
public final DateFormat newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final List<String> avoidList = new ArrayList<>(Arrays.asList("username", "password"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about using ApiConstants.USERNAME and PASSWORD ?

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.

Done - Thanks @ravening

@blueorangutan
Copy link
Copy Markdown

Trillian test result (tid-1718)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 34076 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5337-t1718-kvm-centos7.zip
Smoke tests completed. 89 look OK, 0 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File

@Pearl1594 Pearl1594 closed this Aug 20, 2021
@Pearl1594 Pearl1594 reopened this Aug 20, 2021
@weizhouapache
Copy link
Copy Markdown
Member

@Pearl1594
this has small code change, but might have big impact.
can we skip the username/password check only in some apis ?

@Pearl1594
Copy link
Copy Markdown
Contributor Author

Pearl1594 commented Aug 20, 2021

We could do that @weizhouapache - However, my understanding is, if a null / empty uname / password is provided as part of any API args - the corresponding APIs logic would ideally validate the correctness of the input or the authorization would fails if it's empty - which is the assumption that we had even before this check was added by - #5136.

@weizhouapache
Copy link
Copy Markdown
Member

We could do that @weizhouapache - However, my understanding is, if a null / empty uname / password is provided as part of any API args - the corresponding APIs logic would ideally validate the correctness of the input or the authorization would fails if it's empty - which is the assumption that we had even before this check was added by - #5136.

@Pearl1594
If you can make sure that all required username/password have been verified, this pr is good to me.

Otherwise, I suggest you change the fields from required to optional in the specific API (add host ?) and check if they are null in codes.

@weizhouapache
Copy link
Copy Markdown
Member

We could do that @weizhouapache - However, my understanding is, if a null / empty uname / password is provided as part of any API args - the corresponding APIs logic would ideally validate the correctness of the input or the authorization would fails if it's empty - which is the assumption that we had even before this check was added by - #5136.

#5136 is good I think, it fixes some potential missing validations, and causes few regressions (for example the issue you mentioned in PR description). in my opinion, it's better to fix the regression (eg, optional username/password in specific api), instead of rolling back to old behavior (skip validation on username/password in all apis).

@Pearl1594
Copy link
Copy Markdown
Contributor Author

We could do that @weizhouapache - However, my understanding is, if a null / empty uname / password is provided as part of any API args - the corresponding APIs logic would ideally validate the correctness of the input or the authorization would fails if it's empty - which is the assumption that we had even before this check was added by - #5136.

@Pearl1594
If you can make sure that all required username/password have been verified, this pr is good to me.

Otherwise, I suggest you change the fields from required to optional in the specific API (add host ?) and check if they are null in codes.

Will do @weizhouapache - Thanks.

@weizhouapache
Copy link
Copy Markdown
Member

@Pearl1594
should we check if username/password are null when hypervisor is not vmware ?

Comment thread api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java Outdated
Copy link
Copy Markdown
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

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

code lgtm
thanks for fixing @Pearl1594

@weizhouapache
Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@weizhouapache a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@Pearl1594
Copy link
Copy Markdown
Contributor Author

@weizhouapache I believe this issue is only seen on main branch

Comment thread server/src/main/java/com/cloud/resource/ResourceManagerImpl.java Outdated
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

@yadvr
Copy link
Copy Markdown
Member

yadvr commented Aug 20, 2021

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@weizhouapache
Copy link
Copy Markdown
Member

@weizhouapache I believe this issue is only seen on main branch

@Pearl1594 ok, got it. thanks for confirm

@blueorangutan
Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ debian. SL-JID 955

@blueorangutan
Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 958

@Pearl1594
Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

@blueorangutan
Copy link
Copy Markdown

Trillian test result (tid-1737)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 33721 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5337-t1737-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_snapshots.py
Smoke tests completed. 88 look OK, 1 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_02_list_snapshots_with_removed_data_store Error 51.50 test_snapshots.py

@DaanHoogland
Copy link
Copy Markdown
Contributor

must be unlucky on that snapshot test
@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

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

@Pearl1594 sorry but I don't understand point of this change. We are removing required tag for API params but making them required again in API handling.

Maybe the intention is to check username, password is not empty when they are passed but I don't think the check correspond to that. Sorry if I'm missing something.

@weizhouapache
Copy link
Copy Markdown
Member

@Pearl1594 sorry but I don't understand point of this change. We are removing required tag for API params but making them required again in API handling.

Maybe the intention is to check username, password is not empty when they are passed but I don't think the check correspond to that. Sorry if I'm missing something.

username and password can be empty when add a vmware host.

@weizhouapache
Copy link
Copy Markdown
Member

@Pearl1594 is it possible that username and password are empty in cluster details ?

@blueorangutan
Copy link
Copy Markdown

Trillian test result (tid-1741)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 37249 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5337-t1741-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_snapshots.py
Intermittent failure detected: /marvin/tests/smoke/test_ssvm.py
Intermittent failure detected: /marvin/tests/smoke/test_hostha_kvm.py
Smoke tests completed. 87 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_02_list_snapshots_with_removed_data_store Error 52.38 test_snapshots.py
test_disable_oobm_ha_state_ineligible Error 1511.24 test_hostha_kvm.py

@Pearl1594
Copy link
Copy Markdown
Contributor Author

@Pearl1594 is it possible that username and password are empty in cluster details ?

@weizhouapache even if that's the case - there's a check in place to handle it
https://github.com/apache/cloudstack/blob/main/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java#L701-L706

@weizhouapache
Copy link
Copy Markdown
Member

@Pearl1594 is it possible that username and password are empty in cluster details ?

@weizhouapache even if that's the case - there's a check in place to handle it
https://github.com/apache/cloudstack/blob/main/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java#L701-L706

@Pearl1594 ok, that's good.

throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
}
if (!HypervisorType.VMware.toString().equalsIgnoreCase(hypervisorType) &&
(Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password))) {
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.

We could import org.apache.commons.lang3.StringUtils here and use StringUtils.isAnyEmpty(username, password).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @GutoVeronezi.

Nowadays we already have some discussions about adopting org.apache.commons.lang3.StringUtils vs com.cloud.utils.StringUtils "facade" (@DaanHoogland 🙂); with the google.common.base.Strings adds a third variable to this "equation".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI] Unable to add ESX/ESXi host from UI, Username / Password inputs are missing on Add Host dialog.