Authorization permissive mode
The authorization permissive mode allows you to verify authorization policies before applying them in a production environment.
The authorization permissive mode is an experimental feature in version 1.1. Its interface can change in future releases. If you do not want to try out the permissive mode feature, you can directly enable Istio authorization to skip enabling the permissive mode.
This task covers two scenarios regarding the use of the permissive mode for authorization:
For environments where authorization is disabled, this task helps you test whether it’s safe to enable the authorization.
For environments where authorization is enabled, this task helps you test whether it’s safe to add a new authorization policy.
Before you begin
To complete this task, you should first take the following actions:
Read the authorization concept.
Follow the instructions in the Kubernetes quick start to install Istio with mutual TLS enabled.
Deploy the Bookinfo sample application.
Create service accounts for the Bookinfo application. Run the following command to create service account
bookinfo-productpage
forproductpage
and service accountbookinfo-reviews
forreviews
:$ kubectl apply -f <(istioctl kube-inject -f @samples/bookinfo/platform/kube/bookinfo-add-serviceaccount.yaml@)
Test enabling authorization globally
The following steps show you how to use authorization permissive mode to test whether it’s safe to turn on authorization globally:
To enable the permissive mode in the global authorization configuration, run the following command:
$ kubectl apply -f - <<EOF apiVersion: "rbac.istio.io/v1alpha1" kind: ClusterRbacConfig metadata: name: default spec: mode: 'ON_WITH_INCLUSION' inclusion: namespaces: ["default"] enforcement_mode: PERMISSIVE EOF
Go to the
productpage
athttp://$GATEWAY_URL/productpage
and verify that everything works fine.Apply the
rbac-permissive-telemetry.yaml
YAML file to enable the metric collection for the permissive mode:$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/rbac-permissive-telemetry.yaml@ logentry.config.istio.io/rbacsamplelog created stdio.config.istio.io/rbacsamplehandler created rule.config.istio.io/rabcsamplestdio created
Send traffic to the sample application with the following command:
$ curl http://$GATEWAY_URL/productpage
Go to the
productpage
athttp://$GATEWAY_URL/productpage
and verify that everything works fine.Get the log for telemetry and search for the
permissiveResponseCode
with the following command:$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep \"instance\":\"rbacsamplelog.logentry.istio-system\" {"level":"warn","time":"2018-08-30T21:53:42.059444Z","instance":"rbacsamplelog.logentry.istio-system","destination":"ratings","latency":"9.158879ms","permissiveResponseCode":"denied","permissiveResponsePolicyID":"","responseCode":200,"responseSize":48,"source":"reviews","user":"cluster.local/ns/default/sa/bookinfo-reviews"} {"level":"warn","time":"2018-08-30T21:53:41.037824Z","instance":"rbacsamplelog.logentry.istio-system","destination":"reviews","latency":"1.091670916s","permissiveResponseCode":"denied","permissiveResponsePolicyID":"","responseCode":200,"responseSize":379,"source":"productpage","user":"cluster.local/ns/default/sa/bookinfo-productpage"} {"level":"warn","time":"2018-08-30T21:53:41.019851Z","instance":"rbacsamplelog.logentry.istio-system","destination":"productpage","latency":"1.112521495s","permissiveResponseCode":"denied","permissiveResponsePolicyID":"","responseCode":200,"responseSize":5723,"source":"istio-ingressgateway","user":"cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account"}
Verify that the the log shows a
responseCode
of200
and apermissiveResponseCode
ofdenied
.Apply the
productpage-policy.yaml
authorization policy in permissive mode with the following command:$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/productpage-policy.yaml@
Send traffic to the sample application with the following command:
$ curl http://$GATEWAY_URL/productpage
Get the log for telemetry and search for the
permissiveResponseCode
with the following command:$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep \"instance\":\"rbacsamplelog.logentry.istio-system\" {"level":"warn","time":"2018-08-30T21:55:53.590430Z","instance":"rbacsamplelog.logentry.istio-system","destination":"ratings","latency":"4.415633ms","permissiveResponseCode":"denied","permissiveResponsePolicyID":"","responseCode":200,"responseSize":48,"source":"reviews","user":"cluster.local/ns/default/sa/bookinfo-reviews"} {"level":"warn","time":"2018-08-30T21:55:53.565914Z","instance":"rbacsamplelog.logentry.istio-system","destination":"reviews","latency":"32.97524ms","permissiveResponseCode":"denied","permissiveResponsePolicyID":"","responseCode":200,"responseSize":379,"source":"productpage","user":"cluster.local/ns/default/sa/bookinfo-productpage"} {"level":"warn","time":"2018-08-30T21:55:53.544441Z","instance":"rbacsamplelog.logentry.istio-system","destination":"productpage","latency":"57.800056ms","permissiveResponseCode":"allowed","permissiveResponsePolicyID":"productpage-viewer","responseCode":200,"responseSize":5723,"source":"istio-ingressgateway","user":"cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account"}
Verify that the the log shows a
responseCode
of200
and apermissiveResponseCode
ofallowed
forproductpage
service.Remove the YAML files related to enabling the permissive mode:
$ kubectl delete -f @samples/bookinfo/platform/kube/rbac/productpage-policy.yaml@ $ kubectl delete -f @samples/bookinfo/platform/kube/rbac/rbac-config-on-permissive.yaml@ $ kubectl delete -f @samples/bookinfo/platform/kube/rbac/rbac-permissive-telemetry.yaml@
Congratulations! You tested an authorization policy with permissive mode and verified it works as expected. To enable the authorization policy, follow the steps described in the Enabling Istio authorization task.
Test adding authorization policy
The following steps show how to test a new authorization policy with permissive mode when authorization has already been enabled.
Allow access to the
producepage
service by following the instructions in Enabling authorization for HTTP services step 1.Allow access to the details and reviews service in permissive mode with the following command:
$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/details-reviews-policy-permissive.yaml@
Verify there are errors
Error fetching product details
andError fetching product reviews
on the Bookinfoproductpage
by pointing your browser at theproductpage
(http://$GATEWAY_URL/productpage
), These errors are expected because the policy is inPERMISSIVE
mode.Apply the
rbac-permissive-telemetry.yaml
YAML file to enable the permissive mode metric collection.$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/rbac-permissive-telemetry.yaml@
Send traffic to the sample application:
$ curl http://$GATEWAY_URL/productpage
Get the log for telemetry and search for the
permissiveResponseCode
with the following command:$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep \"instance\":\"rbacsamplelog.logentry.istio-system\" {"level":"warn","time":"2018-08-30T22:59:42.707093Z","instance":"rbacsamplelog.logentry.istio-system","destination":"details","latency":"423.381µs","permissiveResponseCode":"allowed","permissiveResponsePolicyID":"details-reviews-viewer","responseCode":403,"responseSize":19,"source":"productpage","user":"cluster.local/ns/default/sa/bookinfo-productpage"} {"level":"warn","time":"2018-08-30T22:59:42.763423Z","instance":"rbacsamplelog.logentry.istio-system","destination":"reviews","latency":"237.333µs","permissiveResponseCode":"allowed","permissiveResponsePolicyID":"details-reviews-viewer","responseCode":403,"responseSize":19,"source":"productpage","user":"cluster.local/ns/default/sa/bookinfo-productpage"}
Verify that the the log shows a
responseCode
of403
and apermissiveResponseCode
ofallowed
for ratings and reviews services.Remove the YAML files related to enabling the permissive mode:
$ kubectl delete -f @samples/bookinfo/platform/kube/rbac/details-reviews-policy-permissive.yaml@ $ kubectl delete -f @samples/bookinfo/platform/kube/rbac/rbac-permissive-telemetry.yaml@
Congratulations! You tested adding an authorization policy with permissive mode and verified it will work as expected. To add the authorization policy, follow the steps described in the Enabling Istio authorization task.