Documentation
¶
Overview ¶
Package upstreamauth signs requests to provider upstreams that need a gateway-held credential instead of the caller's, so halo-proxy can talk to Amazon Bedrock directly (no orchestrator, no SigV4 sidecar).
Index ¶
- Variables
- func CheckURL(up policy.Upstream, u *url.URL, extra []string, insecure bool) error
- func Credentialed(up policy.Upstream) bool
- func Region(configured, host string) (string, error)
- func Secret(c *policy.Credential, getenv func(string) string) (string, error)
- func SetAuth(h http.Header, kind string, c *policy.Credential, secret string)
- func SetBearer(h http.Header, token string)
- func SignableHost(host string, allow []string) bool
- func StripClientAmz(h http.Header)
- func StripClientCredentials(h http.Header)
- func WithBedrock(ctx context.Context, region string) context.Context
- type Bedrock
- type MetadataTokenSource
- type ServiceAccountTokenSource
- type TokenSource
Constants ¶
This section is empty.
Variables ¶
var ClientCredentialHeaders = identity.ClientCredentialHeaders
ClientCredentialHeaders are the headers a caller can use to present a credential. None of them is ever a gateway-to-provider credential: they are dropped before the gateway installs its own (or none).
var ErrCredentials = errors.New("upstreamauth: no AWS credentials for Bedrock")
ErrCredentials marks a request that could not be signed because no upstream credential was available. Callers answer it with 502, never forward unsigned.
var ErrNoSecret = errors.New("upstreamauth: provider credential unavailable")
ErrNoSecret marks a credential-bearing upstream whose secret could not be read; callers fail the attempt (and may fail over), never forward unauthenticated.
Functions ¶
func CheckURL ¶
CheckURL is the SSRF guard for credentialed upstreams: https only (http only when insecure, the explicit in-cluster/test flag), no userinfo, and the host must be the provider's own domain or an exact entry of extra (operator allow list, e.g. a private endpoint). Other kinds are not checked here.
func Credentialed ¶
Credentialed reports whether halo-proxy attaches its own credential to requests for up (and so must restrict where they can go).
func Region ¶
Region returns the SigV4 region for a Bedrock upstream: the configured one, else the label after bedrock-runtime[-fips] in host (bedrock-runtime.us-east-1.amazonaws.com, vpce-x.bedrock-runtime.eu-west-1.vpce.amazonaws.com).
func Secret ¶
Secret reads the credential from its env var or file at use time (so rotation needs no restart). Policy only names the location.
func SetAuth ¶
SetAuth replaces the client's credentials on h with the provider's: Azure OpenAI takes api-key by default, OpenAI a bearer token; Credential.Scheme overrides.
func SignableHost ¶
SignableHost reports whether SigV4-signing for host (port ignored) is allowed: an AWS endpoint domain or an entry of the operator's allow list (exact hostnames, e.g. a private VPC endpoint DNS name). Anything else would hand gateway-signed requests to a non-AWS party.
func StripClientAmz ¶
StripClientAmz removes every x-amz* / x-amzn* header. Call it on the client's headers before halo-proxy stamps its own, so only gateway-set x-amz headers can end up in the signature.
func StripClientCredentials ¶
StripClientCredentials removes every ClientCredentialHeaders entry from h.
Types ¶
type Bedrock ¶
type Bedrock struct {
// Credentials, when nil, is the AWS SDK default chain (env, shared
// config/SSO, web identity/IRSA, ECS/EC2 IMDS), resolved on first use and
// cached/refreshed by aws.CredentialsCache.
Credentials aws.CredentialsProvider
// contains filtered or unexported fields
}
Bedrock signs requests with AWS SigV4 for service "bedrock". Safe for concurrent use.
func (*Bedrock) Sign ¶
Sign replaces req's auth with a SigV4 signature over its final method, URL (escaped path as sent), host, body hash, Content-Type and x-amz* headers. Other headers are left unsigned so hops that touch them can't break the signature. req.Body is read fully and replaced (callers bound its size).
func (*Bedrock) Transport ¶
func (b *Bedrock) Transport(base http.RoundTripper) http.RoundTripper
Transport signs requests whose context was marked by WithBedrock and passes everything else through. Responses (incl. the application/vnd.amazon.eventstream stream) are returned untouched.
type MetadataTokenSource ¶
type MetadataTokenSource struct {
BaseURL string // default http://metadata.google.internal
Client *http.Client // default 5s timeout
// contains filtered or unexported fields
}
MetadataTokenSource reads tokens from the GCE/GKE metadata server (workload identity, attached service account).
type ServiceAccountTokenSource ¶
type ServiceAccountTokenSource struct {
Client *http.Client
// contains filtered or unexported fields
}
ServiceAccountTokenSource exchanges a service-account key (JSON file) for tokens with the OAuth2 JWT-bearer grant.
func NewServiceAccountTokenSource ¶
func NewServiceAccountTokenSource(keyJSON []byte) (*ServiceAccountTokenSource, error)
NewServiceAccountTokenSource parses a service-account key. token_uri must be an https googleapis.com host: the signed assertion is only sent there.
type TokenSource ¶
TokenSource yields a bearer token for a provider API. Implementations cache and refresh; they are safe for concurrent use.
func DefaultTokenSource ¶
func DefaultTokenSource(getenv func(string) string) (TokenSource, error)
DefaultTokenSource is Google ADC, minus the gcloud user credentials: the service-account key at $GOOGLE_APPLICATION_CREDENTIALS when set, else the metadata server (GKE workload identity, GCE, Cloud Run).