Repository navigation
fix: redact credentials in log messages - #65
Conversation
Name new users and repositories in log messages by their identifiers, leave stored objects out of debug messages for subscriptions and builds, name created pods by name, and log errors of the Kubernetes API by status and reason, so that no log message contains access tokens or other credentials. Tests check the log records of these paths. Closes #64 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Raise the errors for failed pod calls without the API error as their context, as FOCA logs exceptions with their context. - Log failed requests to GitHub for image signing by type, answer them with 500, and strip the GitHub token read from the environment. - Log new subscriptions and builds by identifier, and fix a log message that lacked its f-prefix. - Test exact messages and levels, with a deployment file that holds a token, and document what log messages contain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Clarify the comment on logging the type only, wrap long test lines, and say that responses of GitHub aren't checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationReview the safer logging for repository, user, subscription, and build registration, including the corrected missing-build message.
Review pod creation and deletion logging, which reports safe identifiers and Kubernetes status and reason without retaining the API exception as context.
Review GitHub signing-request handling, which normalizes the token and logs only the exception type on request failure.
DocumentationDocument which identifiers and failure details appear in logs, and clarify that GitHub responses are not checked.
TestsReview regression tests that verify identifiers remain useful in logs while credentials, Kubernetes response bodies, and GitHub header values stay out of logs and propagated exception context.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #65 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 745 752 +7
=========================================
+ Hits 745 752 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pubgrade/modules/endpoints/builds.py" line_range="538" />
<code_context>
- "AppsV1Api->create_namespaced_pod: "
- "%s\n" % e
+ f"Creating pod {dep['metadata']['name']} failed: "
+ f"{e.status} {e.reason}"
)
- raise CreatePodError
</code_context>
<issue_to_address>
**API errors expose credentials**
When the Kubernetes API rejects a valid manifest without `metadata.name`, `dep['metadata']['name']` raises `KeyError` before `CreatePodError from None` runs, leaving the caught `ApiException` as context; FOCA exception logging can include its response body, which may contain credentials, and the caller sees the wrong exception.
Use a safe lookup for the manifest name in the log message and raise `CreatePodError from None` without letting logging mask the API error.
</issue_to_address>
### Comment 2
<location path="tests/pubgrade/endpoints/test_builds.py" line_range="731" />
<code_context>
del os.environ["NAMESPACE"]
del os.environ["KUBERNETES_SERVICE_HOST"]
+ @patch("kubernetes.config.load_kube_config", mocked_load_cluster_config)
+ @patch(
+ "kubernetes.client.api.core_v1_api.CoreV1Api.create_namespaced_pod",
</code_context>
<issue_to_address>
**In-cluster environment breaks pod tests**
When the test process has `KUBERNETES_SERVICE_HOST` set, `build_push_image_using_kaniko` calls the unpatched `load_incluster_config` before reaching the mocked pod call, so `test_build_push_image_using_kaniko_logs_no_token` and `test_build_push_image_using_kaniko_error_logs_no_body` fail before their assertions.
Clear `KUBERNETES_SERVICE_HOST` with `monkeypatch.delenv` in these tests, or patch `load_incluster_config` as well.
Also at `tests/pubgrade/endpoints/test_builds.py:762`.
</issue_to_address>Linked issues
#64 fix: redact credentials in log messages · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Log new repositories by identifier instead of logging the whole object. | ✅ Met | The registration log names the repository ID, and a test checks that its access token is absent. |
| 2 | Log new users by identifier instead of logging the whole object. | ✅ Met | The registration log names the user UID, and a test checks that the user's access token is absent. |
| 3 | Keep subscription objects out of debug messages while storing them. | ✅ Met | The debug message no longer includes the subscription data; the test checks that the subscription token is absent. |
| 4 | Keep build objects out of debug messages while storing them. | ✅ Met | The debug message no longer includes the build data; the test checks that the Docker Hub token is absent. |
| 5 | Log the created build pod by name, and log Kubernetes API errors by status and reason. | ✅ Met | Pod creation logs its name, and pod creation and deletion errors log status and reason without retaining the API error as exception context. |
| 6 | Ensure the named log paths do not expose credentials, with tests checking their log records. | ✅ Met | The added tests check identifiers and credential absence for registration and pod creation, and check Kubernetes error logs and exception formatting. |
Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: pubgrade/modules/endpoints/builds.py:538, tests/pubgrade/endpoints/test_builds.py:731
Read the pod's name before calling the API, so that a manifest without one still raises CreatePodError without the API error as its context, and keep the pod tests independent of KUBERNETES_SERVICE_HOST. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Log messages name objects by their identifiers, so that none of them contains access tokens or other credentials:
repositories.py,users.py,subscriptions.py,builds.py).None.docs/deployment.mdsays what log messages contain.Closes #64
Verification
make test(Python 3.13): 201 passed, 100% coverage. New tests capture the log records (at debug level) of these paths and check exact messages and levels, that identifiers are there, and that tokens, a deployment file's token, response bodies of the Kubernetes API and the GitHub token appear neither in the log nor in the formatted exception that FOCA logs; they fail without the change.Review
Full review (
adversarial-reviewerandquality-reviewer, two rounds). Round 1 fixed: exception context of pod errors, the GitHub request's errors, identifiers for subscriptions and builds, exact test assertions with a real deployment file, the f-prefix, import order and the docs note. Round 2 fixed: comment wording, line length, and the docs on which GitHub failures are logged.Sourcery: 2 threads fixed and resolved (pod name read safely before the API call, so a manifest without one still gets
CreatePodErrorwithout context; pod tests independent ofKUBERNETES_SERVICE_HOST).Declined review findings
devbeyond log messages; the docs now say that responses aren't checked.Open questions
None.
🤖 Generated with Claude Code