forked from haproxytech/haproxy-consul-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownstream.go
More file actions
100 lines (88 loc) · 2.35 KB
/
Copy pathdownstream.go
File metadata and controls
100 lines (88 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package state
import (
"fmt"
"github.com/haproxytech/haproxy-consul-connect/consul"
"github.com/haproxytech/models"
)
func generateDownstream(opts Options, certStore CertificateStore, cfg consul.Downstream, state State) (State, error) {
feName := "front_downstream"
beName := "back_downstream"
caPath, crtPath, err := certStore.CertsPath(cfg.TLS)
if err != nil {
return state, err
}
// Main config
fe := Frontend{
Frontend: models.Frontend{
Name: feName,
DefaultBackend: beName,
ClientTimeout: &clientTimeout,
Mode: models.FrontendModeHTTP,
Httplog: opts.LogRequests,
},
Bind: models.Bind{
Name: fmt.Sprintf("%s_bind", feName),
Address: cfg.LocalBindAddress,
Port: int64p(cfg.LocalBindPort),
Ssl: true,
SslCertificate: crtPath,
SslCafile: caPath,
Verify: models.BindVerifyRequired,
},
}
// Logging
if opts.LogRequests && opts.LogSocket != "" {
fe.LogTarget = &models.LogTarget{
ID: int64p(0),
Address: opts.LogSocket,
Facility: models.LogTargetFacilityLocal0,
Format: models.LogTargetFormatRfc5424,
}
}
// Intentions
if opts.EnableIntentions {
fe.Filter = &FrontendFilter{
Filter: models.Filter{
ID: int64p(0),
Type: models.FilterTypeSpoe,
SpoeEngine: "intentions",
SpoeConfig: opts.SPOEConfigPath,
},
Rule: models.TCPRequestRule{
ID: int64p(0),
Action: models.TCPRequestRuleActionReject,
Cond: models.TCPRequestRuleCondUnless,
CondTest: "{ var(sess.connect.auth) -m int eq 1 }",
Type: models.TCPRequestRuleTypeContent,
},
}
}
state.Frontends = append(state.Frontends, fe)
// Backend
be := Backend{
Backend: models.Backend{
Name: beName,
ServerTimeout: &serverTimeout,
ConnectTimeout: &connectTimeout,
Mode: models.BackendModeHTTP,
},
Servers: []models.Server{
models.Server{
Name: "downstream_node",
Address: cfg.TargetAddress,
Port: int64p(cfg.TargetPort),
},
},
}
// Logging
if opts.LogRequests && opts.LogSocket != "" {
be.LogTarget = &models.LogTarget{
ID: int64p(0),
Address: opts.LogSocket,
Facility: models.LogTargetFacilityLocal0,
Format: models.LogTargetFormatRfc5424,
}
}
state.Backends = append(state.Backends, be)
return state, nil
}