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

Add: network policies to create boundaries for proxies #8340

Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions k8s/dust-kube-private/apply_infra_dust-kube-private.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ echo "-----------------------------------"
echo "Applying network policies"
echo "-----------------------------------"

# kubectl apply -f "$(dirname "$0")/network-policies/allow-same-namespace.yaml"
# kubectl apply -f "$(dirname "$0")/network-policies/default-deny-ingress.yaml"
kubectl apply -f "$(dirname "$0")/network-policies/restrict-egress.yaml"
kubectl apply -f "$(dirname "$0")/network-policies/restrict-ingress.yaml"
12 changes: 10 additions & 2 deletions k8s/dust-kube-private/configmaps/proxy-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ data:
}

http {
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver 8.8.8.8 8.8.4.4 valid=300s ipv6=off;

resolver_timeout 5s;


proxy_bind 0.0.0.0; # Force IPv4

proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
keepalive_timeout 30s;

server {
listen 80;

Expand Down
11 changes: 0 additions & 11 deletions k8s/dust-kube-private/network-policies/allow-same-namespace.yaml

This file was deleted.

This file was deleted.

54 changes: 54 additions & 0 deletions k8s/dust-kube-private/network-policies/restrict-egress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: networking.k8s.io/v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMI, what does this do ? Why do we restrict the egress on the private cluster ?

kind: NetworkPolicy
metadata:
name: restrict-egress
namespace: default
spec:
podSelector: {} # Applies to all pods
policyTypes:
- Egress
egress:
# Internal cluster communication
- to:
- ipBlock:
cidr: 10.11.0.0/17 # VPC CIDR - adjust as needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh so to prevent re-entering the cluster ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to force everything to internet via the nat gateway and we only want to allow internal communication within the cluster (so you cannot access the public cluster via the private one).


# DNS resolution
- to:
- namespaceSelector: {}
- ipBlock:
cidr: 8.8.8.8/32 # Google DNS primary
- ipBlock:
cidr: 8.8.4.4/32 # Google DNS secondary
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53

# Kubernetes API access
- to:
- ipBlock:
cidr: 34.44.36.75/32 # Your control plane IP
ports:
- port: 443
- port: 6443

# Allow metadata access for Cloud NAT
- to:
- ipBlock:
cidr: 169.254.169.254/32 # GCP metadata server
ports:
- protocol: TCP
port: 80

# Allow external internet access through Cloud NAT
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8 # RFC1918 private ranges
- 172.16.0.0/12
- 192.168.0.0/16
- 169.254.0.0/16 # Link local

37 changes: 37 additions & 0 deletions k8s/dust-kube-private/network-policies/restrict-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: restrict-ingress
namespace: default
spec:
podSelector: {} # Applies to all pods
policyTypes:
- Ingress
ingress:
# Allow specific ports for external access
- ports:
- protocol: TCP
port: 80
- protocol: TCP
port: 1080

# Kubernetes API Server access
- from:
- ipBlock:
cidr: 134.44.36.75/32 # Your control plane IP
ports:
- port: 10250 # kubelet metrics
- port: 9153 # kube-dns metrics
- port: 443 # kubernetes API server

# Datadog Agent communication
- from:
- podSelector:
matchLabels:
name: datadog-agent

ports:
- port: 10250 # kubelet
- port: 4194 # cadvisor
- port: 8125 # dogstatsd
- port: 8126 # trace agent
Loading