-
Notifications
You must be signed in to change notification settings - Fork 537
fix: propagate authorization header to subagents #1757
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
Open
towsif-rahman
wants to merge
7
commits into
kagent-dev:main
Choose a base branch
from
towsif-rahman:fix/subagent-authorization-forwarding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97adb51
fix: propagate authorization header to subagents
towsif-rahman a8efb87
Merge branch 'main' into fix/subagent-authorization-forwarding
EItanya d381ee9
fix: propagate authorization header in go subagents
towsif-rahman c45c255
Merge branch 'main' into fix/subagent-authorization-forwarding
supreme-gg-gg b36317a
Merge branch 'main' into fix/subagent-authorization-forwarding
supreme-gg-gg 1272b79
fix: format go remote a2a tests
towsif-rahman 9efd708
Merge branch 'main' into fix/subagent-authorization-forwarding
EItanya 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package tools | ||
|
|
||
| import ( | ||
| "context" | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/a2aproject/a2a-go/a2aclient" | ||
| "github.com/a2aproject/a2a-go/a2asrv" | ||
| ) | ||
|
|
||
| func TestSubagentForwardingInterceptorForwardsUserIDAndAuthorization(t *testing.T) { | ||
| ctx := context.WithValue(context.Background(), userIDContextKey{}, "user-1") | ||
| ctx = context.WithValue(ctx, authorizationHeaderContextKey{}, "Bearer parent-token") | ||
|
|
||
| req := &a2aclient.Request{Meta: a2aclient.CallMeta{}} | ||
| _, err := (&subagentForwardingInterceptor{}).Before(ctx, req) | ||
| if err != nil { | ||
| t.Fatalf("Before() error = %v", err) | ||
| } | ||
|
|
||
| if got, want := req.Meta.Get("x-user-id"), []string{"user-1"}; !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("x-user-id = %v, want %v", got, want) | ||
| } | ||
| if got, want := req.Meta.Get("authorization"), []string{"Bearer parent-token"}; !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("authorization = %v, want %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestSubagentForwardingInterceptorReplacesExistingAuthorization(t *testing.T) { | ||
| ctx := context.WithValue(context.Background(), authorizationHeaderContextKey{}, "Bearer parent-token") | ||
|
|
||
| req := &a2aclient.Request{Meta: a2aclient.CallMeta{}} | ||
| req.Meta.Append("Authorization", "Bearer stale-token") | ||
|
|
||
| _, err := (&subagentForwardingInterceptor{}).Before(ctx, req) | ||
| if err != nil { | ||
| t.Fatalf("Before() error = %v", err) | ||
| } | ||
|
|
||
| if got, want := req.Meta.Get("authorization"), []string{"Bearer parent-token"}; !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("authorization = %v, want %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestAuthorizationHeaderFromContext(t *testing.T) { | ||
| ctx, _ := a2asrv.WithCallContext(context.Background(), a2asrv.NewRequestMeta(map[string][]string{ | ||
| "Authorization": {"Bearer parent-token"}, | ||
| "X-Other": {"ignored"}, | ||
| })) | ||
|
|
||
| if got, want := authorizationHeaderFromContext(ctx), "Bearer parent-token"; got != want { | ||
| t.Fatalf("authorizationHeaderFromContext() = %q, want %q", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestAuthorizationHeaderFromContextWithoutHeader(t *testing.T) { | ||
| ctx, _ := a2asrv.WithCallContext(context.Background(), a2asrv.NewRequestMeta(map[string][]string{ | ||
| "X-Other": {"ignored"}, | ||
| })) | ||
|
|
||
| if got := authorizationHeaderFromContext(ctx); got != "" { | ||
| t.Fatalf("authorizationHeaderFromContext() = %q, want empty", got) | ||
| } | ||
| } | ||
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.
I really don't like that we're creating new context keys for all of our values. Can we re-use something similar to this PR: #1733
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.
Agreed, we should also do the same for userID here so there's no need for context keys for the interceptor and it's self-contained (reads directly from A2A server and tool context)