Please enable Javascript to view the contents

PKI-自签发证书说明

 ·  ☕ 1 分钟

重要

生成自签发证书

  1. 生成CA根证书以及根证书私钥.

output: ca.crtca.key, pem格式. input ''

1
2
3
4
5
# Generate a CA private key
openssl genrsa -out ca.key 4096

# Create a self signed Certificate, valid for 10yrs with the 'signing' option set
openssl req -x509 -new -nodes -key ca.key -subj "/CN=company.COM" -days 3650 -reqexts v3_req -extensions v3_ca -out ca.crt
  1. 生成*.example.domain通配符证书私钥

output: example.domain.key, pem格式. input: ''

1
openssl genrsa -out example.domain.key 4096
  1. 根据*.example.domain通配符证书私钥,生成证书请求文件(csr)example.domain.csr

output: example.domain.csr, pem格式. input: example.domain.key.

1
openssl req -new -sha256 -key example.domain.key -out example.domain.csr -subj "/CN=svc.example.domain"
  1. 根据证书请求文件通过根证书、根证书私钥签发证书。

output: example.domain.crt, pem格式. input: example.domain.csrca.crtca.key 以及配置文件example.domain.ini.
其中,配置文件example.domain.ini的内容如下:

1
2
3
4
5
[ ext ]
subjectAltName = @dns

[ dns ]
DNS.1 = *.example.domain

执行下面命令:

1
openssl x509 -req -in example.domain.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 3560 -out example.domain.crt -extfile example.domain.ini -extensions ext
  1. 生成k8s中的secret.

output: k8s-secret example-certs, pem格式. input: example.domain.crtexample.domain.key pem格式.

1
kubectl create secret tls example-certs --cert=example.domain.crt --key=example.domain.key

Reference

概念说明
生成证书

分享

Hex
作者
Hex
CloudNative Developer

目录