Cloud Service Mesh では、PeerAuthentication ポリシーを適用して、mTLS のみを受け入れるようにサービスを構成できます。Cloud Service Mesh には、サービス メッシュ全体、名前空間、個々のワークロードにポリシーを適用できる柔軟性があります。特定のワークロードにポリシーを指定した場合、そのポリシーが優先されます。たとえば、ワークロード固有のポリシーは、名前空間固有のポリシーよりも優先されます。ワークロードにポリシーが指定されていない場合、名前空間またはメッシュからポリシーが継承されます。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["# Configure transport security\n============================\n\n| **Note:** This guide only supports Cloud Service Mesh with Istio APIs and does not support Google Cloud APIs. For more information see, [Cloud Service Mesh overview](/service-mesh/docs/overview).\n\nIn Cloud Service Mesh with Istio APIs for Kubernetes workloads, auto mutual\nTLS (auto mTLS) is enabled by default. With auto mTLS, a client sidecar proxy\nautomatically detects if the server has a sidecar. The client sidecar sends mTLS\nto workloads with sidecars and sends plaintext to workloads without sidecars.\nNote, however, services *accept* both plaintext and mTLS traffic. As you inject\nsidecar proxies to your Pods, we recommend that you also configure your services\nto only accept mTLS traffic.\n\nWith Cloud Service Mesh, you can configure your services to only accept mTLS\nby applying a `PeerAuthentication` policy. Cloud Service Mesh gives you the\nflexibility to apply the policy to the entire service mesh, to a namespace, or\nto an individual workload. When you specify a policy for a specific workload,\nthat policy takes precedence. For example, a workload-specific policy takes\nprecedence over a namespace-specific one. If no policy is specified for the\nworkload, it inherits the policy from the namespace or the mesh.\n\nSee [Supported features](/service-mesh/v1.23/docs/supported-features) for details of which\nfields of the `PeerAuthentication` CR are supported by platform.\n\nEnable mutual TLS per namespace\n-------------------------------\n\nTo enable mTLS for all workloads within a particular namespace, use a\nnamespace-wide authentication policy. You specify the namespace it applies to\nunder `metadata`. \n\n kubectl apply -f - \u003c\u003cEOF\n apiVersion: \"security.istio.io/v1beta1\"\n kind: \"PeerAuthentication\"\n metadata:\n name: \"\u003cvar translate=\"no\"\u003eAUTH_POLICY_NAME\u003c/var\u003e\"\n namespace: \"\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\"\n spec:\n mtls:\n mode: STRICT\n EOF\n\nExpected output: \n\n```\npeerauthentication.security.istio.io/AUTH_POLICY_NAME created\n```\n\n\u003cbr /\u003e\n\nEnable mutual TLS per workload\n------------------------------\n\nTo set a `PeerAuthentication` policy for a specific workload, you must configure\nthe `selector` section and specify the labels that match the desired workload.\nHowever, Cloud Service Mesh can't aggregate workload-level policies for\noutbound mTLS traffic to a service. You need to configure a destination rule to\nmanage that behavior.\n\n1. Apply an authentication policy to a specific workload in your namespace:\n\n cat \u003c\u003cEOF | kubectl apply -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e -f -\n apiVersion: \"security.istio.io/v1beta1\"\n kind: \"PeerAuthentication\"\n metadata:\n name: \"\u003cvar translate=\"no\"\u003eAUTH_POLICY_NAME\u003c/var\u003e\"\n namespace: \"\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\"\n spec:\n selector:\n matchLabels:\n app: \u003cvar translate=\"no\"\u003eWORKLOAD\u003c/var\u003e\n mtls:\n mode: STRICT\n EOF\n\n Expected output: \n\n ```\n peerauthentication.security.istio.io/AUTH_POLICY_NAME created\n ```\n2. Configure a matching destination rule:\n\n cat \u003c\u003cEOF | kubectl apply -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e -f -\n apiVersion: \"networking.istio.io/v1alpha3\"\n kind: \"DestinationRule\"\n metadata:\n name: \"\u003cvar translate=\"no\"\u003eDEST_RULE_NAME\u003c/var\u003e\"\n spec:\n host: \"\u003cvar translate=\"no\"\u003eWORKLOAD\u003c/var\u003e.\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e.svc.cluster.local\"\n trafficPolicy:\n tls:\n mode: ISTIO_MUTUAL\n EOF\n\n Expected output: \n\n ```\n destinationrule.networking.istio.io/WORKLOAD created\n ```\n\nEnforce mesh-wide mTLS\n----------------------\n\nTo prevent all your services in the mesh from accepting plain-text traffic, set\na mesh-wide `PeerAuthentication` policy with the mTLS mode set to `STRICT` (the\ndefault is `PERMISSIVE`). The mesh-wide `PeerAuthentication` policy shouldn't\nhave a selector and must be applied in the root namespace, `istio-system`. When\nyou deploy the policy, the control plane automatically provisions TLS\ncertificates so that workloads can authenticate with each other.\n\nTo enforce mesh-wide mTLS: \n\n kubectl apply -f - \u003c\u003cEOF\n apiVersion: \"security.istio.io/v1beta1\"\n kind: \"PeerAuthentication\"\n metadata:\n name: \"\u003cvar translate=\"no\"\u003eAUTH_POLICY_NAME\u003c/var\u003e\"\n namespace: \"istio-system\"\n spec:\n mtls:\n mode: STRICT\n EOF\n\nExpected output: \n\n```\npeerauthentication.security.istio.io/AUTH_POLICY_NAME created\n```\n\n\u003cbr /\u003e\n\nFind and delete `PeerAuthentication` policies\n---------------------------------------------\n\nFor a list of all the `PeerAuthentication` policies in the service mesh: \n\n kubectl get peerauthentication --all-namespaces\n\nIf there is a `PeerAuthentication` policy in force, you can delete it with\n`kubectl delete`: \n\n kubectl delete peerauthentication -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e \u003cvar translate=\"no\"\u003eAUTH_POLICY_NAME\u003c/var\u003e\n\nWhat's next\n-----------\n\n- [Cloud Service Mesh by example: mTLS](/service-mesh/v1.23/docs/tutorials/mtls)\n- [Learn about security in Cloud Service Mesh](/service-mesh/v1.23/docs/security/security-overview)"]]