Skip to content

Commit

Permalink
Adding support for Insecure Skip Verify (#24)
Browse files Browse the repository at this point in the history
* adding support for Insecure Skip Verify

* updating docs

* updating comment
  • Loading branch information
ankurs authored Jun 10, 2024
1 parent 22f9d79 commit 27d6beb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type CB interface {
```

<a name="New"></a>
### func [New](<https://github.com/go-coldbrew/core/blob/main/core.go#L414>)
### func [New](<https://github.com/go-coldbrew/core/blob/main/core.go#L415>)

```go
func New(c config.Config) CB
Expand Down
5 changes: 4 additions & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import "github.com/go-coldbrew/core/config"


<a name="Config"></a>
## type [Config](<https://github.com/go-coldbrew/core/blob/main/config/config.go#L6-L95>)
## type [Config](<https://github.com/go-coldbrew/core/blob/main/config/config.go#L6-L98>)

Config is the configuration for the Coldbrew server It is populated from environment variables and has sensible defaults for all fields so that you can just use it as is without any configuration The following environment variables are supported and can be used to override the defaults for the fields

Expand Down Expand Up @@ -110,6 +110,9 @@ type Config struct {
// GRPCTLSCertFile an GRPCTLSKeyFile are the paths to the key and cert files for the GRPC server
// If these are set, the server will be started with TLS enabled
GRPCTLSCertFile string `envconfig:"GRPC_TLS_CERT_FILE"`
// GRPCTLSInsecureSkipVerify is used to skip verification of the server's certificate chain and host name
// Only set this to true if you are sure you want to disable TLS verification for the server
GRPCTLSInsecureSkipVerify bool `envconfig:"GRPC_TLS_INSECURE_SKIP_VERIFY" default:"false"`
}
```

Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ type Config struct {
// GRPCTLSCertFile an GRPCTLSKeyFile are the paths to the key and cert files for the GRPC server
// If these are set, the server will be started with TLS enabled
GRPCTLSCertFile string `envconfig:"GRPC_TLS_CERT_FILE"`
// GRPCTLSInsecureSkipVerify is used to skip verification of the server's certificate chain and host name
// Only set this to true if you are sure you want to disable TLS verification for the server
GRPCTLSInsecureSkipVerify bool `envconfig:"GRPC_TLS_INSECURE_SKIP_VERIFY" default:"false"`
}
9 changes: 5 additions & 4 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (c *cb) getGRPCServerOptions() []grpc.ServerOption {
return so
}

func loadTLSCredentials(certFile, keyFile string) (credentials.TransportCredentials, error) {
func loadTLSCredentials(certFile, keyFile string, insecureSkipVerify bool) (credentials.TransportCredentials, error) {
// Load server's certificate and private key
serverCert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
Expand All @@ -265,8 +265,9 @@ func loadTLSCredentials(certFile, keyFile string) (credentials.TransportCredenti

// Create the credentials and return it
config := &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientAuth: tls.NoClientCert,
Certificates: []tls.Certificate{serverCert},
ClientAuth: tls.NoClientCert,
InsecureSkipVerify: insecureSkipVerify,
}

return credentials.NewTLS(config), nil
Expand All @@ -275,7 +276,7 @@ func loadTLSCredentials(certFile, keyFile string) (credentials.TransportCredenti
func (c *cb) initGRPC(ctx context.Context) (*grpc.Server, error) {
so := c.getGRPCServerOptions()
if c.config.GRPCTLSCertFile != "" && c.config.GRPCTLSKeyFile != "" {
creds, err := loadTLSCredentials(c.config.GRPCTLSCertFile, c.config.GRPCTLSKeyFile)
creds, err := loadTLSCredentials(c.config.GRPCTLSCertFile, c.config.GRPCTLSKeyFile, c.config.GRPCTLSInsecureSkipVerify)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 27d6beb

Please sign in to comment.