Repository navigation
Conversation
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #405 +/- ##
==========================================
+ Coverage 85.53% 86.03% +0.50%
==========================================
Files 49 50 +1
Lines 3001 3087 +86
==========================================
+ Hits 2567 2656 +89
+ Misses 434 431 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
a51f01c to
7ae229e
Compare
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
CBforZ
left a comment
There was a problem hiding this comment.
Ran through the test steps and everything worked as expected
| settings_json = self.__load_settings_json() | ||
| return set(settings_json[self.__settings_key]) | ||
|
|
||
| def add_trusted(self, dir_path: str) -> None: |
There was a problem hiding this comment.
TODO: Require an absolute path to be provided
zFernand0
left a comment
There was a problem hiding this comment.
LGTM! 😋
Left two small Qs about the intended behavior 🙏
| path = os.path.join(current_dir, self.filename) | ||
| is_trusted = True | ||
|
|
||
| if os.path.isfile(path): |
There was a problem hiding this comment.
isfile() seems to follow symlinks. I know we recently tried to prevent following them... should we add an extra check here for symbolic links?
os.path.islink(path) should do the trick
This is unrelated to the PR so it can be handled separately.
There was a problem hiding this comment.
We could add an additional check and not os.path.islink(path), but I agree this is probably best handled in a follow-up PR - likely a breaking change and different from how Zowe CLI behaves.
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
bf6e626 to
e66139f
Compare
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
There was a problem hiding this comment.
🟡 Changes recommended
Active moderate and critical findings remain in trusted path validation, including inconsistent normalization and symlink-based containment bypasses.
2 open issues
What changed in this PR
Adds trusted-directory and world-writable-directory checks to project configuration autodiscovery, with environment overrides, CI support, interactive trust prompts, and persistent trusted-directory settings.
Changes:
- Introduces
TrustedConfigManagerfor trusted-directory persistence and security checks. - Updates
ConfigFileandProfileManagerto enforce trust validation and support trust prompts. - Adds unit and integration coverage and documents the behavior in the changelog.
| File | Description |
|---|---|
| tests/unit/core/test_trusted_config.py | Adds unit tests for trusted-directory persistence and security-check behavior. |
| tests/unit/core/test_profile_manager.py | Adds tests for secure config autodiscovery, overrides, and trust prompt integration. |
| tests/integration/test_config_trust.py | Adds integration coverage for trust behavior with real temporary directories. |
| src/core/zowe/core_for_zowe_sdk/trusted_config.py | Implements trusted-directory management, persistence, environment overrides, and filesystem security checks. |
| src/core/zowe/core_for_zowe_sdk/profile_manager.py | Propagates and caches optional trust prompt callbacks during profile loading. |
| src/core/zowe/core_for_zowe_sdk/config_file.py | Applies trusted-directory and world-writable-directory checks during configuration autodiscovery. |
| src/core/zowe/core_for_zowe_sdk/__init__.py | Exports TrustedConfigManager through the core package. |
| CHANGELOG.md | Documents the new configuration-loading security behavior and related APIs. |
Review effort: Lite
| if Path(dir_path).is_relative_to(Path.home()): | ||
| return True |
| if not self.__is_valid_path(dir_path): | ||
| raise ValueError("Trusted directory path cannot be relative or a symbolic link") |
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
traeok
left a comment
There was a problem hiding this comment.
The changes make sense to me, but the lint stage is failing. I plan to approve the PR once its resolved. I left a couple suggestions as well. Thanks Timothy
| settings_json = self.__load_settings_json() | ||
| if dir_path in settings_json[self.__settings_key]: | ||
| settings_json[self.__settings_key].remove(dir_path) | ||
| with open(self.local_storage_path, "w", encoding="utf-8") as fp: | ||
| fp.write(json.dumps(settings_json, indent=2) + "\n") |
There was a problem hiding this comment.
(nitpick) This only removes the first instance of the directory path. Should we remove all instances to cover the edge case of users manually editing this file?
| def __is_valid_path(self, path) -> bool: | ||
| """Return True if the path is absolute, normalized, and not a symlink.""" | ||
| return os.path.isabs(path) and os.path.normpath(path) == path and not os.path.islink(path) |
There was a problem hiding this comment.
The symlink validation only checks the final component of the path, consider refactoring this to also reject symlinked parents.
Co-Authored-by: Claude @model: Sonnet-5.5 Modified AI generated code: Yes Dev Name: Timothy Johnson Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>


What It Does
Updates the
ConfigFile.autodiscover_config_dirmethod to skip config files in world-writable directories and in directories that are not trusted.ZOWE_CONFIG_ALLOW_WORLD_WRITABLEandZOWE_CONFIG_ALLOW_UNTRUSTED_DIRSenvironment variables.trustedConfigDirssetting of Zowe CLI's~/.zowe/settings/imperative.json.trust_prompt_fnto theProfileManagerorConfigFileclasses.How to Test
test.pyand it should load profile successfullyworld-writableworld-writableand run../test.py- should fail with untrusted warningZOWE_CONFIG_ALLOW_WORLD_WRITABLE=1and run../test.py- should succeedHOMEto the absolute path offake-homechild-dirand run../test.py- should fail with untrusted warningZOWE_CONFIG_ALLOW_UNTRUSTED_DIRS=1and run../test.py- should succeedCI=trueinstead and run../test.py- should succeedtest.pyto passtrust_prompt_fn=trust_prompton theloadcallHOMEvariable is still set../test.pyand answernto prompt - should fail with untrusted warning../test.pyand answeryto prompt - should succeedHOMEvariable is still setchild-dirand run../test.py- should fail with untrusted warningtest.pyto uncomment the call toTrustedConfigManager../test.pyagain - should succeedfake-home/.zowe/settings/imperative.jsonwas created and contains pathReview Checklist
I certify that I have:
Additional Comments