[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Set up Service Security on Envoy sidecar service mesh on GKE\n============================================================\n\nThis page describes how to set up security features on Envoy sidecar service mesh on\nGKE.\n\nPrerequisites\n-------------\n\nAs a starting point, this guide assumes that you have already:\n\n- [Created a GKE cluster and registered it to a fleet](/service-mesh/v1.23/docs/gateway/prepare-gateway#create_and_register_a_cluster).\n- [Setup Envoy sidecar service mesh with Gateway APIs](/service-mesh/v1.23/docs/gateway/set-up-envoy-mesh).\n\n### Setup authorization policies on sidecars on GKE\n\n|\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis section shows you how to set up different kinds of\n[authorization policies](/load-balancing/docs/auth-policy/auth-policy-overview)\non Cloud Service Mesh sidecars on GKE.\n\nBefore you can create an authorization policy, you must install the\nGCPAuthzPolicy CustomResourceDefinition (CRD): \n\n curl https://github.com/GoogleCloudPlatform/gke-networking-recipes/blob/main/gateway-api/config/mesh/crd/experimental/gcpauthzpolicy.yaml \\\n | kubectl apply -f -\n\nAuthorization Policies can enforce access control on traffic entering Envoy sidecars. Policies can be applied on Kubernetes deployments. Deployment should be in the same namespace as Authorization Policy.\n\n#### Authorization policy to deny all the requests\n\nWhen you have a workload that is supposed to make only outbound calls, like a\ncron job, you can configure an authorization policy to deny any incoming HTTP\nrequests to the workload. The following example denies incoming HTTP requests to\nthe workload `whereami`.\n\nPerform the following steps to create and apply the deny authorization policy:\n\n1. Create a deny policy by creating a file called `deny-all-authz-policy.yaml`:\n\n cat \u003edeny-all-authz-policy.yaml \u003c\u003cEOF\n apiVersion: networking.gke.io/v1\n kind: GCPAuthzPolicy\n metadata:\n name: myworkload-authz\n namespace: sidecar-example\n spec:\n targetRefs:\n - kind: Deployment\n name: whereami\n httpRules:\n - to:\n operations:\n - paths:\n - type: Prefix\n value: \"/\"\n action: DENY\n EOF\n\n2. Apply the policy:\n\n kubectl apply -f deny-all-authz-policy.yaml\n\n#### Authorization policy to allow requests\n\nYou can also configure an allow policy that allows only requests that match a\nspecific criteria while rejecting the rest. The following example configures an\nauthorization policy on the `whereami`where o nly `GET` requests that have http header `x-user-role:admin` present in the request will be allowed.\n\nPerform the following steps to create and apply the allow authorization policy, delete the previously created deny policy before adding this policy to see the results:\n\n1. Create a custom policy by creating a file called `allow-authz-policy.yaml`:\n\n cat \u003eallow-authz-policy.yaml \u003c\u003cEOF\n apiVersion: networking.gke.io/v1\n kind: GCPAuthzPolicy\n metadata:\n name: myworkload-authz\n namespace: sidecar-example\n spec:\n targetRefs:\n - kind: Deployment\n name: whereami\n httpRules:\n - to:\n operations:\n - methods: [\"GET\"]\n when: \"request.headers['x-user-role'] == 'admin'\n action: ALLOW\n EOF\n\n2. Apply the policy:\n\n kubectl apply -f allow-authz-policy.yaml\n\n#### Authorization policy to deny requests based on rules\n\nThe following example denies incoming HTTP `GET` requests to\nthe workload `whereami` when it is on the path `/admin` .\n\nPerform the following steps to create and apply the deny authorization policy:\n\n1. Create a deny policy by creating a file called `deny-path-authz-policy.yaml`:\n\n cat \u003edeny-path-authz-policy.yaml \u003c\u003cEOF\n apiVersion: networking.gke.io/v1\n kind: GCPAuthzPolicy\n metadata:\n name: myworkload-authz\n namespace: sidecar-example\n spec:\n targetRefs:\n - kind: Deployment\n name: whereami\n httpRules:\n - to:\n operations:\n - paths:\n - type: Prefix\n value: \"/admin\"\n methods: [\"GET\"]\n action: DENY\n EOF\n\n2. Apply the policy:\n\n kubectl apply -f deny-path-authz-policy.yaml"]]