配置 API7 企业版 和上游之间的 mTLS
Mutal TLS (mTLS) 是一种双向 TLS,客户端和服务器相互验证身份。它通常在对安全要求高的环境中采用,以防止未经授权的访问并加强安全性。
本指南将引导你完成如何在 API7 网关和上游服务之间配置 mTLS 的过程,使用 NGINX 作为示例上游服务。
前提条件
- 安装 API7 企业版。
- 在 API7 企业版上创建令牌。
生成证书和密钥
-
生成 CA 密钥和证书。
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 36500 -out ca.crt \
-subj "/CN=ROOTCA" -
使用
test.com为 API7 企业版生成服务器密钥和证书,并使用 CA 证书签名。openssl genrsa -out server.key 2048 && \
openssl req -new -key server.key -out server.csr -subj "/CN=test.com" && \
cat > server.ext << EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = test.com
EOF
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt -days 36500 \
-sha256 -extfile server.ext -
使用
CLIENT为客户端生成密钥和证书,并使用 CA 证书签名。openssl genrsa -out client.key 2048 && \
openssl req -new -key client.key -out client.csr -subj "/CN=client" && \
cat > client.ext << EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = clientAuth
EOF
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 36500 -sha256 -extfile client.ext -
生成证书和密钥后,检查本地设备以找到这些文件。
❶
client.crt: 客户端证书❷
client.key: 客户端证书密钥❸
ca.crt: CA 证书