等保: Postgresql配置ssl链接

这篇具有很好参考价值的文章主要介绍了等保: Postgresql配置ssl链接。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1 说明

公司某SaaS平台需要进行等保评测,要求pg数据库必须使用ssl链接。

整个ssl方案的调整包括pg数据库端的证书调整和使用pg数据库的服务的调整,如下的操作中以Java服务为例进行说明。

如下的操作中pg的运行用户是postgres,参考本方案的时候根据实际情况修改即可。

  • 服务连接pg数据库的用户是pg
  • 运行pg库的用户是postgres

2 操作步骤

2.1 数据库端调整

2.1.1 生成服务端证书

生成证书key文件


[postgres@localhost ~]$ cd /data/app/postgresql/
[postgres@localhost postgresql]$ ls
bin  include  lib  lib.bak  share
[postgres@localhost postgresql]$ mkdir certs
[postgres@localhost postgresql]$ cd certs/
[postgres@localhost certs]$ openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
......................+++
.......................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key: certpass
Verifying - Enter pass phrase for server.key:  certpass

移除密码


[postgres@localhost certs]$ openssl rsa -in server.key -out server.key
Enter pass phrase for server.key: certpass
writing RSA key

生成证书


[postgres@localhost certs]$ openssl req -new -key server.key -days 36500 -out server.crt -x509
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Hebei
Locality Name (eg, city) [Default City]:langfang
Organization Name (eg, company) [Default Company Ltd]:ltd
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:localhost
Email Address []:

生成根证书 由于没有公证机构提供,只能使用自签名证书,因此可以将服务器证书作为根证书

$ cp server.crt root.crt

2.1.2 配置证书

pg配置文件postgresql.conf增加ssl整数配置项

ssl=on
ssl_ca_file='/data/app/postgresql/certs/root.crt'
ssl_key_file='/data/app/postgresql/certs/server.key'
ssl_cert_file='/data/app/postgresql/certs/server.crt'

更改pg库连接授权 配置文件为pg_hba.conf
如下这行添加到最上边

hostssl all             pg      all                     cert

证书文件权限调整

[postgres@localhost postgresql-12.8]$ cd /data/app/postgresql/certs
[postgres@localhost certs]$ ls
root.crt  server.crt  server.key
[postgres@localhost certs]$ chmod 0600 ./*

重启数据库

bash /data/app/scripts/postgresql restart

2.1.3 生成客户端证书

客户端需要三个文件: root.crt(根证书)、postgresql.crt(客户端证书)、postgresql.key(客户端私钥)

生成客户端私钥

[postgres@localhost ~]$ cd /data/app/postgresql/certs/
[postgres@localhost certs]$ openssl genrsa -des3 -out postgresql.key 2048
Generating RSA private key, 2048 bit long modulus
....................................+++
..+++
e is 65537 (0x10001)
Enter pass phrase for postgresql.key: certpass
Verifying - Enter pass phrase for postgresql.key: certpass

移出密码

[postgres@localhost certs]$ openssl rsa -in postgresql.key -out postgresql.key
Enter pass phrase for postgresql.key: certpass
writing RSA key

生成客户端csr

[postgres@localhost certs]$ openssl req -new -key postgresql.key -out postgresql.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:pg
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

生成客户端证书

[postgres@localhost certs]$ openssl x509 -req -days 36500 -in postgresql.csr -CA root.crt -CAkey server.key -out postgresql.crt -CAcreateserial
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd/CN=pg
Getting CA Private Key

2.2 使用pg库的服务端调整

在Java - jdbc中,客户端密钥必须是用pk8的格式,需要转换一下。

openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt -in postgresql.key -out postgresql.pk8

将证书文件导入到服务目录下 假如是服务目录下的certs目录
/usr/local/service_name/certs

修改jdbc链接

ssl=true&sslmode=verify-ca&sslcert=/usr/local/service_name/certs/postgresql.crt&sslkey=/usr/local/service_name/certs/postgresql.pk8&sslrootcert=/usr/local/service_name/certs/root.crt

重启java服务

3 避坑指南

3.1 证书核验通不过的情况

问题描述

按照上述操作后,如果pg没有配置session_exec,应该是没问题的。
如果配置了session_exec,参考文档等保: pg配置session_exec
那么由于证书核验不通过,会锁定链接用户,导致应用程序无法正常使用pg数据库。

具体的核验命令有两个

命令一 验证客户端证书是否与根证书匹配
openssl verify -CAfile root.crt -purpose sslclient postgresql.crt

命令二 验证证书是否可以用于登录

psql是不能在命令行直接以这种方式使用证书的: psql --sslmode=verify-full --sslcert=
psql使用证书连接的命令行方式如下 等同于上述的–sslmode的参数模式

psql 'host=10.21.0.173 port=5432 dbname=postgres user=postgres sslmode=verify-full sslcert=postgresql.crt sslkey=postgresql.key sslrootcert=root.crt'

命令一的正常返回为

postgresql.crt: OK

命令二的正常返回为: 直接进入pg数据库

修复措施

在2.1的步骤中 生成服务端证书的时候 Common Name字段必须设置为数据库的ip地址,必须是ip地址,vip不可以。
在2.1的步骤中,生成客户端证书的时候 Common Name字段必须设置为连接数据库的用户名,否则会使用服务所在主机的主机名连接。

注意上述两个点后 重新生成证书并配置即可

被这个问题困扰了很久 最后通过这样的方式解决的 实测没问题 不会再锁定用户文章来源地址https://www.toymoban.com/news/detail-423132.html

到了这里,关于等保: Postgresql配置ssl链接的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 网站三级等保该怎么做?有哪些需要注意的?

    三级等保是信息安全技术信息系统安全等级保护中的一个级别,部分网站需要过等保三级,那么等保三级是怎么做的?又有哪些需要注意的问题呢?以下是详细的内容: 网站等保三级办理流程如下: 1、系统分级,可独立分级,也可以找等保测评公司进行咨询; 2、系统备案,可

    2024年02月05日
    浏览(27)
  • 等保二级必须要上的设备有哪些?需要堡垒机吗?

    等保二级属于指导保护级,是指信息系统受到破坏后,会对公民、法人和其他组织的合法权益产生严重损害,或者对社会秩序和公共利益造成损害,但不损害国家安全。企业过等保常见等级为等保二级和等保三级。那你知道等保二级必须要上的设备有哪些?需要堡垒机吗?

    2023年04月21日
    浏览(21)
  • 漏刻有时地理信息系统LOCKGIS小程序配置说明(web-view组件、服务器域名配置、复制链接和转发功能)

    漏刻有时地理信息系统说明文档(LOCKGIS、php后台管理、三端一体PC-H5-微信小程序、百度地图jsAPI二次开发、标注弹窗导航) 漏刻有时地理信息系统LOCKGIS小程序配置说明(web-view组件、服务器域名配置、复制链接和转发功能) 漏刻有时地理信息系统LOCKGIS主程序配置说明(地图调起弹

    2024年02月07日
    浏览(43)
  • 公司创建百度百科需要哪些内容?

    一个公司或是一个品牌想要让自己更有身份,更有知名度,更有含金量,百度百科词条是必不可少的。通过百度百科展示公司的详细信息,有助于增强用户对公司的信任感,提高企业形象。通过百度百科展示公司的发展历程、领导团队、企业荣誉等,可以彰显公司的实力和行

    2024年02月03日
    浏览(29)
  • 【uniapp】 史上最详细手动配置ios平台通用链接 Universal Link 设置

    1.先去苹果开发平台开启服务“Certificates, Identifiers Profiles”页面选择“Identifiers”中选择对应的App ID,确保开启Associated Domains,然后重新生成profile后续打包时用 2.第二步再unapp项目根目录创建apple-app-site-association文件注意此文件不要带后缀,(如果你使用了uniapp的自动生成io

    2024年02月11日
    浏览(33)
  • 【Python爬虫实战】1.爬取A股上市公司年报链接并存入Excel

     数据来源:巨潮资讯  项目需求:按照股票代码,公司名称,年报全称,年份,下载链接等要素写入excel表  使用语言:python  第三方库:requests, re , time等 成品展示:  废话就到这里,直接开干! 1.寻找接口 众所周知,爬取网页数据一般可以通过寻找网页结构规律和爬取接

    2024年02月04日
    浏览(36)
  • 如何异地链接Pycharm服务器进行远程开发并实现与公司服务器资源同步

    本文主要介绍如何使用Pycharm进行远程开发,并实现在家远程与公司服务器资源同步。 新版本 Jetbrains 系列开发IDE( IntelliJ IDEA , PyCharm , GoLand )等都支持远程使用服务器编译,并且可以 通过SFTP同步本地与服务器项目代码 。 这样做的好处是**我们只要连接上服务器就能开始

    2024年02月01日
    浏览(50)
  • PostgreSQL+SSL链路测试

    SSL一个各种证书在此就不详细介绍了,PostgreSQL要支持SSL的前提需要打开openssl选项,包括客户端和服务器端。 测试过程。 1. 生成私钥 root用户:  2. 生成公钥证书  3. 配置PG服务器部分,我的PG服务器是在postgres134用户下,因此需要  su - postgres134  在PG的PGDATA目录中需要生成三

    2024年02月11日
    浏览(21)
  • postgresql 启用ssl安全连接方式

    直接 cp ca.crt root.crt 使用ca的就可以。 我们一般会配置ssl、ssl_cert_file、ssl_key_file这三个,其他的一般维持默认值。这是三个参数分别的含义如下: ssl: 是否支持SSL连接。默认是关闭的。 ssl_cert_file:指定包含SSL服务器证书的文件的名称。默认是server.crt。相对路径相对于数据目录

    2024年02月05日
    浏览(27)
  • 基于Python实现Midjourney集成到(个人/公司)平台中

    目前Midjourney没有对外开放Api,想体验他们的服务只能在discord中进入他们的频道进行体验或者把他们的机器人拉入自己创建的服务器中;而且现在免费的也用不了了,想使用就得订阅。本教程使用midjourney-api这个开源项目,搭建Midjourney相关接口服务,以集成到个人平台中~ 本文

    2024年02月20日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包