代理的自签名证书
不建议在生产环境中使用自签名证书。对于生产环境,建议使用受信任的证书颁发机构。本节概述了一种为测试和演示目的生成自签名证书的实用方法。 但是,如果为每个代理生成唯一的自签名证书,并且可以通过配置和使用这些证书更新 NOM 服务器来轻松轮换这些证书,则可以使用它们为代理启用双向身份验证。 |
NOM 代理包含一个实用程序,用于生成适合您的环境的自签名证书。
$> agent ssc --help
utility to generate self-signed certificate for TEST purposes only
sample usage:
to generate a self-signed certificate for 'localhost', which could either be
accessed through DNS names of 'localhost.localdomain' or 'my.custom.domain', or
with IP addresses of '127.0.0.1' or '192.168.100.5';
$> agent ssc -n localhost -o /tmp \
-d localhost.localdomain,my.custom.domain \
-i 127.0.0.1,192.168.100.5
it creates /tmp/localhost.cert.pem and /tmp/localhost.key.pem files upon completion.
options (required options marked with *):
-d, --dns=<dns>[,<dns>...]
list of dns names to use to access the
agent host, eg. --dns=localhost.localdomain,test.
local.domain
-i, --ip=<ip>[,<ip>...] list of IP addresses to use to access the
agent host, eg. --ip=127.0.0.1,192.168.100.55
* -n, --name=<name> common name to use in generated certificate,
eg. --name=localhost
* -o, --output=<output> target directory, eg. --output=.
-h, --help help
如果您为 localhost
上的代理生成证书,则 localhost
是证书中作为主体名称字段设置的主要名称,并且也用作生成文件的名称。如果没有指定 CONFIG_AGENT_NAME
,则代理客户端证书中的主体名称以及代理的主机信息将用作代理名称。
为了为上述示例生成自签名证书,请执行以下命令
agent ssc -n localhost \
-o ./certificates \
-d nom.example.com \
-i 192.168.10.1,172.16.10.1
它会生成一对密钥和一个自签名证书,并在 ./certificates
目录中创建 localhost.cert.pem
和 localhost.key.pem
文件。
然后,您可以使用这两个文件来配置代理以进行 mTLS 身份验证,如 此处 所述。代理证书也需要通过 GRPC_SERVER_SECURITY_TRUST_CERT_COLLECTION
或 grpc.server.security.trustCertCollection
添加到 NOM 服务器信任库中,以实现双向身份验证。
如果您需要为每个代理生成特定于代理的密钥,请对每个代理使用唯一的代理名称作为主体名称(如果未设置 CONFIG_AGENT_NAME
,则代理名称将被覆盖)。
以下是一个简化的命令,用于生成绑定到代理名称的自签名证书
agent ssc -n nom-agent-1 -o ./certificates
它会生成一对密钥和一个自签名证书,并在 ./certificates
目录中创建 nom-agent-1.cert.pem
和 nom-agent-1.key.pem
文件。