-
Notifications
You must be signed in to change notification settings - Fork 207
Add coding conventions derived from recent PR review feedback #4636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| paths: | ||
| - "**/*.go" | ||
| --- | ||
|
|
||
| # Security Rules | ||
|
|
||
| Applies to all Go files in the project. | ||
|
|
||
| ## Don't Store Internal Addressing in Shared State | ||
|
|
||
| Never persist internal infrastructure addresses (hostnames, IPs, service URLs, pod names) into shared or external state stores (databases, caches, config passed to clients). | ||
|
|
||
| Internal addresses stored externally: | ||
| - Leak topology to anyone who can read the store | ||
| - May allow callers to bypass security middleware by using the stored address directly | ||
| - Couple your routing logic to volatile infrastructure state that changes independently | ||
|
|
||
| **Instead**: derive routing from stable, non-sensitive inputs (e.g. a session ID, a content hash, a logical name). If you must store a target, store a logical identifier and resolve it at use time through a path that enforces security controls. | ||
|
|
||
| ## Route Through Security-Enforcing Components | ||
|
|
||
| Always route traffic through the component responsible for auth, rate limiting, or policy enforcement — never optimize past it. | ||
|
|
||
| A direct path that skips middleware is a vulnerability, not a performance improvement. If you find yourself type-asserting, casting, or reaching into an internal field to get a "more direct" address, stop and ask whether the shortcut bypasses any security boundary. | ||
|
|
||
| When multiple routing options exist (e.g. a proxy vs. a raw address), choose the one where security controls are guaranteed to be in the critical path. | ||
|
|
||
| ## Prefer Stateless Routing Over Stored Routing | ||
|
|
||
| When routing can be derived deterministically from stable request properties, compute it on every request rather than storing it. | ||
|
|
||
| Storing routing decisions: | ||
| - Creates state that must be recovered correctly after restarts | ||
| - Introduces a window where stored state is stale or wrong | ||
| - Expands the attack surface of the state store | ||
|
|
||
| If the same input always maps to the same destination (consistent hashing, modular arithmetic, content addressing), there is no need to store the mapping. Remove the stored state and eliminate the recovery problem entirely. | ||
|
|
||
| ## All Requests Must Pass Through the Proxy Runner | ||
|
|
||
| Every request to a managed container (MCP server or tool) must flow through the proxy runner (`pkg/runner/proxy`). Bypassing it is a vulnerability, not an optimization. | ||
|
|
||
| The proxy runner is the single enforcement point for: | ||
| - Authentication and authorization checks | ||
| - Secret injection and credential management | ||
| - Network policy and egress controls | ||
| - Audit logging | ||
|
|
||
| Any code that constructs a direct connection to a container — by using a raw host:port, reaching past the proxy interface, or type-asserting to an underlying transport — skips these controls entirely. | ||
|
|
||
| **If you find a code path that contacts a container without going through the proxy runner, treat it as a security bug and fix it.** |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.