简体   繁体   English

带证书的 Nifi 和 Postgresql:如何设置客户端证书和密钥?

[英]Nifi and Postgresql with certificate: how to set client certificate and key?

I have a NIFI image running in openshift and a postgres in the cloud "owned" by another department.我有一个在 openshift 中运行的 NIFI 映像和另一个部门“拥有”的云中的 postgres。

They sent to us a certificate(".crt") and a key(".key"), since the log-in is made trough client certificate, instead of username and password.他们向我们发送了一个证书(“.crt”)和一个密钥(“.key”),因为登录是通过客户端证书而不是用户名和密码进行的。 I have succeeded to log-in in pgAdmin 4, but not to connect the NIFI to the Postgres with certificate and key.我已成功登录 pgAdmin 4,但未使用证书和密钥将 NIFI 连接到 Postgres。

I have uploaded the certificate and the key to the image (using a secret and mounting it) so if I go to the pod terminal I can access it.我已经上传了证书和镜像的密钥(使用秘密并安装它),所以如果我去 pod 终端,我可以访问它。

But, when I pass to a DBCPConnectionPoll service the connection string bellow and activates an ExecuteSQL processor, I receive an exception that the certificate is not valid, as follows:但是,当我将下面的连接字符串传递给 DBCPConnectionPoll 服务并激活 ExecuteSQL 处理器时,我收到证书无效的异常,如下所示:

ERROR
ExecuteSQL[id=...] Unable to execute SQL query <...>;
due to java.sql.SQLException: Cannot create a PoolableConnectionFactory (FATAL: connection requires a valid client certificate).
No FlowFile to route to failure: org.apache.nifi.processor.exception.ProcessException: java.sql.SQLException: Cannot create a PoolableConnectionFactory (FATAL: connection requires a valid client certificate)

I have tried to pass the certificate in two ways to the DBCPConnectionPoll service:我尝试通过两种方式将证书传递给 DBCPConnectionPoll 服务:

1) as parameters in the connection string ("database connection url" property: 1) 作为连接字符串中的参数(“数据库连接 url”属性:

jdbc:postgresql://<ip>:<port>/<username>?user=<username>&sslTrue&sslcert=/etc/.../mycerts/mycert.der&sslkey=/etc/.../mycerts/mykey.key.pk8

2) adding properties in the service (+ button and the just parameter name and the path as the value) and just passing this as url: 2)在服务中添加属性(+按钮和刚刚的参数名称和路径作为值)并将其作为url传递:

jdbc:postgresql://<ip>:<port>/<username>

Both seems to work generally speaking, since I can connect to another postgres I have which not requires ssl certification.一般来说,两者似乎都有效,因为我可以连接到另一个不需要 ssl 认证的 postgres。

Some considerations:一些考虑:

1) My assumption here is that the connection string in the NIFI does not know to read properly the file path for the certificate and key. 1)我的假设是 NIFI 中的连接字符串不知道正确读取证书和密钥的文件路径。

2) I have converted the certificates a bunch of times to different types that java can receive in order to see if that was the problem, but I still receive the same exception. 2)我已经多次将证书转换为java可以接收的不同类型,以查看是否是问题所在,但我仍然收到相同的异常。 So it seems that the connection pool just does not "achieve" the files at all.所以看起来连接池根本没有“实现”文件。 Nevertheless, if some one has a say in this topic, it can be handy, after the main problem is solved.不过,如果有人在这个话题上有发言权,那么在主要问题解决后,这会很方便。 So appreciate some tips here as well.所以也请欣赏这里的一些提示。

3) I have also read the NIFI source code and it seems that NIFI uses normally JDBC classes to create the connection pool, so a connection string as I passed would have worked in java code, but somehow doesn't work in NIFI (which is written in java). 3)我还阅读了 NIFI 源代码,似乎 NIFI 通常使用 JDBC 类来创建连接池,所以我传递的连接字符串可以在 java 代码中工作,但不知何故在 NIFI 中不起作用(这是用java写的)。

4) The jdbc driver and everything else is configured properly, since I can work with a non-secure postgres in NIFI. 4) jdbc 驱动程序和其他所有东西都配置正确,因为我可以在 NIFI 中使用非安全的 postgres。

Thank you very much.非常感谢。

A co-worker found the 'simple solution' to the problem I asked and I would like to share so it can help others.一位同事找到了我提出的问题的“简单解决方案”,我想分享一下,以便它可以帮助其他人。

What was missing was the property sslmode = require.缺少的是属性 sslmode = require。 After including that, the service worked perfectly.包括在内后,该服务运行良好。 Actually, I am not sure why it didn't work with sslmode = prefer, since it is what my pgadmin is using for the same database and there it works perfectly.实际上,我不确定为什么它不能与 sslmode = prefer 一起使用,因为它是我的 pgadmin 用于同一个数据库的,并且它在那里工作得很好。 It seems like we must 'force' nifi to use ssl in this case - see documentation here: https://jdbc.postgresql.org/documentation/head/ssl-client.html .在这种情况下,似乎我们必须“强制”nifi 使用 ssl - 请参阅此处的文档: https ://jdbc.postgresql.org/documentation/head/ssl-client.html。

Moreover, some insights:此外,一些见解:

  1. It worked with certificate in '.der' and key in '.pk8' formats (didn't have to use trust-store and key-store as needed in other services).它使用“.der”格式的证书和“.pk8”格式的密钥(不必根据其他服务的需要使用信任库和密钥库)。

  2. One can add in the 'plus' button the properties and give them the right name as we would do in java code, instead of concatenating every property in the connection string (see second option in the question above).可以在“加号”按钮中添加属性并为它们提供正确的名称,就像我们在 java 代码中所做的那样,而不是连接连接字符串中的每个属性(请参阅上面问题中的第二个选项)。

Make it helps others as well.让它也帮助他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM