I am making rest api call to fetch some data but I am getting
Post \"https://url:8200/v1/login\": x509: certificate signed by unknown authority]
then I started sending crt with below modification
certPath := "path/certficate.crt"
cert, crtErr := ioutil.ReadFile(certPath)
if crtErr != nil {
//
}
//var crtErr error
tp := http.DefaultTransport.(*http.Transport).Clone()
if tp.TLSClientConfig.RootCAs, crtErr = x509.SystemCertPool(); crtErr != nil {
//error
}
if tp.TLSClientConfig.RootCAs == nil {
tp.TLSClientConfig.RootCAs = x509.NewCertPool()
}
if tp.TLSClientConfig.RootCAs == nil {
// error msg
}
caCertPool, crtErr := x509.SystemCertPool()
if crtErr != nil {
//error
}
if tp.TLSClientConfig.RootCAs == nil {
caCertPool = x509.NewCertPool()
}
caCertPool.AppendCertsFromPEM(cert)
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
ClientCAs: caCertPool,
// tried this too RootCAs: caCertPool},
},
},
}
// Due to security reason below code is not reommended.
// this works if added.
// tr := &http.Transport{}
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
//}
var jsonByte *bytes.Buffer
jsonByte = bytes.NewBuffer(payloadMap)
req, err := http.NewRequest(httpMethod, url, jsonByte) // URL-encoded payload
if err != nil {
// error
}
req.Header.Add("Content-Type", "application/json")
if headerData != "" {
req.Header.Add("X-Vault-Token", headerData)
}
resp, errr := client.Do(req)
This is not helping, I did try generating crt via docker file using below command due to the interactive command run, it didn't work either
openssl genrsa -out rootCA.key 4096
openssl req -x509 -new -key rootCA.key -days 3650 -out rootCA.crt
Need to resolve this Post "https://url:8200/v1/login": x509: certificate signed by unknown authority] .
#golang #dockeriamge #vaultrestapi-integration