Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/459.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fix being able to use system-wide root certificates in deployments.
```
22 changes: 22 additions & 0 deletions internal/commands/exec/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exec

import (
"context"
"encoding/pem"
"errors"
"flag"
"fmt"
Expand Down Expand Up @@ -151,6 +152,7 @@ func (c *Command) Run(args []string) (ret int) {
if cfg.TLSConfig.CAFile != "" {
cfg.Scheme = "https"
}

// this call mutates the cfg object with a bunch of defaults
// so we're going to keep it for now
consulClient, err := api.NewClient(cfg)
Expand Down Expand Up @@ -261,3 +263,23 @@ Usage: consul-api-gateway exec [options]
Handles service registration, certificate rotation, and spawning envoy.
`
}

func init() {
// this is a hack to ensure we actually have a valid CA file passed to our
// deployment, we parse the CA file just to make sure it's readable, if not,
// then we fallback to system certs by emptying the CAFile option.
caFile := os.Getenv(api.HTTPCAFile)
if caFile != "" {
os.Setenv(api.HTTPSSLEnvName, "true")
cert, err := os.ReadFile(caFile)
if err != nil {
os.Setenv(api.HTTPCAFile, "")
} else {
block, _ := pem.Decode(cert)
if block == nil {
// no pem data
os.Setenv(api.HTTPCAFile, "")
}
}
}
}
1 change: 1 addition & 0 deletions internal/commands/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func RunExec(config ExecConfig) (ret int) {
EnvoyBinary: config.EnvoyConfig.Binary,
ExtraArgs: config.EnvoyConfig.ExtraArgs,
Output: config.EnvoyConfig.Output,
ForceTLS: os.Getenv(api.HTTPSSLEnvName) == "true",
},
)
options := consul.DefaultCertManagerOptions()
Expand Down
17 changes: 17 additions & 0 deletions internal/envoy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type bootstrapArgs struct {
SDSCluster string
Token string
AddressType string
ForceTLS bool
}

func init() {
Expand All @@ -53,6 +54,7 @@ type ManagerConfig struct {
EnvoyBinary string
ExtraArgs []string
Output io.Writer
ForceTLS bool
}

// Manager wraps and manages an envoy process and its bootstrap configuration
Expand Down Expand Up @@ -115,6 +117,7 @@ func (m *Manager) RenderBootstrap(sdsConfig string) error {
ConsulCA: m.ConsulCA,
ConsulAddress: m.ConsulAddress,
ConsulXDSPort: m.ConsulXDSPort,
ForceTLS: m.ForceTLS,
AddressType: common.AddressTypeForAddress(m.ConsulAddress),
Token: m.Token,
}); err != nil {
Expand Down Expand Up @@ -188,6 +191,20 @@ const bootstrapJSONTemplate = `{
}
}
},
{{- else if .ForceTLS }}
"transport_socket": {
"name": "tls",
"typed_config": {
"@type": "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext",
"common_tls_context": {
"validation_context": {
"trusted_ca": {
"filename": "/etc/ssl/certs/ca-certificates.crt"
}
}
}
}
},
{{- end }}
"http2_protocol_options": {},
"loadAssignment": {
Expand Down