proxy

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 69 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxy provides a reverse proxy that accepts client certificates and forwards Common Name and Organizations to backend API servers in HTTP headers. The proxy terminates client TLS and communicates with API servers via mTLS. Traffic is routed based on paths.

An example configuration:

  • path: / backend: https://localhost:6443 backend_server_ca: certs/kcp-ca-cert.pem proxy_client_cert: certs/proxy-client-cert.pem proxy_client_key: certs/proxy-client-key.pem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(ctx context.Context, mappings []types.PathMapping) (http.Handler, error)

func WithProxyAuthHeaders

func WithProxyAuthHeaders(delegate http.Handler, userHeader, groupHeader string, extraHeaderPrefix string) http.HandlerFunc

WithProxyAuthHeaders does client cert termination by extracting the user and groups and passing them through access headers to the shard.

Types

type CompletedConfig added in v0.9.0

type CompletedConfig struct {
	// contains filtered or unexported fields
}

type Config added in v0.9.0

type Config struct {
	Options *proxyoptions.Options

	ExtraConfig
}

func NewConfig added in v0.9.0

func NewConfig(ctx context.Context, opts *proxyoptions.Options) (*Config, error)

NewConfig returns a new Config for the given options.

func (*Config) Complete added in v0.9.0

func (c *Config) Complete() (CompletedConfig, error)

Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.

type ExtraConfig added in v0.9.0

type ExtraConfig struct {
	// CoreIdentityHandler feeds the identities of the core APIs, which the
	// clients built from ShardsConfig inject into their wildcard requests,
	// from the APIIdentity registry that the Admin workspace of the peers
	// serves. Register it on an informer of those entries.
	CoreIdentityHandler cache.ResourceEventHandler
	// CoreIdentitiesReady fails while the identity of a core API is still
	// unknown. It is a readiness check: requests needing an identity fail
	// until it arrives, nothing blocks startup on it.
	CoreIdentitiesReady func() error
	ShardsConfig        *rest.Config
	// ServiceAccounts resolves service accounts and token secrets on the
	// shard hosting them, through the index, for service account
	// authentication.
	ServiceAccounts *ShardRoutedServiceAccounts
	// PeersConfig points at the Admin workspace (/services/admin) of the
	// peer shards with round-robin and per-request failover, and is the only
	// source for Shard discovery and the core identities.
	PeersConfig *rest.Config
	// Peers is the failover set behind PeersConfig: the configured seed
	// peers plus every discovered shard, fed at runtime from the shard
	// informer so discovery survives seed peers going away.
	Peers *Peers

	AuthenticationInfo    genericapiserver.AuthenticationInfo
	ServingInfo           *genericapiserver.SecureServingInfo
	AdditionalAuthEnabled bool
}

type Peers added in v0.34.0

type Peers struct {
	// contains filtered or unexported fields
}

Peers is the failover set of shard endpoints serving the Admin workspace. It consists of two tiers:

  • dynamic peers: every discovered shard (UpsertShard/RemoveShard). This is the primary tier and follows the observed shards, so decommissioned or moved shards stop receiving traffic.
  • seed peers: the endpoints from the peer kubeconfigs. They bootstrap discovery while no shard has been observed yet, and are a last-resort fallback when every dynamic peer fails (e.g. a fully stale dynamic set after a partition). They are never part of the round-robin ring while dynamic peers exist, so stale seeds do not attract traffic.

func NewPeersConfig added in v0.34.0

func NewPeersConfig(kubeconfigPaths []string) (*rest.Config, *Peers, error)

NewPeersConfig loads one or more peer kubeconfigs and returns a rest.Config that talks to the Admin workspace (/services/admin) of the peer shards, distributing requests round-robin and failing over between them, together with the Peers set for extending the peers at runtime with discovered shards.

Every named cluster across all kubeconfigs is a seed peer (duplicates by URL are collapsed), used until shards are discovered and as a fallback afterwards; the first kubeconfig's current context supplies credentials and TLS settings, which must be valid for all peers. Because all peers serve the identical, cache-backed view in a single resourceVersion space, failover is exact: a watch broken by a peer outage can resume against another peer with the same resourceVersion.

