Merge pull request #34864 from fenggw-fnst/update-certificates

[zh-cn] Update certificates.md
This commit is contained in:
Kubernetes Prow Robot
2022-07-07 03:45:34 -07:00
committed by GitHub
@@ -29,26 +29,31 @@ manually through `easyrsa`, `openssl` or `cfssl`.
**easyrsa** 支持以手工方式为你的集群生成证书。 **easyrsa** 支持以手工方式为你的集群生成证书。
<!-- <!--
1. Download, unpack, and initialize the patched version of easyrsa3. 1. Download, unpack, and initialize the patched version of `easyrsa3`.
--> -->
1. 下载、解压、初始化打过补丁的 easyrsa3。 1. 下载、解压、初始化打过补丁的 `easyrsa3`
```shell
curl -LO https://storage.googleapis.com/kubernetes-release/easy-rsa/easy-rsa.tar.gz curl -LO https://storage.googleapis.com/kubernetes-release/easy-rsa/easy-rsa.tar.gz
tar xzf easy-rsa.tar.gz tar xzf easy-rsa.tar.gz
cd easy-rsa-master/easyrsa3 cd easy-rsa-master/easyrsa3
./easyrsa init-pki ./easyrsa init-pki
```
<!-- <!--
2. Generate a new certificate authority (CA). `--batch` sets automatic mode; 1. Generate a new certificate authority (CA). `--batch` sets automatic mode;
`--req-cn` specifies the Common Name (CN) for the CA's new root certificate. `--req-cn` specifies the Common Name (CN) for the CA's new root certificate.
--> -->
2. 生成新的证书颁发机构(CA)。参数 `--batch` 用于设置自动模式; 2. 生成新的证书颁发机构(CA)。参数 `--batch` 用于设置自动模式;
参数 `--req-cn` 用于设置新的根证书的通用名称(CN)。 参数 `--req-cn` 用于设置新的根证书的通用名称(CN)。
```shell
./easyrsa --batch "--req-cn=${MASTER_IP}@`date +%s`" build-ca nopass ./easyrsa --batch "--req-cn=${MASTER_IP}@`date +%s`" build-ca nopass
```
<!-- <!--
3. Generate server certificate and key. 1. Generate server certificate and key.
The argument `--subject-alt-name` sets the possible IPs and DNS names the API server will The argument `--subject-alt-name` sets the possible IPs and DNS names the API server will
be accessed with. The `MASTER_CLUSTER_IP` is usually the first IP from the service CIDR be accessed with. The `MASTER_CLUSTER_IP` is usually the first IP from the service CIDR
that is specified as the `--service-cluster-ip-range` argument for both the API server and that is specified as the `--service-cluster-ip-range` argument for both the API server and
@@ -58,11 +63,14 @@ The sample below also assumes that you are using `cluster.local` as the default
DNS domain name. DNS domain name.
--> -->
3. 生成服务器证书和秘钥。 3. 生成服务器证书和秘钥。
参数 `--subject-alt-name` 设置 API 服务器的 IP 和 DNS 名称。 参数 `--subject-alt-name` 设置 API 服务器的 IP 和 DNS 名称。
`MASTER_CLUSTER_IP` 用于 API 服务器和控制管理器,通常取 CIDR 的第一个 IP,`--service-cluster-ip-range` 的参数提供。 `MASTER_CLUSTER_IP` 用于 API 服务器和控制管理器,通常取 CIDR 的第一个 IP,
由 `--service-cluster-ip-range` 的参数提供。
参数 `--days` 用于设置证书的过期时间。 参数 `--days` 用于设置证书的过期时间。
下面的示例假定你的默认 DNS 域名为 `cluster.local`。 下面的示例假定你的默认 DNS 域名为 `cluster.local`。
```shell
./easyrsa --subject-alt-name="IP:${MASTER_IP},"\ ./easyrsa --subject-alt-name="IP:${MASTER_IP},"\
"IP:${MASTER_CLUSTER_IP},"\ "IP:${MASTER_CLUSTER_IP},"\
"DNS:kubernetes,"\ "DNS:kubernetes,"\
@@ -72,20 +80,23 @@ DNS domain name.
"DNS:kubernetes.default.svc.cluster.local" \ "DNS:kubernetes.default.svc.cluster.local" \
--days=10000 \ --days=10000 \
build-server-full server nopass build-server-full server nopass
```
<!-- <!--
4. Copy `pki/ca.crt`, `pki/issued/server.crt`, and `pki/private/server.key` to your directory. 1. Copy `pki/ca.crt`, `pki/issued/server.crt`, and `pki/private/server.key` to your directory.
--> -->
4. 拷贝文件 `pki/ca.crt`、`pki/issued/server.crt` 和 `pki/private/server.key` 到你的目录中。 4. 拷贝文件 `pki/ca.crt`、`pki/issued/server.crt` 和 `pki/private/server.key` 到你的目录中。
<!-- <!--
5. Fill in and add the following parameters into the API server start parameters: 1. Fill in and add the following parameters into the API server start parameters:
--> -->
5. 在 API 服务器的启动参数中添加以下参数: 5. 在 API 服务器的启动参数中添加以下参数:
```shell
--client-ca-file=/yourdirectory/ca.crt --client-ca-file=/yourdirectory/ca.crt
--tls-cert-file=/yourdirectory/server.crt --tls-cert-file=/yourdirectory/server.crt
--tls-private-key-file=/yourdirectory/server.key --tls-private-key-file=/yourdirectory/server.key
```
### openssl ### openssl
@@ -99,24 +110,31 @@ DNS domain name.
--> -->
1. 生成一个 2048 位的 ca.key 文件 1. 生成一个 2048 位的 ca.key 文件
```shell
openssl genrsa -out ca.key 2048 openssl genrsa -out ca.key 2048
```
<!-- <!--
2. According to the ca.key generate a ca.crt (use -days to set the certificate effective time): 1. According to the ca.key generate a ca.crt (use `-days` to set the certificate effective time):
--> -->
2. 在 ca.key 文件的基础上,生成 ca.crt 文件(用参数 -days 设置证书有效期) 2. 在 ca.key 文件的基础上,生成 ca.crt 文件(用参数 `-days` 设置证书有效期)
```shell
openssl req -x509 -new -nodes -key ca.key -subj "/CN=${MASTER_IP}" -days 10000 -out ca.crt openssl req -x509 -new -nodes -key ca.key -subj "/CN=${MASTER_IP}" -days 10000 -out ca.crt
```
<!-- <!--
3. Generate a server.key with 2048bit: 1. Generate a server.key with 2048bit:
--> -->
3. 生成一个 2048 位的 server.key 文件: 3. 生成一个 2048 位的 server.key 文件:
```shell
openssl genrsa -out server.key 2048 openssl genrsa -out server.key 2048
```
<!-- <!--
4. Create a config file for generating a Certificate Signing Request (CSR). 1. Create a config file for generating a Certificate Signing Request (CSR).
Be sure to substitute the values marked with angle brackets (e.g. `<MASTER_IP>`) Be sure to substitute the values marked with angle brackets (e.g. `<MASTER_IP>`)
with real values before saving this to a file (e.g. `csr.conf`). with real values before saving this to a file (e.g. `csr.conf`).
Note that the value for `MASTER_CLUSTER_IP` is the service cluster IP for the Note that the value for `MASTER_CLUSTER_IP` is the service cluster IP for the
@@ -129,6 +147,7 @@ DNS domain name.
注意:`MASTER_CLUSTER_IP` 就像前一小节所述,它的值是 API 服务器的服务集群 IP。 注意:`MASTER_CLUSTER_IP` 就像前一小节所述,它的值是 API 服务器的服务集群 IP。
下面的例子假定你的默认 DNS 域名为 `cluster.local`。 下面的例子假定你的默认 DNS 域名为 `cluster.local`。
```ini
[ req ] [ req ]
default_bits = 2048 default_bits = 2048
prompt = no prompt = no
@@ -162,36 +181,45 @@ DNS domain name.
keyUsage=keyEncipherment,dataEncipherment keyUsage=keyEncipherment,dataEncipherment
extendedKeyUsage=serverAuth,clientAuth extendedKeyUsage=serverAuth,clientAuth
subjectAltName=@alt_names subjectAltName=@alt_names
```
<!-- <!--
5. Generate the certificate signing request based on the config file: 1. Generate the certificate signing request based on the config file:
--> -->
5. 基于上面的配置文件生成证书签名请求: 5. 基于上面的配置文件生成证书签名请求:
```shell
openssl req -new -key server.key -out server.csr -config csr.conf openssl req -new -key server.key -out server.csr -config csr.conf
```
<!-- <!--
6. Generate the server certificate using the ca.key, ca.crt and server.csr: 1. Generate the server certificate using the ca.key, ca.crt and server.csr:
--> -->
6. 基于 ca.key、ca.crt 和 server.csr 等三个文件生成服务端证书: 6. 基于 ca.key、ca.crt 和 server.csr 等三个文件生成服务端证书:
```shell
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt -days 10000 \ -CAcreateserial -out server.crt -days 10000 \
-extensions v3_ext -extfile csr.conf -extensions v3_ext -extfile csr.conf
```
<!-- <!--
7. View the certificate signing request: 1. View the certificate signing request:
--> -->
7. 查看证书签名请求: 7. 查看证书签名请求:
```shell
openssl req -noout -text -in ./server.csr openssl req -noout -text -in ./server.csr
```
<!-- <!--
8. View the certificate: 1. View the certificate:
--> -->
8. 查看证书: 8. 查看证书:
```shell
openssl x509 -noout -text -in ./server.crt openssl x509 -noout -text -in ./server.crt
```
<!-- <!--
Finally, add the same parameters into the API server start parameters. Finally, add the same parameters into the API server start parameters.
@@ -207,34 +235,41 @@ Finally, add the same parameters into the API server start parameters.
<!-- <!--
1. Download, unpack and prepare the command line tools as shown below. 1. Download, unpack and prepare the command line tools as shown below.
Note that you may need to adapt the sample commands based on the hardware Note that you may need to adapt the sample commands based on the hardware
architecture and cfssl version you are using. architecture and cfssl version you are using.
--> -->
1. 下载、解压并准备如下所示的命令行工具。 1. 下载、解压并准备如下所示的命令行工具。
注意:你可能需要根据所用的硬件体系架构和 cfssl 版本调整示例命令。 注意:你可能需要根据所用的硬件体系架构和 cfssl 版本调整示例命令。
```shell
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssl_1.5.0_linux_amd64 -o cfssl curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssl_1.5.0_linux_amd64 -o cfssl
chmod +x cfssl chmod +x cfssl
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssljson_1.5.0_linux_amd64 -o cfssljson curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssljson_1.5.0_linux_amd64 -o cfssljson
chmod +x cfssljson chmod +x cfssljson
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssl-certinfo_1.5.0_linux_amd64 -o cfssl-certinfo curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssl-certinfo_1.5.0_linux_amd64 -o cfssl-certinfo
chmod +x cfssl-certinfo chmod +x cfssl-certinfo
```
<!-- <!--
2. Create a directory to hold the artifacts and initialize cfssl: 1. Create a directory to hold the artifacts and initialize cfssl:
--> -->
2. 创建一个目录,用它保存所生成的构件和初始化 cfssl: 2. 创建一个目录,用它保存所生成的构件和初始化 cfssl:
```shell
mkdir cert mkdir cert
cd cert cd cert
../cfssl print-defaults config > config.json ../cfssl print-defaults config > config.json
../cfssl print-defaults csr > csr.json ../cfssl print-defaults csr > csr.json
```
<!-- <!--
3. Create a JSON config file for generating the CA file, for example, `ca-config.json`: 1. Create a JSON config file for generating the CA file, for example, `ca-config.json`:
--> -->
3. 创建一个 JSON 配置文件来生成 CA 文件,例如:`ca-config.json` 3. 创建一个 JSON 配置文件来生成 CA 文件,例如:`ca-config.json`
```json
{ {
"signing": { "signing": {
"default": { "default": {
@@ -253,15 +288,17 @@ Finally, add the same parameters into the API server start parameters.
} }
} }
} }
```
<!-- <!--
4. Create a JSON config file for CA certificate signing request (CSR), for example, 1. Create a JSON config file for CA certificate signing request (CSR), for example,
`ca-csr.json`. Be sure to replace the values marked with angle brackets with `ca-csr.json`. Be sure to replace the values marked with angle brackets with
real values you want to use. real values you want to use.
--> -->
4. 创建一个 JSON 配置文件,用于 CA 证书签名请求(CSR),例如:`ca-csr.json`。 4. 创建一个 JSON 配置文件,用于 CA 证书签名请求(CSR),例如:`ca-csr.json`。
确认用你需要的值替换掉尖括号中的值。 确认用你需要的值替换掉尖括号中的值。
```json
{ {
"CN": "kubernetes", "CN": "kubernetes",
"key": { "key": {
@@ -276,18 +313,21 @@ real values you want to use.
"OU": "<organization unit>" "OU": "<organization unit>"
}] }]
} }
```
<!-- <!--
5. Generate CA key (`ca-key.pem`) and certificate (`ca.pem`): 1. Generate CA key (`ca-key.pem`) and certificate (`ca.pem`):
--> -->
5. 生成 CA 秘钥文件(`ca-key.pem`)和证书文件(`ca.pem`): 5. 生成 CA 秘钥文件(`ca-key.pem`)和证书文件(`ca.pem`):
```shell
../cfssl gencert -initca ca-csr.json | ../cfssljson -bare ca ../cfssl gencert -initca ca-csr.json | ../cfssljson -bare ca
```
<!-- <!--
6. Create a JSON config file for generating keys and certificates for the API 1. Create a JSON config file for generating keys and certificates for the API
server, for example, `server-csr.json`. Be sure to replace the values in angle brackets with server, for example, `server-csr.json`. Be sure to replace the values in angle brackets with
real values you want to use. The `MASTER_CLUSTER_IP` is the service cluster real values you want to use. The `<MASTER_CLUSTER_IP>` is the service cluster
IP for the API server as described in previous subsection. IP for the API server as described in previous subsection.
The sample below also assumes that you are using `cluster.local` as the default The sample below also assumes that you are using `cluster.local` as the default
DNS domain name. DNS domain name.
@@ -296,6 +336,7 @@ DNS domain name.
确认用你需要的值替换掉尖括号中的值。`MASTER_CLUSTER_IP` 是为 API 服务器 指定的服务集群 IP,就像前面小节描述的那样。 确认用你需要的值替换掉尖括号中的值。`MASTER_CLUSTER_IP` 是为 API 服务器 指定的服务集群 IP,就像前面小节描述的那样。
以下示例假定你的默认 DNS 域名为`cluster.local`。 以下示例假定你的默认 DNS 域名为`cluster.local`。
```json
{ {
"CN": "kubernetes", "CN": "kubernetes",
"hosts": [ "hosts": [
@@ -320,21 +361,24 @@ DNS domain name.
"OU": "<organization unit>" "OU": "<organization unit>"
}] }]
} }
```
<!-- <!--
7. Generate the key and certificate for the API server, which are by default 1. Generate the key and certificate for the API server, which are by default
saved into file `server-key.pem` and `server.pem` respectively: saved into file `server-key.pem` and `server.pem` respectively:
--> -->
7. 为 API 服务器生成秘钥和证书,默认会分别存储为`server-key.pem` 和 `server.pem` 两个文件。 7. 为 API 服务器生成秘钥和证书,默认会分别存储为`server-key.pem` 和 `server.pem` 两个文件。
```shell
../cfssl gencert -ca=ca.pem -ca-key=ca-key.pem \ ../cfssl gencert -ca=ca.pem -ca-key=ca-key.pem \
--config=ca-config.json -profile=kubernetes \ --config=ca-config.json -profile=kubernetes \
server-csr.json | ../cfssljson -bare server server-csr.json | ../cfssljson -bare server
```
<!-- <!--
## Distributing Self-Signed CA Certificate ## Distributing Self-Signed CA Certificate
--> -->
## 分发自签名的 CA 证书 ## 分发自签名的 CA 证书 {#distributing-self-signed-ca-certificate}
<!-- <!--
A client node may refuse to recognize a self-signed CA certificate as valid. A client node may refuse to recognize a self-signed CA certificate as valid.
@@ -349,12 +393,12 @@ On each client, perform the following operations:
在每一个客户节点,执行以下操作: 在每一个客户节点,执行以下操作:
```bash ```shell
sudo cp ca.crt /usr/local/share/ca-certificates/kubernetes.crt sudo cp ca.crt /usr/local/share/ca-certificates/kubernetes.crt
sudo update-ca-certificates sudo update-ca-certificates
``` ```
``` ```none
Updating certificates in /etc/ssl/certs... Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done. 1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d.... Running hooks in /etc/ca-certificates/update.d....
@@ -369,8 +413,9 @@ done.
<!-- <!--
You can use the `certificates.k8s.io` API to provision You can use the `certificates.k8s.io` API to provision
x509 certificates to use for authentication as documented x509 certificates to use for authentication as documented
[here](/docs/tasks/tls/managing-tls-in-a-cluster). in the [Managing TLS in a cluster](/docs/tasks/tls/managing-tls-in-a-cluster)
task page.
--> -->
你可以通过 `certificates.k8s.io` API 提供 x509 证书,用来做身份验证, 你可以通过 `certificates.k8s.io` API 提供 x509 证书,用来做身份验证,
如[](/zh-cn/docs/tasks/tls/managing-tls-in-a-cluster)文档所述。 如[管理集群中的 TLS 认证](/zh-cn/docs/tasks/tls/managing-tls-in-a-cluster)文档所述。