X.509 客户端证书允许数据库用户访问项目中的数据库部署。 您可以使用 Atlas Kubernetes Operator 为AtlasProject资源和AtlasDatabaseUser资源启用 X.509 身份验证。
Options for X.509 authentication include Atlas-managed X.509 authentication and self-managed X.509 authentication. To learn more about self-managed X.509 authentication, see Set Up Self-Managed X.509 Certificates.
要设置 X.509 身份验证:
生成 X.509 证书。
配置
AtlasProject自定义资源以使用该证书。配置
AtlasDatabaseUser自定义资源以使用 Atlas 托管或自管理的 X.509 身份验证。
先决条件
注意
要使用自管理的 X.509 证书,您必须拥有公钥基础架构才能与 MongoDB Atlas 集成。
您需要以下公共 API 密钥、私有 API 密钥和组织 ID 信息, 配置 Atlas Kubernetes Operator 对 Atlas 的访问权限。
If you want Atlas Kubernetes Operator to create a new Atlas project, Grant Programmatic Access to an Organization. If your organization requires an IP access list for the Atlas Administration API, you must also configure the API access list.
重要
您必须为 API 密钥分配 Organization Project Creator 或更高级别的组织角色。
If you want to work with an existing Atlas project, Add Project Access from a Project. If your organization requires an IP access list for the Atlas Administration API, you must also configure the API access list.
重要
您必须为 API 密钥分配 Project Owner 项目角色。
要了解更多信息,请参阅配置对 Atlas 的访问权限。
Generate an X.509 certificate with cert-manager or the create_X.509.go script.
使用 cert-经理 生成 X.509 证书
要使用cert-manager生成 X.509 证书,请执行以下步骤:
安装证书经理。
要安装 cert-manager,请参阅cert-manager 安装文档。
使用自定义脚本生成 X.509 证书
使用create_X.509.go生成 X.509 证书脚本,执行以下步骤:
运行自定义脚本。
运行 create_X.509.go脚本:
go run scripts/create_x509.go --path={pem-file-path}
示例:
go run scripts/create_x509.go --path=tmp/x509/
将证书添加到密钥中。
要将证书添加到密钥中,运行以下命令:
kubectl create secret generic {secret-name} --from-file={pem-file-directory}
kubectl label secret {secret-name} atlas.mongodb.com/type=credentials
示例:
kubectl create secret generic my-x509-cert --from-file=./tmp/x509/cert.pem
kubectl label secret my-x509-cert atlas.mongodb.com/type=credentials
步骤
配置项目以使用该证书。
在 自定义资源的 spec.x509 CertRef.nameAtlasProject 参数中指定密钥。
示例:
cat <<EOF | kubectl apply -f - apiVersion: atlas.mongodb.com/v1 kind: AtlasProject metadata: name: my-project spec: name: Test Project projectIpAccessList: - ipAddress: "192.0.2.15" comment: "IP address for Application Server A" - cidrBlock: "203.0.113.0/24" comment: "CIDR block for Application Servers B - D" x509CertRef: name: my-x509-cert EOF
添加使用 X.509 身份验证的数据库用户。
为AtlasDatabaseUser自定义资源指定x509Type参数。
此参数接受:
无 | 不使用 X.509 身份验证的用户。 |
托管 | 使用 Atlas 托管的 X.509 的用户。 您必须为 |
客户 | 使用自管理 X.509 的用户。使用此 您必须为 |
To learn more about the configuration parameters available from the API, see the Atlas Database Users API.
示例:
cat <<EOF | kubectl apply -f - apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: username: CN=my-x509-authenticated-user,OU=organizationalunit,O=organization databaseName: "\$external" x509Type: "CUSTOMER" roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project EOF