-
Notifications
You must be signed in to change notification settings - Fork 569
feat: go runtime sts client and adk integration #1880
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
supreme-gg-gg
wants to merge
3
commits into
kagent-dev:main
Choose a base branch
from
supreme-gg-gg:feat/go-sts-client-new
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
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 |
|---|---|---|
|
|
@@ -3,13 +3,17 @@ package runner | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| "github.com/kagent-dev/kagent/go/adk/pkg/agent" | ||
| kagentmemory "github.com/kagent-dev/kagent/go/adk/pkg/memory" | ||
| "github.com/kagent-dev/kagent/go/adk/pkg/session" | ||
| "github.com/kagent-dev/kagent/go/adk/pkg/sts" | ||
| "github.com/kagent-dev/kagent/go/api/adk" | ||
| adkmemory "google.golang.org/adk/memory" | ||
| adkplugin "google.golang.org/adk/plugin" | ||
| "google.golang.org/adk/runner" | ||
| adksession "google.golang.org/adk/session" | ||
| adktool "google.golang.org/adk/tool" | ||
|
|
@@ -31,6 +35,8 @@ func CreateRunnerConfig( | |
| appName string, | ||
| memoryService *kagentmemory.KagentMemoryService, | ||
| ) (runner.Config, map[string]string, error) { | ||
| log := logr.FromContextOrDiscard(ctx) | ||
|
|
||
| var extraTools []adktool.Tool | ||
| if memoryService != nil { | ||
| saveTool, err := kagentmemory.NewSaveMemoryTool(memoryService) | ||
|
|
@@ -40,7 +46,12 @@ func CreateRunnerConfig( | |
| extraTools = append(extraTools, saveTool) | ||
| } | ||
|
|
||
| adkAgent, subagentSessionIDs, err := agent.CreateGoogleADKAgentWithSubagentSessionIDs(ctx, agentConfig, agentNameFromAppName(appName), extraTools...) | ||
| stsPlugin, err := buildTokenPropagationPlugin(ctx, log) | ||
| if err != nil { | ||
| return runner.Config{}, nil, err | ||
| } | ||
|
|
||
| adkAgent, subagentSessionIDs, err := agent.CreateGoogleADKAgentWithSubagentSessionIDs(ctx, agentConfig, agentNameFromAppName(appName), stsPlugin, extraTools...) | ||
| if err != nil { | ||
| return runner.Config{}, nil, fmt.Errorf("failed to create agent: %w", err) | ||
| } | ||
|
|
@@ -61,11 +72,57 @@ func CreateRunnerConfig( | |
| runnerMemory = memoryService | ||
| } | ||
|
|
||
| var adkPlugins []*adkplugin.Plugin | ||
| if stsPlugin != nil { | ||
| p, err := stsPlugin.ADKPlugin() | ||
| if err != nil { | ||
| return runner.Config{}, nil, fmt.Errorf("failed to create STS ADK plugin: %w", err) | ||
| } | ||
| if p != nil { | ||
| adkPlugins = append(adkPlugins, p) | ||
| } | ||
| } | ||
|
|
||
| cfg := runner.Config{ | ||
| AppName: appName, | ||
| Agent: adkAgent, | ||
| SessionService: adkSessionService, | ||
| MemoryService: runnerMemory, | ||
| PluginConfig: runner.PluginConfig{ | ||
| Plugins: adkPlugins, | ||
| }, | ||
| } | ||
|
|
||
| return cfg, subagentSessionIDs, nil | ||
| } | ||
|
|
||
| func buildTokenPropagationPlugin(ctx context.Context, log logr.Logger) (*sts.TokenPropagationPlugin, error) { | ||
| propagateToken := strings.EqualFold(strings.TrimSpace(os.Getenv("KAGENT_PROPAGATE_TOKEN")), "true") | ||
| stsWellKnownURI := strings.TrimSpace(os.Getenv("STS_WELL_KNOWN_URI")) | ||
| if !propagateToken && stsWellKnownURI == "" { | ||
| return nil, nil | ||
| } | ||
|
|
||
| // Propagate-only mode: keep parity with Python by enabling plugin without STS exchange. | ||
| if stsWellKnownURI == "" { | ||
| log.Info("Enabling token propagation plugin without STS exchange") | ||
| return sts.NewTokenPropagationPlugin(nil, log), nil | ||
| } | ||
|
|
||
| integration, err := sts.NewSTSIntegration( | ||
| stsWellKnownURI, | ||
| "", | ||
| nil, // fetchActorToken | ||
| nil, // getSubjectToken | ||
| 0, // default timeout | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the default time out 5s? |
||
| true, // default verifySSL | ||
| false, // default useIssuerHost | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to initialize STS integration: %w", err) | ||
| } | ||
|
|
||
| log.Info("Enabling STS token propagation plugin", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could we format this log as one line? |
||
| "wellKnownURI", stsWellKnownURI) | ||
| return sts.NewTokenPropagationPlugin(integration, log), nil | ||
| } | ||
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,54 @@ | ||
| package sts | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // DefaultServiceAccountTokenPath is the default path for Kubernetes service account tokens. | ||
| const DefaultServiceAccountTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" | ||
|
|
||
| // ActorTokenService provides actor tokens for STS delegation. | ||
| // It reads Kubernetes service account tokens from a file path. | ||
| type ActorTokenService struct { | ||
| tokenPath string | ||
| } | ||
|
|
||
| // NewActorTokenService creates a new ActorTokenService. | ||
| // If tokenPath is empty, it uses the default Kubernetes service account token path. | ||
| func NewActorTokenService(tokenPath string) *ActorTokenService { | ||
| if tokenPath == "" { | ||
| tokenPath = DefaultServiceAccountTokenPath | ||
| } | ||
| return &ActorTokenService{ | ||
| tokenPath: tokenPath, | ||
| } | ||
| } | ||
|
|
||
| // GetActorToken retrieves the actor token for STS delegation. | ||
| // This method reads the token from the file each time it's called. | ||
| // If loading fails, it returns an empty string and an error (or nil if file doesn't exist). | ||
| func (s *ActorTokenService) GetActorToken() (string, error) { | ||
| // Check if file exists first | ||
| if _, err := os.Stat(s.tokenPath); os.IsNotExist(err) { | ||
| return "", nil | ||
| } | ||
|
|
||
| data, err := os.ReadFile(s.tokenPath) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to read actor token from %s: %w", s.tokenPath, err) | ||
| } | ||
|
|
||
| token := strings.TrimSpace(string(data)) | ||
| if token == "" { | ||
| return "", fmt.Errorf("empty actor token found at %s", s.tokenPath) | ||
| } | ||
|
|
||
| return token, nil | ||
| } | ||
|
|
||
| // TokenPath returns the configured token path. | ||
| func (s *ActorTokenService) TokenPath() string { | ||
| return s.tokenPath | ||
| } |
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.
nit:
x-trace-idhere seems to be a bit of a misrepresentation given that our implementation only overwrites theAuthorizationheader.