Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add SentryFlow client #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ observability. It includes detailed commands for each step along with their expl

## 2. Deploying SentryFlow

Configure SentryFlow receiver by following [this](receivers.md). Then deploy updated SentryFlow manifest by following `kubectl` command:
Configure SentryFlow receiver by following [this](receivers.md). Then deploy updated SentryFlow manifest by following
`kubectl` command:

```shell
kubectl apply -f sentryflow.yaml
Expand All @@ -29,24 +30,29 @@ NAME READY STATUS RESTARTS AGE
sentryflow-cff887bbd-rljm7 1/1 Running 0 73s
```

## 3. Deploying SentryFlow Clients
## 3. Viewing Captured API Access Events Clients

SentryFlow has now been deployed in the cluster. In addition, SentryFlow exports API access logs through `gRPC`.
SentryFlow has now been deployed in the cluster. In addition, SentryFlow exports API access events through `gRPC`.

For testing purposes, a client has been developed.

- `log-client`: Simply logs everything on `STDOUT` coming from SentryFlow.

It can be deployed into the cluster under namespace `sentryflow` by following the command:
You can use `sfctl` the SentryFlow client to view or filter captured API access events

```shell
kubectl apply -f https://raw.githubusercontent.com/5GSEC/SentryFlow/refs/heads/main/deployments/sentryflow-client.yaml
$ sfctl event
{"level":"INFO","timestamp":"2025-01-08T18:15:31.720+0530","caller":"apievent/common.go:165","msg":"starting API Events streaming"}
{"level":"INFO","timestamp":"2025-01-08T18:15:31.771+0530","caller":"apievent/common.go:171","msg":"started API Events streaming"}
# API Access Events
{"metadata":{"context_id":9,"timestamp":1736340391,"istio_version":"1.24.1","mesh_id":"cluster.local","node_name":"kind-control-plane"},"source":{"name":"server-c7669846-w5v8m","namespace":"default","ip":"10.244.0.8","port":57754},"destination":{"namespace":"sentryflow","ip":"10.96.79.211","port":9999},"request":{"headers":{":authority":"sentryflow.sentryflow:9999",":method":"HEAD",":path":"/",":scheme":"http","accept":"*/*","user-agent":"curl/7.88.1","x-forwarded-proto":"http","x-request-id":"9ff1f0fb-adca-4cbb-bfbb-7927d5aa02ae"}},"response":{"headers":{":status":"404","content-length":"19","content-type":"text/plain; charset=utf-8","date":"Wed, 08 Jan 2025 12:46:31 GMT","x-content-type-options":"nosniff"}},"protocol":"HTTP/1.1"}
...
```

Then, check if it is up and running by:
### Filter API Events based on some Response Status Code

```shell
kubectl get pods -n sentryflow
$ sfctl event filter --status "4xx"
{"level":"INFO","timestamp":"2025-01-08T18:20:37.096+0530","caller":"apievent/common.go:165","msg":"starting API Events streaming"}
{"level":"INFO","timestamp":"2025-01-08T18:20:37.151+0530","caller":"apievent/common.go:171","msg":"started API Events streaming"}
# API Access Events
{"metadata":{"context_id":10,"timestamp":1736340639,"istio_version":"1.24.1","mesh_id":"cluster.local","node_name":"kind-control-plane"},"source":{"name":"server-c7669846-w5v8m","namespace":"default","ip":"10.244.0.8","port":37154},"destination":{"namespace":"sentryflow","ip":"10.96.79.211","port":9999},"request":{"headers":{":authority":"sentryflow.sentryflow:9999",":method":"HEAD",":path":"/",":scheme":"http","accept":"*/*","user-agent":"curl/7.88.1","x-forwarded-proto":"http","x-request-id":"e20a1002-09d1-4f3f-936e-ce688652ea4d"}},"response":{"headers":{":status":"404","content-length":"19","content-type":"text/plain; charset=utf-8","date":"Wed, 08 Jan 2025 12:50:39 GMT","x-content-type-options":"nosniff"}},"protocol":"HTTP/1.1"}
```

If you observe `log-client`, is running, the setup has been completed successfully.
For more info check [this](../sfctl/README.md).
2 changes: 1 addition & 1 deletion hack/add-license-header
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! command -v addlicense >/dev/null; then
fi

GIT_ROOT=$(git rev-parse --show-toplevel)
LICENSE_HEADER=${GIT_ROOT}/scripts/license.header
LICENSE_HEADER=${GIT_ROOT}/hack/license.header

if [ -z "$1" ]; then
echo "No Argument Supplied, Checking and Fixing all files from project root"
Expand Down
44 changes: 44 additions & 0 deletions sfctl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Authors of SentryFlow

BINARY_NAME ?= sfctl
VERSION ?= $(shell git rev-parse HEAD)
BUILD_TS ?= $(shell date)

.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help

##@ Development
.PHONY: fmt
fmt: ## Run go fmt against code
@go fmt ./...

.PHONY: vet
vet: ## Run go vet against code
@go vet ./...

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.63.0
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
@$(GOLANGCI_LINT) run

.PHONY: license
license: ## Check and fix license header on all go files
@../hack/add-license-header

##@ Build

.PHONY: build
build: fmt vet ## Build sfctl binary
@go mod tidy
@CGO_ENABLED=0 go build -ldflags="-s" -o bin/"${BINARY_NAME}" .
24 changes: 24 additions & 0 deletions sfctl/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# sfctl

SentryFlow CLI to view and filter captured API events streamed from SentryFlow
```shell
$ sfctl
SentryFlow command-line utility for managing captured API events.

Usage:
sfctl [flags]
sfctl [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
event Print the captured API Events
help Help about any command
version Display version information

Flags:
--context string name of the kubeconfig context to use
-h, --help help for sfctl
--kubeconfig string path to the kubeconfig file

Use "sfctl [command] --help" for more information about a command.
```
42 changes: 42 additions & 0 deletions sfctl/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Authors of SentryFlow

package cmd

import (
"os"

"github.com/spf13/cobra"

"github.com/5GSEC/SentryFlow/sfctl/pkg/apievent"
"github.com/5GSEC/SentryFlow/sfctl/pkg/version"
)

var (
kubeConfig string
context string
)

// Todo: Improve the description

func init() {
rootCmd.PersistentFlags().StringVar(&kubeConfig, "kubeconfig", "", "path to the kubeconfig file")
rootCmd.PersistentFlags().StringVar(&context, "context", "", "name of the kubeconfig context to use")
rootCmd.AddCommand(version.VersionCmd, apievent.EventCmd)
}

var rootCmd = &cobra.Command{
Use: "sfctl",
Short: "Manage SentryFlow API events.",
Long: `SentryFlow command-line utility for managing captured API events.`,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
return cmd.Help()
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
88 changes: 88 additions & 0 deletions sfctl/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module github.com/5GSEC/SentryFlow/sfctl

go 1.23.0

toolchain go1.23.4

require (
github.com/5GSEC/SentryFlow/protobuf/golang v0.0.0-20241211042917-1aaef73db0bc
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.66.2
k8s.io/apimachinery v0.32.0
k8s.io/cli-runtime v0.32.0
k8s.io/client-go v0.32.0
sigs.k8s.io/controller-runtime v0.19.3
)

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.32.0 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/kustomize/api v0.18.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.18.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading
Loading