Control Headers and Routing
- Set up Istio on Kubernetes by following the instructions in theInstallation guide.
Policy enforcement must be enabled in your cluster for this task. Follow the steps in to ensure that policy enforcement is enabled.
Follow the set-up instructions in the ingress task to configure an ingress using a gateway.
Customize the configuration for the service containing two route rules that allow traffic for paths
/headers
and/status
:
In this task, we are using a sample policy adapter keyval
. In addition toa policy check result, this adapter returns an output with a single fieldcalled value
. The adapter is configured with a lookup table, which it uses topopulate the output value, or return NOT_FOUND
error status if the inputinstance key is not present in the lookup table.
- Deploy the demo adapter:
$ kubectl run keyval --image=gcr.io/istio-testing/keyval:release-1.1 --namespace istio-system --port 9070 --expose
- Enable the
keyval
adapter by deploying its template and configuration descriptors:
$ kubectl apply -f @samples/httpbin/policy/keyval-template.yaml@
$ kubectl apply -f @samples/httpbin/policy/keyval.yaml@
- Create a handler for the demo adapter with a fixed lookup table:
- Create an instance for the handler with the
user
request header as a lookup key:
$ kubectl apply -f - <<EOF
apiVersion: config.istio.io/v1alpha2
kind: instance
metadata:
name: keyval
namespace: istio-system
spec:
params:
key: request.headers["user"] | ""
EOF
- Ensure the httpbin service is accessible through the ingress gateway:
{
"headers": {
"Accept": "*/*",
"Content-Length": "0",
...
"X-Envoy-Internal": "true"
}
}
The output should be the request headers as they are received by the httpbin service.
- Create a rule for the demo adapter:
- Issue a new request to the ingress gateway with the header
key
set to valuejason
:
$ curl -Huser:jason http://$INGRESS_HOST:$INGRESS_PORT/headers
{
"headers": {
"Accept": "*/*",
"Content-Length": "0",
"User": "jason",
"User-Agent": "curl/7.58.0",
...
"X-Envoy-Internal": "true"
}
Note the presence of the user-group
header with the value derived from therule application of the adapter. The expression x.output.value
in the ruleevaluates to the populated value
field returned by the keyval
adapter.
- Modify the rule to rewrite the URI path to a different virtual service routeif the check succeeds:
$ kubectl apply -f - <<EOF
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: keyval
namespace: istio-system
spec:
match: source.labels["istio"] == "ingressgateway"
actions:
- handler: keyval.istio-system
instances: [ keyval ]
requestHeaderOperations:
- name: :path
values: [ '"/status/418"' ]
EOF
- Repeat the request to the ingress gateway:
The modified request is not checked again by the policy engine within thesame proxy. Therefore, we recommend to use this feature in gateways, sothat the server-side policy checks take effect.
Delete the policy resources for the demo adapter:
$ kubectl delete rule/keyval handler/keyval instance/keyval adapter/keyval template/keyval -n istio-system
Complete the clean-up instructions in ingress task.
Using Istio to secure multi-cloud Kubernetes applications with zero code changes.
Improving availability and reducing latency.
Provides an overview of Mixer's plug-in architecture.
Shows how to control access to a service using simple denials or white/black listing.
This task shows you how to enable Istio policy enforcement.
This task shows you how to use Istio to dynamically limit the traffic to a service.