
我写了一个mTLS认证的golang程序
package main
import (
"context"
"fmt"
"io"
"log"
"github.com/falcosecurity/client-go/pkg/api/outputs"
"github.com/falcosecurity/client-go/pkg/client"
"github.com/gogo/protobuf/jsonpb"
)
func main() {
// Set up a connection to the server.
c, err := client.NewForConfig(context.Background(), &client.Config{
Hostname: "localhost",
Port: 5060,
CertFile: "/etc/falco/certs/client.crt",
KeyFile: "/etc/falco/certs/client.key",
CARootFile: "/etc/falco/certs/ca.crt",
})
}我使用openssl在/etc/falco/certs位置生成了证书。在运行程序时,我得到了这个错误。
2021/10/21 11:58:22 unable to connect: error loading the X.509 key pair: open /etc/falco/certs/client.key: permission denied
exit status 1如何解决这个问题?
发布于 2021-10-21 22:17:33
检查/etc/falco/certs中文件的所有者和权限掩码。如果这些文件的所有者与运行代码的用户不匹配,则会出现权限错误。在大多数linux系统上,需要将.key文件的模式设置为600,所以如果我必须猜测哪个文件可能抛出了您的错误,那就是client.key文件。尝试运行
密钥上的chmod 640和证书文件上的644,然后确保您运行代码的用户拥有这些文件,或者至少在文件所属的组中,并查看发生了什么。
发布于 2021-10-27 08:14:37
通过运行以下命令并更改文件的权限解决了此问题:
sudo chmod o+r+w client.key
sudo chmod o+r+w ca.key
sudo chmod o+r+w server.keyhttps://stackoverflow.com/questions/69657057
复制相似问题