Documentation
¶
Overview ¶
Package k8srelay is the in-cluster side of the Kubernetes relay: it decides which API requests may reach the API server, validates workload bodies, filters responses and enforces limits. It does no network setup of its own.
Index ¶
- Constants
- func FilterJSON(body []byte, forceSecret bool) ([]byte, error)
- func FilterText(s string) string
- func RenderManifest(in ManifestInput) (string, error)
- type Config
- type Decision
- type DenyError
- type Handler
- type Limits
- type ManifestInput
- type PodLimits
- type Policy
- type Target
- type TokenSource
Constants ¶
const AgentNamespace = "levelrail-agent"
AgentNamespace is where the cluster agent runs; it is the only namespace the manifest creates.
Variables ¶
This section is empty.
Functions ¶
func FilterJSON ¶
FilterJSON strips Secret data and redacts token-like fields from one JSON document. forceSecret treats the document as a Secret or SecretList even without a kind field. It fails closed: invalid JSON is an error.
func FilterText ¶
FilterText redacts token shapes from log output. This is best effort: it catches common shapes only and cannot promise logs hold no secrets.
func RenderManifest ¶
func RenderManifest(in ManifestInput) (string, error)
RenderManifest returns the multi-document YAML the operator applies with their own kubectl.
Types ¶
type Config ¶
type Config struct {
Namespaces []string // namespaces the relay may read and (with Writes) mutate
ClusterRead bool // opt-in read of nodes, namespaces and cluster-wide ingress lists
Writes bool // off means observe only
// Workload write scope. Zero values are the strictest setting.
ServiceAccount string // the only service account pods may name; empty refuses the field
AllowServiceAccountToken bool // permit automountServiceAccountToken=true
AllowedSecrets []string // secret names pods may reference
AllowDockerConfig bool // permit writing registry credential secrets
AllowServiceExposure bool // permit externalIPs, ExternalName, NodePort, LoadBalancer
IngressAnnotations []string // extra ingress annotations beyond the built-in list
}
Config scopes what the relay may touch. Everything not named here is denied.
func ConfigFromEnv ¶
ConfigFromEnv reads the scope flags the install manifest sets.
type Decision ¶
type Decision struct {
Target Target
Method string
Verb string
Write bool
Stream bool
Query url.Values // sanitized, safe to forward
}
Decision is what a permitted request looks like after normalization.
type DenyError ¶
type DenyError struct{ Rule string }
DenyError is returned for every refusal; Rule is a short stable code that callers may surface without echoing request content.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler enforces the policy and limits, forwards through an injected RoundTripper (the in-cluster client) and filters what comes back.
func NewHandler ¶
func NewHandler(p *Policy, upstream http.RoundTripper, token TokenSource, baseURL string) (*Handler, error)
NewHandler builds a handler. baseURL is the API server address the RoundTripper resolves, for example the in-cluster service URL.
type Limits ¶
type Limits struct {
MaxInflight int
MaxStreams int
BodyReadTimeout time.Duration
RPS float64
Burst int
MaxRequestBytes int64
MaxResponseBytes int64
RequestTimeout time.Duration
StreamIdleTimeout time.Duration
StreamMaxLifetime time.Duration
MaxLogTailLines int
MaxURLBytes int
MaxSelectorBytes int
MaxLineBytes int
Pod PodLimits
}
Limits holds every numeric threshold the relay applies. Logic reads these values only; DefaultLimits is the single place defaults live.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns the seed values that settings and env override.
func LimitsFromEnv ¶
LimitsFromEnv overlays APP_K8S_RELAY_* values on DefaultLimits. An unset or empty variable keeps the default; an unparsable or non-positive one is an error.
type ManifestInput ¶
type ManifestInput struct {
Cluster string
Image string // must be pinned by digest
ControlPlaneAddr string // host:port the agent dials
CAFingerprint string
JoinToken string
Config Config
}
ManifestInput is everything the install manifest needs. JoinToken is a one-time credential: callers print the manifest to the operator once and never log or store it.
func (ManifestInput) Validate ¶
func (in ManifestInput) Validate() error
Validate refuses anything that could widen scope or smuggle YAML.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy evaluates requests against a Config and Limits.
type Target ¶
type Target struct {
NonResource bool // /version, /readyz
Group string
Version string
Namespace string
Resource string
Name string
Subresource string
}
Target is a parsed, canonical API path.
type TokenSource ¶
TokenSource returns the current service account token. It is called per request so rotated projected tokens are picked up.