ALLOW
policy or a DENY
policy.ALLOW
and DENY
policies of AuthorizationPolicy are applied to a same scope, the DENY
policy takes precedence over the ALLOW
policy. The effective rules are as follows:DENY
policies that match the request, deny the request.ALLOW
policies for the scope, allow the request.ALLOW
policies for the scope and any of the ALLOW
policies matches the request, allow the request.apiVersion: security.istio.io/v1beta1kind: AuthorizationPolicymetadata:name: allow-allnamespace: defaultspec:action: ALLOWrules:- {} # The rule can match any request.
apiVersion: security.istio.io/v1beta1kind: AuthorizationPolicymetadata:name: deny-allnamespace: defaultspec:{} # When the action field is left blank, the value is **ALLOW** by default. In this case, the request cannot match any rule.
Name | Type | Description |
metadata.name | string | AuthorizationPolicy name. |
metadata.namespace | string | AuthorizationPolicy namespace. |
spec.selector | map<string, string> | AuthorizationPolicy uses an entered label key-value pair and an entered namespace to match a scope of workloads to which configurations are to be delivered. If the entered namespace is istio-system and the selector field is left blank, the policy takes effect for the entire mesh. If the entered namespace is not istio-system and the selector field is left blank, the policy takes effect for the entered namespace. If the entered namespace is not istio-system and the selector field is set to a valid key-value pair, the policy takes effect for the workload that is matched based on the selector in the entered namespace. |
spec.action | - | Whether the policy is an ALLOW policy or a DENY policy. |
spec.rules.from.source.principals | string[] | List of source peer identities (that is, service accounts). This field matches the source.principal field and requires mTLS enabled. If this field is left blank, any principal is allowed. |
spec.rules.from.source.requestPrincipals | string[] | List of request identities (that is, iss/sub claim). This field matches the request.auth.principal field. If this field is left blank, any request principal is allowed. |
spec.rules.from.source.namespaces | string[] | List of namespaces of the request source. This field matches the source.namespace field and requires mTLS enabled. If this field is left blank, requests from any namespace are allowed. |
spec.rules.from.source.ipBlocks | string[] | List of IP blocks. This field matches the source.ip field and supports single IP (for example, 1.2.3.4 ) and CIDR (for example, 1.2.3.4/24 ). If this field is left blank, any source IP address is allowed. |
spec.rules.to.operation.hosts | string[] | List of domain names in the request. This field matches the request.host field. If this field is left blank, any domain name is allowed. This field can be used only in HTTP requests. |
spec.rules.to.operation.ports | string[] | List of ports in the request. This field matches the destination.port field. If this field is left blank, any port is allowed. |
spec.rules.to.operation.methods | string[] | List of methods in the request. This field matches the request.method field. If the gRPC protocol is used, this field is always POST . If this field is left blank, any method is allowed. This field can be used only in HTTP requests. |
spec.rules.to.operation.paths | string[] | List of paths in the request. This field matches the request.url_path field. If this field is left blank, any path is allowed. This field can be used only in HTTP requests. |
spec.rules.when.condition.key | string | |
spec.rules.when.condition.values | string[] | List of values for a corresponding condition. |
apiVersion: v1kind: Namespacemetadata:name: testlabels:istio.io/rev: 1-6-9 # Automatic sidecar injection (Istio 1.6.9)spec:finalizers:- kubernetes---apiVersion: apps/v1kind: Deploymentmetadata:name: clientnamespace: testlabels:app: clientspec:replicas: 10selector:matchLabels:app: clienttemplate:metadata:labels:app: clientspec:containers:- name: clientimage: ccr.ccs.tencentyun.com/zhulei/testclient:v1imagePullPolicy: Alwaysenv:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: REGIONvalue: "guangzhou-zoneA"ports:- containerPort: 7000protocol: TCP---apiVersion: v1kind: Servicemetadata:name: clientnamespace: testlabels:app: clientspec:ports:- name: httpport: 7000protocol: TCPselector:app: clienttype: ClusterIP---apiVersion: v1kind: Namespacemetadata:name: baselabels:istio.io/rev: 1-6-9spec:finalizers:- kubernetes---apiVersion: apps/v1kind: Deploymentmetadata:name: usernamespace: baselabels:app: userspec:replicas: 1selector:matchLabels:app: usertemplate:metadata:labels:app: userspec:containers:- name: userimage: ccr.ccs.tencentyun.com/zhulei/testuser:v1imagePullPolicy: Alwaysenv:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: REGIONvalue: "guangzhou-zoneB"ports:- containerPort: 7000---apiVersion: v1kind: Servicemetadata:name: usernamespace: baselabels:app: userspec:ports:- port: 7000name: httpselector:app: user
apiVersion: security.istio.io/v1beta1kind: AuthorizationPolicymetadata:name: base-authznamespace: basespec:action: DENYrules:- from:- source:namespaces:- test
httpbin.foo
and then configure this service to be exposed to the public network through the ingress gateway.apiVersion: v1kind: Namespacemetadata:name: foolabels:istio.io/rev: 1-6-9 # Enable automatic sidecar injection for the namespace (The Istio version is 1.6.9).spec:finalizers:- kubernetes---apiVersion: v1kind: ServiceAccountmetadata:name: httpbinnamespace: foo---apiVersion: v1kind: Servicemetadata:name: httpbinnamespace: foolabels:app: httpbinservice: httpbinspec:ports:- name: httpport: 8000targetPort: 80selector:app: httpbin---apiVersion: apps/v1kind: Deploymentmetadata:name: httpbinnamespace: foospec:replicas: 1selector:matchLabels:app: httpbinversion: v1template:metadata:labels:app: httpbinversion: v1spec:serviceAccountName: httpbincontainers:- image: docker.io/kennethreitz/httpbinimagePullPolicy: IfNotPresentname: httpbinports:- containerPort: 80
apiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: httpbin-gatewaynamespace: foospec:selector:app: istio-ingressgatewayistio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "*"---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: httpbinnamespace: foospec:hosts:- "*"gateways:- httpbin-gatewayhttp:- route:- destination:port:number: 8000host: httpbin.foo.svc.cluster.local
curl "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
. Note that you need to replace $INGRESS_IP
in the statement with the IP address of your ingress gateway. In normal condition, a 200
return code is returned.apiVersion: security.istio.io/v1beta1kind: AuthorizationPolicymetadata:name: black-listnamespace: istio-systemspec:selector:matchLabels:app: istio-ingressgatewayistio: ingressgatewayrules:- from:- source:ipBlocks:- $ IP address of your local hostaction: DENY
curl "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
again. Note that you need to replace $INGRESS_IP
in the statement with the IP address of your ingress gateway. In this case, the access fails and a 403
return code is returned, indicating that the blocklist policy has taken effect.
Was this page helpful?