id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
6,900
aporeto-inc/trireme-lib
policy/types.go
EncodedActionString
func (f *FlowPolicy) EncodedActionString() string { var e string if f.Action.Accepted() && !f.Action.Rejected() { if f.ObserveAction.ObserveContinue() { e = "1" } else if f.ObserveAction.ObserveApply() { e = "2" } else { e = "3" } } else if !f.Action.Accepted() && f.Action.Rejected() { if f.ObserveAction.ObserveContinue() { e = "4" } else if f.ObserveAction.ObserveApply() { e = "5" } else { e = "6" } } else { if f.ObserveAction.ObserveContinue() { e = "7" } else if f.ObserveAction.ObserveApply() { e = "8" } else { e = "9" } } return e }
go
func (f *FlowPolicy) EncodedActionString() string { var e string if f.Action.Accepted() && !f.Action.Rejected() { if f.ObserveAction.ObserveContinue() { e = "1" } else if f.ObserveAction.ObserveApply() { e = "2" } else { e = "3" } } else if !f.Action.Accepted() && f.Action.Rejected() { if f.ObserveAction.ObserveContinue() { e = "4" } else if f.ObserveAction.ObserveApply() { e = "5" } else { e = "6" } } else { if f.ObserveAction.ObserveContinue() { e = "7" } else if f.ObserveAction.ObserveApply() { e = "8" } else { e = "9" } } return e }
[ "func", "(", "f", "*", "FlowPolicy", ")", "EncodedActionString", "(", ")", "string", "{", "var", "e", "string", "\n\n", "if", "f", ".", "Action", ".", "Accepted", "(", ")", "&&", "!", "f", ".", "Action", ".", "Rejected", "(", ")", "{", "if", "f", ".", "ObserveAction", ".", "ObserveContinue", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "if", "f", ".", "ObserveAction", ".", "ObserveApply", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "{", "e", "=", "\"", "\"", "\n", "}", "\n", "}", "else", "if", "!", "f", ".", "Action", ".", "Accepted", "(", ")", "&&", "f", ".", "Action", ".", "Rejected", "(", ")", "{", "if", "f", ".", "ObserveAction", ".", "ObserveContinue", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "if", "f", ".", "ObserveAction", ".", "ObserveApply", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "{", "e", "=", "\"", "\"", "\n", "}", "\n", "}", "else", "{", "if", "f", ".", "ObserveAction", ".", "ObserveContinue", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "if", "f", ".", "ObserveAction", ".", "ObserveApply", "(", ")", "{", "e", "=", "\"", "\"", "\n", "}", "else", "{", "e", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "return", "e", "\n", "}" ]
// EncodedActionString is used to encode observed action as well as action
[ "EncodedActionString", "is", "used", "to", "encode", "observed", "action", "as", "well", "as", "action" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L181-L211
6,901
aporeto-inc/trireme-lib
policy/types.go
EncodedStringToAction
func EncodedStringToAction(e string) (ActionType, ObserveActionType, error) { switch e { case "1": return Observe | Accept, ObserveContinue, nil case "2": return Observe | Accept, ObserveApply, nil case "3": return Accept, ObserveNone, nil case "4": return Observe | Reject, ObserveContinue, nil case "5": return Observe | Reject, ObserveApply, nil case "6": return Reject, ObserveNone, nil case "7": return Observe, ObserveContinue, nil case "8": return Observe, ObserveApply, nil case "9": return 0, ObserveNone, nil } return 0, 0, errors.New("Invalid encoding") }
go
func EncodedStringToAction(e string) (ActionType, ObserveActionType, error) { switch e { case "1": return Observe | Accept, ObserveContinue, nil case "2": return Observe | Accept, ObserveApply, nil case "3": return Accept, ObserveNone, nil case "4": return Observe | Reject, ObserveContinue, nil case "5": return Observe | Reject, ObserveApply, nil case "6": return Reject, ObserveNone, nil case "7": return Observe, ObserveContinue, nil case "8": return Observe, ObserveApply, nil case "9": return 0, ObserveNone, nil } return 0, 0, errors.New("Invalid encoding") }
[ "func", "EncodedStringToAction", "(", "e", "string", ")", "(", "ActionType", ",", "ObserveActionType", ",", "error", ")", "{", "switch", "e", "{", "case", "\"", "\"", ":", "return", "Observe", "|", "Accept", ",", "ObserveContinue", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Observe", "|", "Accept", ",", "ObserveApply", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Accept", ",", "ObserveNone", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Observe", "|", "Reject", ",", "ObserveContinue", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Observe", "|", "Reject", ",", "ObserveApply", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Reject", ",", "ObserveNone", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Observe", ",", "ObserveContinue", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Observe", ",", "ObserveApply", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "0", ",", "ObserveNone", ",", "nil", "\n", "}", "\n\n", "return", "0", ",", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// EncodedStringToAction returns action and observed action from encoded string.
[ "EncodedStringToAction", "returns", "action", "and", "observed", "action", "from", "encoded", "string", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L214-L238
6,902
aporeto-inc/trireme-lib
policy/types.go
Copy
func (l DNSRuleList) Copy() DNSRuleList { list := make(DNSRuleList, len(l)) for i, v := range l { list[i] = v } return list }
go
func (l DNSRuleList) Copy() DNSRuleList { list := make(DNSRuleList, len(l)) for i, v := range l { list[i] = v } return list }
[ "func", "(", "l", "DNSRuleList", ")", "Copy", "(", ")", "DNSRuleList", "{", "list", ":=", "make", "(", "DNSRuleList", ",", "len", "(", "l", ")", ")", "\n\n", "for", "i", ",", "v", ":=", "range", "l", "{", "list", "[", "i", "]", "=", "v", "\n", "}", "\n\n", "return", "list", "\n", "}" ]
// Copy creates a clone of DNS rule list
[ "Copy", "creates", "a", "clone", "of", "DNS", "rule", "list" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L264-L272
6,903
aporeto-inc/trireme-lib
policy/types.go
Copy
func (l IPRuleList) Copy() IPRuleList { list := make(IPRuleList, len(l)) for i, v := range l { list[i] = v } return list }
go
func (l IPRuleList) Copy() IPRuleList { list := make(IPRuleList, len(l)) for i, v := range l { list[i] = v } return list }
[ "func", "(", "l", "IPRuleList", ")", "Copy", "(", ")", "IPRuleList", "{", "list", ":=", "make", "(", "IPRuleList", ",", "len", "(", "l", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "l", "{", "list", "[", "i", "]", "=", "v", "\n", "}", "\n", "return", "list", "\n", "}" ]
// Copy creates a clone of the IP rule list
[ "Copy", "creates", "a", "clone", "of", "the", "IP", "rule", "list" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L275-L281
6,904
aporeto-inc/trireme-lib
policy/types.go
Copy
func (t TagSelectorList) Copy() TagSelectorList { list := make(TagSelectorList, len(t)) for i, v := range t { list[i] = v } return list }
go
func (t TagSelectorList) Copy() TagSelectorList { list := make(TagSelectorList, len(t)) for i, v := range t { list[i] = v } return list }
[ "func", "(", "t", "TagSelectorList", ")", "Copy", "(", ")", "TagSelectorList", "{", "list", ":=", "make", "(", "TagSelectorList", ",", "len", "(", "t", ")", ")", "\n\n", "for", "i", ",", "v", ":=", "range", "t", "{", "list", "[", "i", "]", "=", "v", "\n", "}", "\n\n", "return", "list", "\n", "}" ]
// Copy returns a copy of the TagSelectorList
[ "Copy", "returns", "a", "copy", "of", "the", "TagSelectorList" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L301-L309
6,905
aporeto-inc/trireme-lib
policy/types.go
Copy
func (s ExtendedMap) Copy() ExtendedMap { c := ExtendedMap{} for k, v := range s { c[k] = v } return c }
go
func (s ExtendedMap) Copy() ExtendedMap { c := ExtendedMap{} for k, v := range s { c[k] = v } return c }
[ "func", "(", "s", "ExtendedMap", ")", "Copy", "(", ")", "ExtendedMap", "{", "c", ":=", "ExtendedMap", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "s", "{", "c", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "c", "\n", "}" ]
// Copy copies an ExtendedMap
[ "Copy", "copies", "an", "ExtendedMap" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L315-L321
6,906
aporeto-inc/trireme-lib
policy/types.go
Get
func (s ExtendedMap) Get(key string) (string, bool) { value, ok := s[key] return value, ok }
go
func (s ExtendedMap) Get(key string) (string, bool) { value, ok := s[key] return value, ok }
[ "func", "(", "s", "ExtendedMap", ")", "Get", "(", "key", "string", ")", "(", "string", ",", "bool", ")", "{", "value", ",", "ok", ":=", "s", "[", "key", "]", "\n", "return", "value", ",", "ok", "\n", "}" ]
// Get does a lookup in the map
[ "Get", "does", "a", "lookup", "in", "the", "map" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/policy/types.go#L324-L327
6,907
aporeto-inc/trireme-lib
controller/pkg/remoteenforcer/remoteenforcer_stub.go
newRemoteEnforcer
func newRemoteEnforcer( ctx context.Context, cancel context.CancelFunc, service packetprocessor.PacketProcessor, rpcHandle rpcwrapper.RPCServer, secret string, statsClient statsclient.StatsClient, collector statscollector.Collector, debugClient debugclient.DebugClient, ) (*RemoteEnforcer, error) { return nil, nil }
go
func newRemoteEnforcer( ctx context.Context, cancel context.CancelFunc, service packetprocessor.PacketProcessor, rpcHandle rpcwrapper.RPCServer, secret string, statsClient statsclient.StatsClient, collector statscollector.Collector, debugClient debugclient.DebugClient, ) (*RemoteEnforcer, error) { return nil, nil }
[ "func", "newRemoteEnforcer", "(", "ctx", "context", ".", "Context", ",", "cancel", "context", ".", "CancelFunc", ",", "service", "packetprocessor", ".", "PacketProcessor", ",", "rpcHandle", "rpcwrapper", ".", "RPCServer", ",", "secret", "string", ",", "statsClient", "statsclient", ".", "StatsClient", ",", "collector", "statscollector", ".", "Collector", ",", "debugClient", "debugclient", ".", "DebugClient", ",", ")", "(", "*", "RemoteEnforcer", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// newServer is a fake implementation for building on darwin.
[ "newServer", "is", "a", "fake", "implementation", "for", "building", "on", "darwin", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/remoteenforcer/remoteenforcer_stub.go#L24-L35
6,908
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
NewSecretsProxy
func NewSecretsProxy() *SecretsProxy { return &SecretsProxy{ socketPath: constants.DefaultSecretsPath, drivers: cache.NewCache("secrets driver cache"), apiCacheMapping: cache.NewCache("secrets api cache"), cgroupCache: cache.NewCache("secrets pu cache"), policyCache: cache.NewCache("policy cache"), } }
go
func NewSecretsProxy() *SecretsProxy { return &SecretsProxy{ socketPath: constants.DefaultSecretsPath, drivers: cache.NewCache("secrets driver cache"), apiCacheMapping: cache.NewCache("secrets api cache"), cgroupCache: cache.NewCache("secrets pu cache"), policyCache: cache.NewCache("policy cache"), } }
[ "func", "NewSecretsProxy", "(", ")", "*", "SecretsProxy", "{", "return", "&", "SecretsProxy", "{", "socketPath", ":", "constants", ".", "DefaultSecretsPath", ",", "drivers", ":", "cache", ".", "NewCache", "(", "\"", "\"", ")", ",", "apiCacheMapping", ":", "cache", ".", "NewCache", "(", "\"", "\"", ")", ",", "cgroupCache", ":", "cache", ".", "NewCache", "(", "\"", "\"", ")", ",", "policyCache", ":", "cache", ".", "NewCache", "(", "\"", "\"", ")", ",", "}", "\n", "}" ]
// NewSecretsProxy creates a new secrets proxy.
[ "NewSecretsProxy", "creates", "a", "new", "secrets", "proxy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L41-L50
6,909
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
Run
func (s *SecretsProxy) Run(ctx context.Context) error { s.Lock() defer s.Unlock() var err error // Start a custom listener addr, _ := net.ResolveUnixAddr("unix", s.socketPath) nl, err := net.ListenUnix("unix", addr) if err != nil { return fmt.Errorf("Unable to start API server: %s", err) } s.server = &http.Server{ Handler: http.HandlerFunc(s.apiProcessor), } go func() { <-ctx.Done() s.server.Close() // nolint errcheck }() go s.server.Serve(server.NewUIDListener(nl)) // nolint errcheck return nil }
go
func (s *SecretsProxy) Run(ctx context.Context) error { s.Lock() defer s.Unlock() var err error // Start a custom listener addr, _ := net.ResolveUnixAddr("unix", s.socketPath) nl, err := net.ListenUnix("unix", addr) if err != nil { return fmt.Errorf("Unable to start API server: %s", err) } s.server = &http.Server{ Handler: http.HandlerFunc(s.apiProcessor), } go func() { <-ctx.Done() s.server.Close() // nolint errcheck }() go s.server.Serve(server.NewUIDListener(nl)) // nolint errcheck return nil }
[ "func", "(", "s", "*", "SecretsProxy", ")", "Run", "(", "ctx", "context", ".", "Context", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "var", "err", "error", "\n\n", "// Start a custom listener", "addr", ",", "_", ":=", "net", ".", "ResolveUnixAddr", "(", "\"", "\"", ",", "s", ".", "socketPath", ")", "\n", "nl", ",", "err", ":=", "net", ".", "ListenUnix", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "s", ".", "server", "=", "&", "http", ".", "Server", "{", "Handler", ":", "http", ".", "HandlerFunc", "(", "s", ".", "apiProcessor", ")", ",", "}", "\n\n", "go", "func", "(", ")", "{", "<-", "ctx", ".", "Done", "(", ")", "\n", "s", ".", "server", ".", "Close", "(", ")", "// nolint errcheck", "\n", "}", "(", ")", "\n\n", "go", "s", ".", "server", ".", "Serve", "(", "server", ".", "NewUIDListener", "(", "nl", ")", ")", "// nolint errcheck", "\n\n", "return", "nil", "\n", "}" ]
// Run implements the run method of the CtrlInterface. It starts the proxy // server and initializes the data structures.
[ "Run", "implements", "the", "run", "method", "of", "the", "CtrlInterface", ".", "It", "starts", "the", "proxy", "server", "and", "initializes", "the", "data", "structures", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L54-L79
6,910
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
Enforce
func (s *SecretsProxy) Enforce(puInfo *policy.PUInfo) error { return s.updateService(puInfo) }
go
func (s *SecretsProxy) Enforce(puInfo *policy.PUInfo) error { return s.updateService(puInfo) }
[ "func", "(", "s", "*", "SecretsProxy", ")", "Enforce", "(", "puInfo", "*", "policy", ".", "PUInfo", ")", "error", "{", "return", "s", ".", "updateService", "(", "puInfo", ")", "\n", "}" ]
// Enforce implements the corresponding interface of enforcers.
[ "Enforce", "implements", "the", "corresponding", "interface", "of", "enforcers", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L82-L84
6,911
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
apiProcessor
func (s *SecretsProxy) apiProcessor(w http.ResponseWriter, r *http.Request) { zap.L().Info("Processing secrets call", zap.String("URI", r.RequestURI), zap.String("Host", r.Host), zap.String("Remote address", r.RemoteAddr), ) // The remote address will contain the uid, gid and pid of the calling process. // This is because of the specific socket listener we are uing. parts := strings.Split(r.RemoteAddr, ":") if len(parts) != 3 { httpError(w, fmt.Errorf("Bad Remote Address"), "Unauthorized request", http.StatusUnauthorized) return } // We only care about the originating PID. pid := parts[2] cgroup, err := findParentCgroup(pid) if err != nil { httpError(w, err, "Unauthorized client - not the first process", http.StatusUnauthorized) return } data, err := s.apiCacheMapping.Get(cgroup) if err != nil { httpError(w, err, "Unauthorized client", http.StatusUnauthorized) return } // Find the corresponding API cache with the access permissions for // this particular client. apiCache, ok := data.(*urisearch.APICache) if !ok { httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError) return } // Find the identity of the PU policyData, err := s.policyCache.Get(cgroup) if err != nil { httpError(w, err, "Unauthorized client", http.StatusUnauthorized) return } scopes, ok := policyData.([]string) if !ok { httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError) return } // Search the API cache for matching rules. found, _ := apiCache.FindAndMatchScope(r.Method, r.RequestURI, scopes) if !found { httpError(w, fmt.Errorf("Unauthorized service"), "Unauthorized access", http.StatusUnauthorized) return } // Retrieve the secrets driver data and information. driverData, err := s.drivers.Get(cgroup) if err != nil { httpError(w, err, "No secrets driver for this client", http.StatusBadRequest) return } driver, ok := driverData.(SecretsDriver) if !ok { httpError(w, fmt.Errorf("driver not found"), "Bad driver", http.StatusInternalServerError) return } // Transfor the request based on the driver. if err := driver.Transform(r); err != nil { httpError(w, err, "Secrets driver error", http.StatusInternalServerError) return } // Forward the request. TODO .. we need to massage the return here. forwarder, err := forward.New(forward.RoundTripper(driver.Transport())) if err != nil { httpError(w, err, "Failed to configure forwarder", http.StatusInternalServerError) return } forwarder.ServeHTTP(w, r) }
go
func (s *SecretsProxy) apiProcessor(w http.ResponseWriter, r *http.Request) { zap.L().Info("Processing secrets call", zap.String("URI", r.RequestURI), zap.String("Host", r.Host), zap.String("Remote address", r.RemoteAddr), ) // The remote address will contain the uid, gid and pid of the calling process. // This is because of the specific socket listener we are uing. parts := strings.Split(r.RemoteAddr, ":") if len(parts) != 3 { httpError(w, fmt.Errorf("Bad Remote Address"), "Unauthorized request", http.StatusUnauthorized) return } // We only care about the originating PID. pid := parts[2] cgroup, err := findParentCgroup(pid) if err != nil { httpError(w, err, "Unauthorized client - not the first process", http.StatusUnauthorized) return } data, err := s.apiCacheMapping.Get(cgroup) if err != nil { httpError(w, err, "Unauthorized client", http.StatusUnauthorized) return } // Find the corresponding API cache with the access permissions for // this particular client. apiCache, ok := data.(*urisearch.APICache) if !ok { httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError) return } // Find the identity of the PU policyData, err := s.policyCache.Get(cgroup) if err != nil { httpError(w, err, "Unauthorized client", http.StatusUnauthorized) return } scopes, ok := policyData.([]string) if !ok { httpError(w, fmt.Errorf("Invalid data types"), "Internal server error - invalid type", http.StatusInternalServerError) return } // Search the API cache for matching rules. found, _ := apiCache.FindAndMatchScope(r.Method, r.RequestURI, scopes) if !found { httpError(w, fmt.Errorf("Unauthorized service"), "Unauthorized access", http.StatusUnauthorized) return } // Retrieve the secrets driver data and information. driverData, err := s.drivers.Get(cgroup) if err != nil { httpError(w, err, "No secrets driver for this client", http.StatusBadRequest) return } driver, ok := driverData.(SecretsDriver) if !ok { httpError(w, fmt.Errorf("driver not found"), "Bad driver", http.StatusInternalServerError) return } // Transfor the request based on the driver. if err := driver.Transform(r); err != nil { httpError(w, err, "Secrets driver error", http.StatusInternalServerError) return } // Forward the request. TODO .. we need to massage the return here. forwarder, err := forward.New(forward.RoundTripper(driver.Transport())) if err != nil { httpError(w, err, "Failed to configure forwarder", http.StatusInternalServerError) return } forwarder.ServeHTTP(w, r) }
[ "func", "(", "s", "*", "SecretsProxy", ")", "apiProcessor", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "zap", ".", "L", "(", ")", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "r", ".", "RequestURI", ")", ",", "zap", ".", "String", "(", "\"", "\"", ",", "r", ".", "Host", ")", ",", "zap", ".", "String", "(", "\"", "\"", ",", "r", ".", "RemoteAddr", ")", ",", ")", "\n\n", "// The remote address will contain the uid, gid and pid of the calling process.", "// This is because of the specific socket listener we are uing.", "parts", ":=", "strings", ".", "Split", "(", "r", ".", "RemoteAddr", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "!=", "3", "{", "httpError", "(", "w", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n\n", "// We only care about the originating PID.", "pid", ":=", "parts", "[", "2", "]", "\n", "cgroup", ",", "err", ":=", "findParentCgroup", "(", "pid", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n\n", "data", ",", "err", ":=", "s", ".", "apiCacheMapping", ".", "Get", "(", "cgroup", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n\n", "// Find the corresponding API cache with the access permissions for", "// this particular client.", "apiCache", ",", "ok", ":=", "data", ".", "(", "*", "urisearch", ".", "APICache", ")", "\n", "if", "!", "ok", "{", "httpError", "(", "w", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "// Find the identity of the PU", "policyData", ",", "err", ":=", "s", ".", "policyCache", ".", "Get", "(", "cgroup", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n\n", "scopes", ",", "ok", ":=", "policyData", ".", "(", "[", "]", "string", ")", "\n", "if", "!", "ok", "{", "httpError", "(", "w", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "// Search the API cache for matching rules.", "found", ",", "_", ":=", "apiCache", ".", "FindAndMatchScope", "(", "r", ".", "Method", ",", "r", ".", "RequestURI", ",", "scopes", ")", "\n", "if", "!", "found", "{", "httpError", "(", "w", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n\n", "// Retrieve the secrets driver data and information.", "driverData", ",", "err", ":=", "s", ".", "drivers", ".", "Get", "(", "cgroup", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "driver", ",", "ok", ":=", "driverData", ".", "(", "SecretsDriver", ")", "\n", "if", "!", "ok", "{", "httpError", "(", "w", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "// Transfor the request based on the driver.", "if", "err", ":=", "driver", ".", "Transform", "(", "r", ")", ";", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "// Forward the request. TODO .. we need to massage the return here.", "forwarder", ",", "err", ":=", "forward", ".", "New", "(", "forward", ".", "RoundTripper", "(", "driver", ".", "Transport", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "(", "w", ",", "err", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n\n", "forwarder", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}" ]
// apiProcessor is called for every request. It processes the request // and forwards to the originator of the secrets service after // authenticating that the client can access the service.
[ "apiProcessor", "is", "called", "for", "every", "request", ".", "It", "processes", "the", "request", "and", "forwards", "to", "the", "originator", "of", "the", "secrets", "service", "after", "authenticating", "that", "the", "client", "can", "access", "the", "service", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L105-L188
6,912
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
ValidateOriginProcess
func ValidateOriginProcess(pid string) (string, error) { pidNumber, err := strconv.Atoi(pid) if err != nil { return "", fmt.Errorf("Invalid PID %s", pid) } process, err := process.NewProcess(int32(pidNumber)) if err != nil { return "", fmt.Errorf("Process not found: %s", err) } ppid, err := process.Ppid() if err != nil { return "", fmt.Errorf("Parent process not found: %s", err) } parentPidCgroup, err := processCgroups(strconv.Itoa(int(ppid)), "net_cls,net_prio") if err != nil { return "", fmt.Errorf("Parent cgroup not found: %s", err) } if parentPidCgroup != "/" { return "", fmt.Errorf("Parent is not root cgroup - authorization fail") } return findParentCgroup(pid) }
go
func ValidateOriginProcess(pid string) (string, error) { pidNumber, err := strconv.Atoi(pid) if err != nil { return "", fmt.Errorf("Invalid PID %s", pid) } process, err := process.NewProcess(int32(pidNumber)) if err != nil { return "", fmt.Errorf("Process not found: %s", err) } ppid, err := process.Ppid() if err != nil { return "", fmt.Errorf("Parent process not found: %s", err) } parentPidCgroup, err := processCgroups(strconv.Itoa(int(ppid)), "net_cls,net_prio") if err != nil { return "", fmt.Errorf("Parent cgroup not found: %s", err) } if parentPidCgroup != "/" { return "", fmt.Errorf("Parent is not root cgroup - authorization fail") } return findParentCgroup(pid) }
[ "func", "ValidateOriginProcess", "(", "pid", "string", ")", "(", "string", ",", "error", ")", "{", "pidNumber", ",", "err", ":=", "strconv", ".", "Atoi", "(", "pid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pid", ")", "\n", "}", "\n", "process", ",", "err", ":=", "process", ".", "NewProcess", "(", "int32", "(", "pidNumber", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "ppid", ",", "err", ":=", "process", ".", "Ppid", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "parentPidCgroup", ",", "err", ":=", "processCgroups", "(", "strconv", ".", "Itoa", "(", "int", "(", "ppid", ")", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "parentPidCgroup", "!=", "\"", "\"", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "findParentCgroup", "(", "pid", ")", "\n", "}" ]
// ValidateOriginProcess implements a strict validation of the origin process. We might add later.
[ "ValidateOriginProcess", "implements", "a", "strict", "validation", "of", "the", "origin", "process", ".", "We", "might", "add", "later", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L262-L284
6,913
aporeto-inc/trireme-lib
controller/internal/enforcer/secretsproxy/secretsproxy.go
findParentCgroup
func findParentCgroup(pid string) (string, error) { cgroup, err := processCgroups(pid, "net_cls,net_prio") if err != nil { return "", fmt.Errorf("Invalid cgroup: %s", err) } for i := len(cgroup) - 1; i > 0; i-- { if cgroup[i:i+1] == "/" { return cgroup[:i], nil } } if strings.HasPrefix(cgroup, "/docker/") && len(cgroup) > 8 { return cgroup[8:20], nil } return "", fmt.Errorf("Cannot find parent cgroup: %s", pid) }
go
func findParentCgroup(pid string) (string, error) { cgroup, err := processCgroups(pid, "net_cls,net_prio") if err != nil { return "", fmt.Errorf("Invalid cgroup: %s", err) } for i := len(cgroup) - 1; i > 0; i-- { if cgroup[i:i+1] == "/" { return cgroup[:i], nil } } if strings.HasPrefix(cgroup, "/docker/") && len(cgroup) > 8 { return cgroup[8:20], nil } return "", fmt.Errorf("Cannot find parent cgroup: %s", pid) }
[ "func", "findParentCgroup", "(", "pid", "string", ")", "(", "string", ",", "error", ")", "{", "cgroup", ",", "err", ":=", "processCgroups", "(", "pid", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "for", "i", ":=", "len", "(", "cgroup", ")", "-", "1", ";", "i", ">", "0", ";", "i", "--", "{", "if", "cgroup", "[", "i", ":", "i", "+", "1", "]", "==", "\"", "\"", "{", "return", "cgroup", "[", ":", "i", "]", ",", "nil", "\n", "}", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "cgroup", ",", "\"", "\"", ")", "&&", "len", "(", "cgroup", ")", ">", "8", "{", "return", "cgroup", "[", "8", ":", "20", "]", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pid", ")", "\n", "}" ]
// findParentCgroup returns the parent cgroup of the process caller
[ "findParentCgroup", "returns", "the", "parent", "cgroup", "of", "the", "process", "caller" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/secretsproxy/secretsproxy.go#L314-L329
6,914
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
NewSupervisor
func NewSupervisor( collector collector.EventCollector, enforcerInstance enforcer.Enforcer, mode constants.ModeType, cfg *runtime.Configuration, p packetprocessor.PacketProcessor, ) (Supervisor, error) { if collector == nil || enforcerInstance == nil { return nil, errors.New("Invalid parameters") } filterQueue := enforcerInstance.GetFilterQueue() if filterQueue == nil { return nil, errors.New("enforcer filter queues cannot be nil") } impl, err := iptablesctrl.NewInstance(filterQueue, mode, cfg) if err != nil { return nil, fmt.Errorf("unable to initialize supervisor controllers: %s", err) } return &Config{ mode: mode, impl: impl, versionTracker: cache.NewCache("SupVersionTracker"), collector: collector, filterQueue: filterQueue, service: p, cfg: cfg, }, nil }
go
func NewSupervisor( collector collector.EventCollector, enforcerInstance enforcer.Enforcer, mode constants.ModeType, cfg *runtime.Configuration, p packetprocessor.PacketProcessor, ) (Supervisor, error) { if collector == nil || enforcerInstance == nil { return nil, errors.New("Invalid parameters") } filterQueue := enforcerInstance.GetFilterQueue() if filterQueue == nil { return nil, errors.New("enforcer filter queues cannot be nil") } impl, err := iptablesctrl.NewInstance(filterQueue, mode, cfg) if err != nil { return nil, fmt.Errorf("unable to initialize supervisor controllers: %s", err) } return &Config{ mode: mode, impl: impl, versionTracker: cache.NewCache("SupVersionTracker"), collector: collector, filterQueue: filterQueue, service: p, cfg: cfg, }, nil }
[ "func", "NewSupervisor", "(", "collector", "collector", ".", "EventCollector", ",", "enforcerInstance", "enforcer", ".", "Enforcer", ",", "mode", "constants", ".", "ModeType", ",", "cfg", "*", "runtime", ".", "Configuration", ",", "p", "packetprocessor", ".", "PacketProcessor", ",", ")", "(", "Supervisor", ",", "error", ")", "{", "if", "collector", "==", "nil", "||", "enforcerInstance", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "filterQueue", ":=", "enforcerInstance", ".", "GetFilterQueue", "(", ")", "\n", "if", "filterQueue", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "impl", ",", "err", ":=", "iptablesctrl", ".", "NewInstance", "(", "filterQueue", ",", "mode", ",", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "Config", "{", "mode", ":", "mode", ",", "impl", ":", "impl", ",", "versionTracker", ":", "cache", ".", "NewCache", "(", "\"", "\"", ")", ",", "collector", ":", "collector", ",", "filterQueue", ":", "filterQueue", ",", "service", ":", "p", ",", "cfg", ":", "cfg", ",", "}", ",", "nil", "\n", "}" ]
// NewSupervisor will create a new connection supervisor that uses IPTables // to redirect specific packets to userspace. It instantiates multiple data stores // to maintain efficient mappings between contextID, policy and IP addresses. This // simplifies the lookup operations at the expense of memory.
[ "NewSupervisor", "will", "create", "a", "new", "connection", "supervisor", "that", "uses", "IPTables", "to", "redirect", "specific", "packets", "to", "userspace", ".", "It", "instantiates", "multiple", "data", "stores", "to", "maintain", "efficient", "mappings", "between", "contextID", "policy", "and", "IP", "addresses", ".", "This", "simplifies", "the", "lookup", "operations", "at", "the", "expense", "of", "memory", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L58-L89
6,915
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
Run
func (s *Config) Run(ctx context.Context) error { s.Lock() defer s.Unlock() if err := s.impl.Run(ctx); err != nil { return fmt.Errorf("unable to start the implementer: %s", err) } if err := s.impl.SetTargetNetworks(s.cfg); err != nil { return err } if s.service != nil { s.service.Initialize(s.filterQueue, s.impl.ACLProvider()) } return nil }
go
func (s *Config) Run(ctx context.Context) error { s.Lock() defer s.Unlock() if err := s.impl.Run(ctx); err != nil { return fmt.Errorf("unable to start the implementer: %s", err) } if err := s.impl.SetTargetNetworks(s.cfg); err != nil { return err } if s.service != nil { s.service.Initialize(s.filterQueue, s.impl.ACLProvider()) } return nil }
[ "func", "(", "s", "*", "Config", ")", "Run", "(", "ctx", "context", ".", "Context", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "if", "err", ":=", "s", ".", "impl", ".", "Run", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "impl", ".", "SetTargetNetworks", "(", "s", ".", "cfg", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "s", ".", "service", "!=", "nil", "{", "s", ".", "service", ".", "Initialize", "(", "s", ".", "filterQueue", ",", "s", ".", "impl", ".", "ACLProvider", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Run starts the supervisor
[ "Run", "starts", "the", "supervisor" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L92-L110
6,916
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
Supervise
func (s *Config) Supervise(contextID string, pu *policy.PUInfo) error { if pu == nil || pu.Policy == nil || pu.Runtime == nil { return errors.New("Invalid PU or policy info") } _, err := s.versionTracker.Get(contextID) if err != nil { // ContextID is not found in Cache, New PU: Do create. return s.doCreatePU(contextID, pu) } // Context already in the cache. Just run update return s.doUpdatePU(contextID, pu) }
go
func (s *Config) Supervise(contextID string, pu *policy.PUInfo) error { if pu == nil || pu.Policy == nil || pu.Runtime == nil { return errors.New("Invalid PU or policy info") } _, err := s.versionTracker.Get(contextID) if err != nil { // ContextID is not found in Cache, New PU: Do create. return s.doCreatePU(contextID, pu) } // Context already in the cache. Just run update return s.doUpdatePU(contextID, pu) }
[ "func", "(", "s", "*", "Config", ")", "Supervise", "(", "contextID", "string", ",", "pu", "*", "policy", ".", "PUInfo", ")", "error", "{", "if", "pu", "==", "nil", "||", "pu", ".", "Policy", "==", "nil", "||", "pu", ".", "Runtime", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "s", ".", "versionTracker", ".", "Get", "(", "contextID", ")", "\n", "if", "err", "!=", "nil", "{", "// ContextID is not found in Cache, New PU: Do create.", "return", "s", ".", "doCreatePU", "(", "contextID", ",", "pu", ")", "\n", "}", "\n\n", "// Context already in the cache. Just run update", "return", "s", ".", "doUpdatePU", "(", "contextID", ",", "pu", ")", "\n", "}" ]
// Supervise creates a mapping between an IP address and the corresponding labels. // it invokes the various handlers that process the parameter policy.
[ "Supervise", "creates", "a", "mapping", "between", "an", "IP", "address", "and", "the", "corresponding", "labels", ".", "it", "invokes", "the", "various", "handlers", "that", "process", "the", "parameter", "policy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L114-L128
6,917
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
Unsupervise
func (s *Config) Unsupervise(contextID string) error { s.Lock() defer s.Unlock() data, err := s.versionTracker.Get(contextID) if err != nil { return fmt.Errorf("cannot find policy version: %s", err) } cfg := data.(*cacheData) port := cfg.containerInfo.Policy.ServicesListeningPort() // If local server, delete pu specific chains in Trireme/NetworkSvc/Hostmode chains. puType := cfg.containerInfo.Runtime.PUType() // TODO (varks): Similar to configureRules and UpdateRules, DeleteRules should take // only contextID and *policy.PUInfo as function parameters. if err := s.impl.DeleteRules(cfg.version, contextID, cfg.tcpPorts, cfg.udpPorts, cfg.mark, cfg.username, port, puType); err != nil { zap.L().Warn("Some rules were not deleted during unsupervise", zap.Error(err)) } if err := s.versionTracker.Remove(contextID); err != nil { zap.L().Warn("Failed to clean the rule version cache", zap.Error(err)) } return nil }
go
func (s *Config) Unsupervise(contextID string) error { s.Lock() defer s.Unlock() data, err := s.versionTracker.Get(contextID) if err != nil { return fmt.Errorf("cannot find policy version: %s", err) } cfg := data.(*cacheData) port := cfg.containerInfo.Policy.ServicesListeningPort() // If local server, delete pu specific chains in Trireme/NetworkSvc/Hostmode chains. puType := cfg.containerInfo.Runtime.PUType() // TODO (varks): Similar to configureRules and UpdateRules, DeleteRules should take // only contextID and *policy.PUInfo as function parameters. if err := s.impl.DeleteRules(cfg.version, contextID, cfg.tcpPorts, cfg.udpPorts, cfg.mark, cfg.username, port, puType); err != nil { zap.L().Warn("Some rules were not deleted during unsupervise", zap.Error(err)) } if err := s.versionTracker.Remove(contextID); err != nil { zap.L().Warn("Failed to clean the rule version cache", zap.Error(err)) } return nil }
[ "func", "(", "s", "*", "Config", ")", "Unsupervise", "(", "contextID", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "data", ",", "err", ":=", "s", ".", "versionTracker", ".", "Get", "(", "contextID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "cfg", ":=", "data", ".", "(", "*", "cacheData", ")", "\n", "port", ":=", "cfg", ".", "containerInfo", ".", "Policy", ".", "ServicesListeningPort", "(", ")", "\n\n", "// If local server, delete pu specific chains in Trireme/NetworkSvc/Hostmode chains.", "puType", ":=", "cfg", ".", "containerInfo", ".", "Runtime", ".", "PUType", "(", ")", "\n\n", "// TODO (varks): Similar to configureRules and UpdateRules, DeleteRules should take", "// only contextID and *policy.PUInfo as function parameters.", "if", "err", ":=", "s", ".", "impl", ".", "DeleteRules", "(", "cfg", ".", "version", ",", "contextID", ",", "cfg", ".", "tcpPorts", ",", "cfg", ".", "udpPorts", ",", "cfg", ".", "mark", ",", "cfg", ".", "username", ",", "port", ",", "puType", ")", ";", "err", "!=", "nil", "{", "zap", ".", "L", "(", ")", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "versionTracker", ".", "Remove", "(", "contextID", ")", ";", "err", "!=", "nil", "{", "zap", ".", "L", "(", ")", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Unsupervise removes the mapping from cache and cleans up the iptable rules. ALL // remove operations will print errors by they don't return error. We want to force // as much cleanup as possible to avoid stale state
[ "Unsupervise", "removes", "the", "mapping", "from", "cache", "and", "cleans", "up", "the", "iptable", "rules", ".", "ALL", "remove", "operations", "will", "print", "errors", "by", "they", "don", "t", "return", "error", ".", "We", "want", "to", "force", "as", "much", "cleanup", "as", "possible", "to", "avoid", "stale", "state" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L133-L159
6,918
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
CleanUp
func (s *Config) CleanUp() error { s.Lock() defer s.Unlock() return s.impl.CleanUp() }
go
func (s *Config) CleanUp() error { s.Lock() defer s.Unlock() return s.impl.CleanUp() }
[ "func", "(", "s", "*", "Config", ")", "CleanUp", "(", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "return", "s", ".", "impl", ".", "CleanUp", "(", ")", "\n", "}" ]
// CleanUp implements the cleanup interface
[ "CleanUp", "implements", "the", "cleanup", "interface" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L162-L167
6,919
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
SetTargetNetworks
func (s *Config) SetTargetNetworks(cfg *runtime.Configuration) error { s.Lock() defer s.Unlock() return s.impl.SetTargetNetworks(cfg) }
go
func (s *Config) SetTargetNetworks(cfg *runtime.Configuration) error { s.Lock() defer s.Unlock() return s.impl.SetTargetNetworks(cfg) }
[ "func", "(", "s", "*", "Config", ")", "SetTargetNetworks", "(", "cfg", "*", "runtime", ".", "Configuration", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "return", "s", ".", "impl", ".", "SetTargetNetworks", "(", "cfg", ")", "\n", "}" ]
// SetTargetNetworks sets the target networks of the supervisor
[ "SetTargetNetworks", "sets", "the", "target", "networks", "of", "the", "supervisor" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L170-L176
6,920
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
doUpdatePU
func (s *Config) doUpdatePU(contextID string, pu *policy.PUInfo) error { s.Lock() data, err := s.versionTracker.LockedModify(contextID, revert, 1) if err != nil { return fmt.Errorf("unable to find pu %s in cache: %s", contextID, err) } c := data.(*cacheData) if err := s.impl.UpdateRules(c.version, contextID, pu, c.containerInfo); err != nil { // Try to clean up, even though this is fatal and it will most likely fail s.Unlock() s.Unsupervise(contextID) // nolint return err } // Updated the policy in the cached processing unit. c.containerInfo.Policy = pu.Policy s.Unlock() return nil }
go
func (s *Config) doUpdatePU(contextID string, pu *policy.PUInfo) error { s.Lock() data, err := s.versionTracker.LockedModify(contextID, revert, 1) if err != nil { return fmt.Errorf("unable to find pu %s in cache: %s", contextID, err) } c := data.(*cacheData) if err := s.impl.UpdateRules(c.version, contextID, pu, c.containerInfo); err != nil { // Try to clean up, even though this is fatal and it will most likely fail s.Unlock() s.Unsupervise(contextID) // nolint return err } // Updated the policy in the cached processing unit. c.containerInfo.Policy = pu.Policy s.Unlock() return nil }
[ "func", "(", "s", "*", "Config", ")", "doUpdatePU", "(", "contextID", "string", ",", "pu", "*", "policy", ".", "PUInfo", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n\n", "data", ",", "err", ":=", "s", ".", "versionTracker", ".", "LockedModify", "(", "contextID", ",", "revert", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "contextID", ",", "err", ")", "\n", "}", "\n\n", "c", ":=", "data", ".", "(", "*", "cacheData", ")", "\n", "if", "err", ":=", "s", ".", "impl", ".", "UpdateRules", "(", "c", ".", "version", ",", "contextID", ",", "pu", ",", "c", ".", "containerInfo", ")", ";", "err", "!=", "nil", "{", "// Try to clean up, even though this is fatal and it will most likely fail", "s", ".", "Unlock", "(", ")", "\n", "s", ".", "Unsupervise", "(", "contextID", ")", "// nolint", "\n", "return", "err", "\n", "}", "\n\n", "// Updated the policy in the cached processing unit.", "c", ".", "containerInfo", ".", "Policy", "=", "pu", ".", "Policy", "\n\n", "s", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}" ]
// UpdatePU creates a mapping between an IP address and the corresponding labels //and the invokes the various handlers that process all policies.
[ "UpdatePU", "creates", "a", "mapping", "between", "an", "IP", "address", "and", "the", "corresponding", "labels", "and", "the", "invokes", "the", "various", "handlers", "that", "process", "all", "policies", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L217-L239
6,921
aporeto-inc/trireme-lib
controller/internal/supervisor/supervisor.go
EnableIPTablesPacketTracing
func (s *Config) EnableIPTablesPacketTracing(ctx context.Context, contextID string, interval time.Duration) error { data, err := s.versionTracker.Get(contextID) if err != nil { return fmt.Errorf("cannot find policy version: %s", err) } cfg := data.(*cacheData) iptablesRules := debugRules(cfg, s.mode) ipt := s.impl.ACLProvider() for _, rule := range iptablesRules { if err := ipt.Insert(rule[0], rule[1], 1, rule[2:]...); err != nil { zap.L().Error("Unable to install rule", zap.Error(err)) } } // anonymous go func to flush debug iptables after interval go func() { for { select { case <-ctx.Done(): case <-time.After(interval): for _, rule := range iptablesRules { if err := ipt.Delete(rule[0], rule[1], rule[2:]...); err != nil { zap.L().Debug("Unable to delete trace rules", zap.Error(err)) } } } } }() return nil }
go
func (s *Config) EnableIPTablesPacketTracing(ctx context.Context, contextID string, interval time.Duration) error { data, err := s.versionTracker.Get(contextID) if err != nil { return fmt.Errorf("cannot find policy version: %s", err) } cfg := data.(*cacheData) iptablesRules := debugRules(cfg, s.mode) ipt := s.impl.ACLProvider() for _, rule := range iptablesRules { if err := ipt.Insert(rule[0], rule[1], 1, rule[2:]...); err != nil { zap.L().Error("Unable to install rule", zap.Error(err)) } } // anonymous go func to flush debug iptables after interval go func() { for { select { case <-ctx.Done(): case <-time.After(interval): for _, rule := range iptablesRules { if err := ipt.Delete(rule[0], rule[1], rule[2:]...); err != nil { zap.L().Debug("Unable to delete trace rules", zap.Error(err)) } } } } }() return nil }
[ "func", "(", "s", "*", "Config", ")", "EnableIPTablesPacketTracing", "(", "ctx", "context", ".", "Context", ",", "contextID", "string", ",", "interval", "time", ".", "Duration", ")", "error", "{", "data", ",", "err", ":=", "s", ".", "versionTracker", ".", "Get", "(", "contextID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "cfg", ":=", "data", ".", "(", "*", "cacheData", ")", "\n", "iptablesRules", ":=", "debugRules", "(", "cfg", ",", "s", ".", "mode", ")", "\n", "ipt", ":=", "s", ".", "impl", ".", "ACLProvider", "(", ")", "\n\n", "for", "_", ",", "rule", ":=", "range", "iptablesRules", "{", "if", "err", ":=", "ipt", ".", "Insert", "(", "rule", "[", "0", "]", ",", "rule", "[", "1", "]", ",", "1", ",", "rule", "[", "2", ":", "]", "...", ")", ";", "err", "!=", "nil", "{", "zap", ".", "L", "(", ")", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n", "}", "\n\n", "// anonymous go func to flush debug iptables after interval", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "case", "<-", "time", ".", "After", "(", "interval", ")", ":", "for", "_", ",", "rule", ":=", "range", "iptablesRules", "{", "if", "err", ":=", "ipt", ".", "Delete", "(", "rule", "[", "0", "]", ",", "rule", "[", "1", "]", ",", "rule", "[", "2", ":", "]", "...", ")", ";", "err", "!=", "nil", "{", "zap", ".", "L", "(", ")", ".", "Debug", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "return", "nil", "\n", "}" ]
// EnableIPTablesPacketTracing enables ip tables packet tracing
[ "EnableIPTablesPacketTracing", "enables", "ip", "tables", "packet", "tracing" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/supervisor/supervisor.go#L242-L274
6,922
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
New
func New(serverID string, validity time.Duration, secret secrets.Secrets) (TokenAccessor, error) { tokenEngine, err := tokens.NewJWT(validity, serverID, secret) if err != nil { return nil, err } return &tokenAccessor{ tokens: tokenEngine, serverID: serverID, validity: validity, }, nil }
go
func New(serverID string, validity time.Duration, secret secrets.Secrets) (TokenAccessor, error) { tokenEngine, err := tokens.NewJWT(validity, serverID, secret) if err != nil { return nil, err } return &tokenAccessor{ tokens: tokenEngine, serverID: serverID, validity: validity, }, nil }
[ "func", "New", "(", "serverID", "string", ",", "validity", "time", ".", "Duration", ",", "secret", "secrets", ".", "Secrets", ")", "(", "TokenAccessor", ",", "error", ")", "{", "tokenEngine", ",", "err", ":=", "tokens", ".", "NewJWT", "(", "validity", ",", "serverID", ",", "secret", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "tokenAccessor", "{", "tokens", ":", "tokenEngine", ",", "serverID", ":", "serverID", ",", "validity", ":", "validity", ",", "}", ",", "nil", "\n", "}" ]
// New creates a new instance of TokenAccessor interface
[ "New", "creates", "a", "new", "instance", "of", "TokenAccessor", "interface" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L26-L38
6,923
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
SetToken
func (t *tokenAccessor) SetToken(serverID string, validity time.Duration, secret secrets.Secrets) error { t.Lock() defer t.Unlock() tokenEngine, err := tokens.NewJWT(validity, serverID, secret) if err != nil { return err } t.tokens = tokenEngine return nil }
go
func (t *tokenAccessor) SetToken(serverID string, validity time.Duration, secret secrets.Secrets) error { t.Lock() defer t.Unlock() tokenEngine, err := tokens.NewJWT(validity, serverID, secret) if err != nil { return err } t.tokens = tokenEngine return nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "SetToken", "(", "serverID", "string", ",", "validity", "time", ".", "Duration", ",", "secret", "secrets", ".", "Secrets", ")", "error", "{", "t", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "Unlock", "(", ")", "\n", "tokenEngine", ",", "err", ":=", "tokens", ".", "NewJWT", "(", "validity", ",", "serverID", ",", "secret", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "t", ".", "tokens", "=", "tokenEngine", "\n", "return", "nil", "\n", "}" ]
// SetToken updates sthe stored token in the struct
[ "SetToken", "updates", "sthe", "stored", "token", "in", "the", "struct" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L49-L59
6,924
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
CreateAckPacketToken
func (t *tokenAccessor) CreateAckPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo) ([]byte, error) { claims := &tokens.ConnectionClaims{ LCL: auth.LocalContext, RMT: auth.RemoteContext, } token, err := t.getToken().CreateAndSign(true, claims, auth.LocalContext, claimsheader.NewClaimsHeader()) if err != nil { return []byte{}, err } return token, nil }
go
func (t *tokenAccessor) CreateAckPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo) ([]byte, error) { claims := &tokens.ConnectionClaims{ LCL: auth.LocalContext, RMT: auth.RemoteContext, } token, err := t.getToken().CreateAndSign(true, claims, auth.LocalContext, claimsheader.NewClaimsHeader()) if err != nil { return []byte{}, err } return token, nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "CreateAckPacketToken", "(", "context", "*", "pucontext", ".", "PUContext", ",", "auth", "*", "connection", ".", "AuthInfo", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "claims", ":=", "&", "tokens", ".", "ConnectionClaims", "{", "LCL", ":", "auth", ".", "LocalContext", ",", "RMT", ":", "auth", ".", "RemoteContext", ",", "}", "\n\n", "token", ",", "err", ":=", "t", ".", "getToken", "(", ")", ".", "CreateAndSign", "(", "true", ",", "claims", ",", "auth", ".", "LocalContext", ",", "claimsheader", ".", "NewClaimsHeader", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "token", ",", "nil", "\n", "}" ]
// CreateAckPacketToken creates the authentication token
[ "CreateAckPacketToken", "creates", "the", "authentication", "token" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L72-L85
6,925
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
CreateSynPacketToken
func (t *tokenAccessor) CreateSynPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo) (token []byte, err error) { token, serviceContext, err := context.GetCachedTokenAndServiceContext() if err == nil && bytes.Equal(auth.LocalServiceContext, serviceContext) { // Randomize the nonce and send it err = t.getToken().Randomize(token, auth.LocalContext) if err == nil { return token, nil } // If there is an error, let's try to create a new one } claims := &tokens.ConnectionClaims{ T: context.Identity(), EK: auth.LocalServiceContext, } if token, err = t.getToken().CreateAndSign(false, claims, auth.LocalContext, claimsheader.NewClaimsHeader()); err != nil { return []byte{}, nil } context.UpdateCachedTokenAndServiceContext(token, auth.LocalServiceContext) return token, nil }
go
func (t *tokenAccessor) CreateSynPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo) (token []byte, err error) { token, serviceContext, err := context.GetCachedTokenAndServiceContext() if err == nil && bytes.Equal(auth.LocalServiceContext, serviceContext) { // Randomize the nonce and send it err = t.getToken().Randomize(token, auth.LocalContext) if err == nil { return token, nil } // If there is an error, let's try to create a new one } claims := &tokens.ConnectionClaims{ T: context.Identity(), EK: auth.LocalServiceContext, } if token, err = t.getToken().CreateAndSign(false, claims, auth.LocalContext, claimsheader.NewClaimsHeader()); err != nil { return []byte{}, nil } context.UpdateCachedTokenAndServiceContext(token, auth.LocalServiceContext) return token, nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "CreateSynPacketToken", "(", "context", "*", "pucontext", ".", "PUContext", ",", "auth", "*", "connection", ".", "AuthInfo", ")", "(", "token", "[", "]", "byte", ",", "err", "error", ")", "{", "token", ",", "serviceContext", ",", "err", ":=", "context", ".", "GetCachedTokenAndServiceContext", "(", ")", "\n", "if", "err", "==", "nil", "&&", "bytes", ".", "Equal", "(", "auth", ".", "LocalServiceContext", ",", "serviceContext", ")", "{", "// Randomize the nonce and send it", "err", "=", "t", ".", "getToken", "(", ")", ".", "Randomize", "(", "token", ",", "auth", ".", "LocalContext", ")", "\n", "if", "err", "==", "nil", "{", "return", "token", ",", "nil", "\n", "}", "\n", "// If there is an error, let's try to create a new one", "}", "\n\n", "claims", ":=", "&", "tokens", ".", "ConnectionClaims", "{", "T", ":", "context", ".", "Identity", "(", ")", ",", "EK", ":", "auth", ".", "LocalServiceContext", ",", "}", "\n\n", "if", "token", ",", "err", "=", "t", ".", "getToken", "(", ")", ".", "CreateAndSign", "(", "false", ",", "claims", ",", "auth", ".", "LocalContext", ",", "claimsheader", ".", "NewClaimsHeader", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "nil", "\n", "}", "\n\n", "context", ".", "UpdateCachedTokenAndServiceContext", "(", "token", ",", "auth", ".", "LocalServiceContext", ")", "\n\n", "return", "token", ",", "nil", "\n", "}" ]
// createSynPacketToken creates the authentication token
[ "createSynPacketToken", "creates", "the", "authentication", "token" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L88-L112
6,926
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
CreateSynAckPacketToken
func (t *tokenAccessor) CreateSynAckPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo, claimsHeader *claimsheader.ClaimsHeader) (token []byte, err error) { claims := &tokens.ConnectionClaims{ T: context.Identity(), RMT: auth.RemoteContext, EK: auth.LocalServiceContext, } if token, err = t.getToken().CreateAndSign(false, claims, auth.LocalContext, claimsHeader); err != nil { return []byte{}, nil } return token, nil }
go
func (t *tokenAccessor) CreateSynAckPacketToken(context *pucontext.PUContext, auth *connection.AuthInfo, claimsHeader *claimsheader.ClaimsHeader) (token []byte, err error) { claims := &tokens.ConnectionClaims{ T: context.Identity(), RMT: auth.RemoteContext, EK: auth.LocalServiceContext, } if token, err = t.getToken().CreateAndSign(false, claims, auth.LocalContext, claimsHeader); err != nil { return []byte{}, nil } return token, nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "CreateSynAckPacketToken", "(", "context", "*", "pucontext", ".", "PUContext", ",", "auth", "*", "connection", ".", "AuthInfo", ",", "claimsHeader", "*", "claimsheader", ".", "ClaimsHeader", ")", "(", "token", "[", "]", "byte", ",", "err", "error", ")", "{", "claims", ":=", "&", "tokens", ".", "ConnectionClaims", "{", "T", ":", "context", ".", "Identity", "(", ")", ",", "RMT", ":", "auth", ".", "RemoteContext", ",", "EK", ":", "auth", ".", "LocalServiceContext", ",", "}", "\n\n", "if", "token", ",", "err", "=", "t", ".", "getToken", "(", ")", ".", "CreateAndSign", "(", "false", ",", "claims", ",", "auth", ".", "LocalContext", ",", "claimsHeader", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "nil", "\n", "}", "\n\n", "return", "token", ",", "nil", "\n", "}" ]
// createSynAckPacketToken creates the authentication token for SynAck packets // We need to sign the received token. No caching possible here
[ "createSynAckPacketToken", "creates", "the", "authentication", "token", "for", "SynAck", "packets", "We", "need", "to", "sign", "the", "received", "token", ".", "No", "caching", "possible", "here" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L116-L129
6,927
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
ParsePacketToken
func (t *tokenAccessor) ParsePacketToken(auth *connection.AuthInfo, data []byte) (*tokens.ConnectionClaims, error) { // Validate the certificate and parse the token claims, nonce, cert, err := t.getToken().Decode(false, data, auth.RemotePublicKey) if err != nil { return nil, err } // We always a need a valid remote context ID if claims.T == nil { return nil, errors.New("no claims found") } remoteContextID, ok := claims.T.Get(enforcerconstants.TransmitterLabel) if !ok { return nil, errors.New("no transmitter label") } auth.RemotePublicKey = cert auth.RemoteContext = nonce auth.RemoteContextID = remoteContextID auth.RemoteServiceContext = claims.EK return claims, nil }
go
func (t *tokenAccessor) ParsePacketToken(auth *connection.AuthInfo, data []byte) (*tokens.ConnectionClaims, error) { // Validate the certificate and parse the token claims, nonce, cert, err := t.getToken().Decode(false, data, auth.RemotePublicKey) if err != nil { return nil, err } // We always a need a valid remote context ID if claims.T == nil { return nil, errors.New("no claims found") } remoteContextID, ok := claims.T.Get(enforcerconstants.TransmitterLabel) if !ok { return nil, errors.New("no transmitter label") } auth.RemotePublicKey = cert auth.RemoteContext = nonce auth.RemoteContextID = remoteContextID auth.RemoteServiceContext = claims.EK return claims, nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "ParsePacketToken", "(", "auth", "*", "connection", ".", "AuthInfo", ",", "data", "[", "]", "byte", ")", "(", "*", "tokens", ".", "ConnectionClaims", ",", "error", ")", "{", "// Validate the certificate and parse the token", "claims", ",", "nonce", ",", "cert", ",", "err", ":=", "t", ".", "getToken", "(", ")", ".", "Decode", "(", "false", ",", "data", ",", "auth", ".", "RemotePublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// We always a need a valid remote context ID", "if", "claims", ".", "T", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "remoteContextID", ",", "ok", ":=", "claims", ".", "T", ".", "Get", "(", "enforcerconstants", ".", "TransmitterLabel", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "auth", ".", "RemotePublicKey", "=", "cert", "\n", "auth", ".", "RemoteContext", "=", "nonce", "\n", "auth", ".", "RemoteContextID", "=", "remoteContextID", "\n", "auth", ".", "RemoteServiceContext", "=", "claims", ".", "EK", "\n\n", "return", "claims", ",", "nil", "\n", "}" ]
// parsePacketToken parses the packet token and populates the right state. // Returns an error if the token cannot be parsed or the signature fails
[ "parsePacketToken", "parses", "the", "packet", "token", "and", "populates", "the", "right", "state", ".", "Returns", "an", "error", "if", "the", "token", "cannot", "be", "parsed", "or", "the", "signature", "fails" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L133-L156
6,928
aporeto-inc/trireme-lib
controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go
ParseAckToken
func (t *tokenAccessor) ParseAckToken(auth *connection.AuthInfo, data []byte) (*tokens.ConnectionClaims, error) { gt := t.getToken() if gt == nil { return nil, errors.New("token is nil") } if auth == nil { return nil, errors.New("auth is nil") } // Validate the certificate and parse the token claims, _, _, err := t.getToken().Decode(true, data, auth.RemotePublicKey) if err != nil { return nil, err } // Compare the incoming random context with the stored context matchLocal := bytes.Compare(claims.RMT, auth.LocalContext) matchRemote := bytes.Compare(claims.LCL, auth.RemoteContext) if matchLocal != 0 || matchRemote != 0 { return nil, errors.New("failed to match context in ack packet") } return claims, nil }
go
func (t *tokenAccessor) ParseAckToken(auth *connection.AuthInfo, data []byte) (*tokens.ConnectionClaims, error) { gt := t.getToken() if gt == nil { return nil, errors.New("token is nil") } if auth == nil { return nil, errors.New("auth is nil") } // Validate the certificate and parse the token claims, _, _, err := t.getToken().Decode(true, data, auth.RemotePublicKey) if err != nil { return nil, err } // Compare the incoming random context with the stored context matchLocal := bytes.Compare(claims.RMT, auth.LocalContext) matchRemote := bytes.Compare(claims.LCL, auth.RemoteContext) if matchLocal != 0 || matchRemote != 0 { return nil, errors.New("failed to match context in ack packet") } return claims, nil }
[ "func", "(", "t", "*", "tokenAccessor", ")", "ParseAckToken", "(", "auth", "*", "connection", ".", "AuthInfo", ",", "data", "[", "]", "byte", ")", "(", "*", "tokens", ".", "ConnectionClaims", ",", "error", ")", "{", "gt", ":=", "t", ".", "getToken", "(", ")", "\n", "if", "gt", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "auth", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "// Validate the certificate and parse the token", "claims", ",", "_", ",", "_", ",", "err", ":=", "t", ".", "getToken", "(", ")", ".", "Decode", "(", "true", ",", "data", ",", "auth", ".", "RemotePublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Compare the incoming random context with the stored context", "matchLocal", ":=", "bytes", ".", "Compare", "(", "claims", ".", "RMT", ",", "auth", ".", "LocalContext", ")", "\n", "matchRemote", ":=", "bytes", ".", "Compare", "(", "claims", ".", "LCL", ",", "auth", ".", "RemoteContext", ")", "\n", "if", "matchLocal", "!=", "0", "||", "matchRemote", "!=", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "claims", ",", "nil", "\n", "}" ]
// parseAckToken parses the tokens in Ack packets. They don't carry all the state context // and it needs to be recovered
[ "parseAckToken", "parses", "the", "tokens", "in", "Ack", "packets", ".", "They", "don", "t", "carry", "all", "the", "state", "context", "and", "it", "needs", "to", "be", "recovered" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/nfqdatapath/tokenaccessor/tokenaccessor.go#L160-L183
6,929
aporeto-inc/trireme-lib
collector/mockcollector/mockcollector.go
NewMockEventCollector
func NewMockEventCollector(ctrl *gomock.Controller) *MockEventCollector { mock := &MockEventCollector{ctrl: ctrl} mock.recorder = &MockEventCollectorMockRecorder{mock} return mock }
go
func NewMockEventCollector(ctrl *gomock.Controller) *MockEventCollector { mock := &MockEventCollector{ctrl: ctrl} mock.recorder = &MockEventCollectorMockRecorder{mock} return mock }
[ "func", "NewMockEventCollector", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockEventCollector", "{", "mock", ":=", "&", "MockEventCollector", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockEventCollectorMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockEventCollector creates a new mock instance // nolint
[ "NewMockEventCollector", "creates", "a", "new", "mock", "instance", "nolint" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/collector/mockcollector/mockcollector.go#L29-L33
6,930
aporeto-inc/trireme-lib
collector/mockcollector/mockcollector.go
CollectFlowEvent
func (mr *MockEventCollectorMockRecorder) CollectFlowEvent(record interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CollectFlowEvent", reflect.TypeOf((*MockEventCollector)(nil).CollectFlowEvent), record) }
go
func (mr *MockEventCollectorMockRecorder) CollectFlowEvent(record interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CollectFlowEvent", reflect.TypeOf((*MockEventCollector)(nil).CollectFlowEvent), record) }
[ "func", "(", "mr", "*", "MockEventCollectorMockRecorder", ")", "CollectFlowEvent", "(", "record", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockEventCollector", ")", "(", "nil", ")", ".", "CollectFlowEvent", ")", ",", "record", ")", "\n", "}" ]
// CollectFlowEvent indicates an expected call of CollectFlowEvent // nolint
[ "CollectFlowEvent", "indicates", "an", "expected", "call", "of", "CollectFlowEvent", "nolint" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/collector/mockcollector/mockcollector.go#L49-L51
6,931
aporeto-inc/trireme-lib
controller/pkg/usertokens/oidc/oidc.go
NewClient
func NewClient(ctx context.Context, v *TokenVerifier) (*TokenVerifier, error) { // Initialize caches only once if they are nil. if stateCache == nil { stateCache = gcache.New(2048).LRU().Expiration(120 * time.Second).Build() } if tokenCache == nil { tokenCache = gcache.New(2048).LRU().Build() } // Create a new generic OIDC provider based on the provider URL. // The library will auto-discover the configuration of the provider. // If it is not a compliant provider we should report and error here. provider, err := oidc.NewProvider(ctx, v.ProviderURL) if err != nil { return nil, fmt.Errorf("Failed to initialize provider: %s", err) } oidConfig := &oidc.Config{ ClientID: v.ClientID, SkipClientIDCheck: true, } v.oauthVerifier = provider.Verifier(oidConfig) scopes := []string{oidc.ScopeOpenID, "profile", "email"} for _, scope := range v.Scopes { if scope != oidc.ScopeOpenID && scope != "profile" && scope != "email" { scopes = append(scopes, scope) } } v.clientConfig = &oauth2.Config{ ClientID: v.ClientID, ClientSecret: v.ClientSecret, Endpoint: provider.Endpoint(), RedirectURL: v.RedirectURL, Scopes: scopes, } // Google does not honor the OIDC standard to refresh tokens // with a proper scope. Instead it requires a prompt parameter // to be passed. In order to deal wit this, we will have to // detect Google as the OIDC and pass the parameters. if strings.Contains(v.ProviderURL, "accounts.google.com") { v.googleHack = true } return v, nil }
go
func NewClient(ctx context.Context, v *TokenVerifier) (*TokenVerifier, error) { // Initialize caches only once if they are nil. if stateCache == nil { stateCache = gcache.New(2048).LRU().Expiration(120 * time.Second).Build() } if tokenCache == nil { tokenCache = gcache.New(2048).LRU().Build() } // Create a new generic OIDC provider based on the provider URL. // The library will auto-discover the configuration of the provider. // If it is not a compliant provider we should report and error here. provider, err := oidc.NewProvider(ctx, v.ProviderURL) if err != nil { return nil, fmt.Errorf("Failed to initialize provider: %s", err) } oidConfig := &oidc.Config{ ClientID: v.ClientID, SkipClientIDCheck: true, } v.oauthVerifier = provider.Verifier(oidConfig) scopes := []string{oidc.ScopeOpenID, "profile", "email"} for _, scope := range v.Scopes { if scope != oidc.ScopeOpenID && scope != "profile" && scope != "email" { scopes = append(scopes, scope) } } v.clientConfig = &oauth2.Config{ ClientID: v.ClientID, ClientSecret: v.ClientSecret, Endpoint: provider.Endpoint(), RedirectURL: v.RedirectURL, Scopes: scopes, } // Google does not honor the OIDC standard to refresh tokens // with a proper scope. Instead it requires a prompt parameter // to be passed. In order to deal wit this, we will have to // detect Google as the OIDC and pass the parameters. if strings.Contains(v.ProviderURL, "accounts.google.com") { v.googleHack = true } return v, nil }
[ "func", "NewClient", "(", "ctx", "context", ".", "Context", ",", "v", "*", "TokenVerifier", ")", "(", "*", "TokenVerifier", ",", "error", ")", "{", "// Initialize caches only once if they are nil.", "if", "stateCache", "==", "nil", "{", "stateCache", "=", "gcache", ".", "New", "(", "2048", ")", ".", "LRU", "(", ")", ".", "Expiration", "(", "120", "*", "time", ".", "Second", ")", ".", "Build", "(", ")", "\n", "}", "\n", "if", "tokenCache", "==", "nil", "{", "tokenCache", "=", "gcache", ".", "New", "(", "2048", ")", ".", "LRU", "(", ")", ".", "Build", "(", ")", "\n", "}", "\n\n", "// Create a new generic OIDC provider based on the provider URL.", "// The library will auto-discover the configuration of the provider.", "// If it is not a compliant provider we should report and error here.", "provider", ",", "err", ":=", "oidc", ".", "NewProvider", "(", "ctx", ",", "v", ".", "ProviderURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "oidConfig", ":=", "&", "oidc", ".", "Config", "{", "ClientID", ":", "v", ".", "ClientID", ",", "SkipClientIDCheck", ":", "true", ",", "}", "\n", "v", ".", "oauthVerifier", "=", "provider", ".", "Verifier", "(", "oidConfig", ")", "\n", "scopes", ":=", "[", "]", "string", "{", "oidc", ".", "ScopeOpenID", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "for", "_", ",", "scope", ":=", "range", "v", ".", "Scopes", "{", "if", "scope", "!=", "oidc", ".", "ScopeOpenID", "&&", "scope", "!=", "\"", "\"", "&&", "scope", "!=", "\"", "\"", "{", "scopes", "=", "append", "(", "scopes", ",", "scope", ")", "\n", "}", "\n", "}", "\n\n", "v", ".", "clientConfig", "=", "&", "oauth2", ".", "Config", "{", "ClientID", ":", "v", ".", "ClientID", ",", "ClientSecret", ":", "v", ".", "ClientSecret", ",", "Endpoint", ":", "provider", ".", "Endpoint", "(", ")", ",", "RedirectURL", ":", "v", ".", "RedirectURL", ",", "Scopes", ":", "scopes", ",", "}", "\n\n", "// Google does not honor the OIDC standard to refresh tokens", "// with a proper scope. Instead it requires a prompt parameter", "// to be passed. In order to deal wit this, we will have to", "// detect Google as the OIDC and pass the parameters.", "if", "strings", ".", "Contains", "(", "v", ".", "ProviderURL", ",", "\"", "\"", ")", "{", "v", ".", "googleHack", "=", "true", "\n", "}", "\n\n", "return", "v", ",", "nil", "\n", "}" ]
// NewClient creates a new validator client
[ "NewClient", "creates", "a", "new", "validator", "client" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/usertokens/oidc/oidc.go#L56-L102
6,932
aporeto-inc/trireme-lib
controller/pkg/usertokens/oidc/oidc.go
Callback
func (v *TokenVerifier) Callback(r *http.Request) (string, string, int, error) { // We first validate that the callback state matches the original redirect // state. We clean up the cache once it is validated. During this process // we recover the original URL that initiated the protocol. This allows // us to redirect the client to their original request. receivedState := r.URL.Query().Get("state") originURL, err := stateCache.Get(receivedState) if err != nil { return "", "", http.StatusBadRequest, fmt.Errorf("bad state") } stateCache.Remove(receivedState) // We exchange the authorization code with an OAUTH token. This is the main // step where the OAUTH provider will match the code to the token. oauth2Token, err := v.clientConfig.Exchange(r.Context(), r.URL.Query().Get("code"), oauth2.AccessTypeOffline) if err != nil { return "", "", http.StatusInternalServerError, fmt.Errorf("bad code: %s", err) } // We extract the rawID token. rawIDToken, ok := oauth2Token.Extra("id_token").(string) if !ok { return "", "", http.StatusInternalServerError, fmt.Errorf("bad ID") } if err := tokenCache.SetWithExpire( rawIDToken, &clientData{ tokenSource: v.clientConfig.TokenSource(context.Background(), oauth2Token), expiry: oauth2Token.Expiry, }, time.Until(oauth2Token.Expiry.Add(3600*time.Second)), ); err != nil { return "", "", http.StatusInternalServerError, fmt.Errorf("failed to insert token in the cache: %s", err) } return rawIDToken, originURL.(string), http.StatusTemporaryRedirect, nil }
go
func (v *TokenVerifier) Callback(r *http.Request) (string, string, int, error) { // We first validate that the callback state matches the original redirect // state. We clean up the cache once it is validated. During this process // we recover the original URL that initiated the protocol. This allows // us to redirect the client to their original request. receivedState := r.URL.Query().Get("state") originURL, err := stateCache.Get(receivedState) if err != nil { return "", "", http.StatusBadRequest, fmt.Errorf("bad state") } stateCache.Remove(receivedState) // We exchange the authorization code with an OAUTH token. This is the main // step where the OAUTH provider will match the code to the token. oauth2Token, err := v.clientConfig.Exchange(r.Context(), r.URL.Query().Get("code"), oauth2.AccessTypeOffline) if err != nil { return "", "", http.StatusInternalServerError, fmt.Errorf("bad code: %s", err) } // We extract the rawID token. rawIDToken, ok := oauth2Token.Extra("id_token").(string) if !ok { return "", "", http.StatusInternalServerError, fmt.Errorf("bad ID") } if err := tokenCache.SetWithExpire( rawIDToken, &clientData{ tokenSource: v.clientConfig.TokenSource(context.Background(), oauth2Token), expiry: oauth2Token.Expiry, }, time.Until(oauth2Token.Expiry.Add(3600*time.Second)), ); err != nil { return "", "", http.StatusInternalServerError, fmt.Errorf("failed to insert token in the cache: %s", err) } return rawIDToken, originURL.(string), http.StatusTemporaryRedirect, nil }
[ "func", "(", "v", "*", "TokenVerifier", ")", "Callback", "(", "r", "*", "http", ".", "Request", ")", "(", "string", ",", "string", ",", "int", ",", "error", ")", "{", "// We first validate that the callback state matches the original redirect", "// state. We clean up the cache once it is validated. During this process", "// we recover the original URL that initiated the protocol. This allows", "// us to redirect the client to their original request.", "receivedState", ":=", "r", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", "\n", "originURL", ",", "err", ":=", "stateCache", ".", "Get", "(", "receivedState", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "http", ".", "StatusBadRequest", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "stateCache", ".", "Remove", "(", "receivedState", ")", "\n\n", "// We exchange the authorization code with an OAUTH token. This is the main", "// step where the OAUTH provider will match the code to the token.", "oauth2Token", ",", "err", ":=", "v", ".", "clientConfig", ".", "Exchange", "(", "r", ".", "Context", "(", ")", ",", "r", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "oauth2", ".", "AccessTypeOffline", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// We extract the rawID token.", "rawIDToken", ",", "ok", ":=", "oauth2Token", ".", "Extra", "(", "\"", "\"", ")", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "tokenCache", ".", "SetWithExpire", "(", "rawIDToken", ",", "&", "clientData", "{", "tokenSource", ":", "v", ".", "clientConfig", ".", "TokenSource", "(", "context", ".", "Background", "(", ")", ",", "oauth2Token", ")", ",", "expiry", ":", "oauth2Token", ".", "Expiry", ",", "}", ",", "time", ".", "Until", "(", "oauth2Token", ".", "Expiry", ".", "Add", "(", "3600", "*", "time", ".", "Second", ")", ")", ",", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "http", ".", "StatusInternalServerError", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "rawIDToken", ",", "originURL", ".", "(", "string", ")", ",", "http", ".", "StatusTemporaryRedirect", ",", "nil", "\n", "}" ]
// Callback is the function that is called back by the IDP to catch the token // and perform all other validations. It will return the resulting token, // the original URL that was called to initiate the protocol, and the // http status response.
[ "Callback", "is", "the", "function", "that", "is", "called", "back", "by", "the", "IDP", "to", "catch", "the", "token", "and", "perform", "all", "other", "validations", ".", "It", "will", "return", "the", "resulting", "token", "the", "original", "URL", "that", "was", "called", "to", "initiate", "the", "protocol", "and", "the", "http", "status", "response", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/usertokens/oidc/oidc.go#L132-L170
6,933
aporeto-inc/trireme-lib
controller/internal/enforcer/acls/aclcache.go
AddRule
func (c *ACLCache) AddRule(rule policy.IPRule) (err error) { if rule.Policy.ObserveAction.ObserveApply() { return c.observe.addRule(rule) } if rule.Policy.Action.Accepted() { return c.accept.addRule(rule) } return c.reject.addRule(rule) }
go
func (c *ACLCache) AddRule(rule policy.IPRule) (err error) { if rule.Policy.ObserveAction.ObserveApply() { return c.observe.addRule(rule) } if rule.Policy.Action.Accepted() { return c.accept.addRule(rule) } return c.reject.addRule(rule) }
[ "func", "(", "c", "*", "ACLCache", ")", "AddRule", "(", "rule", "policy", ".", "IPRule", ")", "(", "err", "error", ")", "{", "if", "rule", ".", "Policy", ".", "ObserveAction", ".", "ObserveApply", "(", ")", "{", "return", "c", ".", "observe", ".", "addRule", "(", "rule", ")", "\n", "}", "\n\n", "if", "rule", ".", "Policy", ".", "Action", ".", "Accepted", "(", ")", "{", "return", "c", ".", "accept", ".", "addRule", "(", "rule", ")", "\n", "}", "\n\n", "return", "c", ".", "reject", ".", "addRule", "(", "rule", ")", "\n", "}" ]
// AddRule adds a single rule to the ACL Cache
[ "AddRule", "adds", "a", "single", "rule", "to", "the", "ACL", "Cache" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/acls/aclcache.go#L34-L45
6,934
aporeto-inc/trireme-lib
controller/internal/enforcer/acls/aclcache.go
AddRuleList
func (c *ACLCache) AddRuleList(rules policy.IPRuleList) (err error) { for _, rule := range rules { if err = c.AddRule(rule); err != nil { return } } c.reject.reverseSort() c.accept.reverseSort() c.observe.reverseSort() return }
go
func (c *ACLCache) AddRuleList(rules policy.IPRuleList) (err error) { for _, rule := range rules { if err = c.AddRule(rule); err != nil { return } } c.reject.reverseSort() c.accept.reverseSort() c.observe.reverseSort() return }
[ "func", "(", "c", "*", "ACLCache", ")", "AddRuleList", "(", "rules", "policy", ".", "IPRuleList", ")", "(", "err", "error", ")", "{", "for", "_", ",", "rule", ":=", "range", "rules", "{", "if", "err", "=", "c", ".", "AddRule", "(", "rule", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "c", ".", "reject", ".", "reverseSort", "(", ")", "\n", "c", ".", "accept", ".", "reverseSort", "(", ")", "\n", "c", ".", "observe", ".", "reverseSort", "(", ")", "\n", "return", "\n", "}" ]
// AddRuleList adds a list of rules to the cache
[ "AddRuleList", "adds", "a", "list", "of", "rules", "to", "the", "cache" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/acls/aclcache.go#L48-L60
6,935
aporeto-inc/trireme-lib
controller/internal/enforcer/acls/aclcache.go
GetMatchingAction
func (c *ACLCache) GetMatchingAction(ip []byte, port uint16) (report *policy.FlowPolicy, packet *policy.FlowPolicy, err error) { report, packet, err = c.reject.getMatchingAction(ip, port, report) if err == nil { return } report, packet, err = c.accept.getMatchingAction(ip, port, report) if err == nil { return } report, packet, err = c.observe.getMatchingAction(ip, port, report) if err == nil { return } if report == nil { report = catchAllPolicy } if packet == nil { packet = catchAllPolicy } return report, packet, errors.New("no match") }
go
func (c *ACLCache) GetMatchingAction(ip []byte, port uint16) (report *policy.FlowPolicy, packet *policy.FlowPolicy, err error) { report, packet, err = c.reject.getMatchingAction(ip, port, report) if err == nil { return } report, packet, err = c.accept.getMatchingAction(ip, port, report) if err == nil { return } report, packet, err = c.observe.getMatchingAction(ip, port, report) if err == nil { return } if report == nil { report = catchAllPolicy } if packet == nil { packet = catchAllPolicy } return report, packet, errors.New("no match") }
[ "func", "(", "c", "*", "ACLCache", ")", "GetMatchingAction", "(", "ip", "[", "]", "byte", ",", "port", "uint16", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "packet", "*", "policy", ".", "FlowPolicy", ",", "err", "error", ")", "{", "report", ",", "packet", ",", "err", "=", "c", ".", "reject", ".", "getMatchingAction", "(", "ip", ",", "port", ",", "report", ")", "\n", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n\n", "report", ",", "packet", ",", "err", "=", "c", ".", "accept", ".", "getMatchingAction", "(", "ip", ",", "port", ",", "report", ")", "\n", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n\n", "report", ",", "packet", ",", "err", "=", "c", ".", "observe", ".", "getMatchingAction", "(", "ip", ",", "port", ",", "report", ")", "\n", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n\n", "if", "report", "==", "nil", "{", "report", "=", "catchAllPolicy", "\n", "}", "\n\n", "if", "packet", "==", "nil", "{", "packet", "=", "catchAllPolicy", "\n", "}", "\n\n", "return", "report", ",", "packet", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// GetMatchingAction gets the matching action
[ "GetMatchingAction", "gets", "the", "matching", "action" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/acls/aclcache.go#L63-L89
6,936
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
Enforce
func (s *ProxyInfo) Enforce(contextID string, puInfo *policy.PUInfo) error { initEnforcer, err := s.prochdl.LaunchRemoteEnforcer( contextID, puInfo.Runtime.Pid(), puInfo.Runtime.NSPath(), s.commandArg, s.statsServerSecret, s.procMountPoint, ) if err != nil { return err } zap.L().Debug("Called enforce and launched process", zap.String("contextID", contextID), zap.Reflect("Policy Object", puInfo)) if initEnforcer { if err := s.initRemoteEnforcer(contextID); err != nil { s.prochdl.KillRemoteEnforcer(contextID, true) // nolint errcheck return err } } enforcerPayload := &rpcwrapper.EnforcePayload{ ContextID: contextID, Policy: puInfo.Policy.ToPublicPolicy(), } //Only the secrets need to be under lock. They can change async to the enforce call from Updatesecrets s.RLock() enforcerPayload.Secrets = s.Secrets.PublicSecrets() s.RUnlock() request := &rpcwrapper.Request{ Payload: enforcerPayload, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.Enforce, request, &rpcwrapper.Response{}); err != nil { s.prochdl.KillRemoteEnforcer(contextID, true) // nolint errcheck return fmt.Errorf("failed to send message to remote enforcer: %s", err) } return nil }
go
func (s *ProxyInfo) Enforce(contextID string, puInfo *policy.PUInfo) error { initEnforcer, err := s.prochdl.LaunchRemoteEnforcer( contextID, puInfo.Runtime.Pid(), puInfo.Runtime.NSPath(), s.commandArg, s.statsServerSecret, s.procMountPoint, ) if err != nil { return err } zap.L().Debug("Called enforce and launched process", zap.String("contextID", contextID), zap.Reflect("Policy Object", puInfo)) if initEnforcer { if err := s.initRemoteEnforcer(contextID); err != nil { s.prochdl.KillRemoteEnforcer(contextID, true) // nolint errcheck return err } } enforcerPayload := &rpcwrapper.EnforcePayload{ ContextID: contextID, Policy: puInfo.Policy.ToPublicPolicy(), } //Only the secrets need to be under lock. They can change async to the enforce call from Updatesecrets s.RLock() enforcerPayload.Secrets = s.Secrets.PublicSecrets() s.RUnlock() request := &rpcwrapper.Request{ Payload: enforcerPayload, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.Enforce, request, &rpcwrapper.Response{}); err != nil { s.prochdl.KillRemoteEnforcer(contextID, true) // nolint errcheck return fmt.Errorf("failed to send message to remote enforcer: %s", err) } return nil }
[ "func", "(", "s", "*", "ProxyInfo", ")", "Enforce", "(", "contextID", "string", ",", "puInfo", "*", "policy", ".", "PUInfo", ")", "error", "{", "initEnforcer", ",", "err", ":=", "s", ".", "prochdl", ".", "LaunchRemoteEnforcer", "(", "contextID", ",", "puInfo", ".", "Runtime", ".", "Pid", "(", ")", ",", "puInfo", ".", "Runtime", ".", "NSPath", "(", ")", ",", "s", ".", "commandArg", ",", "s", ".", "statsServerSecret", ",", "s", ".", "procMountPoint", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "zap", ".", "L", "(", ")", ".", "Debug", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "contextID", ")", ",", "zap", ".", "Reflect", "(", "\"", "\"", ",", "puInfo", ")", ")", "\n\n", "if", "initEnforcer", "{", "if", "err", ":=", "s", ".", "initRemoteEnforcer", "(", "contextID", ")", ";", "err", "!=", "nil", "{", "s", ".", "prochdl", ".", "KillRemoteEnforcer", "(", "contextID", ",", "true", ")", "// nolint errcheck", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "enforcerPayload", ":=", "&", "rpcwrapper", ".", "EnforcePayload", "{", "ContextID", ":", "contextID", ",", "Policy", ":", "puInfo", ".", "Policy", ".", "ToPublicPolicy", "(", ")", ",", "}", "\n\n", "//Only the secrets need to be under lock. They can change async to the enforce call from Updatesecrets", "s", ".", "RLock", "(", ")", "\n", "enforcerPayload", ".", "Secrets", "=", "s", ".", "Secrets", ".", "PublicSecrets", "(", ")", "\n", "s", ".", "RUnlock", "(", ")", "\n", "request", ":=", "&", "rpcwrapper", ".", "Request", "{", "Payload", ":", "enforcerPayload", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "rpchdl", ".", "RemoteCall", "(", "contextID", ",", "remoteenforcer", ".", "Enforce", ",", "request", ",", "&", "rpcwrapper", ".", "Response", "{", "}", ")", ";", "err", "!=", "nil", "{", "s", ".", "prochdl", ".", "KillRemoteEnforcer", "(", "contextID", ",", "true", ")", "// nolint errcheck", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Enforce method makes a RPC call for the remote enforcer enforce method
[ "Enforce", "method", "makes", "a", "RPC", "call", "for", "the", "remote", "enforcer", "enforce", "method" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L50-L93
6,937
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
Unenforce
func (s *ProxyInfo) Unenforce(contextID string) error { request := &rpcwrapper.Request{ Payload: &rpcwrapper.UnEnforcePayload{ ContextID: contextID, }, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.Unenforce, request, &rpcwrapper.Response{}); err != nil { zap.L().Error("failed to send message to remote enforcer", zap.Error(err)) } return s.prochdl.KillRemoteEnforcer(contextID, true) }
go
func (s *ProxyInfo) Unenforce(contextID string) error { request := &rpcwrapper.Request{ Payload: &rpcwrapper.UnEnforcePayload{ ContextID: contextID, }, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.Unenforce, request, &rpcwrapper.Response{}); err != nil { zap.L().Error("failed to send message to remote enforcer", zap.Error(err)) } return s.prochdl.KillRemoteEnforcer(contextID, true) }
[ "func", "(", "s", "*", "ProxyInfo", ")", "Unenforce", "(", "contextID", "string", ")", "error", "{", "request", ":=", "&", "rpcwrapper", ".", "Request", "{", "Payload", ":", "&", "rpcwrapper", ".", "UnEnforcePayload", "{", "ContextID", ":", "contextID", ",", "}", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "rpchdl", ".", "RemoteCall", "(", "contextID", ",", "remoteenforcer", ".", "Unenforce", ",", "request", ",", "&", "rpcwrapper", ".", "Response", "{", "}", ")", ";", "err", "!=", "nil", "{", "zap", ".", "L", "(", ")", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "return", "s", ".", "prochdl", ".", "KillRemoteEnforcer", "(", "contextID", ",", "true", ")", "\n", "}" ]
// Unenforce stops enforcing policy for the given contextID.
[ "Unenforce", "stops", "enforcing", "policy", "for", "the", "given", "contextID", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L96-L109
6,938
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
CleanUp
func (s *ProxyInfo) CleanUp() error { // request := &rpcwrapper.Request{} var allErrors string for _, contextID := range s.rpchdl.ContextList() { if err := s.prochdl.KillRemoteEnforcer(contextID, false); err != nil { allErrors = allErrors + " contextID:" + err.Error() } } if len(allErrors) > 0 { return fmt.Errorf("Remote enforcers failed: %s", allErrors) } return nil }
go
func (s *ProxyInfo) CleanUp() error { // request := &rpcwrapper.Request{} var allErrors string for _, contextID := range s.rpchdl.ContextList() { if err := s.prochdl.KillRemoteEnforcer(contextID, false); err != nil { allErrors = allErrors + " contextID:" + err.Error() } } if len(allErrors) > 0 { return fmt.Errorf("Remote enforcers failed: %s", allErrors) } return nil }
[ "func", "(", "s", "*", "ProxyInfo", ")", "CleanUp", "(", ")", "error", "{", "// request := &rpcwrapper.Request{}", "var", "allErrors", "string", "\n\n", "for", "_", ",", "contextID", ":=", "range", "s", ".", "rpchdl", ".", "ContextList", "(", ")", "{", "if", "err", ":=", "s", ".", "prochdl", ".", "KillRemoteEnforcer", "(", "contextID", ",", "false", ")", ";", "err", "!=", "nil", "{", "allErrors", "=", "allErrors", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "allErrors", ")", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "allErrors", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CleanUp sends a cleanup command to all the remotes forcing them to exit and clean their state.
[ "CleanUp", "sends", "a", "cleanup", "command", "to", "all", "the", "remotes", "forcing", "them", "to", "exit", "and", "clean", "their", "state", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L140-L158
6,939
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
EnableDatapathPacketTracing
func (s *ProxyInfo) EnableDatapathPacketTracing(contextID string, direction packettracing.TracingDirection, interval time.Duration) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.EnableDatapathPacketTracingPayLoad{ Direction: direction, Interval: interval, ContextID: contextID, }, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.EnableDatapathPacketTracing, request, resp); err != nil { return fmt.Errorf("unable to enable datapath packet tracing %s -- %s", err, resp.Status) } return nil }
go
func (s *ProxyInfo) EnableDatapathPacketTracing(contextID string, direction packettracing.TracingDirection, interval time.Duration) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.EnableDatapathPacketTracingPayLoad{ Direction: direction, Interval: interval, ContextID: contextID, }, } if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.EnableDatapathPacketTracing, request, resp); err != nil { return fmt.Errorf("unable to enable datapath packet tracing %s -- %s", err, resp.Status) } return nil }
[ "func", "(", "s", "*", "ProxyInfo", ")", "EnableDatapathPacketTracing", "(", "contextID", "string", ",", "direction", "packettracing", ".", "TracingDirection", ",", "interval", "time", ".", "Duration", ")", "error", "{", "resp", ":=", "&", "rpcwrapper", ".", "Response", "{", "}", "\n\n", "request", ":=", "&", "rpcwrapper", ".", "Request", "{", "Payload", ":", "&", "rpcwrapper", ".", "EnableDatapathPacketTracingPayLoad", "{", "Direction", ":", "direction", ",", "Interval", ":", "interval", ",", "ContextID", ":", "contextID", ",", "}", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "rpchdl", ".", "RemoteCall", "(", "contextID", ",", "remoteenforcer", ".", "EnableDatapathPacketTracing", ",", "request", ",", "resp", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "resp", ".", "Status", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// EnableDatapathPacketTracing enable nfq packet tracing in remote container
[ "EnableDatapathPacketTracing", "enable", "nfq", "packet", "tracing", "in", "remote", "container" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L161-L178
6,940
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
SetTargetNetworks
func (s *ProxyInfo) SetTargetNetworks(cfg *runtime.Configuration) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.SetTargetNetworksPayload{ Configuration: cfg, }, } var allErrors string for _, contextID := range s.rpchdl.ContextList() { if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.SetTargetNetworks, request, resp); err != nil { allErrors = allErrors + " contextID " + contextID + ":" + err.Error() } } s.Lock() s.cfg = cfg s.Unlock() if len(allErrors) > 0 { return fmt.Errorf("Remote enforcers failed: %s", allErrors) } return nil }
go
func (s *ProxyInfo) SetTargetNetworks(cfg *runtime.Configuration) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.SetTargetNetworksPayload{ Configuration: cfg, }, } var allErrors string for _, contextID := range s.rpchdl.ContextList() { if err := s.rpchdl.RemoteCall(contextID, remoteenforcer.SetTargetNetworks, request, resp); err != nil { allErrors = allErrors + " contextID " + contextID + ":" + err.Error() } } s.Lock() s.cfg = cfg s.Unlock() if len(allErrors) > 0 { return fmt.Errorf("Remote enforcers failed: %s", allErrors) } return nil }
[ "func", "(", "s", "*", "ProxyInfo", ")", "SetTargetNetworks", "(", "cfg", "*", "runtime", ".", "Configuration", ")", "error", "{", "resp", ":=", "&", "rpcwrapper", ".", "Response", "{", "}", "\n", "request", ":=", "&", "rpcwrapper", ".", "Request", "{", "Payload", ":", "&", "rpcwrapper", ".", "SetTargetNetworksPayload", "{", "Configuration", ":", "cfg", ",", "}", ",", "}", "\n\n", "var", "allErrors", "string", "\n\n", "for", "_", ",", "contextID", ":=", "range", "s", ".", "rpchdl", ".", "ContextList", "(", ")", "{", "if", "err", ":=", "s", ".", "rpchdl", ".", "RemoteCall", "(", "contextID", ",", "remoteenforcer", ".", "SetTargetNetworks", ",", "request", ",", "resp", ")", ";", "err", "!=", "nil", "{", "allErrors", "=", "allErrors", "+", "\"", "\"", "+", "contextID", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}", "\n\n", "s", ".", "Lock", "(", ")", "\n", "s", ".", "cfg", "=", "cfg", "\n", "s", ".", "Unlock", "(", ")", "\n\n", "if", "len", "(", "allErrors", ")", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "allErrors", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetTargetNetworks does the RPC call for SetTargetNetworks to the corresponding // remote enforcers
[ "SetTargetNetworks", "does", "the", "RPC", "call", "for", "SetTargetNetworks", "to", "the", "corresponding", "remote", "enforcers" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L200-L225
6,941
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
Run
func (s *ProxyInfo) Run(ctx context.Context) error { statsServer := rpcwrapper.NewRPCWrapper() rpcServer := &StatsServer{ rpchdl: statsServer, collector: s.collector, secret: s.statsServerSecret, } // Start the server for statistics collection. go statsServer.StartServer(ctx, "unix", constants.StatsChannel, rpcServer) // nolint return nil }
go
func (s *ProxyInfo) Run(ctx context.Context) error { statsServer := rpcwrapper.NewRPCWrapper() rpcServer := &StatsServer{ rpchdl: statsServer, collector: s.collector, secret: s.statsServerSecret, } // Start the server for statistics collection. go statsServer.StartServer(ctx, "unix", constants.StatsChannel, rpcServer) // nolint return nil }
[ "func", "(", "s", "*", "ProxyInfo", ")", "Run", "(", "ctx", "context", ".", "Context", ")", "error", "{", "statsServer", ":=", "rpcwrapper", ".", "NewRPCWrapper", "(", ")", "\n", "rpcServer", ":=", "&", "StatsServer", "{", "rpchdl", ":", "statsServer", ",", "collector", ":", "s", ".", "collector", ",", "secret", ":", "s", ".", "statsServerSecret", ",", "}", "\n\n", "// Start the server for statistics collection.", "go", "statsServer", ".", "StartServer", "(", "ctx", ",", "\"", "\"", ",", "constants", ".", "StatsChannel", ",", "rpcServer", ")", "// nolint", "\n", "return", "nil", "\n", "}" ]
// Run starts the the remote enforcer proxy.
[ "Run", "starts", "the", "the", "remote", "enforcer", "proxy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L233-L245
6,942
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
initRemoteEnforcer
func (s *ProxyInfo) initRemoteEnforcer(contextID string) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.InitRequestPayload{ FqConfig: s.filterQueue, MutualAuth: s.mutualAuth, Validity: s.validity, ServerID: s.serverID, ExternalIPCacheTimeout: s.ExternalIPCacheTimeout, PacketLogs: s.packetLogs, Secrets: s.Secrets.PublicSecrets(), Configuration: s.cfg, }, } return s.rpchdl.RemoteCall(contextID, remoteenforcer.InitEnforcer, request, resp) }
go
func (s *ProxyInfo) initRemoteEnforcer(contextID string) error { resp := &rpcwrapper.Response{} request := &rpcwrapper.Request{ Payload: &rpcwrapper.InitRequestPayload{ FqConfig: s.filterQueue, MutualAuth: s.mutualAuth, Validity: s.validity, ServerID: s.serverID, ExternalIPCacheTimeout: s.ExternalIPCacheTimeout, PacketLogs: s.packetLogs, Secrets: s.Secrets.PublicSecrets(), Configuration: s.cfg, }, } return s.rpchdl.RemoteCall(contextID, remoteenforcer.InitEnforcer, request, resp) }
[ "func", "(", "s", "*", "ProxyInfo", ")", "initRemoteEnforcer", "(", "contextID", "string", ")", "error", "{", "resp", ":=", "&", "rpcwrapper", ".", "Response", "{", "}", "\n\n", "request", ":=", "&", "rpcwrapper", ".", "Request", "{", "Payload", ":", "&", "rpcwrapper", ".", "InitRequestPayload", "{", "FqConfig", ":", "s", ".", "filterQueue", ",", "MutualAuth", ":", "s", ".", "mutualAuth", ",", "Validity", ":", "s", ".", "validity", ",", "ServerID", ":", "s", ".", "serverID", ",", "ExternalIPCacheTimeout", ":", "s", ".", "ExternalIPCacheTimeout", ",", "PacketLogs", ":", "s", ".", "packetLogs", ",", "Secrets", ":", "s", ".", "Secrets", ".", "PublicSecrets", "(", ")", ",", "Configuration", ":", "s", ".", "cfg", ",", "}", ",", "}", "\n\n", "return", "s", ".", "rpchdl", ".", "RemoteCall", "(", "contextID", ",", "remoteenforcer", ".", "InitEnforcer", ",", "request", ",", "resp", ")", "\n", "}" ]
// initRemoteEnforcer method makes a RPC call to the remote enforcer
[ "initRemoteEnforcer", "method", "makes", "a", "RPC", "call", "to", "the", "remote", "enforcer" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L248-L266
6,943
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
NewProxyEnforcer
func NewProxyEnforcer( mutualAuth bool, filterQueue *fqconfig.FilterQueue, collector collector.EventCollector, secrets secrets.Secrets, serverID string, validity time.Duration, cmdArg string, procMountPoint string, ExternalIPCacheTimeout time.Duration, packetLogs bool, cfg *runtime.Configuration, runtimeError chan *policy.RuntimeError, remoteParameters *env.RemoteParameters, ) enforcer.Enforcer { statsServersecret, err := crypto.GenerateRandomString(32) if err != nil { // There is a very small chance of this happening we will log an error here. zap.L().Error("Failed to generate random secret for stats reporting", zap.Error(err)) // We will use current time as the secret statsServersecret = time.Now().String() } rpcClient := rpcwrapper.NewRPCWrapper() return &ProxyInfo{ mutualAuth: mutualAuth, Secrets: secrets, serverID: serverID, validity: validity, prochdl: processmon.New(context.Background(), remoteParameters, runtimeError, rpcClient), rpchdl: rpcClient, filterQueue: filterQueue, commandArg: cmdArg, statsServerSecret: statsServersecret, procMountPoint: procMountPoint, ExternalIPCacheTimeout: ExternalIPCacheTimeout, packetLogs: packetLogs, collector: collector, cfg: cfg, } }
go
func NewProxyEnforcer( mutualAuth bool, filterQueue *fqconfig.FilterQueue, collector collector.EventCollector, secrets secrets.Secrets, serverID string, validity time.Duration, cmdArg string, procMountPoint string, ExternalIPCacheTimeout time.Duration, packetLogs bool, cfg *runtime.Configuration, runtimeError chan *policy.RuntimeError, remoteParameters *env.RemoteParameters, ) enforcer.Enforcer { statsServersecret, err := crypto.GenerateRandomString(32) if err != nil { // There is a very small chance of this happening we will log an error here. zap.L().Error("Failed to generate random secret for stats reporting", zap.Error(err)) // We will use current time as the secret statsServersecret = time.Now().String() } rpcClient := rpcwrapper.NewRPCWrapper() return &ProxyInfo{ mutualAuth: mutualAuth, Secrets: secrets, serverID: serverID, validity: validity, prochdl: processmon.New(context.Background(), remoteParameters, runtimeError, rpcClient), rpchdl: rpcClient, filterQueue: filterQueue, commandArg: cmdArg, statsServerSecret: statsServersecret, procMountPoint: procMountPoint, ExternalIPCacheTimeout: ExternalIPCacheTimeout, packetLogs: packetLogs, collector: collector, cfg: cfg, } }
[ "func", "NewProxyEnforcer", "(", "mutualAuth", "bool", ",", "filterQueue", "*", "fqconfig", ".", "FilterQueue", ",", "collector", "collector", ".", "EventCollector", ",", "secrets", "secrets", ".", "Secrets", ",", "serverID", "string", ",", "validity", "time", ".", "Duration", ",", "cmdArg", "string", ",", "procMountPoint", "string", ",", "ExternalIPCacheTimeout", "time", ".", "Duration", ",", "packetLogs", "bool", ",", "cfg", "*", "runtime", ".", "Configuration", ",", "runtimeError", "chan", "*", "policy", ".", "RuntimeError", ",", "remoteParameters", "*", "env", ".", "RemoteParameters", ",", ")", "enforcer", ".", "Enforcer", "{", "statsServersecret", ",", "err", ":=", "crypto", ".", "GenerateRandomString", "(", "32", ")", "\n", "if", "err", "!=", "nil", "{", "// There is a very small chance of this happening we will log an error here.", "zap", ".", "L", "(", ")", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "// We will use current time as the secret", "statsServersecret", "=", "time", ".", "Now", "(", ")", ".", "String", "(", ")", "\n", "}", "\n\n", "rpcClient", ":=", "rpcwrapper", ".", "NewRPCWrapper", "(", ")", "\n\n", "return", "&", "ProxyInfo", "{", "mutualAuth", ":", "mutualAuth", ",", "Secrets", ":", "secrets", ",", "serverID", ":", "serverID", ",", "validity", ":", "validity", ",", "prochdl", ":", "processmon", ".", "New", "(", "context", ".", "Background", "(", ")", ",", "remoteParameters", ",", "runtimeError", ",", "rpcClient", ")", ",", "rpchdl", ":", "rpcClient", ",", "filterQueue", ":", "filterQueue", ",", "commandArg", ":", "cmdArg", ",", "statsServerSecret", ":", "statsServersecret", ",", "procMountPoint", ":", "procMountPoint", ",", "ExternalIPCacheTimeout", ":", "ExternalIPCacheTimeout", ",", "packetLogs", ":", "packetLogs", ",", "collector", ":", "collector", ",", "cfg", ":", "cfg", ",", "}", "\n", "}" ]
// NewProxyEnforcer creates a new proxy to remote enforcers.
[ "NewProxyEnforcer", "creates", "a", "new", "proxy", "to", "remote", "enforcers", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L269-L311
6,944
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
GetStats
func (r *StatsServer) GetStats(req rpcwrapper.Request, resp *rpcwrapper.Response) error { if !r.rpchdl.ProcessMessage(&req, r.secret) { return errors.New("message sender cannot be verified") } payload := req.Payload.(rpcwrapper.StatsPayload) for _, record := range payload.Flows { r.collector.CollectFlowEvent(record) } for _, record := range payload.Users { r.collector.CollectUserEvent(record) } return nil }
go
func (r *StatsServer) GetStats(req rpcwrapper.Request, resp *rpcwrapper.Response) error { if !r.rpchdl.ProcessMessage(&req, r.secret) { return errors.New("message sender cannot be verified") } payload := req.Payload.(rpcwrapper.StatsPayload) for _, record := range payload.Flows { r.collector.CollectFlowEvent(record) } for _, record := range payload.Users { r.collector.CollectUserEvent(record) } return nil }
[ "func", "(", "r", "*", "StatsServer", ")", "GetStats", "(", "req", "rpcwrapper", ".", "Request", ",", "resp", "*", "rpcwrapper", ".", "Response", ")", "error", "{", "if", "!", "r", ".", "rpchdl", ".", "ProcessMessage", "(", "&", "req", ",", "r", ".", "secret", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "payload", ":=", "req", ".", "Payload", ".", "(", "rpcwrapper", ".", "StatsPayload", ")", "\n\n", "for", "_", ",", "record", ":=", "range", "payload", ".", "Flows", "{", "r", ".", "collector", ".", "CollectFlowEvent", "(", "record", ")", "\n", "}", "\n\n", "for", "_", ",", "record", ":=", "range", "payload", ".", "Users", "{", "r", ".", "collector", ".", "CollectUserEvent", "(", "record", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GetStats is the function called from the remoteenforcer when it has new flow events to publish.
[ "GetStats", "is", "the", "function", "called", "from", "the", "remoteenforcer", "when", "it", "has", "new", "flow", "events", "to", "publish", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L321-L338
6,945
aporeto-inc/trireme-lib
controller/internal/enforcer/proxy/enforcerproxy.go
PostPacketEvent
func (r *StatsServer) PostPacketEvent(req rpcwrapper.Request, resp *rpcwrapper.Response) error { if !r.rpchdl.ProcessMessage(&req, r.secret) { return errors.New("message sender cannot be verified") } payload := req.Payload.(rpcwrapper.DebugPacketPayload) for _, record := range payload.PacketRecords { r.collector.CollectPacketEvent(record) } return nil }
go
func (r *StatsServer) PostPacketEvent(req rpcwrapper.Request, resp *rpcwrapper.Response) error { if !r.rpchdl.ProcessMessage(&req, r.secret) { return errors.New("message sender cannot be verified") } payload := req.Payload.(rpcwrapper.DebugPacketPayload) for _, record := range payload.PacketRecords { r.collector.CollectPacketEvent(record) } return nil }
[ "func", "(", "r", "*", "StatsServer", ")", "PostPacketEvent", "(", "req", "rpcwrapper", ".", "Request", ",", "resp", "*", "rpcwrapper", ".", "Response", ")", "error", "{", "if", "!", "r", ".", "rpchdl", ".", "ProcessMessage", "(", "&", "req", ",", "r", ".", "secret", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "payload", ":=", "req", ".", "Payload", ".", "(", "rpcwrapper", ".", "DebugPacketPayload", ")", "\n", "for", "_", ",", "record", ":=", "range", "payload", ".", "PacketRecords", "{", "r", ".", "collector", ".", "CollectPacketEvent", "(", "record", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PostPacketEvent is called from the remote to post multiple records from the remoteenforcer
[ "PostPacketEvent", "is", "called", "from", "the", "remote", "to", "post", "multiple", "records", "from", "the", "remoteenforcer" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/proxy/enforcerproxy.go#L341-L352
6,946
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/http/http.go
NewHTTPProxy
func NewHTTPProxy( c collector.EventCollector, puContext string, caPool *x509.CertPool, applicationProxy bool, mark int, secrets secrets.Secrets, registry *serviceregistry.Registry, ) *Config { return &Config{ collector: c, puContext: puContext, ca: caPool, applicationProxy: applicationProxy, mark: mark, secrets: secrets, localIPs: markedconn.GetInterfaces(), registry: registry, tlsClientConfig: &tls.Config{ RootCAs: caPool, }, } }
go
func NewHTTPProxy( c collector.EventCollector, puContext string, caPool *x509.CertPool, applicationProxy bool, mark int, secrets secrets.Secrets, registry *serviceregistry.Registry, ) *Config { return &Config{ collector: c, puContext: puContext, ca: caPool, applicationProxy: applicationProxy, mark: mark, secrets: secrets, localIPs: markedconn.GetInterfaces(), registry: registry, tlsClientConfig: &tls.Config{ RootCAs: caPool, }, } }
[ "func", "NewHTTPProxy", "(", "c", "collector", ".", "EventCollector", ",", "puContext", "string", ",", "caPool", "*", "x509", ".", "CertPool", ",", "applicationProxy", "bool", ",", "mark", "int", ",", "secrets", "secrets", ".", "Secrets", ",", "registry", "*", "serviceregistry", ".", "Registry", ",", ")", "*", "Config", "{", "return", "&", "Config", "{", "collector", ":", "c", ",", "puContext", ":", "puContext", ",", "ca", ":", "caPool", ",", "applicationProxy", ":", "applicationProxy", ",", "mark", ":", "mark", ",", "secrets", ":", "secrets", ",", "localIPs", ":", "markedconn", ".", "GetInterfaces", "(", ")", ",", "registry", ":", "registry", ",", "tlsClientConfig", ":", "&", "tls", ".", "Config", "{", "RootCAs", ":", "caPool", ",", "}", ",", "}", "\n", "}" ]
// NewHTTPProxy creates a new instance of proxy reate a new instance of Proxy
[ "NewHTTPProxy", "creates", "a", "new", "instance", "of", "proxy", "reate", "a", "new", "instance", "of", "Proxy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/http/http.go#L69-L92
6,947
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/http/http.go
clientTLSConfiguration
func (p *Config) clientTLSConfiguration(conn net.Conn, originalConfig *tls.Config) (*tls.Config, error) { if mconn, ok := conn.(*markedconn.ProxiedConnection); ok { ip, port := mconn.GetOriginalDestination() portContext, err := p.registry.RetrieveExposedServiceContext(ip, port, "") if err != nil { return nil, fmt.Errorf("Unknown service: %s", err) } if portContext.Service.UserAuthorizationType == policy.UserAuthorizationMutualTLS || portContext.Service.UserAuthorizationType == policy.UserAuthorizationJWT { clientCAs := p.ca if portContext.ClientTrustedRoots != nil { clientCAs = portContext.ClientTrustedRoots } config := p.newBaseTLSConfig() config.ClientAuth = tls.VerifyClientCertIfGiven config.ClientCAs = clientCAs return config, nil } return originalConfig, nil } return nil, fmt.Errorf("Invalid connection") }
go
func (p *Config) clientTLSConfiguration(conn net.Conn, originalConfig *tls.Config) (*tls.Config, error) { if mconn, ok := conn.(*markedconn.ProxiedConnection); ok { ip, port := mconn.GetOriginalDestination() portContext, err := p.registry.RetrieveExposedServiceContext(ip, port, "") if err != nil { return nil, fmt.Errorf("Unknown service: %s", err) } if portContext.Service.UserAuthorizationType == policy.UserAuthorizationMutualTLS || portContext.Service.UserAuthorizationType == policy.UserAuthorizationJWT { clientCAs := p.ca if portContext.ClientTrustedRoots != nil { clientCAs = portContext.ClientTrustedRoots } config := p.newBaseTLSConfig() config.ClientAuth = tls.VerifyClientCertIfGiven config.ClientCAs = clientCAs return config, nil } return originalConfig, nil } return nil, fmt.Errorf("Invalid connection") }
[ "func", "(", "p", "*", "Config", ")", "clientTLSConfiguration", "(", "conn", "net", ".", "Conn", ",", "originalConfig", "*", "tls", ".", "Config", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "if", "mconn", ",", "ok", ":=", "conn", ".", "(", "*", "markedconn", ".", "ProxiedConnection", ")", ";", "ok", "{", "ip", ",", "port", ":=", "mconn", ".", "GetOriginalDestination", "(", ")", "\n", "portContext", ",", "err", ":=", "p", ".", "registry", ".", "RetrieveExposedServiceContext", "(", "ip", ",", "port", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "portContext", ".", "Service", ".", "UserAuthorizationType", "==", "policy", ".", "UserAuthorizationMutualTLS", "||", "portContext", ".", "Service", ".", "UserAuthorizationType", "==", "policy", ".", "UserAuthorizationJWT", "{", "clientCAs", ":=", "p", ".", "ca", "\n", "if", "portContext", ".", "ClientTrustedRoots", "!=", "nil", "{", "clientCAs", "=", "portContext", ".", "ClientTrustedRoots", "\n", "}", "\n", "config", ":=", "p", ".", "newBaseTLSConfig", "(", ")", "\n", "config", ".", "ClientAuth", "=", "tls", ".", "VerifyClientCertIfGiven", "\n", "config", ".", "ClientCAs", "=", "clientCAs", "\n", "return", "config", ",", "nil", "\n", "}", "\n", "return", "originalConfig", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// clientTLSConfiguration calculates the right certificates and requests to the clients.
[ "clientTLSConfiguration", "calculates", "the", "right", "certificates", "and", "requests", "to", "the", "clients", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/http/http.go#L95-L115
6,948
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/http/http.go
newBaseTLSConfig
func (p *Config) newBaseTLSConfig() *tls.Config { return &tls.Config{ GetCertificate: p.GetCertificateFunc(), NextProtos: []string{"h2"}, PreferServerCipherSuites: true, SessionTicketsDisabled: true, CipherSuites: []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, }, } }
go
func (p *Config) newBaseTLSConfig() *tls.Config { return &tls.Config{ GetCertificate: p.GetCertificateFunc(), NextProtos: []string{"h2"}, PreferServerCipherSuites: true, SessionTicketsDisabled: true, CipherSuites: []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, }, } }
[ "func", "(", "p", "*", "Config", ")", "newBaseTLSConfig", "(", ")", "*", "tls", ".", "Config", "{", "return", "&", "tls", ".", "Config", "{", "GetCertificate", ":", "p", ".", "GetCertificateFunc", "(", ")", ",", "NextProtos", ":", "[", "]", "string", "{", "\"", "\"", "}", ",", "PreferServerCipherSuites", ":", "true", ",", "SessionTicketsDisabled", ":", "true", ",", "CipherSuites", ":", "[", "]", "uint16", "{", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", ",", "tls", ".", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", ",", "}", ",", "}", "\n", "}" ]
// newBaseTLSConfig creates the new basic TLS configuration for the server.
[ "newBaseTLSConfig", "creates", "the", "new", "basic", "TLS", "configuration", "for", "the", "server", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/http/http.go#L118-L132
6,949
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/http/http.go
UpdateSecrets
func (p *Config) UpdateSecrets(cert *tls.Certificate, caPool *x509.CertPool, s secrets.Secrets, certPEM, keyPEM string) { p.Lock() defer p.Unlock() p.cert = cert p.ca = caPool p.secrets = s p.certPEM = certPEM p.keyPEM = keyPEM p.tlsClientConfig.RootCAs = caPool }
go
func (p *Config) UpdateSecrets(cert *tls.Certificate, caPool *x509.CertPool, s secrets.Secrets, certPEM, keyPEM string) { p.Lock() defer p.Unlock() p.cert = cert p.ca = caPool p.secrets = s p.certPEM = certPEM p.keyPEM = keyPEM p.tlsClientConfig.RootCAs = caPool }
[ "func", "(", "p", "*", "Config", ")", "UpdateSecrets", "(", "cert", "*", "tls", ".", "Certificate", ",", "caPool", "*", "x509", ".", "CertPool", ",", "s", "secrets", ".", "Secrets", ",", "certPEM", ",", "keyPEM", "string", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "cert", "=", "cert", "\n", "p", ".", "ca", "=", "caPool", "\n", "p", ".", "secrets", "=", "s", "\n", "p", ".", "certPEM", "=", "certPEM", "\n", "p", ".", "keyPEM", "=", "keyPEM", "\n", "p", ".", "tlsClientConfig", ".", "RootCAs", "=", "caPool", "\n", "}" ]
// UpdateSecrets updates the secrets
[ "UpdateSecrets", "updates", "the", "secrets" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/http/http.go#L306-L316
6,950
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/http/http.go
GetCertificateFunc
func (p *Config) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error) { return func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { p.RLock() defer p.RUnlock() // First we check if this is a direct access to the public port. In this case // we will use the service public certificate. Otherwise, we will return the // enforcer certificate since this is internal access. if mconn, ok := clientHello.Conn.(*markedconn.ProxiedConnection); ok { ip, port := mconn.GetOriginalDestination() portContext, err := p.registry.RetrieveExposedServiceContext(ip, port, "") if err != nil { return nil, fmt.Errorf("service not available: %s %d", ip.String(), port) } service := portContext.Service if service.PublicNetworkInfo != nil && service.PublicNetworkInfo.Ports.Min == uint16(port) && len(service.PublicServiceCertificate) > 0 { tlsCert, err := tls.X509KeyPair(service.PublicServiceCertificate, service.PublicServiceCertificateKey) if err != nil { return nil, fmt.Errorf("failed to parse server certificate: %s", err) } return &tlsCert, nil } } if p.cert != nil { return p.cert, nil } return nil, fmt.Errorf("no cert available - cert is nil") } }
go
func (p *Config) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error) { return func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { p.RLock() defer p.RUnlock() // First we check if this is a direct access to the public port. In this case // we will use the service public certificate. Otherwise, we will return the // enforcer certificate since this is internal access. if mconn, ok := clientHello.Conn.(*markedconn.ProxiedConnection); ok { ip, port := mconn.GetOriginalDestination() portContext, err := p.registry.RetrieveExposedServiceContext(ip, port, "") if err != nil { return nil, fmt.Errorf("service not available: %s %d", ip.String(), port) } service := portContext.Service if service.PublicNetworkInfo != nil && service.PublicNetworkInfo.Ports.Min == uint16(port) && len(service.PublicServiceCertificate) > 0 { tlsCert, err := tls.X509KeyPair(service.PublicServiceCertificate, service.PublicServiceCertificateKey) if err != nil { return nil, fmt.Errorf("failed to parse server certificate: %s", err) } return &tlsCert, nil } } if p.cert != nil { return p.cert, nil } return nil, fmt.Errorf("no cert available - cert is nil") } }
[ "func", "(", "p", "*", "Config", ")", "GetCertificateFunc", "(", ")", "func", "(", "*", "tls", ".", "ClientHelloInfo", ")", "(", "*", "tls", ".", "Certificate", ",", "error", ")", "{", "return", "func", "(", "clientHello", "*", "tls", ".", "ClientHelloInfo", ")", "(", "*", "tls", ".", "Certificate", ",", "error", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "// First we check if this is a direct access to the public port. In this case", "// we will use the service public certificate. Otherwise, we will return the", "// enforcer certificate since this is internal access.", "if", "mconn", ",", "ok", ":=", "clientHello", ".", "Conn", ".", "(", "*", "markedconn", ".", "ProxiedConnection", ")", ";", "ok", "{", "ip", ",", "port", ":=", "mconn", ".", "GetOriginalDestination", "(", ")", "\n", "portContext", ",", "err", ":=", "p", ".", "registry", ".", "RetrieveExposedServiceContext", "(", "ip", ",", "port", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ip", ".", "String", "(", ")", ",", "port", ")", "\n", "}", "\n", "service", ":=", "portContext", ".", "Service", "\n", "if", "service", ".", "PublicNetworkInfo", "!=", "nil", "&&", "service", ".", "PublicNetworkInfo", ".", "Ports", ".", "Min", "==", "uint16", "(", "port", ")", "&&", "len", "(", "service", ".", "PublicServiceCertificate", ")", ">", "0", "{", "tlsCert", ",", "err", ":=", "tls", ".", "X509KeyPair", "(", "service", ".", "PublicServiceCertificate", ",", "service", ".", "PublicServiceCertificateKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "tlsCert", ",", "nil", "\n", "}", "\n", "}", "\n", "if", "p", ".", "cert", "!=", "nil", "{", "return", "p", ".", "cert", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// GetCertificateFunc implements the TLS interface for getting the certificate. This // allows us to update the certificates of the connection on the fly.
[ "GetCertificateFunc", "implements", "the", "TLS", "interface", "for", "getting", "the", "certificate", ".", "This", "allows", "us", "to", "update", "the", "certificates", "of", "the", "connection", "on", "the", "fly", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/http/http.go#L320-L347
6,951
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
NewGoIPTablesProvider
func NewGoIPTablesProvider(batchTables []string) (*BatchProvider, error) { ipt, err := iptables.New() if err != nil { return nil, err } batchTablesMap := map[string]bool{} // We will only support the batch method if there is iptables-restore and iptables // version 1.6.2 or better. Otherwise, we fall back to classic iptables instructions. // This will allow us to support older kernel versions. if restoreHasWait() { for _, t := range batchTables { batchTablesMap[t] = true } } b := &BatchProvider{ ipt: ipt, rules: map[string]map[string][]string{}, batchTables: batchTablesMap, } b.commitFunc = b.restore return b, nil }
go
func NewGoIPTablesProvider(batchTables []string) (*BatchProvider, error) { ipt, err := iptables.New() if err != nil { return nil, err } batchTablesMap := map[string]bool{} // We will only support the batch method if there is iptables-restore and iptables // version 1.6.2 or better. Otherwise, we fall back to classic iptables instructions. // This will allow us to support older kernel versions. if restoreHasWait() { for _, t := range batchTables { batchTablesMap[t] = true } } b := &BatchProvider{ ipt: ipt, rules: map[string]map[string][]string{}, batchTables: batchTablesMap, } b.commitFunc = b.restore return b, nil }
[ "func", "NewGoIPTablesProvider", "(", "batchTables", "[", "]", "string", ")", "(", "*", "BatchProvider", ",", "error", ")", "{", "ipt", ",", "err", ":=", "iptables", ".", "New", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "batchTablesMap", ":=", "map", "[", "string", "]", "bool", "{", "}", "\n", "// We will only support the batch method if there is iptables-restore and iptables", "// version 1.6.2 or better. Otherwise, we fall back to classic iptables instructions.", "// This will allow us to support older kernel versions.", "if", "restoreHasWait", "(", ")", "{", "for", "_", ",", "t", ":=", "range", "batchTables", "{", "batchTablesMap", "[", "t", "]", "=", "true", "\n", "}", "\n", "}", "\n\n", "b", ":=", "&", "BatchProvider", "{", "ipt", ":", "ipt", ",", "rules", ":", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "string", "{", "}", ",", "batchTables", ":", "batchTablesMap", ",", "}", "\n\n", "b", ".", "commitFunc", "=", "b", ".", "restore", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// NewGoIPTablesProvider returns an IptablesProvider interface based on the go-iptables // external package.
[ "NewGoIPTablesProvider", "returns", "an", "IptablesProvider", "interface", "based", "on", "the", "go", "-", "iptables", "external", "package", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L61-L86
6,952
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
NewCustomBatchProvider
func NewCustomBatchProvider(ipt BaseIPTables, commit func(buf *bytes.Buffer) error, batchTables []string) *BatchProvider { batchTablesMap := map[string]bool{} for _, t := range batchTables { batchTablesMap[t] = true } return &BatchProvider{ ipt: ipt, rules: map[string]map[string][]string{}, batchTables: batchTablesMap, commitFunc: commit, } }
go
func NewCustomBatchProvider(ipt BaseIPTables, commit func(buf *bytes.Buffer) error, batchTables []string) *BatchProvider { batchTablesMap := map[string]bool{} for _, t := range batchTables { batchTablesMap[t] = true } return &BatchProvider{ ipt: ipt, rules: map[string]map[string][]string{}, batchTables: batchTablesMap, commitFunc: commit, } }
[ "func", "NewCustomBatchProvider", "(", "ipt", "BaseIPTables", ",", "commit", "func", "(", "buf", "*", "bytes", ".", "Buffer", ")", "error", ",", "batchTables", "[", "]", "string", ")", "*", "BatchProvider", "{", "batchTablesMap", ":=", "map", "[", "string", "]", "bool", "{", "}", "\n\n", "for", "_", ",", "t", ":=", "range", "batchTables", "{", "batchTablesMap", "[", "t", "]", "=", "true", "\n", "}", "\n\n", "return", "&", "BatchProvider", "{", "ipt", ":", "ipt", ",", "rules", ":", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "string", "{", "}", ",", "batchTables", ":", "batchTablesMap", ",", "commitFunc", ":", "commit", ",", "}", "\n", "}" ]
// NewCustomBatchProvider is a custom batch provider wher the downstream // iptables utility is provided by the caller. Very useful for testing // the ACL functions with a mock.
[ "NewCustomBatchProvider", "is", "a", "custom", "batch", "provider", "wher", "the", "downstream", "iptables", "utility", "is", "provided", "by", "the", "caller", ".", "Very", "useful", "for", "testing", "the", "ACL", "functions", "with", "a", "mock", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L91-L105
6,953
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
Append
func (b *BatchProvider) Append(table, chain string, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Append(table, chain, rulespec...) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } if _, ok := b.rules[table][chain]; !ok { b.rules[table][chain] = []string{} } rule := strings.Join(rulespec, " ") b.rules[table][chain] = append(b.rules[table][chain], rule) return nil }
go
func (b *BatchProvider) Append(table, chain string, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Append(table, chain, rulespec...) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } if _, ok := b.rules[table][chain]; !ok { b.rules[table][chain] = []string{} } rule := strings.Join(rulespec, " ") b.rules[table][chain] = append(b.rules[table][chain], rule) return nil }
[ "func", "(", "b", "*", "BatchProvider", ")", "Append", "(", "table", ",", "chain", "string", ",", "rulespec", "...", "string", ")", "error", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "batchTables", "[", "table", "]", ";", "!", "ok", "{", "return", "b", ".", "ipt", ".", "Append", "(", "table", ",", "chain", ",", "rulespec", "...", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", ";", "!", "ok", "{", "b", ".", "rules", "[", "table", "]", "=", "map", "[", "string", "]", "[", "]", "string", "{", "}", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ";", "!", "ok", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "[", "]", "string", "{", "}", "\n", "}", "\n\n", "rule", ":=", "strings", ".", "Join", "(", "rulespec", ",", "\"", "\"", ")", "\n\n", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "append", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ",", "rule", ")", "\n\n", "return", "nil", "\n", "}" ]
// Append will append the provided rule to the local cache or call // directly the iptables command depending on the table.
[ "Append", "will", "append", "the", "provided", "rule", "to", "the", "local", "cache", "or", "call", "directly", "the", "iptables", "command", "depending", "on", "the", "table", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L109-L130
6,954
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
Insert
func (b *BatchProvider) Insert(table, chain string, pos int, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Insert(table, chain, pos, rulespec...) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } if _, ok := b.rules[table][chain]; !ok { b.rules[table][chain] = []string{} } rule := strings.Join(rulespec, " ") if pos == 1 { b.rules[table][chain] = append([]string{rule}, b.rules[table][chain]...) } else if pos > len(b.rules[table][chain]) { b.rules[table][chain] = append(b.rules[table][chain], rule) } else { b.rules[table][chain] = append(b.rules[table][chain], "newvalue") copy(b.rules[table][chain][pos-1:], b.rules[table][chain][pos-2:]) b.rules[table][chain][pos-1] = rule } return nil }
go
func (b *BatchProvider) Insert(table, chain string, pos int, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Insert(table, chain, pos, rulespec...) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } if _, ok := b.rules[table][chain]; !ok { b.rules[table][chain] = []string{} } rule := strings.Join(rulespec, " ") if pos == 1 { b.rules[table][chain] = append([]string{rule}, b.rules[table][chain]...) } else if pos > len(b.rules[table][chain]) { b.rules[table][chain] = append(b.rules[table][chain], rule) } else { b.rules[table][chain] = append(b.rules[table][chain], "newvalue") copy(b.rules[table][chain][pos-1:], b.rules[table][chain][pos-2:]) b.rules[table][chain][pos-1] = rule } return nil }
[ "func", "(", "b", "*", "BatchProvider", ")", "Insert", "(", "table", ",", "chain", "string", ",", "pos", "int", ",", "rulespec", "...", "string", ")", "error", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "batchTables", "[", "table", "]", ";", "!", "ok", "{", "return", "b", ".", "ipt", ".", "Insert", "(", "table", ",", "chain", ",", "pos", ",", "rulespec", "...", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", ";", "!", "ok", "{", "b", ".", "rules", "[", "table", "]", "=", "map", "[", "string", "]", "[", "]", "string", "{", "}", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ";", "!", "ok", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "[", "]", "string", "{", "}", "\n", "}", "\n\n", "rule", ":=", "strings", ".", "Join", "(", "rulespec", ",", "\"", "\"", ")", "\n\n", "if", "pos", "==", "1", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "append", "(", "[", "]", "string", "{", "rule", "}", ",", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "...", ")", "\n", "}", "else", "if", "pos", ">", "len", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ")", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "append", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ",", "rule", ")", "\n", "}", "else", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "append", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ",", "\"", "\"", ")", "\n", "copy", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", "pos", "-", "1", ":", "]", ",", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", "pos", "-", "2", ":", "]", ")", "\n", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", "pos", "-", "1", "]", "=", "rule", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Insert will insert the rule in the corresponding position in the local // cache or call the corresponding iptables command, depending on the table.
[ "Insert", "will", "insert", "the", "rule", "in", "the", "corresponding", "position", "in", "the", "local", "cache", "or", "call", "the", "corresponding", "iptables", "command", "depending", "on", "the", "table", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L134-L164
6,955
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
Delete
func (b *BatchProvider) Delete(table, chain string, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Delete(table, chain, rulespec...) } if _, ok := b.rules[table]; !ok { return nil } if _, ok := b.rules[table][chain]; !ok { return nil } rule := strings.Join(rulespec, " ") for index, r := range b.rules[table][chain] { if rule == r { switch index { case 0: if len(b.rules[table][chain]) == 1 { b.rules[table][chain] = []string{} } else { b.rules[table][chain] = b.rules[table][chain][1:] } case len(b.rules[table][chain]) - 1: b.rules[table][chain] = b.rules[table][chain][:index] default: b.rules[table][chain] = append(b.rules[table][chain][:index], b.rules[table][chain][index+1:]...) } break } } return nil }
go
func (b *BatchProvider) Delete(table, chain string, rulespec ...string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.Delete(table, chain, rulespec...) } if _, ok := b.rules[table]; !ok { return nil } if _, ok := b.rules[table][chain]; !ok { return nil } rule := strings.Join(rulespec, " ") for index, r := range b.rules[table][chain] { if rule == r { switch index { case 0: if len(b.rules[table][chain]) == 1 { b.rules[table][chain] = []string{} } else { b.rules[table][chain] = b.rules[table][chain][1:] } case len(b.rules[table][chain]) - 1: b.rules[table][chain] = b.rules[table][chain][:index] default: b.rules[table][chain] = append(b.rules[table][chain][:index], b.rules[table][chain][index+1:]...) } break } } return nil }
[ "func", "(", "b", "*", "BatchProvider", ")", "Delete", "(", "table", ",", "chain", "string", ",", "rulespec", "...", "string", ")", "error", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "batchTables", "[", "table", "]", ";", "!", "ok", "{", "return", "b", ".", "ipt", ".", "Delete", "(", "table", ",", "chain", ",", "rulespec", "...", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "rule", ":=", "strings", ".", "Join", "(", "rulespec", ",", "\"", "\"", ")", "\n\n", "for", "index", ",", "r", ":=", "range", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "{", "if", "rule", "==", "r", "{", "switch", "index", "{", "case", "0", ":", "if", "len", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ")", "==", "1", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "[", "]", "string", "{", "}", "\n", "}", "else", "{", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", "1", ":", "]", "\n", "}", "\n", "case", "len", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", ")", "-", "1", ":", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", ":", "index", "]", "\n", "default", ":", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "append", "(", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", ":", "index", "]", ",", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "[", "index", "+", "1", ":", "]", "...", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete will delete the rule from the local cache or the system.
[ "Delete", "will", "delete", "the", "rule", "from", "the", "local", "cache", "or", "the", "system", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L167-L204
6,956
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
ListChains
func (b *BatchProvider) ListChains(table string) ([]string, error) { b.Lock() defer b.Unlock() return b.ipt.ListChains(table) }
go
func (b *BatchProvider) ListChains(table string) ([]string, error) { b.Lock() defer b.Unlock() return b.ipt.ListChains(table) }
[ "func", "(", "b", "*", "BatchProvider", ")", "ListChains", "(", "table", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "return", "b", ".", "ipt", ".", "ListChains", "(", "table", ")", "\n", "}" ]
// ListChains will provide a list of the current chains.
[ "ListChains", "will", "provide", "a", "list", "of", "the", "current", "chains", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L207-L212
6,957
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
NewChain
func (b *BatchProvider) NewChain(table, chain string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.NewChain(table, chain) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } b.rules[table][chain] = []string{} return nil }
go
func (b *BatchProvider) NewChain(table, chain string) error { b.Lock() defer b.Unlock() if _, ok := b.batchTables[table]; !ok { return b.ipt.NewChain(table, chain) } if _, ok := b.rules[table]; !ok { b.rules[table] = map[string][]string{} } b.rules[table][chain] = []string{} return nil }
[ "func", "(", "b", "*", "BatchProvider", ")", "NewChain", "(", "table", ",", "chain", "string", ")", "error", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "batchTables", "[", "table", "]", ";", "!", "ok", "{", "return", "b", ".", "ipt", ".", "NewChain", "(", "table", ",", "chain", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "b", ".", "rules", "[", "table", "]", ";", "!", "ok", "{", "b", ".", "rules", "[", "table", "]", "=", "map", "[", "string", "]", "[", "]", "string", "{", "}", "\n", "}", "\n", "b", ".", "rules", "[", "table", "]", "[", "chain", "]", "=", "[", "]", "string", "{", "}", "\n\n", "return", "nil", "\n", "}" ]
// NewChain creates a new chain.
[ "NewChain", "creates", "a", "new", "chain", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L254-L268
6,958
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
Commit
func (b *BatchProvider) Commit() error { b.Lock() defer b.Unlock() // We don't commit if we don't have any tables. This is old // kernel compatibility mode. if len(b.batchTables) == 0 { return nil } buf, err := b.createDataBuffer() if err != nil { return fmt.Errorf("Failed to crete buffer %s", err) } return b.commitFunc(buf) }
go
func (b *BatchProvider) Commit() error { b.Lock() defer b.Unlock() // We don't commit if we don't have any tables. This is old // kernel compatibility mode. if len(b.batchTables) == 0 { return nil } buf, err := b.createDataBuffer() if err != nil { return fmt.Errorf("Failed to crete buffer %s", err) } return b.commitFunc(buf) }
[ "func", "(", "b", "*", "BatchProvider", ")", "Commit", "(", ")", "error", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "// We don't commit if we don't have any tables. This is old", "// kernel compatibility mode.", "if", "len", "(", "b", ".", "batchTables", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "buf", ",", "err", ":=", "b", ".", "createDataBuffer", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "b", ".", "commitFunc", "(", "buf", ")", "\n", "}" ]
// Commit commits the rules to the system
[ "Commit", "commits", "the", "rules", "to", "the", "system" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L271-L287
6,959
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
RetrieveTable
func (b *BatchProvider) RetrieveTable() map[string]map[string][]string { b.Lock() defer b.Unlock() return b.rules }
go
func (b *BatchProvider) RetrieveTable() map[string]map[string][]string { b.Lock() defer b.Unlock() return b.rules }
[ "func", "(", "b", "*", "BatchProvider", ")", "RetrieveTable", "(", ")", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "string", "{", "b", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "Unlock", "(", ")", "\n\n", "return", "b", ".", "rules", "\n", "}" ]
// RetrieveTable allows a caller to retrieve the final table. Mostly // needed for debuging and unit tests.
[ "RetrieveTable", "allows", "a", "caller", "to", "retrieve", "the", "final", "table", ".", "Mostly", "needed", "for", "debuging", "and", "unit", "tests", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L291-L296
6,960
aporeto-inc/trireme-lib
controller/pkg/aclprovider/iptablesprovider.go
restore
func (b *BatchProvider) restore(buf *bytes.Buffer) error { cmd := exec.Command(restoreCmd, "--wait") cmd.Stdin = buf out, err := cmd.CombinedOutput() if err != nil { again, _ := b.createDataBuffer() zap.L().Error("Failed to execute command", zap.Error(err), zap.ByteString("Output", out), zap.String("Output", again.String()), ) return fmt.Errorf("Failed to execute iptables-restore: %s", err) } return nil }
go
func (b *BatchProvider) restore(buf *bytes.Buffer) error { cmd := exec.Command(restoreCmd, "--wait") cmd.Stdin = buf out, err := cmd.CombinedOutput() if err != nil { again, _ := b.createDataBuffer() zap.L().Error("Failed to execute command", zap.Error(err), zap.ByteString("Output", out), zap.String("Output", again.String()), ) return fmt.Errorf("Failed to execute iptables-restore: %s", err) } return nil }
[ "func", "(", "b", "*", "BatchProvider", ")", "restore", "(", "buf", "*", "bytes", ".", "Buffer", ")", "error", "{", "cmd", ":=", "exec", ".", "Command", "(", "restoreCmd", ",", "\"", "\"", ")", "\n", "cmd", ".", "Stdin", "=", "buf", "\n", "out", ",", "err", ":=", "cmd", ".", "CombinedOutput", "(", ")", "\n", "if", "err", "!=", "nil", "{", "again", ",", "_", ":=", "b", ".", "createDataBuffer", "(", ")", "\n", "zap", ".", "L", "(", ")", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ",", "zap", ".", "ByteString", "(", "\"", "\"", ",", "out", ")", ",", "zap", ".", "String", "(", "\"", "\"", ",", "again", ".", "String", "(", ")", ")", ",", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// restore will save the current DB to iptables.
[ "restore", "will", "save", "the", "current", "DB", "to", "iptables", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/aclprovider/iptablesprovider.go#L326-L340
6,961
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockNewRPCClient
func (m *testRPC) MockNewRPCClient(t *testing.T, impl func(contextID string, channel string, secret string) error) { m.currentMocks(t).NewRPCClientMock = impl }
go
func (m *testRPC) MockNewRPCClient(t *testing.T, impl func(contextID string, channel string, secret string) error) { m.currentMocks(t).NewRPCClientMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockNewRPCClient", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "contextID", "string", ",", "channel", "string", ",", "secret", "string", ")", "error", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "NewRPCClientMock", "=", "impl", "\n", "}" ]
// MockNewRPCClient mocks the NewRPCClient function
[ "MockNewRPCClient", "mocks", "the", "NewRPCClient", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L69-L71
6,962
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockGetRPCClient
func (m *testRPC) MockGetRPCClient(t *testing.T, impl func(contextID string) (*RPCHdl, error)) { m.currentMocks(t).GetRPCClientMock = impl }
go
func (m *testRPC) MockGetRPCClient(t *testing.T, impl func(contextID string) (*RPCHdl, error)) { m.currentMocks(t).GetRPCClientMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockGetRPCClient", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "contextID", "string", ")", "(", "*", "RPCHdl", ",", "error", ")", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "GetRPCClientMock", "=", "impl", "\n", "}" ]
// MockGetRPCClient mocks the GetRPCClient function
[ "MockGetRPCClient", "mocks", "the", "GetRPCClient", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L74-L76
6,963
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockRemoteCall
func (m *testRPC) MockRemoteCall(t *testing.T, impl func(contextID string, methodName string, req *Request, resp *Response) error) { m.currentMocks(t).RemoteCallMock = impl }
go
func (m *testRPC) MockRemoteCall(t *testing.T, impl func(contextID string, methodName string, req *Request, resp *Response) error) { m.currentMocks(t).RemoteCallMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockRemoteCall", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "contextID", "string", ",", "methodName", "string", ",", "req", "*", "Request", ",", "resp", "*", "Response", ")", "error", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "RemoteCallMock", "=", "impl", "\n", "}" ]
// MockRemoteCall mocks the RemoteCall function
[ "MockRemoteCall", "mocks", "the", "RemoteCall", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L79-L81
6,964
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockDestroyRPCClient
func (m *testRPC) MockDestroyRPCClient(t *testing.T, impl func(contextID string)) { m.currentMocks(t).DestroyRPCClientMock = impl }
go
func (m *testRPC) MockDestroyRPCClient(t *testing.T, impl func(contextID string)) { m.currentMocks(t).DestroyRPCClientMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockDestroyRPCClient", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "contextID", "string", ")", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "DestroyRPCClientMock", "=", "impl", "\n", "}" ]
// MockDestroyRPCClient mocks the DestroyRPCClient function
[ "MockDestroyRPCClient", "mocks", "the", "DestroyRPCClient", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L84-L86
6,965
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockStartServer
func (m *testRPC) MockStartServer(t *testing.T, impl func(ctx context.Context, protocol string, path string, handler interface{}) error) { m.currentMocks(t).StartServerMock = impl }
go
func (m *testRPC) MockStartServer(t *testing.T, impl func(ctx context.Context, protocol string, path string, handler interface{}) error) { m.currentMocks(t).StartServerMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockStartServer", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "ctx", "context", ".", "Context", ",", "protocol", "string", ",", "path", "string", ",", "handler", "interface", "{", "}", ")", "error", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "StartServerMock", "=", "impl", "\n\n", "}" ]
// MockStartServer mocks the StartServer function
[ "MockStartServer", "mocks", "the", "StartServer", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L89-L92
6,966
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockProcessMessage
func (m *testRPC) MockProcessMessage(t *testing.T, impl func(req *Request, secret string) bool) { m.currentMocks(t).ProcessMessageMock = impl }
go
func (m *testRPC) MockProcessMessage(t *testing.T, impl func(req *Request, secret string) bool) { m.currentMocks(t).ProcessMessageMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockProcessMessage", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "req", "*", "Request", ",", "secret", "string", ")", "bool", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "ProcessMessageMock", "=", "impl", "\n", "}" ]
// MockProcessMessage mocks the ProcessMessage function
[ "MockProcessMessage", "mocks", "the", "ProcessMessage", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L95-L97
6,967
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockContextList
func (m *testRPC) MockContextList(t *testing.T, impl func() []string) { m.currentMocks(t).ContextListMock = impl }
go
func (m *testRPC) MockContextList(t *testing.T, impl func() []string) { m.currentMocks(t).ContextListMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockContextList", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", ")", "[", "]", "string", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "ContextListMock", "=", "impl", "\n", "}" ]
// MockContextList mocks the ContextList function
[ "MockContextList", "mocks", "the", "ContextList", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L100-L102
6,968
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
MockCheckValidity
func (m *testRPC) MockCheckValidity(t *testing.T, impl func(req *Request, secret string) bool) { m.currentMocks(t).CheckValidityMock = impl }
go
func (m *testRPC) MockCheckValidity(t *testing.T, impl func(req *Request, secret string) bool) { m.currentMocks(t).CheckValidityMock = impl }
[ "func", "(", "m", "*", "testRPC", ")", "MockCheckValidity", "(", "t", "*", "testing", ".", "T", ",", "impl", "func", "(", "req", "*", "Request", ",", "secret", "string", ")", "bool", ")", "{", "m", ".", "currentMocks", "(", "t", ")", ".", "CheckValidityMock", "=", "impl", "\n", "}" ]
// MockCheckValidity mocks the CheckValidity function
[ "MockCheckValidity", "mocks", "the", "CheckValidity", "function" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L105-L107
6,969
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
NewRPCClient
func (m *testRPC) NewRPCClient(contextID string, channel string, secret string) error { if mock := m.currentMocks(nil); mock != nil && mock.NewRPCClientMock != nil { return mock.NewRPCClientMock(contextID, channel, secret) } return nil }
go
func (m *testRPC) NewRPCClient(contextID string, channel string, secret string) error { if mock := m.currentMocks(nil); mock != nil && mock.NewRPCClientMock != nil { return mock.NewRPCClientMock(contextID, channel, secret) } return nil }
[ "func", "(", "m", "*", "testRPC", ")", "NewRPCClient", "(", "contextID", "string", ",", "channel", "string", ",", "secret", "string", ")", "error", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "NewRPCClientMock", "!=", "nil", "{", "return", "mock", ".", "NewRPCClientMock", "(", "contextID", ",", "channel", ",", "secret", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// NewRPCClient implements the new interface
[ "NewRPCClient", "implements", "the", "new", "interface" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L110-L115
6,970
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
GetRPCClient
func (m *testRPC) GetRPCClient(contextID string) (*RPCHdl, error) { if mock := m.currentMocks(nil); mock != nil && mock.GetRPCClientMock != nil { return mock.GetRPCClientMock(contextID) } return nil, nil }
go
func (m *testRPC) GetRPCClient(contextID string) (*RPCHdl, error) { if mock := m.currentMocks(nil); mock != nil && mock.GetRPCClientMock != nil { return mock.GetRPCClientMock(contextID) } return nil, nil }
[ "func", "(", "m", "*", "testRPC", ")", "GetRPCClient", "(", "contextID", "string", ")", "(", "*", "RPCHdl", ",", "error", ")", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "GetRPCClientMock", "!=", "nil", "{", "return", "mock", ".", "GetRPCClientMock", "(", "contextID", ")", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// GetRPCClient implements the interface with a mock
[ "GetRPCClient", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L118-L123
6,971
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
RemoteCall
func (m *testRPC) RemoteCall(contextID string, methodName string, req *Request, resp *Response) error { if mock := m.currentMocks(nil); mock != nil && mock.RemoteCallMock != nil { return mock.RemoteCallMock(contextID, methodName, req, resp) } return nil }
go
func (m *testRPC) RemoteCall(contextID string, methodName string, req *Request, resp *Response) error { if mock := m.currentMocks(nil); mock != nil && mock.RemoteCallMock != nil { return mock.RemoteCallMock(contextID, methodName, req, resp) } return nil }
[ "func", "(", "m", "*", "testRPC", ")", "RemoteCall", "(", "contextID", "string", ",", "methodName", "string", ",", "req", "*", "Request", ",", "resp", "*", "Response", ")", "error", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "RemoteCallMock", "!=", "nil", "{", "return", "mock", ".", "RemoteCallMock", "(", "contextID", ",", "methodName", ",", "req", ",", "resp", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoteCall implements the interface with a mock
[ "RemoteCall", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L126-L131
6,972
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
DestroyRPCClient
func (m *testRPC) DestroyRPCClient(contextID string) { if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil { mock.DestroyRPCClientMock(contextID) return } }
go
func (m *testRPC) DestroyRPCClient(contextID string) { if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil { mock.DestroyRPCClientMock(contextID) return } }
[ "func", "(", "m", "*", "testRPC", ")", "DestroyRPCClient", "(", "contextID", "string", ")", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "DestroyRPCClientMock", "!=", "nil", "{", "mock", ".", "DestroyRPCClientMock", "(", "contextID", ")", "\n", "return", "\n", "}", "\n", "}" ]
// DestroyRPCClient implements the interface with a Mock
[ "DestroyRPCClient", "implements", "the", "interface", "with", "a", "Mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L134-L139
6,973
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
CheckValidity
func (m *testRPC) CheckValidity(req *Request, secret string) bool { if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil { return mock.CheckValidityMock(req, secret) } return false }
go
func (m *testRPC) CheckValidity(req *Request, secret string) bool { if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil { return mock.CheckValidityMock(req, secret) } return false }
[ "func", "(", "m", "*", "testRPC", ")", "CheckValidity", "(", "req", "*", "Request", ",", "secret", "string", ")", "bool", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "DestroyRPCClientMock", "!=", "nil", "{", "return", "mock", ".", "CheckValidityMock", "(", "req", ",", "secret", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// CheckValidity implements the interface with a mock
[ "CheckValidity", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L142-L147
6,974
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
StartServer
func (m *testRPC) StartServer(ctx context.Context, protocol string, path string, handler interface{}) error { if mock := m.currentMocks(nil); mock != nil && mock.StartServerMock != nil { return mock.StartServerMock(ctx, protocol, path, handler) } return nil }
go
func (m *testRPC) StartServer(ctx context.Context, protocol string, path string, handler interface{}) error { if mock := m.currentMocks(nil); mock != nil && mock.StartServerMock != nil { return mock.StartServerMock(ctx, protocol, path, handler) } return nil }
[ "func", "(", "m", "*", "testRPC", ")", "StartServer", "(", "ctx", "context", ".", "Context", ",", "protocol", "string", ",", "path", "string", ",", "handler", "interface", "{", "}", ")", "error", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "StartServerMock", "!=", "nil", "{", "return", "mock", ".", "StartServerMock", "(", "ctx", ",", "protocol", ",", "path", ",", "handler", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StartServer implements the interface with a mock
[ "StartServer", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L150-L155
6,975
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
ProcessMessage
func (m *testRPC) ProcessMessage(req *Request, secret string) bool { if mock := m.currentMocks(nil); mock != nil && mock.ProcessMessageMock != nil { return mock.ProcessMessageMock(req, secret) } return true }
go
func (m *testRPC) ProcessMessage(req *Request, secret string) bool { if mock := m.currentMocks(nil); mock != nil && mock.ProcessMessageMock != nil { return mock.ProcessMessageMock(req, secret) } return true }
[ "func", "(", "m", "*", "testRPC", ")", "ProcessMessage", "(", "req", "*", "Request", ",", "secret", "string", ")", "bool", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "nil", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "ProcessMessageMock", "!=", "nil", "{", "return", "mock", ".", "ProcessMessageMock", "(", "req", ",", "secret", ")", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ProcessMessage implements the interface with a mock
[ "ProcessMessage", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L158-L163
6,976
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
ContextList
func (m *testRPC) ContextList() []string { if mock := m.currentMocks(m.currentTest); mock != nil && mock.ContextListMock != nil { return mock.ContextListMock() } return []string{} }
go
func (m *testRPC) ContextList() []string { if mock := m.currentMocks(m.currentTest); mock != nil && mock.ContextListMock != nil { return mock.ContextListMock() } return []string{} }
[ "func", "(", "m", "*", "testRPC", ")", "ContextList", "(", ")", "[", "]", "string", "{", "if", "mock", ":=", "m", ".", "currentMocks", "(", "m", ".", "currentTest", ")", ";", "mock", "!=", "nil", "&&", "mock", ".", "ContextListMock", "!=", "nil", "{", "return", "mock", ".", "ContextListMock", "(", ")", "\n", "}", "\n", "return", "[", "]", "string", "{", "}", "\n", "}" ]
// ContextList implements the interface with a mock
[ "ContextList", "implements", "the", "interface", "with", "a", "mock" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L166-L171
6,977
aporeto-inc/trireme-lib
controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go
currentMocks
func (m *testRPC) currentMocks(t *testing.T) *mockedMethods { m.lock.Lock() defer m.lock.Unlock() if t == nil { t = m.currentTest } else { m.currentTest = t } mocks := m.mocks[t] if mocks == nil { mocks = &mockedMethods{} m.mocks[t] = mocks } return mocks }
go
func (m *testRPC) currentMocks(t *testing.T) *mockedMethods { m.lock.Lock() defer m.lock.Unlock() if t == nil { t = m.currentTest } else { m.currentTest = t } mocks := m.mocks[t] if mocks == nil { mocks = &mockedMethods{} m.mocks[t] = mocks } return mocks }
[ "func", "(", "m", "*", "testRPC", ")", "currentMocks", "(", "t", "*", "testing", ".", "T", ")", "*", "mockedMethods", "{", "m", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "t", "==", "nil", "{", "t", "=", "m", ".", "currentTest", "\n", "}", "else", "{", "m", ".", "currentTest", "=", "t", "\n", "}", "\n\n", "mocks", ":=", "m", ".", "mocks", "[", "t", "]", "\n", "if", "mocks", "==", "nil", "{", "mocks", "=", "&", "mockedMethods", "{", "}", "\n", "m", ".", "mocks", "[", "t", "]", "=", "mocks", "\n", "}", "\n\n", "return", "mocks", "\n", "}" ]
// currentMocks returns the list of current mocks
[ "currentMocks", "returns", "the", "list", "of", "current", "mocks" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/utils/rpcwrapper/rpc_handlemock.go#L174-L191
6,978
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
NewPU
func NewPU(contextID string, puInfo *policy.PUInfo, timeout time.Duration) (*PUContext, error) { ctx := context.Background() ctx, cancelFunc := context.WithCancel(ctx) pu := &PUContext{ id: contextID, username: puInfo.Runtime.Options().UserID, autoport: puInfo.Runtime.Options().AutoPort, managementID: puInfo.Policy.ManagementID(), puType: puInfo.Runtime.PUType(), identity: puInfo.Policy.Identity(), annotations: puInfo.Policy.Annotations(), externalIPCache: cache.NewCacheWithExpiration("External IP Cache", timeout), ApplicationACLs: acls.NewACLCache(), networkACLs: acls.NewACLCache(), mark: puInfo.Runtime.Options().CgroupMark, scopes: puInfo.Policy.Scopes(), CancelFunc: cancelFunc, } pu.CreateRcvRules(puInfo.Policy.ReceiverRules()) pu.CreateTxtRules(puInfo.Policy.TransmitterRules()) tcpPorts, udpPorts := common.ConvertServicesToProtocolPortList(puInfo.Runtime.Options().Services) pu.tcpPorts = strings.Split(tcpPorts, ",") pu.udpPorts = strings.Split(udpPorts, ",") if err := pu.UpdateApplicationACLs(puInfo.Policy.ApplicationACLs()); err != nil { return nil, err } if err := pu.UpdateNetworkACLs(puInfo.Policy.NetworkACLs()); err != nil { return nil, err } dnsACL := puInfo.Policy.DNSNameACLs() pu.startDNS(ctx, &dnsACL) return pu, nil }
go
func NewPU(contextID string, puInfo *policy.PUInfo, timeout time.Duration) (*PUContext, error) { ctx := context.Background() ctx, cancelFunc := context.WithCancel(ctx) pu := &PUContext{ id: contextID, username: puInfo.Runtime.Options().UserID, autoport: puInfo.Runtime.Options().AutoPort, managementID: puInfo.Policy.ManagementID(), puType: puInfo.Runtime.PUType(), identity: puInfo.Policy.Identity(), annotations: puInfo.Policy.Annotations(), externalIPCache: cache.NewCacheWithExpiration("External IP Cache", timeout), ApplicationACLs: acls.NewACLCache(), networkACLs: acls.NewACLCache(), mark: puInfo.Runtime.Options().CgroupMark, scopes: puInfo.Policy.Scopes(), CancelFunc: cancelFunc, } pu.CreateRcvRules(puInfo.Policy.ReceiverRules()) pu.CreateTxtRules(puInfo.Policy.TransmitterRules()) tcpPorts, udpPorts := common.ConvertServicesToProtocolPortList(puInfo.Runtime.Options().Services) pu.tcpPorts = strings.Split(tcpPorts, ",") pu.udpPorts = strings.Split(udpPorts, ",") if err := pu.UpdateApplicationACLs(puInfo.Policy.ApplicationACLs()); err != nil { return nil, err } if err := pu.UpdateNetworkACLs(puInfo.Policy.NetworkACLs()); err != nil { return nil, err } dnsACL := puInfo.Policy.DNSNameACLs() pu.startDNS(ctx, &dnsACL) return pu, nil }
[ "func", "NewPU", "(", "contextID", "string", ",", "puInfo", "*", "policy", ".", "PUInfo", ",", "timeout", "time", ".", "Duration", ")", "(", "*", "PUContext", ",", "error", ")", "{", "ctx", ":=", "context", ".", "Background", "(", ")", "\n", "ctx", ",", "cancelFunc", ":=", "context", ".", "WithCancel", "(", "ctx", ")", "\n\n", "pu", ":=", "&", "PUContext", "{", "id", ":", "contextID", ",", "username", ":", "puInfo", ".", "Runtime", ".", "Options", "(", ")", ".", "UserID", ",", "autoport", ":", "puInfo", ".", "Runtime", ".", "Options", "(", ")", ".", "AutoPort", ",", "managementID", ":", "puInfo", ".", "Policy", ".", "ManagementID", "(", ")", ",", "puType", ":", "puInfo", ".", "Runtime", ".", "PUType", "(", ")", ",", "identity", ":", "puInfo", ".", "Policy", ".", "Identity", "(", ")", ",", "annotations", ":", "puInfo", ".", "Policy", ".", "Annotations", "(", ")", ",", "externalIPCache", ":", "cache", ".", "NewCacheWithExpiration", "(", "\"", "\"", ",", "timeout", ")", ",", "ApplicationACLs", ":", "acls", ".", "NewACLCache", "(", ")", ",", "networkACLs", ":", "acls", ".", "NewACLCache", "(", ")", ",", "mark", ":", "puInfo", ".", "Runtime", ".", "Options", "(", ")", ".", "CgroupMark", ",", "scopes", ":", "puInfo", ".", "Policy", ".", "Scopes", "(", ")", ",", "CancelFunc", ":", "cancelFunc", ",", "}", "\n\n", "pu", ".", "CreateRcvRules", "(", "puInfo", ".", "Policy", ".", "ReceiverRules", "(", ")", ")", "\n\n", "pu", ".", "CreateTxtRules", "(", "puInfo", ".", "Policy", ".", "TransmitterRules", "(", ")", ")", "\n\n", "tcpPorts", ",", "udpPorts", ":=", "common", ".", "ConvertServicesToProtocolPortList", "(", "puInfo", ".", "Runtime", ".", "Options", "(", ")", ".", "Services", ")", "\n", "pu", ".", "tcpPorts", "=", "strings", ".", "Split", "(", "tcpPorts", ",", "\"", "\"", ")", "\n", "pu", ".", "udpPorts", "=", "strings", ".", "Split", "(", "udpPorts", ",", "\"", "\"", ")", "\n\n", "if", "err", ":=", "pu", ".", "UpdateApplicationACLs", "(", "puInfo", ".", "Policy", ".", "ApplicationACLs", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "pu", ".", "UpdateNetworkACLs", "(", "puInfo", ".", "Policy", ".", "NetworkACLs", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "dnsACL", ":=", "puInfo", ".", "Policy", ".", "DNSNameACLs", "(", ")", "\n", "pu", ".", "startDNS", "(", "ctx", ",", "&", "dnsACL", ")", "\n", "return", "pu", ",", "nil", "\n", "}" ]
// NewPU creates a new PU context
[ "NewPU", "creates", "a", "new", "PU", "context" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L64-L103
6,979
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
RetrieveCachedExternalFlowPolicy
func (p *PUContext) RetrieveCachedExternalFlowPolicy(id string) (interface{}, error) { return p.externalIPCache.Get(id) }
go
func (p *PUContext) RetrieveCachedExternalFlowPolicy(id string) (interface{}, error) { return p.externalIPCache.Get(id) }
[ "func", "(", "p", "*", "PUContext", ")", "RetrieveCachedExternalFlowPolicy", "(", "id", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "p", ".", "externalIPCache", ".", "Get", "(", "id", ")", "\n", "}" ]
// RetrieveCachedExternalFlowPolicy returns the policy for an external IP
[ "RetrieveCachedExternalFlowPolicy", "returns", "the", "policy", "for", "an", "external", "IP" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L247-L249
6,980
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
NetworkACLPolicy
func (p *PUContext) NetworkACLPolicy(packet *packet.Packet) (report *policy.FlowPolicy, action *policy.FlowPolicy, err error) { defer p.RUnlock() p.RLock() return p.networkACLs.GetMatchingAction(packet.SourceAddress(), packet.DestPort()) }
go
func (p *PUContext) NetworkACLPolicy(packet *packet.Packet) (report *policy.FlowPolicy, action *policy.FlowPolicy, err error) { defer p.RUnlock() p.RLock() return p.networkACLs.GetMatchingAction(packet.SourceAddress(), packet.DestPort()) }
[ "func", "(", "p", "*", "PUContext", ")", "NetworkACLPolicy", "(", "packet", "*", "packet", ".", "Packet", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "action", "*", "policy", ".", "FlowPolicy", ",", "err", "error", ")", "{", "defer", "p", ".", "RUnlock", "(", ")", "\n", "p", ".", "RLock", "(", ")", "\n\n", "return", "p", ".", "networkACLs", ".", "GetMatchingAction", "(", "packet", ".", "SourceAddress", "(", ")", ",", "packet", ".", "DestPort", "(", ")", ")", "\n", "}" ]
// NetworkACLPolicy retrieves the policy based on ACLs
[ "NetworkACLPolicy", "retrieves", "the", "policy", "based", "on", "ACLs" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L252-L257
6,981
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
NetworkACLPolicyFromAddr
func (p *PUContext) NetworkACLPolicyFromAddr(addr net.IP, port uint16) (report *policy.FlowPolicy, action *policy.FlowPolicy, err error) { defer p.RUnlock() p.RLock() return p.networkACLs.GetMatchingAction(addr, port) }
go
func (p *PUContext) NetworkACLPolicyFromAddr(addr net.IP, port uint16) (report *policy.FlowPolicy, action *policy.FlowPolicy, err error) { defer p.RUnlock() p.RLock() return p.networkACLs.GetMatchingAction(addr, port) }
[ "func", "(", "p", "*", "PUContext", ")", "NetworkACLPolicyFromAddr", "(", "addr", "net", ".", "IP", ",", "port", "uint16", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "action", "*", "policy", ".", "FlowPolicy", ",", "err", "error", ")", "{", "defer", "p", ".", "RUnlock", "(", ")", "\n", "p", ".", "RLock", "(", ")", "\n\n", "return", "p", ".", "networkACLs", ".", "GetMatchingAction", "(", "addr", ",", "port", ")", "\n", "}" ]
// NetworkACLPolicyFromAddr retrieve the policy given an address and port.
[ "NetworkACLPolicyFromAddr", "retrieve", "the", "policy", "given", "an", "address", "and", "port", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L260-L265
6,982
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
UpdateApplicationACLs
func (p *PUContext) UpdateApplicationACLs(rules policy.IPRuleList) error { defer p.Unlock() p.Lock() return p.ApplicationACLs.AddRuleList(rules) }
go
func (p *PUContext) UpdateApplicationACLs(rules policy.IPRuleList) error { defer p.Unlock() p.Lock() return p.ApplicationACLs.AddRuleList(rules) }
[ "func", "(", "p", "*", "PUContext", ")", "UpdateApplicationACLs", "(", "rules", "policy", ".", "IPRuleList", ")", "error", "{", "defer", "p", ".", "Unlock", "(", ")", "\n", "p", ".", "Lock", "(", ")", "\n", "return", "p", ".", "ApplicationACLs", ".", "AddRuleList", "(", "rules", ")", "\n", "}" ]
// UpdateApplicationACLs updates the application ACL policy
[ "UpdateApplicationACLs", "updates", "the", "application", "ACL", "policy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L275-L279
6,983
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
UpdateNetworkACLs
func (p *PUContext) UpdateNetworkACLs(rules policy.IPRuleList) error { defer p.Unlock() p.Lock() return p.networkACLs.AddRuleList(rules) }
go
func (p *PUContext) UpdateNetworkACLs(rules policy.IPRuleList) error { defer p.Unlock() p.Lock() return p.networkACLs.AddRuleList(rules) }
[ "func", "(", "p", "*", "PUContext", ")", "UpdateNetworkACLs", "(", "rules", "policy", ".", "IPRuleList", ")", "error", "{", "defer", "p", ".", "Unlock", "(", ")", "\n", "p", ".", "Lock", "(", ")", "\n", "return", "p", ".", "networkACLs", ".", "AddRuleList", "(", "rules", ")", "\n", "}" ]
// UpdateNetworkACLs updates the network ACL policy
[ "UpdateNetworkACLs", "updates", "the", "network", "ACL", "policy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L282-L286
6,984
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
CacheExternalFlowPolicy
func (p *PUContext) CacheExternalFlowPolicy(packet *packet.Packet, plc interface{}) { p.externalIPCache.AddOrUpdate(packet.SourceAddress().String()+":"+strconv.Itoa(int(packet.SourcePort())), plc) }
go
func (p *PUContext) CacheExternalFlowPolicy(packet *packet.Packet, plc interface{}) { p.externalIPCache.AddOrUpdate(packet.SourceAddress().String()+":"+strconv.Itoa(int(packet.SourcePort())), plc) }
[ "func", "(", "p", "*", "PUContext", ")", "CacheExternalFlowPolicy", "(", "packet", "*", "packet", ".", "Packet", ",", "plc", "interface", "{", "}", ")", "{", "p", ".", "externalIPCache", ".", "AddOrUpdate", "(", "packet", ".", "SourceAddress", "(", ")", ".", "String", "(", ")", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "int", "(", "packet", ".", "SourcePort", "(", ")", ")", ")", ",", "plc", ")", "\n", "}" ]
// CacheExternalFlowPolicy will cache an external flow
[ "CacheExternalFlowPolicy", "will", "cache", "an", "external", "flow" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L289-L291
6,985
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
GetProcessKeys
func (p *PUContext) GetProcessKeys() (string, []string, []string) { return p.mark, p.tcpPorts, p.udpPorts }
go
func (p *PUContext) GetProcessKeys() (string, []string, []string) { return p.mark, p.tcpPorts, p.udpPorts }
[ "func", "(", "p", "*", "PUContext", ")", "GetProcessKeys", "(", ")", "(", "string", ",", "[", "]", "string", ",", "[", "]", "string", ")", "{", "return", "p", ".", "mark", ",", "p", ".", "tcpPorts", ",", "p", ".", "udpPorts", "\n", "}" ]
// GetProcessKeys returns the cache keys for a process
[ "GetProcessKeys", "returns", "the", "cache", "keys", "for", "a", "process" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L294-L296
6,986
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
SynServiceContext
func (p *PUContext) SynServiceContext() []byte { p.RLock() defer p.RUnlock() return p.synServiceContext }
go
func (p *PUContext) SynServiceContext() []byte { p.RLock() defer p.RUnlock() return p.synServiceContext }
[ "func", "(", "p", "*", "PUContext", ")", "SynServiceContext", "(", ")", "[", "]", "byte", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "return", "p", ".", "synServiceContext", "\n", "}" ]
// SynServiceContext returns synServiceContext
[ "SynServiceContext", "returns", "synServiceContext" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L299-L303
6,987
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
UpdateSynServiceContext
func (p *PUContext) UpdateSynServiceContext(synServiceContext []byte) { p.Lock() p.synServiceContext = synServiceContext p.Unlock() }
go
func (p *PUContext) UpdateSynServiceContext(synServiceContext []byte) { p.Lock() p.synServiceContext = synServiceContext p.Unlock() }
[ "func", "(", "p", "*", "PUContext", ")", "UpdateSynServiceContext", "(", "synServiceContext", "[", "]", "byte", ")", "{", "p", ".", "Lock", "(", ")", "\n", "p", ".", "synServiceContext", "=", "synServiceContext", "\n", "p", ".", "Unlock", "(", ")", "\n", "}" ]
// UpdateSynServiceContext updates the synServiceContext
[ "UpdateSynServiceContext", "updates", "the", "synServiceContext" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L306-L311
6,988
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
GetCachedTokenAndServiceContext
func (p *PUContext) GetCachedTokenAndServiceContext() ([]byte, []byte, error) { p.RLock() defer p.RUnlock() if p.synExpiration.After(time.Now()) && len(p.synToken) > 0 { token := make([]byte, len(p.synToken)) copy(token, p.synToken) return token, p.synServiceContext, nil } return nil, nil, fmt.Errorf("expired Token") }
go
func (p *PUContext) GetCachedTokenAndServiceContext() ([]byte, []byte, error) { p.RLock() defer p.RUnlock() if p.synExpiration.After(time.Now()) && len(p.synToken) > 0 { token := make([]byte, len(p.synToken)) copy(token, p.synToken) return token, p.synServiceContext, nil } return nil, nil, fmt.Errorf("expired Token") }
[ "func", "(", "p", "*", "PUContext", ")", "GetCachedTokenAndServiceContext", "(", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n\n", "if", "p", ".", "synExpiration", ".", "After", "(", "time", ".", "Now", "(", ")", ")", "&&", "len", "(", "p", ".", "synToken", ")", ">", "0", "{", "token", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "p", ".", "synToken", ")", ")", "\n", "copy", "(", "token", ",", "p", ".", "synToken", ")", "\n", "return", "token", ",", "p", ".", "synServiceContext", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// GetCachedTokenAndServiceContext returns the cached syn packet token
[ "GetCachedTokenAndServiceContext", "returns", "the", "cached", "syn", "packet", "token" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L314-L326
6,989
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
UpdateCachedTokenAndServiceContext
func (p *PUContext) UpdateCachedTokenAndServiceContext(token []byte, serviceContext []byte) { p.Lock() p.synToken = token p.synExpiration = time.Now().Add(time.Millisecond * 500) p.synServiceContext = serviceContext p.Unlock() }
go
func (p *PUContext) UpdateCachedTokenAndServiceContext(token []byte, serviceContext []byte) { p.Lock() p.synToken = token p.synExpiration = time.Now().Add(time.Millisecond * 500) p.synServiceContext = serviceContext p.Unlock() }
[ "func", "(", "p", "*", "PUContext", ")", "UpdateCachedTokenAndServiceContext", "(", "token", "[", "]", "byte", ",", "serviceContext", "[", "]", "byte", ")", "{", "p", ".", "Lock", "(", ")", "\n\n", "p", ".", "synToken", "=", "token", "\n", "p", ".", "synExpiration", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "time", ".", "Millisecond", "*", "500", ")", "\n", "p", ".", "synServiceContext", "=", "serviceContext", "\n\n", "p", ".", "Unlock", "(", ")", "\n\n", "}" ]
// UpdateCachedTokenAndServiceContext updates the local cached token
[ "UpdateCachedTokenAndServiceContext", "updates", "the", "local", "cached", "token" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L329-L339
6,990
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
Scopes
func (p *PUContext) Scopes() []string { p.RLock() defer p.RUnlock() return p.scopes }
go
func (p *PUContext) Scopes() []string { p.RLock() defer p.RUnlock() return p.scopes }
[ "func", "(", "p", "*", "PUContext", ")", "Scopes", "(", ")", "[", "]", "string", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n\n", "return", "p", ".", "scopes", "\n", "}" ]
// Scopes returns the scopes.
[ "Scopes", "returns", "the", "scopes", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L342-L347
6,991
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
GetJWT
func (p *PUContext) GetJWT() (string, error) { p.RLock() defer p.RUnlock() if p.jwtExpiration.After(time.Now()) && len(p.jwt) > 0 { return p.jwt, nil } return "", fmt.Errorf("expired token") }
go
func (p *PUContext) GetJWT() (string, error) { p.RLock() defer p.RUnlock() if p.jwtExpiration.After(time.Now()) && len(p.jwt) > 0 { return p.jwt, nil } return "", fmt.Errorf("expired token") }
[ "func", "(", "p", "*", "PUContext", ")", "GetJWT", "(", ")", "(", "string", ",", "error", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n\n", "if", "p", ".", "jwtExpiration", ".", "After", "(", "time", ".", "Now", "(", ")", ")", "&&", "len", "(", "p", ".", "jwt", ")", ">", "0", "{", "return", "p", ".", "jwt", ",", "nil", "\n", "}", "\n\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// GetJWT retrieves the JWT if it exists in the cache. Returns error otherwise.
[ "GetJWT", "retrieves", "the", "JWT", "if", "it", "exists", "in", "the", "cache", ".", "Returns", "error", "otherwise", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L350-L359
6,992
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
UpdateJWT
func (p *PUContext) UpdateJWT(jwt string, expiration time.Time) { p.Lock() defer p.Unlock() p.jwt = jwt p.jwtExpiration = expiration }
go
func (p *PUContext) UpdateJWT(jwt string, expiration time.Time) { p.Lock() defer p.Unlock() p.jwt = jwt p.jwtExpiration = expiration }
[ "func", "(", "p", "*", "PUContext", ")", "UpdateJWT", "(", "jwt", "string", ",", "expiration", "time", ".", "Time", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "p", ".", "jwt", "=", "jwt", "\n", "p", ".", "jwtExpiration", "=", "expiration", "\n", "}" ]
// UpdateJWT updates the JWT and provides a new expiration date.
[ "UpdateJWT", "updates", "the", "JWT", "and", "provides", "a", "new", "expiration", "date", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L362-L368
6,993
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
createRuleDBs
func (p *PUContext) createRuleDBs(policyRules policy.TagSelectorList) *policies { policyDB := &policies{ rejectRules: lookup.NewPolicyDB(), observeRejectRules: lookup.NewPolicyDB(), acceptRules: lookup.NewPolicyDB(), observeAcceptRules: lookup.NewPolicyDB(), observeApplyRules: lookup.NewPolicyDB(), encryptRules: lookup.NewPolicyDB(), } for _, rule := range policyRules { // Add encrypt rule to encrypt table. if rule.Policy.Action.Encrypted() { policyDB.encryptRules.AddPolicy(rule) } if rule.Policy.ObserveAction.ObserveContinue() { if rule.Policy.Action.Accepted() { policyDB.observeAcceptRules.AddPolicy(rule) } else if rule.Policy.Action.Rejected() { policyDB.observeRejectRules.AddPolicy(rule) } } else if rule.Policy.ObserveAction.ObserveApply() { policyDB.observeApplyRules.AddPolicy(rule) } else if rule.Policy.Action.Accepted() { policyDB.acceptRules.AddPolicy(rule) } else if rule.Policy.Action.Rejected() { policyDB.rejectRules.AddPolicy(rule) } else { continue } } return policyDB }
go
func (p *PUContext) createRuleDBs(policyRules policy.TagSelectorList) *policies { policyDB := &policies{ rejectRules: lookup.NewPolicyDB(), observeRejectRules: lookup.NewPolicyDB(), acceptRules: lookup.NewPolicyDB(), observeAcceptRules: lookup.NewPolicyDB(), observeApplyRules: lookup.NewPolicyDB(), encryptRules: lookup.NewPolicyDB(), } for _, rule := range policyRules { // Add encrypt rule to encrypt table. if rule.Policy.Action.Encrypted() { policyDB.encryptRules.AddPolicy(rule) } if rule.Policy.ObserveAction.ObserveContinue() { if rule.Policy.Action.Accepted() { policyDB.observeAcceptRules.AddPolicy(rule) } else if rule.Policy.Action.Rejected() { policyDB.observeRejectRules.AddPolicy(rule) } } else if rule.Policy.ObserveAction.ObserveApply() { policyDB.observeApplyRules.AddPolicy(rule) } else if rule.Policy.Action.Accepted() { policyDB.acceptRules.AddPolicy(rule) } else if rule.Policy.Action.Rejected() { policyDB.rejectRules.AddPolicy(rule) } else { continue } } return policyDB }
[ "func", "(", "p", "*", "PUContext", ")", "createRuleDBs", "(", "policyRules", "policy", ".", "TagSelectorList", ")", "*", "policies", "{", "policyDB", ":=", "&", "policies", "{", "rejectRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "observeRejectRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "acceptRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "observeAcceptRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "observeApplyRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "encryptRules", ":", "lookup", ".", "NewPolicyDB", "(", ")", ",", "}", "\n\n", "for", "_", ",", "rule", ":=", "range", "policyRules", "{", "// Add encrypt rule to encrypt table.", "if", "rule", ".", "Policy", ".", "Action", ".", "Encrypted", "(", ")", "{", "policyDB", ".", "encryptRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "\n\n", "if", "rule", ".", "Policy", ".", "ObserveAction", ".", "ObserveContinue", "(", ")", "{", "if", "rule", ".", "Policy", ".", "Action", ".", "Accepted", "(", ")", "{", "policyDB", ".", "observeAcceptRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "else", "if", "rule", ".", "Policy", ".", "Action", ".", "Rejected", "(", ")", "{", "policyDB", ".", "observeRejectRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "\n", "}", "else", "if", "rule", ".", "Policy", ".", "ObserveAction", ".", "ObserveApply", "(", ")", "{", "policyDB", ".", "observeApplyRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "else", "if", "rule", ".", "Policy", ".", "Action", ".", "Accepted", "(", ")", "{", "policyDB", ".", "acceptRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "else", "if", "rule", ".", "Policy", ".", "Action", ".", "Rejected", "(", ")", "{", "policyDB", ".", "rejectRules", ".", "AddPolicy", "(", "rule", ")", "\n", "}", "else", "{", "continue", "\n", "}", "\n", "}", "\n", "return", "policyDB", "\n", "}" ]
// createRuleDBs creates the database of rules from the policy
[ "createRuleDBs", "creates", "the", "database", "of", "rules", "from", "the", "policy" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L371-L405
6,994
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
CreateRcvRules
func (p *PUContext) CreateRcvRules(policyRules policy.TagSelectorList) { p.rcv = p.createRuleDBs(policyRules) }
go
func (p *PUContext) CreateRcvRules(policyRules policy.TagSelectorList) { p.rcv = p.createRuleDBs(policyRules) }
[ "func", "(", "p", "*", "PUContext", ")", "CreateRcvRules", "(", "policyRules", "policy", ".", "TagSelectorList", ")", "{", "p", ".", "rcv", "=", "p", ".", "createRuleDBs", "(", "policyRules", ")", "\n", "}" ]
// CreateRcvRules create receive rules for this PU based on the update of the policy.
[ "CreateRcvRules", "create", "receive", "rules", "for", "this", "PU", "based", "on", "the", "update", "of", "the", "policy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L408-L410
6,995
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
CreateTxtRules
func (p *PUContext) CreateTxtRules(policyRules policy.TagSelectorList) { p.txt = p.createRuleDBs(policyRules) }
go
func (p *PUContext) CreateTxtRules(policyRules policy.TagSelectorList) { p.txt = p.createRuleDBs(policyRules) }
[ "func", "(", "p", "*", "PUContext", ")", "CreateTxtRules", "(", "policyRules", "policy", ".", "TagSelectorList", ")", "{", "p", ".", "txt", "=", "p", ".", "createRuleDBs", "(", "policyRules", ")", "\n", "}" ]
// CreateTxtRules create receive rules for this PU based on the update of the policy.
[ "CreateTxtRules", "create", "receive", "rules", "for", "this", "PU", "based", "on", "the", "update", "of", "the", "policy", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L413-L415
6,996
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
searchRules
func (p *PUContext) searchRules( policies *policies, tags *policy.TagStore, skipRejectPolicies bool, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { var reportingAction *policy.FlowPolicy var packetAction *policy.FlowPolicy if !skipRejectPolicies { // Look for rejection rules observeIndex, observeAction := policies.observeRejectRules.Search(tags) if observeIndex >= 0 { reportingAction = observeAction.(*policy.FlowPolicy) } index, action := policies.rejectRules.Search(tags) if index >= 0 { packetAction = action.(*policy.FlowPolicy) if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } } if reportingAction == nil { // Look for allow rules observeIndex, observeAction := policies.observeAcceptRules.Search(tags) if observeIndex >= 0 { reportingAction = observeAction.(*policy.FlowPolicy) } } index, action := policies.acceptRules.Search(tags) if index >= 0 { packetAction = action.(*policy.FlowPolicy) // Look for encrypt rules encryptIndex, _ := policies.encryptRules.Search(tags) if encryptIndex >= 0 { // Do not overwrite the action for accept rules. finalAction := action.(*policy.FlowPolicy) packetAction = &policy.FlowPolicy{ Action: policy.Accept | policy.Encrypt, PolicyID: finalAction.PolicyID, ServiceID: finalAction.ServiceID, } } if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } // Look for observe apply rules observeIndex, observeAction := policies.observeApplyRules.Search(tags) if observeIndex >= 0 { packetAction = observeAction.(*policy.FlowPolicy) if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } // Handle default if nothing provides to drop with no policyID. packetAction = &policy.FlowPolicy{ Action: policy.Reject, PolicyID: "default", } if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction }
go
func (p *PUContext) searchRules( policies *policies, tags *policy.TagStore, skipRejectPolicies bool, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { var reportingAction *policy.FlowPolicy var packetAction *policy.FlowPolicy if !skipRejectPolicies { // Look for rejection rules observeIndex, observeAction := policies.observeRejectRules.Search(tags) if observeIndex >= 0 { reportingAction = observeAction.(*policy.FlowPolicy) } index, action := policies.rejectRules.Search(tags) if index >= 0 { packetAction = action.(*policy.FlowPolicy) if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } } if reportingAction == nil { // Look for allow rules observeIndex, observeAction := policies.observeAcceptRules.Search(tags) if observeIndex >= 0 { reportingAction = observeAction.(*policy.FlowPolicy) } } index, action := policies.acceptRules.Search(tags) if index >= 0 { packetAction = action.(*policy.FlowPolicy) // Look for encrypt rules encryptIndex, _ := policies.encryptRules.Search(tags) if encryptIndex >= 0 { // Do not overwrite the action for accept rules. finalAction := action.(*policy.FlowPolicy) packetAction = &policy.FlowPolicy{ Action: policy.Accept | policy.Encrypt, PolicyID: finalAction.PolicyID, ServiceID: finalAction.ServiceID, } } if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } // Look for observe apply rules observeIndex, observeAction := policies.observeApplyRules.Search(tags) if observeIndex >= 0 { packetAction = observeAction.(*policy.FlowPolicy) if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction } // Handle default if nothing provides to drop with no policyID. packetAction = &policy.FlowPolicy{ Action: policy.Reject, PolicyID: "default", } if reportingAction == nil { reportingAction = packetAction } return reportingAction, packetAction }
[ "func", "(", "p", "*", "PUContext", ")", "searchRules", "(", "policies", "*", "policies", ",", "tags", "*", "policy", ".", "TagStore", ",", "skipRejectPolicies", "bool", ",", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "packet", "*", "policy", ".", "FlowPolicy", ")", "{", "var", "reportingAction", "*", "policy", ".", "FlowPolicy", "\n", "var", "packetAction", "*", "policy", ".", "FlowPolicy", "\n\n", "if", "!", "skipRejectPolicies", "{", "// Look for rejection rules", "observeIndex", ",", "observeAction", ":=", "policies", ".", "observeRejectRules", ".", "Search", "(", "tags", ")", "\n", "if", "observeIndex", ">=", "0", "{", "reportingAction", "=", "observeAction", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "}", "\n\n", "index", ",", "action", ":=", "policies", ".", "rejectRules", ".", "Search", "(", "tags", ")", "\n", "if", "index", ">=", "0", "{", "packetAction", "=", "action", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "if", "reportingAction", "==", "nil", "{", "reportingAction", "=", "packetAction", "\n", "}", "\n", "return", "reportingAction", ",", "packetAction", "\n", "}", "\n", "}", "\n\n", "if", "reportingAction", "==", "nil", "{", "// Look for allow rules", "observeIndex", ",", "observeAction", ":=", "policies", ".", "observeAcceptRules", ".", "Search", "(", "tags", ")", "\n", "if", "observeIndex", ">=", "0", "{", "reportingAction", "=", "observeAction", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "}", "\n", "}", "\n\n", "index", ",", "action", ":=", "policies", ".", "acceptRules", ".", "Search", "(", "tags", ")", "\n", "if", "index", ">=", "0", "{", "packetAction", "=", "action", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "// Look for encrypt rules", "encryptIndex", ",", "_", ":=", "policies", ".", "encryptRules", ".", "Search", "(", "tags", ")", "\n", "if", "encryptIndex", ">=", "0", "{", "// Do not overwrite the action for accept rules.", "finalAction", ":=", "action", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "packetAction", "=", "&", "policy", ".", "FlowPolicy", "{", "Action", ":", "policy", ".", "Accept", "|", "policy", ".", "Encrypt", ",", "PolicyID", ":", "finalAction", ".", "PolicyID", ",", "ServiceID", ":", "finalAction", ".", "ServiceID", ",", "}", "\n", "}", "\n", "if", "reportingAction", "==", "nil", "{", "reportingAction", "=", "packetAction", "\n", "}", "\n", "return", "reportingAction", ",", "packetAction", "\n", "}", "\n\n", "// Look for observe apply rules", "observeIndex", ",", "observeAction", ":=", "policies", ".", "observeApplyRules", ".", "Search", "(", "tags", ")", "\n", "if", "observeIndex", ">=", "0", "{", "packetAction", "=", "observeAction", ".", "(", "*", "policy", ".", "FlowPolicy", ")", "\n", "if", "reportingAction", "==", "nil", "{", "reportingAction", "=", "packetAction", "\n", "}", "\n", "return", "reportingAction", ",", "packetAction", "\n", "}", "\n\n", "// Handle default if nothing provides to drop with no policyID.", "packetAction", "=", "&", "policy", ".", "FlowPolicy", "{", "Action", ":", "policy", ".", "Reject", ",", "PolicyID", ":", "\"", "\"", ",", "}", "\n\n", "if", "reportingAction", "==", "nil", "{", "reportingAction", "=", "packetAction", "\n", "}", "\n\n", "return", "reportingAction", ",", "packetAction", "\n", "}" ]
// searchRules searches all reject, accpet and observed rules and returns reporting and packet forwarding action
[ "searchRules", "searches", "all", "reject", "accpet", "and", "observed", "rules", "and", "returns", "reporting", "and", "packet", "forwarding", "action" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L418-L493
6,997
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
SearchTxtRules
func (p *PUContext) SearchTxtRules( tags *policy.TagStore, skipRejectPolicies bool, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { return p.searchRules(p.txt, tags, skipRejectPolicies) }
go
func (p *PUContext) SearchTxtRules( tags *policy.TagStore, skipRejectPolicies bool, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { return p.searchRules(p.txt, tags, skipRejectPolicies) }
[ "func", "(", "p", "*", "PUContext", ")", "SearchTxtRules", "(", "tags", "*", "policy", ".", "TagStore", ",", "skipRejectPolicies", "bool", ",", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "packet", "*", "policy", ".", "FlowPolicy", ")", "{", "return", "p", ".", "searchRules", "(", "p", ".", "txt", ",", "tags", ",", "skipRejectPolicies", ")", "\n", "}" ]
// SearchTxtRules searches both receive and observed transmit rules and returns the index and action
[ "SearchTxtRules", "searches", "both", "receive", "and", "observed", "transmit", "rules", "and", "returns", "the", "index", "and", "action" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L496-L501
6,998
aporeto-inc/trireme-lib
controller/pkg/pucontext/pucontext.go
SearchRcvRules
func (p *PUContext) SearchRcvRules( tags *policy.TagStore, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { return p.searchRules(p.rcv, tags, false) }
go
func (p *PUContext) SearchRcvRules( tags *policy.TagStore, ) (report *policy.FlowPolicy, packet *policy.FlowPolicy) { return p.searchRules(p.rcv, tags, false) }
[ "func", "(", "p", "*", "PUContext", ")", "SearchRcvRules", "(", "tags", "*", "policy", ".", "TagStore", ",", ")", "(", "report", "*", "policy", ".", "FlowPolicy", ",", "packet", "*", "policy", ".", "FlowPolicy", ")", "{", "return", "p", ".", "searchRules", "(", "p", ".", "rcv", ",", "tags", ",", "false", ")", "\n", "}" ]
// SearchRcvRules searches both receive and observed receive rules and returns the index and action
[ "SearchRcvRules", "searches", "both", "receive", "and", "observed", "receive", "rules", "and", "returns", "the", "index", "and", "action" ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/pkg/pucontext/pucontext.go#L504-L508
6,999
aporeto-inc/trireme-lib
controller/internal/enforcer/applicationproxy/serviceregistry/serviceregistry.go
Register
func (r *Registry) Register( puID string, pu *policy.PUInfo, puContext *pucontext.PUContext, secrets secrets.Secrets, ) (*ServiceContext, error) { r.Lock() defer r.Unlock() sctx := &ServiceContext{ PU: pu, PUContext: puContext, dependentServiceCache: servicecache.NewTable(), RootCA: [][]byte{}, } // Delete all old references first. Since the registry is locked // nobody will be affected. r.indexByPort.DeleteByID(puID, true) r.indexByPort.DeleteByID(puID, false) if err := r.updateDependentServices(sctx); err != nil { return nil, err } if err := r.updateExposedServices(sctx, secrets); err != nil { return nil, err } r.indexByName[puID] = sctx return sctx, nil }
go
func (r *Registry) Register( puID string, pu *policy.PUInfo, puContext *pucontext.PUContext, secrets secrets.Secrets, ) (*ServiceContext, error) { r.Lock() defer r.Unlock() sctx := &ServiceContext{ PU: pu, PUContext: puContext, dependentServiceCache: servicecache.NewTable(), RootCA: [][]byte{}, } // Delete all old references first. Since the registry is locked // nobody will be affected. r.indexByPort.DeleteByID(puID, true) r.indexByPort.DeleteByID(puID, false) if err := r.updateDependentServices(sctx); err != nil { return nil, err } if err := r.updateExposedServices(sctx, secrets); err != nil { return nil, err } r.indexByName[puID] = sctx return sctx, nil }
[ "func", "(", "r", "*", "Registry", ")", "Register", "(", "puID", "string", ",", "pu", "*", "policy", ".", "PUInfo", ",", "puContext", "*", "pucontext", ".", "PUContext", ",", "secrets", "secrets", ".", "Secrets", ",", ")", "(", "*", "ServiceContext", ",", "error", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "sctx", ":=", "&", "ServiceContext", "{", "PU", ":", "pu", ",", "PUContext", ":", "puContext", ",", "dependentServiceCache", ":", "servicecache", ".", "NewTable", "(", ")", ",", "RootCA", ":", "[", "]", "[", "]", "byte", "{", "}", ",", "}", "\n\n", "// Delete all old references first. Since the registry is locked", "// nobody will be affected.", "r", ".", "indexByPort", ".", "DeleteByID", "(", "puID", ",", "true", ")", "\n", "r", ".", "indexByPort", ".", "DeleteByID", "(", "puID", ",", "false", ")", "\n\n", "if", "err", ":=", "r", ".", "updateDependentServices", "(", "sctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "r", ".", "updateExposedServices", "(", "sctx", ",", "secrets", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "r", ".", "indexByName", "[", "puID", "]", "=", "sctx", "\n\n", "return", "sctx", ",", "nil", "\n", "}" ]
// Register registers a new service with the registry. If the service // already exists it updates the service with the new information, otherwise // it creates a new service.
[ "Register", "registers", "a", "new", "service", "with", "the", "registry", ".", "If", "the", "service", "already", "exists", "it", "updates", "the", "service", "with", "the", "new", "information", "otherwise", "it", "creates", "a", "new", "service", "." ]
009258cf9b4f3f70f71994d9fadebe564f7e0437
https://github.com/aporeto-inc/trireme-lib/blob/009258cf9b4f3f70f71994d9fadebe564f7e0437/controller/internal/enforcer/applicationproxy/serviceregistry/serviceregistry.go#L78-L111