Skip to content

Commit

Permalink
set ip whitelist for passthrough routes (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealak12 authored Jan 11, 2024
1 parent 3ac43ae commit 50a270a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/controller/route/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (r *Reconciler) assembleHttpproxy(ctx context.Context, owner *routev1.Route
// use `tcpproxy` for passthrough mode and `routes` for other termination modes
if owner.Spec.TLS != nil && owner.Spec.TLS.Termination == routev1.TLSTerminationPassthrough {
httpproxy.Spec.TCPProxy = &contourv1.TCPProxy{}
var ipWhiteList []contourv1.IPFilterPolicy
for _, sameRoute := range sameHostRoutes {
ports, err := r.getTargetPorts(ctx, &sameRoute)
// Continue if unable to fetch TargetPorts of the route.
Expand All @@ -362,6 +363,11 @@ func (r *Reconciler) assembleHttpproxy(ctx context.Context, owner *routev1.Route
continue
}

routeIpWhitelist := utils.GetIPWhitelist(&sameRoute)
if len(routeIpWhitelist) > 0 {
ipWhiteList = append(ipWhiteList, routeIpWhitelist...)
}

for _, port := range ports {
svc := contourv1.Service{
Name: sameRoute.Spec.To.Name,
Expand All @@ -371,6 +377,9 @@ func (r *Reconciler) assembleHttpproxy(ctx context.Context, owner *routev1.Route
httpproxy.Spec.TCPProxy.Services = append(httpproxy.Spec.TCPProxy.Services, svc)
}
}
if len(ipWhiteList) > 0 {
httpproxy.Spec.VirtualHost.IPAllowFilterPolicy = ipWhiteList
}
if len(httpproxy.Spec.TCPProxy.Services) == 0 {
return nil, fmt.Errorf("no valid routes found")
}
Expand Down

0 comments on commit 50a270a

Please sign in to comment.