Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set IP whitelist for passthrough routes #20

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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