Secure coding improvements, pr number 1#391
Secure coding improvements, pr number 1#391TomasTomecek wants to merge 4 commits intopackit:mainfrom
Conversation
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com> Assisted-by: Claude
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com> Assisted-by: Claude
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com> Assisted-by: Claude
There was a problem hiding this comment.
Code Review
This pull request significantly enhances application security by implementing credential redaction in logs and strengthening Kubernetes deployment configurations. Specifically, a new _redact utility and associated regex patterns were introduced in mcp_server/gateway.py to prevent sensitive data like API keys and tokens from appearing in log outputs, with comprehensive unit tests added for validation. The set_litellm_debug function was updated to prevent token leakage by requiring an explicit environment variable for debug logging and adding a clear warning. Furthermore, all Kubernetes deployment files were updated to enforce runAsNonRoot: true and apply a default seccompProfile for improved runtime security. A review comment suggested making the _REDACT_PATTERNS a frozenset to ensure its immutability.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
I will send more with followup PRs. There were even more changes here but decided to split/cut them because I didn't like Claude's proposals.
Claude's detailed overview:
2. Add credential redaction to MCP gateway logs (HIGH)
Files:
mcp_server/gateway.py,mcp_server/tests/unit/test_gateway.pyAdded
_redact()function with regex patterns matching common credential formats:glpat-...)sk-ant-...)AIzaSy...)oauth2:...@)The
log_tool_calldecorator now redacts all tool arguments and error messages before logging.Test coverage: 20 unit tests covering pattern matching, edge cases, and real-world scenarios.
3. Add LITELLM_DEBUG environment variable guard (HIGH)
Files:
agents/utils.py,templates/beeai-agent.envset_litellm_debug()now checks forLITELLM_DEBUGenv var before enabling debug mode. If not set, logs a warning and returns without enabling token-leaking debug output.Added comprehensive documentation explaining the security risk and usage.
5. Add SecurityContext to K8s deployments (LOW)
Files:
openshift/deployment-*.yml(10 files)Replaced empty
securityContext: {}with:Matches the pattern already used in cronjob manifests.