Prevent secret leakage#1103
Draft
mxsrc wants to merge 4 commits into
Draft
Conversation
RPCClient, SNodeClient, mgmt_node_ops, and the Grafana/Graylog helpers in cluster_ops now accept SecretStr-typed credentials so payload dicts and model objects can be logged at DEBUG without leaking the value (SecretStr masks in repr/str/dict-repr). Secrets are unwrapped only at the wire-send site via the shared helper ``unwrap_secrets_for_send``. Response bodies are gated behind a new ``SB_LOG_RESPONSE_BODIES`` setting (default off). The previous wholesale ``response.text`` / ``response.content`` logging at DEBUG is the leak vector here: responses are untyped, so there is no equivalent of SecretStr masking once a body is in hand. Drop the body from exception messages too — keep the status code, hide the text.
e11b049 to
97d1167
Compare
|
|
||
| default_cluster = None | ||
| monitoring_secret = os.environ.get("MONITORING_SECRET", "") | ||
| monitoring_secret = SecretStr(os.environ.get("MONITORING_SECRET", "")) |
| db_controller = DBController() | ||
|
|
||
| def _create_update_user(cluster_id, grafana_url, grafana_secret, user_secret, update_secret=False): | ||
| def _create_update_user(cluster_id, grafana_url, grafana_secret: SecretStr, user_secret: SecretStr, update_secret=False): |
| from pydantic import SecretBytes, SecretStr | ||
|
|
||
|
|
||
| def unwrap_secrets_for_send(obj: Any) -> Any: |
| return obj | ||
|
|
||
|
|
||
| def unwrap_secret(value: Union[SecretStr, str, None]) -> Optional[str]: |
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.
The extensive logging done throughout the application may inadvertently leak confidential data. This PR aims to mitigate this, preventing secrets to be present in the logs.
The core tool in this PR is the use of pydantic's
SecretStr/SecretBytes. They are a simple wrapper aroundstr/bytes, that, when converted to string yield a redacted string (**********). The actual value needs to be explicitly unwrapped viaget_secret_value().This changeset introduces:
What htis PR notably does not do, is prevent explicit leakage through endpoints that currently allow access to the confidential values. Handling that in a better way is left as a follow-up.