Skip to content
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
1 change: 1 addition & 0 deletions consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Downstream struct {
Protocol string
TargetAddress string
TargetPort int
EnableForwardFor bool

TLS
}
Expand Down
13 changes: 8 additions & 5 deletions consul/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type downstream struct {
Protocol string
TargetAddress string
TargetPort int
EnableForwardFor bool
}

type certLeaf struct {
Expand Down Expand Up @@ -118,15 +119,15 @@ func (w *Watcher) handleProxyChange(first bool, srv *api.AgentService) {
if c, ok := srv.Proxy.Config["protocol"].(string); ok {
w.downstream.Protocol = c
}
}

if srv.Connect != nil && srv.Connect.SidecarService != nil && srv.Connect.SidecarService.Proxy != nil && srv.Connect.SidecarService.Proxy.Config != nil {
if b, ok := srv.Connect.SidecarService.Proxy.Config["bind_address"].(string); ok {
if b, ok := srv.Proxy.Config["bind_address"].(string); ok {
w.downstream.LocalBindAddress = b
}
if a, ok := srv.Connect.SidecarService.Proxy.Config["local_service_address"].(string); ok {
if a, ok := srv.Proxy.Config["local_service_address"].(string); ok {
w.downstream.TargetAddress = a
}
if f, ok := srv.Proxy.Config["enable_forwardfor"].(bool); ok {
w.downstream.EnableForwardFor = f
}
}

keep := make(map[string]bool)
Expand Down Expand Up @@ -348,6 +349,8 @@ func (w *Watcher) genCfg() Config {
TargetAddress: w.downstream.TargetAddress,
TargetPort: w.downstream.TargetPort,
Protocol: w.downstream.Protocol,
EnableForwardFor: w.downstream.EnableForwardFor,

TLS: TLS{
CAs: w.certCAs,
Cert: w.leaf.Cert,
Expand Down
8 changes: 8 additions & 0 deletions haproxy/state/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ func generateDownstream(opts Options, certStore CertificateStore, cfg consul.Dow

state.Frontends = append(state.Frontends, fe)

var forwardFor *models.Forwardfor
if cfg.EnableForwardFor && beMode == models.BackendModeHTTP {
forwardFor = &models.Forwardfor{
Enabled: stringp(models.ForwardforEnabledEnabled),
}
}

// Backend
be := Backend{
Backend: models.Backend{
Name: beName,
ServerTimeout: &serverTimeout,
ConnectTimeout: &connectTimeout,
Mode: beMode,
Forwardfor: forwardFor,
},
Servers: []models.Server{
models.Server{
Expand Down
4 changes: 4 additions & 0 deletions haproxy/state/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func int64p(i int) *int64 {
s := int64(i)
return &s
}

func stringp(s string) *string {
return &s
}