@@ -14,27 +14,27 @@ if [ ! -f "${SA_DIR}/token" ]; then
14
14
fi
15
15
16
16
# Remove the old chains, to generate new configs.
17
- iptables -t nat -D PREROUTING -p tcp -j ctrlmesh_PROXY_INBOUND 2> /dev/null
18
- iptables -t mangle -D PREROUTING -p tcp -j ctrlmesh_PROXY_INBOUND 2> /dev/null
19
- iptables -t nat -D OUTPUT -p tcp -j ctrlmesh_PROXY_OUTPUT 2> /dev/null
17
+ iptables -t nat -D PREROUTING -p tcp -j CTRLMESH_INBOUND 2> /dev/null
18
+ iptables -t mangle -D PREROUTING -p tcp -j CTRLMESH_INBOUND 2> /dev/null
19
+ iptables -t nat -D OUTPUT -p tcp -j CTRLMESH_OUTPUT 2> /dev/null
20
20
21
21
# Flush and delete the ctrlmesh chains.
22
- iptables -t nat -F ctrlmesh_PROXY_OUTPUT 2> /dev/null
23
- iptables -t nat -X ctrlmesh_PROXY_OUTPUT 2> /dev/null
24
- iptables -t nat -F ctrlmesh_PROXY_INBOUND 2> /dev/null
25
- iptables -t nat -X ctrlmesh_PROXY_INBOUND 2> /dev/null
26
- iptables -t mangle -F ctrlmesh_PROXY_INBOUND 2> /dev/null
27
- iptables -t mangle -X ctrlmesh_PROXY_INBOUND 2> /dev/null
28
- iptables -t mangle -F ctrlmesh_PROXY_DIVERT 2> /dev/null
29
- iptables -t mangle -X ctrlmesh_PROXY_DIVERT 2> /dev/null
30
- iptables -t mangle -F ctrlmesh_PROXY_TPROXY 2> /dev/null
31
- iptables -t mangle -X ctrlmesh_PROXY_TPROXY 2> /dev/null
22
+ iptables -t nat -F CTRLMESH_OUTPUT 2> /dev/null
23
+ iptables -t nat -X CTRLMESH_OUTPUT 2> /dev/null
24
+ iptables -t nat -F CTRLMESH_INBOUND 2> /dev/null
25
+ iptables -t nat -X CTRLMESH_INBOUND 2> /dev/null
26
+ iptables -t mangle -F CTRLMESH_INBOUND 2> /dev/null
27
+ iptables -t mangle -X CTRLMESH_INBOUND 2> /dev/null
28
+ iptables -t mangle -F CTRLMESH_DIVERT 2> /dev/null
29
+ iptables -t mangle -X CTRLMESH_DIVERT 2> /dev/null
30
+ iptables -t mangle -F CTRLMESH_TPROXY 2> /dev/null
31
+ iptables -t mangle -X CTRLMESH_TPROXY 2> /dev/null
32
32
33
33
# Must be last, the others refer to it
34
- iptables -t nat -F ctrlmesh_PROXY_REDIRECT 2> /dev/null
35
- iptables -t nat -X ctrlmesh_PROXY_REDIRECT 2> /dev/null
36
- iptables -t nat -F ctrlmesh_PROXY_IN_REDIRECT 2> /dev/null
37
- iptables -t nat -X ctrlmesh_PROXY_IN_REDIRECT 2> /dev/null
34
+ iptables -t nat -F CTRLMESH_REDIRECT 2> /dev/null
35
+ iptables -t nat -X CTRLMESH_REDIRECT 2> /dev/null
36
+ iptables -t nat -F CTRLMESH_IN_REDIRECT 2> /dev/null
37
+ iptables -t nat -X CTRLMESH_IN_REDIRECT 2> /dev/null
38
38
39
39
if [ " ${1:- } " = " clean" ]; then
40
40
echo " Only cleaning, no new rules added"
@@ -70,13 +70,13 @@ set -o pipefail
70
70
set -x # echo on
71
71
72
72
# Create a new chain for redirecting outbound traffic to the apiserver port.
73
- # In both chains, '-j RETURN' bypasses Proxy and '-j ctrlmesh_PROXY_REDIRECT ' redirects to Proxy.
74
- iptables -t nat -N ctrlmesh_PROXY_REDIRECT
75
- iptables -t nat -A ctrlmesh_PROXY_REDIRECT -p tcp -j REDIRECT --to-port " ${PROXY_APISERVER_PORT} "
73
+ # In both chains, '-j RETURN' bypasses Proxy and '-j CTRLMESH_REDIRECT ' redirects to Proxy.
74
+ iptables -t nat -N CTRLMESH_REDIRECT
75
+ iptables -t nat -A CTRLMESH_REDIRECT -p tcp -j REDIRECT --to-port " ${PROXY_APISERVER_PORT} "
76
76
77
77
# Use this chain also for redirecting inbound traffic to the webhook port when not using TPROXY.
78
- iptables -t nat -N ctrlmesh_PROXY_IN_REDIRECT
79
- iptables -t nat -A ctrlmesh_PROXY_IN_REDIRECT -p tcp -j REDIRECT --to-port " ${PROXY_WEBHOOK_PORT} "
78
+ iptables -t nat -N CTRLMESH_IN_REDIRECT
79
+ iptables -t nat -A CTRLMESH_IN_REDIRECT -p tcp -j REDIRECT --to-port " ${PROXY_WEBHOOK_PORT} "
80
80
81
81
# Handling of inbound ports. Traffic will be redirected to Proxy, which will process and forward
82
82
# to the local webhook. If not set, no inbound port will be intercepted by the iptables.
@@ -85,56 +85,56 @@ if [ -n "${INBOUND_WEBHOOK_PORT}" ]; then
85
85
# When using TPROXY, create a new chain for routing all inbound traffic to
86
86
# Proxy. Any packet entering this chain gets marked with the ${INBOUND_TPROXY_MARK} mark,
87
87
# so that they get routed to the loopback interface in order to get redirected to Proxy.
88
- # In the ctrlmesh_PROXY_INBOUND chain, '-j ctrlmesh_PROXY_DIVERT ' reroutes to the loopback
88
+ # In the CTRLMESH_INBOUND chain, '-j CTRLMESH_DIVERT ' reroutes to the loopback
89
89
# interface.
90
90
# Mark all inbound packets.
91
- iptables -t mangle -N ctrlmesh_PROXY_DIVERT
92
- iptables -t mangle -A ctrlmesh_PROXY_DIVERT -j MARK --set-mark " ${INBOUND_TPROXY_MARK} "
93
- iptables -t mangle -A ctrlmesh_PROXY_DIVERT -j ACCEPT
91
+ iptables -t mangle -N CTRLMESH_DIVERT
92
+ iptables -t mangle -A CTRLMESH_DIVERT -j MARK --set-mark " ${INBOUND_TPROXY_MARK} "
93
+ iptables -t mangle -A CTRLMESH_DIVERT -j ACCEPT
94
94
95
- # Route all packets marked in chain ctrlmesh_PROXY_DIVERT using routing table ${INBOUND_TPROXY_ROUTE_TABLE}.
95
+ # Route all packets marked in chain CTRLMESH_DIVERT using routing table ${INBOUND_TPROXY_ROUTE_TABLE}.
96
96
ip -f inet rule add fwmark " ${INBOUND_TPROXY_MARK} " lookup " ${INBOUND_TPROXY_ROUTE_TABLE} "
97
97
# In routing table ${INBOUND_TPROXY_ROUTE_TABLE}, create a single default rule to route all traffic to
98
98
# the loopback interface.
99
99
ip -f inet route add local default dev lo table " ${INBOUND_TPROXY_ROUTE_TABLE} " || ip route show table all
100
100
101
101
# Create a new chain for redirecting inbound traffic to the common Envoy
102
102
# port.
103
- # In the ctrlmesh_PROXY_INBOUND chain, '-j RETURN' bypasses Envoy and
104
- # '-j ctrlmesh_PROXY_TPROXY ' redirects to Envoy.
105
- iptables -t mangle -N ctrlmesh_PROXY_TPROXY
106
- iptables -t mangle -A ctrlmesh_PROXY_TPROXY ! -d 127.0.0.1/32 -p tcp -j TPROXY --tproxy-mark " ${INBOUND_TPROXY_MARK} " /0xffffffff --on-port " ${PROXY_PORT} "
103
+ # In the CTRLMESH_INBOUND chain, '-j RETURN' bypasses Envoy and
104
+ # '-j CTRLMESH_TPROXY ' redirects to Envoy.
105
+ iptables -t mangle -N CTRLMESH_TPROXY
106
+ iptables -t mangle -A CTRLMESH_TPROXY ! -d 127.0.0.1/32 -p tcp -j TPROXY --tproxy-mark " ${INBOUND_TPROXY_MARK} " /0xffffffff --on-port " ${PROXY_PORT} "
107
107
108
108
table=mangle
109
109
else
110
110
table=nat
111
111
fi
112
- iptables -t " ${table} " -N ctrlmesh_PROXY_INBOUND
113
- iptables -t " ${table} " -A PREROUTING -p tcp -j ctrlmesh_PROXY_INBOUND
112
+ iptables -t " ${table} " -N CTRLMESH_INBOUND
113
+ iptables -t " ${table} " -A PREROUTING -p tcp -j CTRLMESH_INBOUND
114
114
115
115
if [ " ${INBOUND_INTERCEPTION_MODE} " = " TPROXY" ]; then
116
- iptables -t mangle -A ctrlmesh_PROXY_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -m socket -j ctrlmesh_PROXY_DIVERT || echo " No socket match support"
117
- iptables -t mangle -A ctrlmesh_PROXY_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -m socket -j ctrlmesh_PROXY_DIVERT || echo " No socket match support"
118
- iptables -t mangle -A ctrlmesh_PROXY_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -j ctrlmesh_PROXY_TPROXY
116
+ iptables -t mangle -A CTRLMESH_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -m socket -j CTRLMESH_DIVERT || echo " No socket match support"
117
+ iptables -t mangle -A CTRLMESH_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -m socket -j CTRLMESH_DIVERT || echo " No socket match support"
118
+ iptables -t mangle -A CTRLMESH_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -j CTRLMESH_TPROXY
119
119
else
120
- iptables -t nat -A ctrlmesh_PROXY_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -j ctrlmesh_PROXY_IN_REDIRECT
120
+ iptables -t nat -A CTRLMESH_INBOUND -p tcp --dport " ${INBOUND_WEBHOOK_PORT} " -j CTRLMESH_IN_REDIRECT
121
121
fi
122
122
fi
123
123
124
124
# Create a new chain for selectively redirecting outbound packets to Proxy.
125
- iptables -t nat -N ctrlmesh_PROXY_OUTPUT
125
+ iptables -t nat -N CTRLMESH_OUTPUT
126
126
127
- # Jump to the ctrlmesh_PROXY_OUTPUT chain from OUTPUT chain for all tcp traffic.
128
- iptables -t nat -A OUTPUT -p tcp -j ctrlmesh_PROXY_OUTPUT
127
+ # Jump to the CTRLMESH_OUTPUT chain from OUTPUT chain for all tcp traffic.
128
+ iptables -t nat -A OUTPUT -p tcp -j CTRLMESH_OUTPUT
129
129
130
130
for uid in ${PROXY_UID} ; do
131
131
# Avoid infinite loops. Don't redirect Proxy traffic directly back to
132
132
# Proxy for non-loopback traffic.
133
- iptables -t nat -A ctrlmesh_PROXY_OUTPUT -m owner --uid-owner " ${uid} " -j RETURN
133
+ iptables -t nat -A CTRLMESH_OUTPUT -m owner --uid-owner " ${uid} " -j RETURN
134
134
done
135
135
136
136
# Redirect all apiserver outbound traffic to Proxy.
137
- iptables -t nat -A ctrlmesh_PROXY_OUTPUT -d " ${KUBERNETES_SERVICE_HOST} " -j ctrlmesh_PROXY_REDIRECT
137
+ iptables -t nat -A CTRLMESH_OUTPUT -d " ${KUBERNETES_SERVICE_HOST} " -j CTRLMESH_REDIRECT
138
138
139
139
# Generate certs
140
140
mount -o remount,rw " ${SA_DIR} "
0 commit comments