-
Notifications
You must be signed in to change notification settings - Fork 51
/
helpers.go
42 lines (34 loc) · 1.58 KB
/
helpers.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
package controller
import (
enforcerconstants "go.aporeto.io/trireme-lib/controller/internal/enforcer/constants"
"go.aporeto.io/trireme-lib/controller/pkg/packetprocessor"
"go.aporeto.io/trireme-lib/controller/pkg/remoteenforcer"
"go.aporeto.io/trireme-lib/policy"
"go.uber.org/zap"
)
// LaunchRemoteEnforcer launches a remote enforcer instance.
func LaunchRemoteEnforcer(service packetprocessor.PacketProcessor, zapConfig zap.Config) error {
return remoteenforcer.LaunchRemoteEnforcer(service, zapConfig)
}
// addTransmitterLabel adds the enforcerconstants.TransmitterLabel as a fixed label in the policy.
// The ManagementID part of the policy is used as the enforcerconstants.TransmitterLabel.
// If the Policy didn't set the ManagementID, we use the Local contextID as the
// default enforcerconstants.TransmitterLabel.
func addTransmitterLabel(contextID string, containerInfo *policy.PUInfo) {
if containerInfo.Policy.ManagementID() == "" {
containerInfo.Policy.AddIdentityTag(enforcerconstants.TransmitterLabel, contextID)
} else {
containerInfo.Policy.AddIdentityTag(enforcerconstants.TransmitterLabel, containerInfo.Policy.ManagementID())
}
}
// MustEnforce returns true if the Policy should go Through the Enforcer/internal/supervisor.
// Return false if:
// - PU is in host namespace.
// - Policy got the AllowAll tag.
func mustEnforce(contextID string, containerInfo *policy.PUInfo) bool {
if containerInfo.Policy.TriremeAction() == policy.AllowAll {
zap.L().Debug("PUPolicy with AllowAll Action. Not policing", zap.String("contextID", contextID))
return false
}
return true
}