4.2. 创建证书颁发机构
使用以下步骤设置您自己的 CA,并使用它来为您的域发布服务器证书。这可让您使用自己的证书保护与 SSL/TLS 的通信。
流程
输入以下命令生成 root CA 密钥:
$ openssl genrsa -out rootCA.key 2048
输入以下命令生成 root CA 证书:
$ openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
输入要合并到证书请求中的信息,包括服务器主机名,例如:
Country Name (2 letter code) [XX]:IE State or Province Name (full name) []:GALWAY Locality Name (eg, city) [Default City]:GALWAY Organization Name (eg, company) [Default Company Ltd]:QUAY Organizational Unit Name (eg, section) []:DOCS Common Name (eg, your name or your server's hostname) []:quay-server.example.com
输入以下命令生成服务器密钥:
$ openssl genrsa -out ssl.key 2048
输入以下命令生成签名请求:
$ openssl req -new -key ssl.key -out ssl.csr
输入要合并到证书请求中的信息,包括服务器主机名,例如:
Country Name (2 letter code) [XX]:IE State or Province Name (full name) []:GALWAY Locality Name (eg, city) [Default City]:GALWAY Organization Name (eg, company) [Default Company Ltd]:QUAY Organizational Unit Name (eg, section) []:DOCS Common Name (eg, your name or your server's hostname) []:quay-server.example.com Email Address []:
创建配置文件
openssl.cnf
,指定服务器主机名,例如:openssl.cnf
文件示例[req] req_extensions = v3_req distinguished_name = req_distinguished_name [req_distinguished_name] [ v3_req ] basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = <quay-server.example.com> IP.1 = 192.168.1.112
使用配置文件生成证书
ssl.cert
:$ openssl x509 -req -in ssl.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out ssl.cert -days 356 -extensions v3_req -extfile openssl.cnf
输入以下命令确认您的创建证书和密钥:
$ ls /path/to/certificates
输出示例
rootCA.key ssl-bundle.cert ssl.key custom-ssl-config-bundle-secret.yaml rootCA.pem ssl.cert openssl.cnf rootCA.srl ssl.csr