Documentation
¶
Index ¶
- Constants
- Variables
- func AddNAT64Prefix(cidr string) error
- func CheckBounds() error
- func DefaultTimeout() time.Duration
- func LoadConfigMaps(ctx context.Context, c client.Reader, templateName, namespace string) error
- func ReadResponseBody(r io.Reader) ([]byte, error)
- func RequestTimeout(s string) (time.Duration, error)
- func SecureTransport(base *http.Transport, policy Policy) *http.Transport
- func SetDenyFragment(fragment Policy)
- func SetEnhancer(fn PolicyEnhancer)
- func SetupWatcher(mgr manager.Manager, templateName, namespace string) error
- type Policy
- type PolicyEnhancer
Constants ¶
const ( // ConfigMapKeyDenyCIDRs is the ConfigMap data key for CIDR/IP denylist lines. ConfigMapKeyDenyCIDRs = "denyCIDRs" // ConfigMapKeyDenyHosts is the ConfigMap data key for hostname denylist lines. ConfigMapKeyDenyHosts = "denyHosts" )
const ( // ConfigTemplateLabel identifies the ConfigTemplate that produced a config. ConfigTemplateLabel = "config.oam.dev/type" // WorkflowHTTPDenyConfigTemplate is the vela-workflow chart ConfigTemplate // name and discovery label value (config.oam.dev/type). vela-core uses its // own prefixed default (vela-core-http-deny) so dual install has no shared // Helm-owned ConfigTemplate. WorkflowHTTPDenyConfigTemplate = "vela-workflow-http-deny" )
Variables ¶
var ( // DefaultRequestTimeout is the timeout of a request that sets none, capped at // MaxRequestTimeout; DefaultTimeout applies the cap. DefaultRequestTimeout = 3 * time.Second // MaxRequestTimeout is the longest timeout a request may set. MaxRequestTimeout = 60 * time.Second // MaxResponseBytes is the largest response body a request may read, bounding what the // controller holds in memory. A body within it can still be too large for the step's context // ConfigMap once its other variables are added, and fails the step when the context is saved. MaxResponseBytes int64 = 1 << 20 )
A workflow HTTP request runs inside a reconcile and holds one of the controller's few reconcile workers until it returns, so its duration and response size are bounded.
var NAT64Prefixes = []*net.IPNet{ {IP: net.ParseIP("64:ff9b::"), Mask: net.CIDRMask(96, 128)}, {IP: net.ParseIP("64:ff9b:1::"), Mask: net.CIDRMask(48, 128)}, }
NAT64Prefixes are the NAT64 prefixes whose addresses are judged by the IPv4 address they carry: the well-known prefix (RFC 6052) and the local-use prefix (RFC 8215) by default, and any network-specific prefix added with AddNAT64Prefix.
Functions ¶
func AddNAT64Prefix ¶
AddNAT64Prefix adds a network-specific NAT64 prefix, of a length RFC 6052 allows.
func CheckBounds ¶
func CheckBounds() error
CheckBounds refuses bounds a request could never meet, as the controller's flags set them.
func DefaultTimeout ¶
DefaultTimeout is the timeout of a request that sets none: DefaultRequestTimeout, or MaxRequestTimeout when that is lower.
func LoadConfigMaps ¶
LoadConfigMaps discovers ConfigMaps produced by templateName and atomically installs the union of all deny entries on top of BuiltinDeny. Zero discovered labeled ConfigMaps is allowed and leaves only the builtin floor in effect.
func ReadResponseBody ¶
ReadResponseBody reads a response body of at most MaxResponseBytes, and fails on a longer one rather than truncate it.
func RequestTimeout ¶
RequestTimeout parses a request's timeout. Empty means DefaultTimeout; zero, negative and anything over MaxRequestTimeout are refused rather than taken as unbounded or clamped.
func SecureTransport ¶
SecureTransport returns a copy of base with dial-time SSRF validation applied. Every connection, including redirect follows, re-enters the dial hook. Proxy settings and any DialTLS or DialTLSContext hook on base are dropped: the TLS handshake runs over the guarded DialContext.
func SetDenyFragment ¶
func SetDenyFragment(fragment Policy)
SetDenyFragment atomically replaces the denylist overlay.
func SetEnhancer ¶
func SetEnhancer(fn PolicyEnhancer)
SetEnhancer registers a hook applied on every Current() call.
func SetupWatcher ¶
SetupWatcher watches the template's ConfigMaps in the controller namespace with an informer scoped to that namespace and label, so the controller does not cache every ConfigMap in the cluster. Reloads read through the API reader. After startup, reload failures keep the last good aggregate.
Types ¶
type Policy ¶
type Policy struct {
// BlockPrivate denies RFC-1918 and RFC-4193 ULA ranges. Off by default
// because workflow HTTP steps legitimately call in-cluster ClusterIP services.
BlockPrivate bool
// BlockLoopback denies 127.0.0.0/8 and ::1. Off by default.
BlockLoopback bool
// DenyCIDRs blocks any destination IP contained in these networks.
DenyCIDRs []*net.IPNet
ExactIPs []net.IP
// ExactHosts are lower-case hostnames that must be rejected.
ExactHosts map[string]struct{}
// WildcardSuffixes are lower-case DNS suffixes without the leading "*."
// (for example "corp.internal" from "*.corp.internal").
WildcardSuffixes []string
}
Policy controls which destination hosts and IPs outbound HTTP clients may connect to. Host checks run on the URL before dial; IP checks run at dial time on the resolved address.
func BuiltinDeny ¶
func BuiltinDeny() Policy
BuiltinDeny returns a copy of the immutable denylist floor shipped with the binary. Cluster ConfigMaps can only add denies; they cannot remove these entries. Callers must not rely on mutating the returned Policy.
func Current ¶
func Current() Policy
Current returns DefaultPolicy, then enhancer, then the immutable builtin denylist floor, then any discovered ConfigMap deny overlay.
func DefaultPolicy ¶
func DefaultPolicy() Policy
DefaultPolicy returns the base outbound HTTP policy. Destination deny rules are supplied by discovered workflow HTTP deny ConfigMaps.
func ParseConfigMap ¶
ParseConfigMap builds a denylist Policy fragment from a ConfigMap.
func ParseDenyList ¶
ParseDenyList parses denyCIDRs and denyHosts text blobs into a Policy fragment that only carries denylist fields. Blank lines and # comments are ignored.
func (Policy) Blocked ¶
Blocked reports whether ip must be rejected under policy. A NAT64 address is also rejected when the IPv4 address it carries is, because the gateway connects to that address.
func (Policy) BlockedAddress ¶
BlockedAddress parses host:port from a dial address and reports whether it is blocked. Non-IP hosts are allowed through; host denylist must be checked separately via BlockedHost before dial.
func (Policy) BlockedHost ¶
BlockedHost reports whether hostname must be rejected under the denylist. Host may include a port; IP literals are checked against ExactIPs/DenyCIDRs.
type PolicyEnhancer ¶
PolicyEnhancer optionally mutates base policy (for example enabling BlockPrivate from a feature gate) before denylist merge.