-
Notifications
You must be signed in to change notification settings - Fork 51
/
trireme.go
141 lines (119 loc) · 3.91 KB
/
trireme.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package trireme
import (
"fmt"
"time"
"github.com/aporeto-inc/trireme-lib/collector"
"github.com/aporeto-inc/trireme-lib/constants"
"github.com/aporeto-inc/trireme-lib/enforcer/packetprocessor"
"github.com/aporeto-inc/trireme-lib/enforcer/utils/fqconfig"
"github.com/aporeto-inc/trireme-lib/enforcer/utils/secrets"
"github.com/aporeto-inc/trireme-lib/internal/monitor"
"go.uber.org/zap"
)
// config specifies all configurations accepted by trireme to start.
type config struct {
// Required Parameters.
serverID string
// External Interface implementations that we allow to plugin to components.
collector collector.EventCollector
resolver PolicyResolver
service packetprocessor.PacketProcessor
secret secrets.Secrets
// Configurations for fine tuning internal components.
monitors *monitor.Config
mode constants.ModeType
fq *fqconfig.FilterQueue
linuxProcess bool
mutualAuth bool
packetLogs bool
validity time.Duration
procMountPoint string
externalIPcacheTimeout time.Duration
targetNetworks []string
}
// Option is provided using functional arguments.
type Option func(*config)
// OptionCollector is an option to provide an external collector implementation.
func OptionCollector(c collector.EventCollector) func(*config) {
return func(cfg *config) {
cfg.collector = c
}
}
// OptionPolicyResolver is an option to provide an external policy resolver implementation.
func OptionPolicyResolver(r PolicyResolver) func(*config) {
return func(cfg *config) {
cfg.resolver = r
}
}
// OptionDatapathService is an option to provide an external datapath service implementation.
func OptionDatapathService(s packetprocessor.PacketProcessor) func(*config) {
return func(cfg *config) {
cfg.service = s
}
}
// OptionSecret is an option to provide an external datapath service implementation.
func OptionSecret(s secrets.Secrets) func(*config) {
return func(cfg *config) {
cfg.secret = s
}
}
// OptionMonitors is an option to provide configurations for monitors.
func OptionMonitors(m *monitor.Config) func(*config) {
return func(cfg *config) {
cfg.monitors = m
}
}
// OptionEnforceLocal is an option to request local enforcer. Absence of this options
// implies use remote enforcers.
func OptionEnforceLocal() func(*config) {
return func(cfg *config) {
cfg.mode = constants.LocalContainer
}
}
// OptionEnforceLinuxProcess is an option to request support for linux process support.
func OptionEnforceLinuxProcess() func(*config) {
return func(cfg *config) {
cfg.linuxProcess = true
}
}
// OptionEnforceFqConfig is an option to override filter queues.
func OptionEnforceFqConfig(f *fqconfig.FilterQueue) func(*config) {
return func(cfg *config) {
cfg.fq = f
}
}
// OptionTargetNetworks is an option to provide target network configuration.
func OptionTargetNetworks(n []string) func(*config) {
return func(cfg *config) {
cfg.targetNetworks = n
}
}
// OptionProcMountPoint is an option to provide proc mount point.
func OptionProcMountPoint(p string) func(*config) {
return func(cfg *config) {
cfg.procMountPoint = p
}
}
// OptionPacketLogs is an option to enable packet level logging.
func OptionPacketLogs() func(*config) {
return func(cfg *config) {
cfg.packetLogs = true
}
}
// New returns a trireme interface implementation based on configuration provided.
func New(serverID string, opts ...Option) Trireme {
c := &config{
serverID: serverID,
mode: constants.RemoteContainer,
fq: fqconfig.NewFilterQueueWithDefaults(),
mutualAuth: true,
validity: time.Hour * 8760,
procMountPoint: constants.DefaultProcMountPoint,
externalIPcacheTimeout: -1,
}
for _, opt := range opts {
opt(c)
}
zap.L().Debug("Trireme configuration", zap.String("configuration", fmt.Sprintf("%+v", c)))
return newTrireme(c)
}