upstreamauth

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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).

View Source
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.

View Source
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

func CheckURL(up policy.Upstream, u *url.URL, extra []string, insecure bool) error

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

func Credentialed(up policy.Upstream) bool

Credentialed reports whether halo-proxy attaches its own credential to requests for up (and so must restrict where they can go).

func Region

func Region(configured, host string) (string, error)

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

func Secret(c *policy.Credential, getenv func(string) string) (string, error)

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

func SetAuth(h http.Header, kind string, c *policy.Credential, secret string)

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 SetBearer

func SetBearer(h http.Header, token string)

SetBearer replaces the client's credentials on h with a bearer token.

func SignableHost

func SignableHost(host string, allow []string) bool

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

func StripClientAmz(h http.Header)

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

func StripClientCredentials(h http.Header)

StripClientCredentials removes every ClientCredentialHeaders entry from h.

func WithBedrock

func WithBedrock(ctx context.Context, region string) context.Context

WithBedrock marks ctx so Transport signs the request for region.

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

func (b *Bedrock) Sign(req *http.Request, region string) error

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).

func (*MetadataTokenSource) Token

func (m *MetadataTokenSource) Token(ctx context.Context) (string, error)

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.

func (*ServiceAccountTokenSource) Token

type TokenSource

type TokenSource interface {
	Token(ctx context.Context) (string, error)
}

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL