管理 CA 捆绑包

使用证书颁发机构 (CA) 捆绑包,可以将 CA 证书分组到一起,并使用它们来验证与数据库的连接。

您可以通过查询 CA_BUNDLES 系统表来查看现有 CA 捆绑包。

创建 CA 捆绑包

要创建 CA 捆绑包,请使用 创建 CA 捆绑包 并指定一个或多个 CA 证书。如果您没有指定 CA 证书,则 CA 捆绑包将为空。

此示例创建一个名为 ca_bundle 的 CA 捆绑包,其中包含 CA 证书 root_ca 和 root_ca2:

=> CREATE CA BUNDLE ca_bundle CERTIFICATES root_ca, root_ca2;
CREATE CA BUNDLE

=> SELECT * FROM ca_bundles WHERE name='ca_bundle';
        oid        |   name    |       owner       |              certificates
-------------------+-----------+-------------------+----------------------------------------
 45035996274026954 | ca_bundle | 45035996273704962 | [45035996274026764, 45035996274026766]
(1 row)

修改现有 CA 捆绑包

CA_BUNDLES 仅存储 OID。由于对 CA 捆绑包的操作需要证书和所有者名称,因此可以使用以下查询将捆绑包映射到证书和所有者名称:

=> SELECT user_name AS owner_name,
       owner     AS owner_oid,
       b.name    AS bundle_name,
       c.name    AS cert_name
FROM   (SELECT name,
               STRING_TO_ARRAY(certificates) :: array[INT] AS certs
        FROM   ca_bundles) b
       LEFT JOIN certificates c
              ON CONTAINS(b.certs, c.oid)
       LEFT JOIN users
              ON user_id = owner
ORDER  BY 1;

 owner_name |     owner_oid     | bundle_name  | cert_name
------------+-------------------+--------------+-----------
 dbadmin    | 45035996273704962 | ca_bundle    | root_ca
 dbadmin    | 45035996273704962 | ca_bundle    | ca_cert
(2 rows)

添加和移除 CA 证书

如果您拥有 CA 捆绑包的所有权,则可以使用 ALTER CA BUNDLE 添加和移除证书。

此示例通过添加 ca_cert 和移除 root_ca2 来修改 ca_bundle:

=> ALTER CA BUNDLE ca_bundle ADD CERTIFICATES ca_cert;
ALTER CA BUNDLE

=> SELECT * FROM ca_bundles WHERE name='ca_bundle';
        oid        |   name    |       owner       |                       certificates
-------------------+-----------+-------------------+-----------------------------------------------------------
 45035996274027356 | ca_bundle | 45035996273704962 | [45035996274027342, 45035996274027348, 45035996274027396]
(1 row)

=> ALTER CA BUNDLE ca_bundle REMOVE CERTIFICATES root_ca2;
ALTER CA BUNDLE

=> SELECT * FROM CA_BUNDLES;
        oid        |   name    |       owner       |              certificates
-------------------+-----------+-------------------+----------------------------------------
 45035996274027356 | ca_bundle | 45035996273704962 | [45035996274027342, 45035996274027396]
(1 row)

管理 CA 捆绑包所有权

超级用户和 CA 捆绑包所有者可以通过查询 CA_BUNDLES 系统表来查看捆绑包是否存在,但只有给定捆绑包的所有者才能看到其中的证书。

在以下示例中,dbadmin 用户拥有 ca_bundle。将捆绑包的所有权授予“Alice”后,dbadmin 无法再看到捆绑包中的证书:

=> => SELECT * FROM ca_bundles WHERE name='ca_bundle';
        oid        |   name    |       owner       |              certificates
-------------------+-----------+-------------------+----------------------------------------
 45035996274027356 | ca_bundle | 45035996273704962 | [45035996274027342, 45035996274027396]
(1 row)

=> ALTER CA BUNDLE ca_bundle OWNER TO Alice;
ALTER CA BUNDLE

=> SELECT * FROM ca_bundles WHERE name='ca_bundle';
        oid        |   name    |       owner       | certificates
-------------------+-----------+-------------------+--------------
 45035996274027356 | ca_bundle | 45035996274027586 | []
(1 row)

删除 CA 捆绑包

您必须拥有 CA 捆绑包的所有权才能删除它:

=> DROP CA BUNDLE ca_bundle;
DROP CA BUNDLE