feat: Decrypt passwords for topology objects (Switch, PowerMng, OSD)#11
Open
a-gorczew wants to merge 2 commits into
Open
feat: Decrypt passwords for topology objects (Switch, PowerMng, OSD)#11a-gorczew wants to merge 2 commits into
a-gorczew wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds transparent Fernet decryption for password-like fields across topology-related models (switches, power management, OSD controller, and host management/connection passwords) to allow storing encrypted secrets in config while keeping runtime behavior unchanged.
Changes:
- Added shared decryption helpers and integrated them into switch/host/power management/OSD controller object creation.
- Introduced
create_osd_controller_from_modeland refactored MAC-based connection establishment to use it. - Updated unit tests, README docs, and the example topology YAML to reflect decryption support.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
pytest_mfd_config/fixtures.py |
Adds decryption helpers, hooks them into object creation, and introduces an OSD controller factory used by MAC-based connections. |
tests/unit/test_pytest_mfd_config/test_fixtures.py |
Expands coverage for new fixtures/decryption logic and adds tests for OSD controller/power management/switch flows. |
README.md |
Documents new decryption behavior for PowerMng/OSD/Switch and adds the new OSD factory function to the API list. |
examples/topology_host_config_with_secrets.yaml |
Demonstrates encrypted secrets usage for host/switch/power management (and attempts to show OSD usage). |
Comments suppressed due to low confidence (3)
pytest_mfd_config/fixtures.py:404
- _decrypt_switch_password swallows PyTestMFDConfigException from _get_encryption_obj and returns the original model. This means truly encrypted passwords will silently remain encrypted when AMBER_ENCRYPTION_KEY is missing, contradicting the README text that an exception is raised when decryption is needed. Consider either (a) detecting whether a value looks like a Fernet token and raising if the key is missing, or (b) updating the documentation/tests to match the intended non-raising behavior.
if not _has_secret_switch_password_fields(switch_model):
return switch_model
try:
cipher = _get_encryption_obj()
except PyTestMFDConfigException as info:
logger.log(level=log_levels.MODULE_DEBUG, msg=info)
return switch_model
pytest_mfd_config/fixtures.py:372
- _try_decrypt_secret treats InvalidToken the same as "not encrypted" and returns the original SecretStr without any logging. With a wrong AMBER_ENCRYPTION_KEY (or a corrupted token), this will silently pass the encrypted token downstream and failures will occur later during authentication. Consider logging (or raising) when the input looks like a Fernet token but decryption fails, so configuration mistakes are easier to diagnose.
try:
decrypted = cipher.decrypt(value.get_secret_value().encode("utf-8")).decode()
return SecretStr(decrypted)
except (InvalidToken, AttributeError):
return value
pytest_mfd_config/fixtures.py:505
- _decrypt_model_password catches PyTestMFDConfigException (missing AMBER_ENCRYPTION_KEY) and returns the model unchanged. If the field actually contains an encrypted Fernet token, this silently propagates the encrypted value into constructors (PowerMng/OSD), which is hard to debug and conflicts with the documented behavior for password decryption. Consider raising when decryption is required (e.g., token-like value) or updating docs/tests to reflect the non-raising behavior.
try:
cipher = _get_encryption_obj()
except PyTestMFDConfigException as info:
logger.log(level=log_levels.MODULE_DEBUG, msg=info)
return model
decrypted = _try_decrypt_secret(password, cipher)
if decrypted is password:
return model
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9fcdc95 to
e5c443b
Compare
Signed-off-by: Agnieszka Flizikowska <agnieszka.flizikowska@intel.com>
e5c443b to
ec5cf95
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for automatic decryption of password fields stored in encrypted (Fernet) form for multiple model types, improving security and simplifying usage. It introduces utility functions to handle decryption for
SwitchModel,PowerMngModel,OSDControllerModel, andHostModel, and updates relevant object creation routines to transparently decrypt passwords when needed. Documentation and example files are updated to reflect and demonstrate the new behavior.Decryption support for model password fields:
mng_passwordandenable_passwordfields inSwitchModelduring switch object creation, using theAMBER_ENCRYPTION_KEYenvironment variable. If decryption is needed but the key is missing, aPyTestMFDConfigExceptionis raised. [1] [2] [3]passwordfield inPowerMngModelandOSDControllerModelwhen creating respective objects. [1] [2] [3] [4]HostModel, supporting both host-level and per-connection password fields, and refactored the code for clarity and robustness. [1] [2]Documentation and examples:
README.mdto document the new password decryption behavior forSwitchModel,PowerMngModel, andOSDControllerModel, including usage notes and error handling. [1] [2] [3]Fixture API improvements:
create_osd_controller_from_modelfor consistent OSD controller object creation with decryption support. [1] [2] [3]These changes make it easier and safer to manage secrets in test configurations by supporting encrypted password fields throughout the configuration models.