doutang6130 2018-12-12 13:39
浏览 54

go Scratch容器和PG容器之间的SSL连接问题。 怎么解决? [关闭]

UPDATE

I believe I resolved this issue with this connection...

db, err := gorm.Open("postgres", "host='postgres'&user:docker&port=5432&dbname='docker'&password='password'&sslmode=disable")

I am getting a connection refused between a Docker PG container and a GoLang Scratch container. The error is:

============   exiting ==========
todo_1      | pq: SSL is not enabled on the server
todo_1      | panic: failed to connect database e

The docker-compose.yml file

The main.go file which is panicking

Complete code base with Docker files

OTHER NOTE:

  • I am using GORM library to connect with PG.

REQUEST: Please look over code and give some hints on where and how to resolve this SSL issue.

  • 写回答

1条回答 默认 最新

  • dpwo36915 2018-12-12 14:09
    关注

    You can follow the code to find the documentation on how to use the Postgres calls.

    • github.com/jinzhu/gorm calls
    • database/sql which calls
    • lib/pq

    And lib/pq documents it's usage including:

    • dbname - The name of the database to connect to
    • user - The user to sign in as
    • password - The user's password
    • host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
    • port - The port to bind to. (default is 5432)
    • sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
    • fallback_application_name - An application_name to fall back to if one isn't provided.
    • connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
    • sslcert - Cert file location. The file must contain PEM encoded data.
    • sslkey - Key file location. The file must contain PEM encoded data.
    • sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.

    And:

    • disable - No SSL
    • require - Always SSL (skip verification)
    • verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
    • verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name
      matches the one in the certificate)

    So your connect string for a database without SSL is simply:

    db, err := gorm.Open("postgres", "host='postgres' port=5432 user=docker dbname='docker' password='password' sslmode=disable")
    

    Or you could configure Postgres with an SSL key. That's less trivial, but to implement you'd need to modify the postgresql.conf file to enable the ssl settings and mount the TLS key pair as a volume, or preferably a secret with swarm mode. One of the many examples of how to do this can be found at: https://gist.github.com/likwid/86193ef581c530ea55d3

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line