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

Secure value censorship refactor #2424

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

awharn
Copy link
Member

@awharn awharn commented Feb 3, 2025

What It Does

Refactors LoggerUtils into a new Censor class to globally use the same list of censored options, and intelligently add options to censor on the fly. Also removes duplication (and deprecates functions) to the old utilities. Points old utilities to use the new utility when possible.

Fixes #2430

How to Test

Make configuration file modifications, adding various properties to the config's secure array.
Any property that is added to the secure array should be hidden when running any Zowe CLI command with --show-inputs-only.

Additionally, run commands with ZOWE_APP_LOG_LEVEL=info and ZOWE_IMPERATIVE_LOG_LEVEL=info environment variables, and view the logs. Any secure property should be hidden in the logs, even if passed in on the command line.

To test the #2430 fix, set ZOWE_SHOW_SECURE_ARGS to true, and run a command with --show-inputs-only. Observe secure values are not masked.

Review Checklist
I certify that I have:

Additional Comments

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.44%. Comparing base (59b1fc5) to head (348b65d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2424      +/-   ##
==========================================
+ Coverage   91.37%   91.44%   +0.07%     
==========================================
  Files         639      641       +2     
  Lines       18280    18371      +91     
  Branches     3847     3945      +98     
==========================================
+ Hits        16703    16800      +97     
+ Misses       1575     1569       -6     
  Partials        2        2              

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

Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
Signed-off-by: Andrew W. Harn <[email protected]>
@awharn awharn marked this pull request as ready for review February 6, 2025 21:47
Copy link

github-actions bot commented Feb 6, 2025

📅 Suggested merge-by date: 2/20/2025

Copy link
Contributor

@anaxceron anaxceron left a comment

Choose a reason for hiding this comment

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

Left some comments re: minor edits for changelog

packages/imperative/CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: Andrew W. Harn <[email protected]>
Copy link
Contributor

@anaxceron anaxceron left a comment

Choose a reason for hiding this comment

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

thanks for the changelog update, @awharn, everything looks good

@pjfarleyiii
Copy link

Question from a CLI user: Will this resolve the non-printing of secure user and password values in the output from zowe config list? And if yes, will a new release be posted to the npm registry so that ordinary users can get back the ability to see secure values when really needed?

@adam-wolfe
Copy link
Contributor

adam-wolfe commented Feb 13, 2025

Question from a CLI user: Will this resolve the non-printing of secure user and password values in the output from zowe config list? And if yes, will a new release be posted to the npm registry so that ordinary users can get back the ability to see secure values when really needed?

That was not the intention with this PR, which was mainly to clean up how we determine what should be considered to be a secure property.

However, it's something we should consider (for a future PR). We'll take another look at #2259.

Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this Andrew! I see there was quite a bit of refactoring done to keep our behavior consistent - its much appreciated 🙏 I had a couple comments from the code review, but wanted to post those ahead of time before continuing with manual testing.

Comment on lines +230 to +258
if (censorOpts.config) {
const secureOptions: Set<string> = new Set();

// Try to use the command and inputs to find the profiles being loaded
if (censorOpts.commandDefinition && censorOpts.commandArguments) {
const profiles = [];
for (const prof of censorOpts.commandDefinition.profile?.required || []) {
profiles.push(prof);
}
for (const prof of censorOpts.commandDefinition.profile?.optional || []) {
profiles.push(prof);
}

for (const prof of profiles) {
// If the profile exists, append all of the secure props to the censored list
let profName = censorOpts.commandArguments?.[`${prof}-profile`];
if (!profName) { profName = this.mConfig.mProperties.defaults[`${prof}`]; }
if (profName && censorOpts.config.api.profiles.get(profName)) {
censorOpts.config.api.secure.securePropsForProfile(profName).forEach(prop => secureOptions.add(prop));
}
}
} else {
// We only have a configuration file, assume every property that is secured should be censored
censorOpts.config.api.secure.findSecure(censorOpts.config.mProperties.profiles, "profiles").forEach(
prop => secureOptions.add(prop.split(".").pop())
);
}
secureOptions.forEach(prop => this.addCensoredOption(prop));
}
Copy link
Member

Choose a reason for hiding this comment

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

SonarCloud flagged the setCensoredOptions function for complexity. I was wondering if we could move this part of the function into a helper function to reduce complexity? I think it would make it a bit easier to follow the different branches of logic, while also resolving the SonarCloud issue as a result.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do that, though the data would need to be passed through to the second helper function, and it would probably only be called in this function. I attempted to do some reduction of calling addCensoredOption in here, which might not be as easily possible if I break this up into multiple functions.

packages/imperative/src/censor/src/Censor.ts Outdated Show resolved Hide resolved
packages/imperative/src/censor/src/Censor.ts Outdated Show resolved Hide resolved
packages/imperative/src/censor/src/Censor.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review/QA
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior with ZOWE_SHOW_SECURE_ARGS
5 participants