-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev-docs: full L3 connectivity in VPN chart
- Loading branch information
Showing
15 changed files
with
296 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
# TODO: this needs to be determined from Helm values! | ||
vpn_frontend=vpn-frontend-0 | ||
|
||
all_ips() { | ||
kubectl get pods "${vpn_frontend}" -o go-template --template '{{ range .status.podIPs }}{{ printf "%s " .ip }}{{ end }}' | ||
echo "${VPN_PEER_CIDRS}" | ||
} | ||
|
||
cep_patch() { | ||
printf '[{"op": "replace", "path": "/status/networking/addressing", "value": ' | ||
for ip in $(all_ips); do printf '{"ipv4": "%s"}' "${ip}"; done | jq -s -c -j | ||
echo '}]' | ||
} | ||
|
||
# Format the space-separated CIDRs into a JSON array. | ||
vpn_cidrs=$(for ip in ${VPN_PEER_CIDRS}; do printf '"%s" ' "${ip}"; done | jq -s -c -j) | ||
|
||
masq_patch() { | ||
kubectl -n kube-system get configmap ip-masq-agent -o json | | ||
jq -r .data.config | | ||
jq "{ masqLinkLocal: .masqLinkLocal, nonMasqueradeCIDRs: ((.nonMasqueradeCIDRs - ${vpn_cidrs}) + ${vpn_cidrs}) }" | | ||
jq '@json | [{op: "replace", path: "/data/config", value: . }]' | ||
} | ||
|
||
reconcile_masq() { | ||
if ! kubectl -n kube-system get configmap ip-masq-agent > /dev/null; then | ||
# We don't know enough to create an ip-masq-agent. | ||
return 0 | ||
fi | ||
|
||
kubectl -n kube-system patch configmap ip-masq-agent --type json --patch "$(masq_patch)" > /dev/null | ||
} | ||
|
||
while true; do | ||
# Reconcile CiliumEndpoint to advertise VPN CIDRs. | ||
kubectl patch ciliumendpoint "${vpn_frontend}" --type json --patch "$(cep_patch)" > /dev/null | ||
|
||
# Reconcile ip-masq-agent configuration to exclude VPN traffic. | ||
reconcile_masq | ||
|
||
sleep 10 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
if [ "$$" -eq "1" ]; then | ||
echo 'This script must run in the root PID namespace, but $$ == 1!' >&2 | ||
exit 1 | ||
fi | ||
|
||
# Set up routes for VPN traffic. Inside our netns, point to the VPN interface. | ||
# In the host network namespace, point to the pod interface. | ||
|
||
for cidr in ${VPN_PEER_CIDRS}; do | ||
ip route replace "${cidr}" dev "${VPN_INTERFACE}" | ||
done | ||
|
||
rm -f /var/run/netns/root | ||
ip netns attach root 1 | ||
|
||
ip_root() { | ||
ip netns exec root ip "$@" | ||
} | ||
|
||
lower_interface_id=$(ip -j l show eth0 | jq '.[0].link_index') | ||
lower_interface=$(ip_root -j link show | jq -r ".[] | select(.ifindex == ${lower_interface_id}) | .ifname") | ||
|
||
myip=$(ip -j addr show eth0 | jq -r '.[0].addr_info[] | select(.family == "inet") | .local') | ||
for cidr in ${VPN_PEER_CIDRS}; do | ||
ip_root route replace "${cidr}" via "${myip}" dev "${lower_interface}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
|
||
# Disable source IP verification on our network interface. Otherwise, VPN | ||
# packets will be dropped by Cilium. | ||
|
||
reconcile_sip_verification() { | ||
|
||
# Disable source IP verification on our network interface. Otherwise, VPN | ||
# packets will be dropped by Cilium. | ||
|
||
cilium_agent=$(pidof cilium-agent) | ||
myip=$(ip -j addr show eth0 | jq -r '.[0].addr_info[] | select(.family == "inet") | .local') | ||
|
||
cilium() { | ||
nsenter -t "${cilium_agent}" -a -r -w cilium "$@" | ||
} | ||
|
||
myendpoint=$(cilium endpoint get "ipv4:${myip}" | jq '.[0].id') | ||
|
||
if [ "$(cilium endpoint config "${myendpoint}" -o json | jq -r .realized.options.SourceIPVerification)" = "Enabled" ]; then | ||
cilium endpoint config "${myendpoint}" SourceIPVerification=Disabled | ||
fi | ||
|
||
} | ||
|
||
while true; do | ||
reconcile_sip_verification | ||
sleep 10 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
ip link add dev "${VPN_INTERFACE}" type xfrm dev eth0 if_id 0xfe | ||
ip link set dev "${VPN_INTERFACE}" up |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dev-docs/howto/vpn/helm/templates/operator-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "..fullname" . }}-operator | ||
labels: {{- include "..labels" . | nindent 4 }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
{{- include "..selectorLabels" . | nindent 6 }} | ||
component: operator | ||
template: | ||
metadata: | ||
labels: | ||
{{- include "..selectorLabels" . | nindent 8 }} | ||
component: operator | ||
spec: | ||
serviceAccountName: {{ include "..fullname" . }} | ||
automountServiceAccountToken: true | ||
containers: | ||
- name: operator | ||
image: {{ .Values.image | quote }} | ||
command: ["/bin/sh", "/scripts/operator.sh"] | ||
env: {{- include "..commonEnv" . | nindent 10 }} | ||
volumeMounts: | ||
- name: scripts | ||
mountPath: "/scripts" | ||
readOnly: true | ||
volumes: | ||
- name: scripts | ||
configMap: | ||
name: {{ include "..fullname" . }}-scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ include "..fullname" . }} | ||
automountServiceAccountToken: false | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: {{ include "..fullname" . }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods"] | ||
verbs: ["get"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["get", "patch"] | ||
- apiGroups: ["cilium.io"] | ||
resources: ["ciliumendpoints"] | ||
verbs: ["get", "patch"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: {{ include "..fullname" . }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ include "..fullname" . }} | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
kind: ClusterRole | ||
name: {{ include "..fullname" . }} | ||
apiGroup: rbac.authorization.k8s.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.