You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The README now has an example for a DenyDefaultLoadBalancerSourceRanges that denies implicitly set loadBalancerSourceRanges fields - e.g.
// DenyDefaultLoadBalancerSourceRanges denies any kind: Service of type:// LoadBalancer that does not explicitly set .spec.loadBalancerSourceRanges -// which defaults to 0.0.0.0/0 (e.g. Internet traffic, if routable).//// This prevents LoadBalancers from being accidentally exposed to the Internet.funcDenyDefaultLoadBalancerSourceRanges() AdmitFunc {
// Return a function of type AdmitFuncreturnfunc(admissionReview*admission.AdmissionReview) (*admission.AdmissionResponse, error) {
kind:=admissionReview.Request.Kind.Kind// Create an *admission.AdmissionResponse that denies by default.resp:=newDefaultDenyResponse()
// Create an object to deserialize our requests' object intoservice:= core.Service{}
deserializer:=serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer()
if_, _, err:=deserializer.Decode(admissionReview.Request.Object.Raw, nil, &service); err!=nil {
returnnil, err
}
// Allow non-LoadBalancer Services to pass through.ifservice.Spec.Type!="LoadBalancer" {
resp.Allowed=trueresp.Result.Message=fmt.Sprintf(
"received a non-LoadBalancer type (%s)",
service.Spec.Type,
)
returnresp, nil
}
// Inspect the service.Spec.LoadBalancerSourceRanges field// If unset, reject it.// Returning an error from an AdmitFunc will automatically deny admission of that requests' object.ifservice.Spec.LoadBalancerSourceRanges==nil {
returnresp, fmt.Errorf("LoadBalancers without explicitly configured LoadBalancerSourceRanges are not allowed.")
}
// Set resp.Allowed to true before returning your AdmissionResponseresp.Allowed=truereturnresp, nil
}
}
We should provide a real version of this, and consider:
supporting the ability to outright deny the 0.0.0.0/0 range
rejecting cases where the user did not provide explicit ranges - which allows 0.0.0.0/0 as per the docs
Note: If .spec.loadBalancerSourceRanges is not set, Kubernetes allows traffic from 0.0.0.0/0 to the Node Security Group(s). If nodes have public IP addresses, be aware that non-NLB traffic can also reach all instances in those modified security groups.
The README now has an example for a
DenyDefaultLoadBalancerSourceRanges
that denies implicitly setloadBalancerSourceRanges
fields - e.g.We should provide a real version of this, and consider:
Possible API:
Docs:
The text was updated successfully, but these errors were encountered: