-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(aibridge/provider): disable keep-alive on the STS assume-role client #26971
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ package provider | |
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" | ||
| awsconfig "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/credentials" | ||
| "github.com/aws/aws-sdk-go-v2/credentials/stscreds" | ||
|
|
@@ -77,7 +79,24 @@ func buildBedrockCredentials(ctx context.Context, cfg config.AWSBedrock) (aws.Cr | |
| // cache to avoid re-assuming the role on every request. | ||
| credsProvider := base.Credentials | ||
| if cfg.RoleARN != "" { | ||
| credsProvider = stscreds.NewAssumeRoleProvider(sts.NewFromConfig(base), cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) { | ||
| // Disable keep-alive on the STS client so each AssumeRole opens a | ||
| // fresh connection. Observed: with keep-alive, AssumeRole calls reuse | ||
| // one connection pinned to a single STS endpoint, and after a | ||
| // trust-policy change that connection kept returning AccessDenied for | ||
| // minutes while a fresh connection (e.g. the AWS CLI) accepted the | ||
| // identical request at once; the gateway recovered only when that | ||
| // connection recycled or the process restarted. The STS-internal reason is | ||
| // unconfirmed (likely per-endpoint propagation of the change); what we | ||
| // verified is that a fresh connection per call recovers in seconds | ||
| // instead of minutes. AssumeRole runs at most once per credential-cache | ||
| // lifetime, so keep-alive saves nothing here. Scoped to the STS client | ||
| // only; Bedrock requests use a separate client and keep pooling. | ||
|
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 [CRF-3] The commit subject names the mechanism ("disable keep-alive on the STS assume-role client") instead of the condition it fixes. A
|
||
| stsClient := sts.NewFromConfig(base, func(o *sts.Options) { | ||
| o.HTTPClient = awshttp.NewBuildableClient().WithTransportOptions(func(t *http.Transport) { | ||
| t.DisableKeepAlives = true | ||
|
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. P3 [CRF-1] No test asserts that the STS client disables keep-alives, the entire point of this PR.
The existing require.Equal(t, "close", r.Header.Get("Connection"),
"STS client should disable keep-alives so each AssumeRole opens a fresh connection")The thorough comment at lines 82-93 mitigates accidental removal, but comments don't prevent regressions. A regression here means multi-minute production recovery windows after trust-policy changes, a failure mode that only surfaces under specific conditions. (Bisky)
Contributor
Author
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. Good suggestion, done: fa282e4 |
||
| }) | ||
| }) | ||
| credsProvider = stscreds.NewAssumeRoleProvider(stsClient, cfg.RoleARN, func(o *stscreds.AssumeRoleOptions) { | ||
| o.RoleSessionName = bedrockSessionName | ||
| if cfg.ExternalID != "" { | ||
| o.ExternalID = aws.String(cfg.ExternalID) | ||
|
|
||
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 [CRF-2] Comment is 12 lines; 4 carry the why-not-what and trap, the rest is narrative padding.
Gon proposed trimming to:
This cuts the "Observed:" investigation narrative, the AWS CLI verification detail, the "STS-internal reason is unconfirmed" speculation, and the scope sentence that repeats what the local
stsClientvariable already shows.Orchestrator note: downgraded from Gon's P2. Three reviewers (Leorio, Knov, Mafu-san) independently praised this comment's structure, specifically its observation-inference separation and honest uncertainty disclosure. The trim is good advice; the original is not a defect. (Gon P2, downgraded by orchestrator)