简体   繁体   中英

Error "x509: certificate signed by unknown authority" while connecting to Snowflake Database from Docker Using Golang

I'm trying to connect to Snowflake DB using Golang. I found sample code online and it works fine when I run on my machine. When I put the sample code inside a docker container and try to run it, I got below error. I'm not sure if I need to contact Snowflake DB Admin to get any certs. Anyone faced similar issues?

https://XXXX.us-east-1.snowflakecomputing.com:443/session/v1/login-request?databaseName=XXXX&requestId=XXXXX&request_guid=XXXX" : x509: certificate signed by unknown authority

Below is the Sample code.

package main 

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/snowflakedb/gosnowflake"
)

func main() {
    user:="XXXX"
    password:="XXX"
    host:="XXXX.us-east-1.snowflakecomputing.com"

    database:="XXX"
    warehouse :="XXX"
    schema :="XXX"
    port :="443"


    dsn := fmt.Sprintf("%v:%v@%v:%v/%v",user,password,host,port,database)
    
    fmt.Println("DSN",dsn)
    db, err := sql.Open("snowflake", dsn)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    query :=`SELECT * FROM INFORMATION_SCHEMA.APPLICABLE_ROLES `
    rows, err := db.Query(query)
    if err !=nil{
        fmt.Println("error in query", err)
        return
    }

    cols, err := rows.Columns()
    if err !=nil{
        fmt.Println("error in reading columns ", err)
        return
    }
    fmt.Printf("\n\n %+v \n", cols)
}

That's because you don't have the certificates needed to form this ssl connection. I'll guess that you used scratch docker image to dockerize your application as most of the guides out there does.

So you can just copy the needed CA's certificates using from your builder image using something like this:

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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