使用证书验证 Kubernetes API(NodeJS) 客户端未成功

Authenticating Kubernetes API(NodeJS) client using certificate not successful

我已经在 google 云中部署了一个 Kubernetes 集群,并尝试使用 Kubernetes NodeJS API,一个 kubernetes 客户端访问它。

为此,我们需要使用集群进行身份验证。我尝试只使用 Username and Password 方法。我收到以下错误:

{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

然后我尝试使用 CAcert, ClientCert and ClientKey 进行身份验证。我基本上对密钥进行了硬编码,而不是从文件中导入它。我从 Lambda 函数中调用此 API,我无法将证书存储在文件中。这样做,我得到以下错误:

[Error: error:0906D06C:PEM routines:PEM_read_bio:no start line]

我的直觉是只有使用密钥才能进行身份验证。但我认为我对证书做错了什么。我是否需要从中创建一些其他证书,或者使用证书的方法是错误的?

答案:

请参阅 Robert Bailey 的 评论。我错过了 Base64 东西。补充一点,我可以成功验证到 kubernetes 集群并显示和部署新的 pods,等等,

To do so, we need to authenticate with cluster. I tried using just the Username and Password method. I get the following error:

查看 NodeJS 客户端,我看不到提供集群 CA 证书以及用户名和密码的方法,因此除非您将 strictSSL 设置为 false,否则此错误消息似乎是合理的(您的系统是说它不信任服务器提供的证书,这是正确的,因为它是一个自签名证书颁发机构)。您可以通过将集群 CA 证书安装到系统证书根存储中来解决此问题,但使用不同的身份验证方法(并针对 NodeJS 客户端提交错误)似乎更可取。

Then I tried the authentication using the CAcert, ClientCert and ClientKey. I basically hardcoded the keys instead of importing it from the files.

您是否也尝试过导入文件(用于比较)?看起来这是您指定 PEM 块的方式的解析错误,库可能会更好地从文件而不是内联数据中读取块。

My intuition is authentication is possible only with keys. But I think I am doing something wrong with the certs. Do I need to create some other certificates out of this or is the method of using the certs is wrong ?

应该可以使用用户名/密码或客户端密钥进行身份验证。 NodeJS 库还允许您指向一个 kubeconfig 文件,该文件应该允许您指定用户名/密码以及集群 CA 证书,以便您可以安全地连接到 API 端点(如果需要)使用基本身份验证凭据。