-
Notifications
You must be signed in to change notification settings - Fork 54
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
228 additions
and
246 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,46 @@ | ||
#!/bin/sh | ||
|
||
signaled() { | ||
exit 143 | ||
} | ||
|
||
trap signaled INT TERM | ||
|
||
all_ips() { | ||
kubectl get pods "${VPN_FRONTEND_POD}" -o go-template --template '{{ range .status.podIPs }}{{ printf "%s " .ip }}{{ end }}' | ||
echo "${VPN_PEER_CIDRS}" | ||
} | ||
|
||
cep_patch() { | ||
for ip in $(all_ips); do printf '{"ipv4": "%s"}' "${ip}"; done | jq -s -c -j | | ||
jq '[{op: "replace", path: "/status/networking/addressing", value: . }]' | ||
} | ||
|
||
# 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_POD}" --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,44 @@ | ||
#!/bin/sh | ||
|
||
set -u | ||
|
||
if [ "$$" -eq "1" ]; then | ||
echo 'This script must run in the root PID namespace, but $$ == 1!' >&2 | ||
exit 1 | ||
fi | ||
|
||
myip() { | ||
ip -j addr show eth0 | jq -r '.[0].addr_info[] | select(.family == "inet") | .local' | ||
} | ||
|
||
# Disable source IP verification on our network interface. Otherwise, VPN | ||
# packets will be dropped by Cilium. | ||
reconcile_sip_verification() { | ||
# We want all of the cilium calls in this function to target the same | ||
# process, so that we fail if the agent restarts in between. Thus, we only | ||
# query the pid once per reconciliation. | ||
cilium_agent=$(pidof cilium-agent) || return 0 | ||
|
||
cilium() { | ||
nsenter -t "${cilium_agent}" -a -r -w cilium "$@" | ||
} | ||
|
||
myendpoint=$(cilium endpoint get "ipv4:$(myip)" | jq '.[0].id') || return 0 | ||
|
||
if [ "$(cilium endpoint config "${myendpoint}" -o json | jq -r .realized.options.SourceIPVerification)" = "Enabled" ]; then | ||
cilium endpoint config "${myendpoint}" SourceIPVerification=Disabled | ||
fi | ||
} | ||
|
||
# Set up the route from the node network namespace to the VPN pod. | ||
reconcile_route() { | ||
for cidr in ${VPN_PEER_CIDRS}; do | ||
nsenter -t 1 -n ip route replace "${cidr}" via "$(myip)" | ||
done | ||
} | ||
|
||
while true; do | ||
reconcile_route | ||
reconcile_sip_verification | ||
sleep 10 | ||
done |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "..fullname" . }}-tproxy | ||
name: {{ include "..fullname" . }}-operator | ||
labels: {{- include "..labels" . | nindent 4 }} | ||
data: | ||
{{ (.Files.Glob "files/tproxy-setup.sh").AsConfig | indent 2 }} | ||
{{ (.Files.Glob "files/operator/*").AsConfig | indent 2 }} | ||
--- | ||
{{- if .Values.wireguard.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "..fullname" . }}-wg | ||
labels: {{- include "..labels" . | nindent 4 }} | ||
data: | ||
{{ (.Files.Glob "files/wireguard-setup.sh").AsConfig | indent 2 }} | ||
{{- end }} | ||
--- | ||
{{ if .Values.ipsec.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "..fullname" . }}-strongswan | ||
labels: {{- include "..labels" . | nindent 4 }} | ||
data: | ||
{{ (.Files.Glob "files/strongswan/*").AsConfig | indent 2 }} | ||
{{- end }} |
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: ["sh", "/scripts/entrypoint.sh"] | ||
env: {{- include "..commonEnv" . | nindent 10 }} | ||
volumeMounts: | ||
- name: scripts | ||
mountPath: "/scripts" | ||
readOnly: true | ||
volumes: | ||
- name: scripts | ||
configMap: | ||
name: {{ include "..fullname" . }}-operator |
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
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.