-
Notifications
You must be signed in to change notification settings - Fork 683
fix(cloud): audit denied request authentication (#1134) #1161
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
dnlrsls
merged 5 commits into
Gentleman-Programming:main
from
danielgap:fix/1134-audit-log-bounded
Sep 15, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f04d6b6
fix(cloud): audit and log failed request auth in the sync middleware β¦
danielgap 5c218f5
fix(cloud): bound request auth audit inserts
danielgap 2fcea42
fix(cloud): sharpen request-auth audit classification and bearer parsing
danielgap 797e463
fix(cloud): complete denied auth audit coverage
dnlrsls 7a0e060
Merge branch 'main' into fix/1134-audit-log-bounded
dnlrsls 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/Gentleman-Programming/engram/v2/internal/cloud" | ||
| "github.com/Gentleman-Programming/engram/v2/internal/cloud/cloudstore" | ||
| ) | ||
|
|
||
| func TestCloudRuntimePersistsUnknownTokenRequestAuthAudit(t *testing.T) { | ||
| testDSN := openIsolatedCloudRuntimeSchema(t) | ||
|
|
||
| const legacySyncToken = "audit-integration-legacy-token" | ||
| const unknownToken = "audit-integration-unknown-token" | ||
| t.Setenv("ENGRAM_CLOUD_TOKEN", legacySyncToken) | ||
| t.Setenv("ENGRAM_CLOUD_INSECURE_NO_AUTH", "") | ||
|
|
||
| runtime, err := newCloudRuntime(cloud.Config{ | ||
| DSN: testDSN, | ||
| JWTSecret: "audit-integration-jwt-secret-32-bytes-plus", | ||
| AllowedProjects: []string{"audit-project"}, | ||
| TokenPepper: "audit-integration-token-pepper-at-least-32-bytes", | ||
| MaxPushBodyBytes: cloud.DefaultMaxPushBodyBytes, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("newCloudRuntime: %v", err) | ||
| } | ||
| dcr, ok := runtime.(*defaultCloudRuntime) | ||
| if !ok { | ||
| t.Fatalf("expected *defaultCloudRuntime, got %T", runtime) | ||
| } | ||
| t.Cleanup(func() { _ = dcr.store.Close() }) | ||
|
|
||
| status, body := doBearerRequest(t, dcr.server.Handler(), http.MethodGet, "/sync/pull?project=audit-project", unknownToken) | ||
| if status != http.StatusUnauthorized { | ||
| t.Fatalf("unknown token status = %d, want %d body=%q", status, http.StatusUnauthorized, body) | ||
| } | ||
| if body != "unauthorized: unknown token\n" { | ||
| t.Fatalf("unknown token 401 body = %q", body) | ||
| } | ||
|
|
||
| events, err := dcr.store.ListAuthAuditEvents(context.Background(), cloudstore.AuthAuditQuery{Limit: 10}) | ||
| if err != nil { | ||
| t.Fatalf("ListAuthAuditEvents: %v", err) | ||
| } | ||
| if len(events) != 1 { | ||
| t.Fatalf("auth audit events = %d, want 1: %+v", len(events), events) | ||
| } | ||
| event := events[0] | ||
| if event.ActorPrincipalID != "" || event.ActorSource != "request" || event.Project != "" || event.Action != "sync.auth" || event.Outcome != "denied" || event.ReasonCode != "unknown_token" { | ||
| t.Fatalf("unexpected persisted unknown-token auth audit event: %+v", event) | ||
| } | ||
| if event.Metadata["source"] != "request" || strings.Contains(fmt.Sprintf("%+v", event), unknownToken) { | ||
| t.Fatalf("unknown-token audit event must contain only safe metadata: %+v", event) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π― Functional Correctness | π‘ Minor | β‘ Quick win
Cover an empty token principal ID.
ResolveBearerTokenmaps an emptyManagedTokenRecord.PrincipalIDtoErrTokenPrincipalMismatch, but this test only covers different nonempty IDs. Add an empty-ID fixture and assert the same sentinel.As per path instructions,
**/*_test.go: βVerify coverage of happy path, error paths, and edge cases.βπ€ Prompt for AI Agents
Source: Path instructions