@@ -82,7 +82,7 @@ CertificateSigningRequest 资源类型允许客户端基于签名请求申请发
82
82
CertificateSigningRequest 对象在 ` spec.request ` 字段中包含一个 PEM 编码的 PKCS #10 签名请求。
83
83
CertificateSigningRequest 使用 ` spec.signerName ` 字段标示签名者(请求的接收方)。
84
84
注意,` spec.signerName ` 在 ` certificates.k8s.io/v1 ` 之后的 API 版本是必填项。
85
- 在 Kubernetes v1.22 和以后的版本 ,客户可以设置 ` spec.expirationSeconds `
85
+ 在 Kubernetes v1.22 及更高版本中 ,客户可以设置 ` spec.expirationSeconds `
86
86
字段(可选)来为颁发的证书设定一个特定的有效期。该字段的最小有效值是 ` 600 ` ,也就是 10 分钟。
87
87
88
88
<!--
@@ -878,206 +878,11 @@ See the [clusterTrustBundle projected volume source](/docs/concepts/storage/proj
878
878
ClusterTrustBundle 的内容可以注入到容器文件系统,这与 ConfigMap 和 Secret 类似。
879
879
更多细节参阅 [ClusterTrustBundle 投射卷源](/zh-cn/docs/concepts/storage/projected-volumes#clustertrustbundle)。
880
880
881
- <!-- TODO this should become a task page -->
882
-
883
- <!--
884
- # # How to issue a certificate for a user {#normal-user}
885
-
886
- A few steps are required in order to get a normal user to be able to
887
- authenticate and invoke an API. First, this user must have a certificate issued
888
- by the Kubernetes cluster, and then present that certificate to the Kubernetes API.
889
- -->
890
- # # 如何为用户签发证书 {#normal-user}
891
-
892
- 为了让普通用户能够通过认证并调用 API,需要执行几个步骤。
893
- 首先,该用户必须拥有 Kubernetes 集群签发的证书,
894
- 然后将该证书提供给 Kubernetes API。
895
-
896
- <!--
897
- # ## Create private key
898
-
899
- The following scripts show how to generate PKI private key and CSR. It is
900
- important to set CN and O attribute of the CSR. CN is the name of the user and
901
- O is the group that this user will belong to. You can refer to
902
- [RBAC](/docs/reference/access-authn-authz/rbac/) for standard groups.
903
- -->
904
- # ## 创建私钥 {#create-private-key}
905
-
906
- 下面的脚本展示了如何生成 PKI 私钥和 CSR。
907
- 设置 CSR 的 CN 和 O 属性很重要。CN 是用户名,O 是该用户归属的组。
908
- 你可以参考 [RBAC](/zh-cn/docs/reference/access-authn-authz/rbac/) 了解标准组的信息。
909
-
910
- ` ` ` shell
911
- openssl genrsa -out myuser.key 2048
912
- openssl req -new -key myuser.key -out myuser.csr -subj "/CN=myuser"
913
- ` ` `
914
-
915
- <!--
916
- # ## Create a CertificateSigningRequest {#create-certificatessigningrequest}
917
-
918
- Create a [CertificateSigningRequest](/docs/reference/kubernetes-api/authentication-resources/certificate-signing-request-v1/)
919
- and submit it to a Kubernetes Cluster via kubectl. Below is a script to generate the
920
- CertificateSigningRequest. a CertificateSigningRequest and submit it to a Kubernetes Cluster via kubectl. Below is a script to generate the CertificateSigningRequest.
921
- -->
922
- # ## 创建 CertificateSigningRequest {#create-certificatesigningrequest}
923
-
924
- 创建一个 [CertificateSigningRequest](/zh-cn/docs/reference/kubernetes-api/authentication-resources/certificate-signing-request-v1/),
925
- 并通过 kubectl 将其提交到 Kubernetes 集群。
926
- 下面是生成 CertificateSigningRequest 的脚本。
927
-
928
- ` ` ` shell
929
- cat <<EOF | kubectl apply -f -
930
- apiVersion: certificates.k8s.io/v1
931
- kind: CertificateSigningRequest
932
- metadata:
933
- name: myuser
934
- spec:
935
- request: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0KTUlJQ1ZqQ0NBVDRDQVFBd0VURVBNQTBHQTFVRUF3d0dZVzVuWld4aE1JSUJJakFOQmdrcWhraUc5dzBCQVFFRgpBQU9DQVE4QU1JSUJDZ0tDQVFFQTByczhJTHRHdTYxakx2dHhWTTJSVlRWMDNHWlJTWWw0dWluVWo4RElaWjBOCnR2MUZtRVFSd3VoaUZsOFEzcWl0Qm0wMUFSMkNJVXBGd2ZzSjZ4MXF3ckJzVkhZbGlBNVhwRVpZM3ExcGswSDQKM3Z3aGJlK1o2MVNrVHF5SVBYUUwrTWM5T1Nsbm0xb0R2N0NtSkZNMUlMRVI3QTVGZnZKOEdFRjJ6dHBoaUlFMwpub1dtdHNZb3JuT2wzc2lHQ2ZGZzR4Zmd4eW8ybmlneFNVekl1bXNnVm9PM2ttT0x1RVF6cXpkakJ3TFJXbWlECklmMXBMWnoyalVnald4UkhCM1gyWnVVV1d1T09PZnpXM01LaE8ybHEvZi9DdS8wYk83c0x0MCt3U2ZMSU91TFcKcW90blZtRmxMMytqTy82WDNDKzBERHk5aUtwbXJjVDBnWGZLemE1dHJRSURBUUFCb0FBd0RRWUpLb1pJaHZjTgpBUUVMQlFBRGdnRUJBR05WdmVIOGR4ZzNvK21VeVRkbmFjVmQ1N24zSkExdnZEU1JWREkyQTZ1eXN3ZFp1L1BVCkkwZXpZWFV0RVNnSk1IRmQycVVNMjNuNVJsSXJ3R0xuUXFISUh5VStWWHhsdnZsRnpNOVpEWllSTmU3QlJvYXgKQVlEdUI5STZXT3FYbkFvczFqRmxNUG5NbFpqdU5kSGxpT1BjTU1oNndLaTZzZFhpVStHYTJ2RUVLY01jSVUyRgpvU2djUWdMYTk0aEpacGk3ZnNMdm1OQUxoT045UHdNMGM1dVJVejV4T0dGMUtCbWRSeEgvbUNOS2JKYjFRQm1HCkkwYitEUEdaTktXTU0xMzhIQXdoV0tkNjVoVHdYOWl4V3ZHMkh4TG1WQzg0L1BHT0tWQW9FNkpsYWFHdTlQVmkKdjlOSjVaZlZrcXdCd0hKbzZXdk9xVlA3SVFjZmg3d0drWm89Ci0tLS0tRU5EIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLQo=
936
- signerName: kubernetes.io/kube-apiserver-client
937
- expirationSeconds: 86400 # one day
938
- usages:
939
- - client auth
940
- EOF
941
- ` ` `
942
-
943
- <!--
944
- Some points to note :
945
-
946
- - ` usages` has to be '`client auth`'
947
- - ` expirationSeconds` could be made longer (i.e. `864000` for ten days) or shorter (i.e. `3600` for one hour)
948
- - ` request` is the base64 encoded value of the CSR file content.
949
- You can get the content using this command :
950
- -->
951
- 需要注意的几点:
952
-
953
- - ` usage` 字段必须是 '`client auth`'
954
- - ` expirationSeconds` 可以设置为更长(例如 `864000` 是十天)或者更短(例如 `3600` 是一个小时)
955
- - ` request` 字段是 CSR 文件内容的 base64 编码值,
956
- 要得到该值,可以执行命令:
957
-
958
- ` ` ` shell
959
- cat myuser.csr | base64 | tr -d "\n "
960
- ` ` `
961
-
962
- <!--
963
- # ## Approve the CertificateSigningRequest {#approve-certificate-signing-request}
964
-
965
- Use kubectl to create a CSR and approve it.
966
-
967
- Get the list of CSRs :
968
- -->
969
- # ## 批准 CertificateSigningRequest {#approve-certificate-signing-request}
970
-
971
- 使用 kubectl 创建 CSR 并批准。
972
-
973
- 获取 CSR 列表:
974
-
975
- ` ` ` shell
976
- kubectl get csr
977
- ` ` `
978
-
979
- <!--
980
- Approve the CSR :
981
- -->
982
- 批准 CSR:
983
-
984
- ` ` ` shell
985
- kubectl certificate approve myuser
986
- ` ` `
987
-
988
- <!--
989
- # ## Get the certificate
990
-
991
- Retrieve the certificate from the CSR :
992
- -->
993
- # ## 取得证书 {#get-the-certificate}
994
-
995
- 从 CSR 取得证书:
996
-
997
- ` ` ` shell
998
- kubectl get csr/myuser -o yaml
999
- ` ` `
1000
-
1001
- <!--
1002
- The certificate value is in Base64-encoded format under `status.certificate`.
1003
-
1004
- Export the issued certificate from the CertificateSigningRequest.
1005
- -->
1006
- 证书的内容使用 base64 编码,存放在字段 `status.certificate`。
1007
-
1008
- 从 CertificateSigningRequest 导出颁发的证书:
1009
-
1010
- ` ` ` shell
1011
- kubectl get csr myuser -o jsonpath='{.status.certificate}'| base64 -d > myuser.crt
1012
- ` ` `
1013
-
1014
- <!--
1015
- # ## Create Role and RoleBinding
1016
-
1017
- With the certificate created it is time to define the Role and RoleBinding for
1018
- this user to access Kubernetes cluster resources.
1019
-
1020
- This is a sample command to create a Role for this new user :
1021
- -->
1022
- # ## 创建角色和角色绑定 {#create-role-and-role-binding}
1023
-
1024
- 创建了证书之后,为了让这个用户能访问 Kubernetes 集群资源,现在就要创建
1025
- Role 和 RoleBinding 了。
1026
-
1027
- 下面是为这个新用户创建 Role 的示例命令:
1028
-
1029
- ` ` ` shell
1030
- kubectl create role developer --verb=create --verb=get --verb=list --verb=update --verb=delete --resource=pods
1031
- ` ` `
1032
-
1033
- <!--
1034
- This is a sample command to create a RoleBinding for this new user :
1035
- -->
1036
- 下面是为这个新用户创建 RoleBinding 的示例命令:
1037
-
1038
- ` ` ` shell
1039
- kubectl create rolebinding developer-binding-myuser --role=developer --user=myuser
1040
- ` ` `
1041
-
1042
- <!--
1043
- # ## Add to kubeconfig
1044
-
1045
- The last step is to add this user into the kubeconfig file.
1046
-
1047
- First, you need to add new credentials :
1048
- -->
1049
- # ## 添加到 kubeconfig {#add-to-kubeconfig}
1050
-
1051
- 最后一步是将这个用户添加到 kubeconfig 文件。
1052
-
1053
- 首先,你需要添加新的凭据:
1054
-
1055
- ` ` ` shell
1056
- kubectl config set-credentials myuser --client-key=myuser.key --client-certificate=myuser.crt --embed-certs=true
1057
- ` ` `
1058
-
1059
- <!--
1060
- Then, you need to add the context :
1061
- -->
1062
- 然后,你需要添加上下文:
1063
-
1064
- ` ` ` shell
1065
- kubectl config set-context myuser --cluster=kubernetes --user=myuser
1066
- ` ` `
1067
-
1068
- <!--
1069
- To test it, change the context to `myuser` :
1070
- -->
1071
- 来测试一下,把上下文切换为 `myuser`:
1072
-
1073
- ` ` ` shell
1074
- kubectl config use-context myuser
1075
- ` ` `
1076
-
1077
881
# # {{% heading "whatsnext" %}}
1078
882
1079
883
<!--
1080
884
* Read [Manage TLS Certificates in a Cluster](/docs/tasks/tls/managing-tls-in-a-cluster/)
885
+ * Read [Issue a Certificate for a Kubernetes API Client Using A CertificateSigningRequest](/docs/tasks/tls/certificate-issue-client-csr/)
1081
886
* View the source code for the kube-controller-manager built in
1082
887
[signer](https://github.com/kubernetes/kubernetes/blob/32ec6c212ec9415f604ffc1f4c1f29b782968ff1/pkg/controller/certificates/signer/cfssl_signer.go)
1083
888
* View the source code for the kube-controller-manager built in
@@ -1088,6 +893,7 @@ kubectl config use-context myuser
1088
893
* {{< page-api-reference kind="ClusterTrustBundle" >}}
1089
894
-->
1090
895
* 参阅[管理集群中的 TLS 认证](/zh-cn/docs/tasks/tls/managing-tls-in-a-cluster/)
896
+ * 参阅[使用 CertificateSigningRequest 为 Kubernetes API 客户端颁发证书](/zh-cn/docs/tasks/tls/certificate-issue-client-csr/)
1091
897
* 查看 kube-controller-manager 中[签名者](https://github.com/kubernetes/kubernetes/blob/32ec6c212ec9415f604ffc1f4c1f29b782968ff1/pkg/controller/certificates/signer/cfssl_signer.go)部分的源代码
1092
898
* 查看 kube-controller-manager 中[批准者](https://github.com/kubernetes/kubernetes/blob/32ec6c212ec9415f604ffc1f4c1f29b782968ff1/pkg/controller/certificates/approver/sarapprove.go)部分的源代码
1093
899
* 有关 X.509 本身的详细信息,请参阅 [RFC 5280](https://tools.ietf.org/html/rfc5280#section-3.1) 第 3.1 节
0 commit comments