设计并部署服务间双向TLS
为服务间通信规划证书身份、轮换与访问授权,并制定分阶段启用双向TLS的实施方案。
完整提示词
<context>
mTLS gives each service a cryptographic identity, but most of the work is operational. The two classic outages are expired certificates and a CA rotation that some clients never picked up, so short-lived certificates with automated renewal (hours to days, not years) are safer than long-lived ones that someone has to remember. There are three implementation paths: a service mesh (Istio, Linkerd, Cilium) that does it transparently in sidecars or the node; an identity system such as SPIFFE/SPIRE or cert-manager issuing certificates the apps load themselves; or a reverse proxy in front of each service. A mesh is the least code but the most platform. mTLS alone only proves who is calling; without authorization based on the peer identity (the SPIFFE ID or certificate SAN), any service with a certificate can call any other. Turning on strict mode in one step breaks every client that is not ready, which is why meshes offer a permissive mode that accepts both plain and mutual TLS.
</context>
<task>
Set up mutual TLS for: {{services}}
{{#goal}}Goal: {{goal}}{{/goal}}
1. Read the deployment config and the code that makes service-to-service calls. List each caller, callee, protocol (HTTP, gRPC, database, queue) and current auth between them.
2. Recommend one approach (mesh, identity system with app-loaded certs, or proxy) for this setup, with the reason and the operational cost. Ask before committing if the choice depends on something unknown, such as whether the team can run a mesh.
3. Design identity and the CA: naming scheme for identities (per service, not per instance), where the root and intermediate keys live, and how the root is protected (offline or managed CA service).
4. Design rotation: certificate lifetime, renewal before expiry, how apps reload certificates without restart, and how to roll the CA itself with an overlap period where both CAs are trusted.
5. Add authorization by peer identity: which identities may call which service and route, expressed in the mesh policy or in app middleware.
6. Plan the rollout: permissive mode or dual listeners, metrics on how much traffic is plain versus mutual, then strict per service once all callers use mTLS.
7. Implement the first service pair in the repo (config, policy, any app changes for loading certificates), validate configs, and run what tests exist.
8. List failure modes and their alerts: certificate expiry, clock skew, CA mismatch, and SAN mismatch after a service rename.
</task>
<constraints>
- Never put private keys in the repo, images or logs; keys are generated where they are used or delivered by the issuing system.
- Do not switch any service to strict mode as part of this change; leave that as a later, explicit step.
- Do not invent product features or flags; if unsure whether a mesh or tool supports something, say so and how to check.
{{> guardrails/investigate-before-answering}}
{{> guardrails/verify-before-done}}
</constraints>
<output_format>
## Approach
The chosen path, the reason, and the alternatives rejected.
## Identity and CA
Identity naming, CA hierarchy and key protection.
## Rotation
Lifetimes, renewal, reload and CA rollover steps.
## Authorization
Table: callee, allowed caller identities, routes.
## Rollout
Numbered stages with the metric that gates each.
## Failure modes
Table: failure, symptom, alert, fix.
## Verification
Config validation and tests run, with results.
</output_format>可替换内容
- {{services}}
- {{#goal}}
- {{goal}}
- {{/goal}}
- {{> guardrails/investigate-before-answering}}
- {{> guardrails/verify-before-done}}
分类与标签
编程开发、双向TLS、服务通信、证书轮换、访问控制