func (*Peers) RemoveShard added in v0.34.0

func (p *Peers) RemoveShard(name string)

RemoveShard drops the shard's endpoint from the dynamic peer set.

func (*Peers) UpsertShard added in v0.34.0

func (p *Peers) UpsertShard(name, endpoint string) error

UpsertShard adds or replaces the discovered shard's endpoint in the dynamic peer set. Endpoints with a path cannot be failover targets - the round tripper only swaps scheme and host - and are rejected.

type Server added in v0.9.0

type Server struct {
	CompletedConfig
	Handler                  http.Handler
	IndexController          *index.Controller
	AuthController           *authentication.Controller
	KcpSharedInformerFactory kcpinformers.SharedScopedInformerFactory
	// CoreIdentityInformerFactory watches the APIIdentity registry entries
	// owned by the root workspace's APIExports, through the Admin workspace
	// of the peers. Their identities are injected into wildcard requests.
	CoreIdentityInformerFactory kcpinformers.SharedScopedInformerFactory
}

func NewServer added in v0.9.0

func NewServer(ctx context.Context, c CompletedConfig) (*Server, error)

func (*Server) PrepareRun added in v0.9.0

func (s *Server) PrepareRun(ctx context.Context) (preparedServer, error)

type ShardRoutedServiceAccounts added in v0.34.0

type ShardRoutedServiceAccounts struct {
	// contains filtered or unexported fields
}

ShardRoutedServiceAccounts looks ServiceAccounts and their token Secrets up on the shard that hosts the logical cluster a service account token names, found through the proxy's index, using the shards credential. It is what lets the proxy validate service account tokens of workspaces on any shard without a connection to the root shard.

It serves two roles for the authenticator: the token getter, through Cluster, and the writer the legacy token validator stamps last-used annotations with, through SecretsWriter.

ServiceAccounts and Secrets are cached per logical cluster for shardlookup.DefaultSuccessTTL, failed lookups for DefaultFailureTTL, the same as the shards cache them for logical clusters on other shards. A deleted service account or token secret therefore keeps authenticating at the proxy for up to that long. Index misses are not cached: a cluster the index learns about is found on the next request.

func NewShardRoutedServiceAccounts added in v0.34.0

func NewShardRoutedServiceAccounts(shardsConfig *rest.Config) *ShardRoutedServiceAccounts

NewShardRoutedServiceAccounts creates the lookup over the shards credential. The index is attached with SetIndex once the index controller exists; lookups before that fail with ServiceUnavailable. Call Start to evict expired entries in the background.

func (*ShardRoutedServiceAccounts) Cluster added in v0.34.0

Cluster implements serviceaccount.ServiceAccountTokenClusterGetter.

func (*ShardRoutedServiceAccounts) SecretsWriter added in v0.34.0

SecretsWriter returns the secret client the legacy token validator writes through, routed the same way as the lookups.

func (*ShardRoutedServiceAccounts) SetIndex added in v0.34.0

func (s *ShardRoutedServiceAccounts) SetIndex(index shardIndex)

SetIndex attaches the index the lookups resolve shards through.

func (*ShardRoutedServiceAccounts) Start added in v0.34.0

Start evicts expired cache entries until ctx is done. Lookups do not depend on it; without it expired entries stay in memory until replaced.

Directories

Path Synopsis
Package authheaders contains helpers for stamping the request-header identity headers (X-Remote-User / X-Remote-Group / X-Remote-Extra-*) that kcp proxies use to forward an authenticated identity to a backend shard or virtual workspace.
Package authheaders contains helpers for stamping the request-header identity headers (X-Remote-User / X-Remote-Group / X-Remote-Extra-*) that kcp proxies use to forward an authenticated identity to a backend shard or virtual workspace.

Jump to

Keyboard shortcuts

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