Files
kubeshark/api/pkg/resolver
nimrod-up9 6f47ad862e TRA-3317 Tap and show outbound traffic (#83)
* Tap outgoing: If --anydirection flag is passed with HOST_MODE, tap by source IP.

* Moved ConnectionInfo from http_matcher to http_reader.

* Generalized shouldTap in stream factory to get more properties.

* tap reports IsOutgoing property of tcp connection.

* gofmt.

* CLI instructs tapper to tap outgoing connections.

* API saves IsOutgoing to DB and passes it to UI.

* Add a visual marker in the HAR list for outgoing messages.

* Fixed: Swapped src and dst.

* Resolver keeps a list of all ClusterIP services.

* Do not save HARs with destination ClusterIP services.

* CLI accepts flag that controls traffic direction.

* Indicate incoming/outgoing with icon instead of with border color.

* Fixed: Didn't filter messages to services in aggregator.

* Clearer syntax around the direction icon. Added title text.

* Fixed width around direction icon.

* Less repetition.

* Removed TODO.

* Renamed incoming -> ingoing.

* More verbose title text to image.

* Switched routine order for readability.
2021-06-24 15:10:11 +03:00
..

Usage

Full example

errOut := make(chan error, 100)
k8sResolver, err := resolver.NewFromOutOfCluster("", errOut)
if err != nil {
    fmt.Printf("error creating k8s resolver %s", err)
}

ctx, cancel := context.WithCancel(context.Background())
k8sResolver.Start(ctx)

resolvedName := k8sResolver.Resolve("10.107.251.91") // will always return `nil` in real scenarios as the internal map takes a moment to populate after `Start` is called
if resolvedName != nil {
    fmt.Printf("resolved 10.107.251.91=%s", *resolvedName)
} else {
    fmt.Printf("Could not find a resolved name for 10.107.251.91")
}

for {
    select {
        case err := <- errOut:
            fmt.Printf("name resolving error %s", err)
    }
}

In cluster authentication

Create resolver using the function NewFromInCluster(errOut chan error)

Out of cluster authentication

Create resolver using the function NewFromOutOfCluster(kubeConfigPath string, errOut chan error)

the kubeConfigPath param is optional, pass an empty string "" for resolver to auto locate the default kubeconfig file

Error handling

Please ensure there is always a thread reading from the errOut channel, not doing so will result in the resolver threads getting blocked and the resolver will fail to update.

Also note that any error you receive through this channel does not necessarily mean that resolver is no longer running. the resolver will infinitely retry watching k8s resources until the provided context is cancelled.