Authorization for TCP traffic
This task shows you how to set up Istio authorization for TCP traffic in an Istio mesh.
Before you begin
Before you begin this task, do the following:
Read the Istio authorization concepts.
Install Istio using the Istio installation guide2.
Deploy two workloads named
sleep
andtcp-echo
together in a namespace, for examplefoo
. Both workloads run with an Envoy proxy in front of each. Thetcp-echo
workload listens on port 9000, 9001 and 9002 and echoes back any traffic it received with a prefixhello
. For example, if you send “world” totcp-echo
, it will reply withhello world
. Thetcp-echo
Kubernetes service object only declares the ports 9000 and 9001, and omits the port 9002. A pass-through filter chain will handle port 9002 traffic. Deploy the example namespace and workloads using the following command:Verify that
sleep
successfully communicates withtcp-echo
on ports 9000 and 9001 using the following command:Verify that
sleep
successfully communicates withtcp-echo
on port 9002. You need to send the traffic directly to the pod IP oftcp-echo
because the port 9002 is not defined in the Kubernetes service object oftcp-echo
. Get the pod IP address and send the request with the following command:
Configure access control for a TCP workload
Create the
tcp-policy
authorization policy for thetcp-echo
workload in thefoo
namespace. Run the following command to apply the policy to allow requests to port 9000 and 9001:Verify that requests to port 9000 are allowed using the following command:
Verify that requests to port 9001 are allowed using the following command:
Verify that requests to port 9002 are denied. This is enforced by the authorization policy which also applies to the pass through filter chain, even if the port is not declared explicitly in the
tcp-echo
Kubernetes service object. Run the following command and verify the output:Update the policy to add an HTTP-only field named
methods
for port 9000 using the following command:Verify that requests to port 9000 are denied. This occurs because the rule becomes invalid when it uses an HTTP-only field (
methods
) for TCP traffic. Istio ignores the invalid ALLOW rule. The final result is that the request is rejected, because it does not match any ALLOW rules. Run the following command and verify the output:Verify that requests to port 9001 are denied. This occurs because the requests do not match any ALLOW rules. Run the following command and verify the output:
Update the policy to a DENY policy using the following command:
Verify that requests to port 9000 are denied. This occurs because Istio ignores the HTTP-only fields in an invalid DENY rule. This is different from an invalid ALLOW rule, which causes Istio to ignore the entire rule. The final result is that only the
ports
field is used by Istio and the requests are denied because they match with theports
:Verify that requests to port 9001 are allowed. This occurs because the requests do not match the
ports
in the DENY policy:
Clean up
Remove the namespace foo: