其他分享
首页 > 其他分享> > 基于CFSSL工具创建CA证书

基于CFSSL工具创建CA证书

作者:互联网

背景描述

CA(Certification Authority)证书,指的是权威机构给我们颁发的证书。

在局域网中部署组件时,想要通过证书来实现身份的认证,确保通信的安全性,可以通过cfssl工具来进行CA证书,服务端证书,客户端证书的创建。

 

部署cfssl工具

下载cfssl,cfssljson,cfssl-certinfo工具

下载地址:https://pkg.cfssl.org/

[root@localhost tools]# wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
[root@localhost tools]# wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
[root@localhost tools]# wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64

 

 

增加命令的执行权限,并且增加到相关目录

[root@localhost tools]# chmod +x cfssl*
[root@localhost tools]# mv cfssl_linux-amd64 /usr/local/bin/cfssl
[root@localhost tools]# mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
[root@localhost tools]# mv cfssl-certinfo_linux-amd64 /usr/bin/cfssl-certinfo

 

 

创建认证中心(CA)

CFSSL可以创建一个获取和操作证书的内部认证中心。

运行认证中心需要一个CA证书和相应的CA私钥。任何知道私钥的人都可以充当CA颁发证书。因此,私钥的保护至关重要

配置证书生成策略

配置证书生成策略,让CA软件知道颁发有什么功能的证书。

生成CA证书和私钥(root证书和私钥)

创建一个文件ca-csr.json

#vim ca-csr.json
{
  "CN": "kubernetes",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "ShangHai",
      "L": "ShangHai",
      "O": "k8s",
      "OU": "System"
    }
  ]
}

 

参数介绍:

 

生成CA证书和CA私钥和CSR(证书签名请求)

[root@localhost tools]# cfssl gencert -initca ca-csr.json | cfssljson -bare ca
2020/12/04 14:20:39 [INFO] generating a new CA key and certificate from CSR
2020/12/04 14:20:39 [INFO] generate received request
2020/12/04 14:20:39 [INFO] received CSR
2020/12/04 14:20:39 [INFO] generating key: rsa-2048
2020/12/04 14:20:39 [INFO] encoded CSR
2020/12/04 14:20:39 [INFO] signed certificate with serial number 497233672920328375338343228164630446467151606126

[root@localhost tools]# ls -l ca*
-rw-r--r-- 1 root root  294 Dec  4 14:13 ca-config.json
-rw-r--r-- 1 root root 1045 Dec  4 14:20 ca.csr
-rw-r--r-- 1 root root  246 Dec  4 14:19 ca-csr.json
-rw------- 1 root root 1675 Dec  4 14:20 ca-key.pem
-rw-r--r-- 1 root root 1310 Dec  4 14:20 ca.pem

 

该命令会生成运行CA所必需的文件ca-key.pem(私钥)和ca.pem(证书),还会生成ca.csr(证书签名请求),用于交叉签名或重新签名。

查看cert(证书信息):

# cfssl certinfo -cert ca.pem

 

查看CSR(证书签名请求)信息:

# cfssl certinfo -csr ca.csr

 

 

创建etcd服务端证书

创建一个文件etcd-csr.json

#vim etcd-csr.json
{
  "CN": "etcd",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "Beijing",
      "L": "Beijing",
      "O": "DC",
      "OU": "System"
    }
  ]
}

 

用CA签发etcd证书和私钥
cfssl gencert \
  -ca=ca.pem \
  -ca-key=ca-key.pem \
  -config=ca-config.json \
  -profile=kubernetes etcd-csr.json | cfssljson -bare etcd

2020/12/04 14:33:00 [INFO] generate received request
2020/12/04 14:33:00 [INFO] received CSR
2020/12/04 14:33:00 [INFO] generating key: rsa-2048
2020/12/04 14:33:00 [INFO] encoded CSR
2020/12/04 14:33:00 [INFO] signed certificate with serial number 86899219278041222746661164070003623992607015229
2020/12/04 14:33:00 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for
websites. For more information see the Baseline Requirements for the Issuance and Management
of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);
specifically, section 10.2.3 ("Information Requirements").

[root@localhost tools]# ls -l etcd*
-rw-r--r-- 1 root root  993 Dec  4 14:33 etcd.csr
-rw-r--r-- 1 root root  201 Dec  4 14:30 etcd-csr.json
-rw------- 1 root root 1679 Dec  4 14:33 etcd-key.pem
-rw-r--r-- 1 root root 1383 Dec  4 14:33 etcd.pem

 

etcd.csr为etcd的证书请求文件,etcd-key.pem为etcd的私钥,etcd.pem为etcd的证书。至此,etcd的证书签发完成。此证书可以作为etcd的服务端证书来使用。

 

 

标签:14,证书,ca,cfssl,CFSSL,etcd,root,CA
来源: https://www.cnblogs.com/shadow-yin/p/14843075.html