#!/bin/bash # shellcheck disable=SC2034,SC2153,SC2155,SC2164 # Copyright Istio Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #################################################################################################### # WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE: # docs/tasks/security/authorization/authz-custom/index.md #################################################################################################### snip_before_you_begin_1() { kubectl create ns foo kubectl label ns foo istio-injection=enabled kubectl apply -f samples/httpbin/httpbin.yaml -n foo kubectl apply -f samples/sleep/sleep.yaml -n foo } snip_before_you_begin_2() { kubectl exec "$(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name})" -c sleep -n foo -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n" } ! read -r -d '' snip_before_you_begin_2_out <<\ENDSNIP 200 ENDSNIP snip_deploy_the_external_authorizer_1() { kubectl apply -n foo -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/extauthz/ext-authz.yaml } ! read -r -d '' snip_deploy_the_external_authorizer_1_out <<\ENDSNIP service/ext-authz created deployment.apps/ext-authz created ENDSNIP snip_deploy_the_external_authorizer_2() { kubectl logs "$(kubectl get pod -l app=ext-authz -n foo -o jsonpath={.items..metadata.name})" -n foo -c ext-authz } ! read -r -d '' snip_deploy_the_external_authorizer_2_out <<\ENDSNIP 2021/01/07 22:55:47 Starting HTTP server at [::]:8000 2021/01/07 22:55:47 Starting gRPC server at [::]:9000 ENDSNIP ! read -r -d '' snip_deploy_the_external_authorizer_3 <<\ENDSNIP apiVersion: networking.istio.io/v1alpha3 kind: ServiceEntry metadata: name: external-authz-grpc-local spec: hosts: - "external-authz-grpc.local" # The service name to be used in the extension provider in the mesh config. endpoints: - address: "127.0.0.1" ports: - name: grpc number: 9191 # The port number to be used in the extension provider in the mesh config. protocol: GRPC resolution: STATIC ENDSNIP snip_define_the_external_authorizer_1() { kubectl edit configmap istio -n istio-system } ! read -r -d '' snip_define_the_external_authorizer_2 <<\ENDSNIP data: mesh: |- # Add the following content to define the external authorizers. extensionProviders: - name: "sample-ext-authz-grpc" envoyExtAuthzGrpc: service: "ext-authz.foo.svc.cluster.local" port: "9000" - name: "sample-ext-authz-http" envoyExtAuthzHttp: service: "ext-authz.foo.svc.cluster.local" port: "8000" includeRequestHeadersInCheck: ["x-ext-authz"] ENDSNIP ! read -r -d '' snip_define_the_external_authorizer_3 <<\ENDSNIP data: mesh: |- extensionProviders: - name: "oauth2-proxy" envoyExtAuthzHttp: service: "oauth2-proxy.foo.svc.cluster.local" port: "4180" # The default port used by oauth2-proxy. includeRequestHeadersInCheck: ["authorization", "cookie"] # headers sent to the oauth2-proxy in the check request. headersToUpstreamOnAllow: ["authorization", "path", "x-auth-request-user", "x-auth-request-email", "x-auth-request-access-token"] # headers sent to backend application when request is allowed. headersToDownstreamOnAllow: ["set-cookie"] # headers sent back to the client when request is allowed. headersToDownstreamOnDeny: ["content-type", "set-cookie"] # headers sent back to the client when request is denied. ENDSNIP snip_enable_with_external_authorization_1() { kubectl apply -n foo -f - <