Compare commits

..

10 Commits

Author SHA1 Message Date
Roee Gadot
193fc2becc no message 2021-07-15 14:38:07 +03:00
Roee Gadot
9b616839bc Merge branch 'feature/TRA-3442_versioning' into feature/versioning 2021-07-15 14:35:42 +03:00
nimrod-up9
29ed9edb64 Added endpoint for metadata. 2021-07-15 14:34:48 +03:00
Roee Gadot
c88d068bfa no message 2021-07-15 14:34:40 +03:00
Roee Gadot
f839212b30 no message 2021-07-15 14:09:27 +03:00
Roee Gadot
6b7cb16a9f no message 2021-07-15 13:46:24 +03:00
Roee Gadot
919a5e6e6d no message 2021-07-15 13:28:56 +03:00
nimrod-up9
69dbd81837 Renamed public_routes.go -> entries_routes.go 2021-07-15 13:26:47 +03:00
nimrod-up9
d93913733e Moved version parser to shared. 2021-07-15 13:20:42 +03:00
nimrod-up9
7e52f46030 Default image uses semver. 2021-07-15 13:00:42 +03:00
17 changed files with 21 additions and 176 deletions

View File

@@ -4,6 +4,7 @@ on:
branches:
- 'develop'
- 'main'
- 'feature/versioning'
jobs:
docker:
runs-on: ubuntu-latest

View File

@@ -26,49 +26,6 @@ SHA256 checksums are available on the [Releases](https://github.com/up9inc/mizu/
### Development (unstable) build
Pick one from the [Releases](https://github.com/up9inc/mizu/releases) page.
## Prerequisites
1. Set `KUBECONFIG` environment variable to your kubernetes configuration. If this is not set, mizu assumes that configuration is at `${HOME}/.kube/config`
2. mizu needs following permissions on your kubernetes cluster to run
```
- apiGroups:
- ""
- apps
resources:
- pods
- services
verbs:
- list
- get
- create
- delete
- apiGroups:
- ""
- apps
resources:
- daemonsets
verbs:
- list
- get
- create
- patch
- delete
```
3. Optionally, for resolving traffic ip to kubernetes service name, mizu needs below permissions
```
- apiGroups:
- ""
- apps
- "rbac.authorization.k8s.io"
resources:
- clusterroles
- clusterrolebindings
- serviceaccounts
verbs:
- get
- create
- delete
```
## How to run
1. Find pod you'd like to tap to in your Kubernetes cluster

View File

@@ -16,6 +16,7 @@ import (
"mizuserver/pkg/routes"
"mizuserver/pkg/sensitiveDataFiltering"
"mizuserver/pkg/utils"
"mizuserver/pkg/version"
"os"
"os/signal"
"strings"
@@ -27,6 +28,8 @@ var standalone = flag.Bool("standalone", false, "Run in standalone tapper and AP
var aggregatorAddress = flag.String("aggregator-address", "", "Address of mizu collector for tapping")
func main() {
rlog.Infof("Version parameters are: %s %s %s %s", version.Branch, version.SemVer, version.GitCommitHash, version.BuildTimestamp)
flag.Parse()
hostMode := os.Getenv(shared.HostModeEnvVar) == "1"
tapOpts := &tap.TapOpts{HostMode: hostMode}

View File

@@ -2,11 +2,13 @@ package controllers
import (
"github.com/gofiber/fiber/v2"
"github.com/up9inc/mizu/shared"
"mizuserver/pkg/version"
)
type VersionResponse struct {
SemVer string `json:"semver"`
}
func GetVersion(c *fiber.Ctx) error {
resp := shared.VersionResponse{SemVer: version.SemVer}
resp := VersionResponse{SemVer: "1.2.3"}
return c.Status(fiber.StatusOK).JSON(resp)
}

View File

@@ -10,7 +10,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"path/filepath"
"os"
)
func NewFromInCluster(errOut chan error) (*Resolver, error) {
@@ -27,13 +26,8 @@ func NewFromInCluster(errOut chan error) (*Resolver, error) {
func NewFromOutOfCluster(kubeConfigPath string, errOut chan error) (*Resolver, error) {
if kubeConfigPath == "" {
env := os.Getenv("KUBECONFIG")
if env != "" {
kubeConfigPath = env
} else {
home := homedir.HomeDir()
kubeConfigPath = filepath.Join(home, ".kube", "config")
}
home := homedir.HomeDir()
kubeConfigPath = filepath.Join(home, ".kube", "config")
}
configPathList := filepath.SplitList(kubeConfigPath)

View File

@@ -5,7 +5,7 @@ import (
"mizuserver/pkg/controllers"
)
// EntriesRoutes defines the group of har entries routes.
// EntriesRoutes func for describe group of public routes.
func EntriesRoutes(fiberApp *fiber.App) {
routeGroup := fiberApp.Group("/api")

View File

@@ -5,7 +5,7 @@ import (
"mizuserver/pkg/controllers"
)
// MetadataRoutes defines the group of metadata routes.
// EntriesRoutes func for describe group of public routes.
func MetadataRoutes(fiberApp *fiber.App) {
routeGroup := fiberApp.Group("/metadata")

View File

@@ -2,7 +2,7 @@ package routes
import "github.com/gofiber/fiber/v2"
// NotFoundRoute defines the 404 Error route.
// NotFoundRoute func for describe 404 Error route.
func NotFoundRoute(fiberApp *fiber.App) {
fiberApp.Use(
func(c *fiber.Ctx) error {

View File

@@ -3,6 +3,7 @@ COMMIT_HASH=$(shell git rev-parse HEAD)
GIT_BRANCH=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]')
GIT_VERSION=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]')
BUILD_TIMESTAMP=$(shell date +%s)
SEM_VER=0.0.0
.PHONY: help
.DEFAULT_GOAL := help

View File

@@ -2,7 +2,6 @@ package cmd
import (
"github.com/spf13/cobra"
"github.com/up9inc/mizu/cli/mizu"
)
type MizuFetchOptions struct {
@@ -18,12 +17,6 @@ var fetchCmd = &cobra.Command{
Use: "fetch",
Short: "Download recorded traffic to files",
RunE: func(cmd *cobra.Command, args []string) error {
go mizu.ReportRun("tap", mizuTapOptions)
if isCompatible, err := mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort); err != nil {
return err
} else if !isCompatible {
return nil
}
RunMizuFetch(&mizuFetchOptions)
return nil
},

View File

@@ -31,9 +31,9 @@ var mizuTapOptions = &MizuTapOptions{}
var direction string
var humanMaxEntriesDBSize string
var regex *regexp.Regexp
const maxEntriesDBSizeFlagName = "max-entries-db-size"
const analysisMessageToConfirm = `NOTE: running mizu with --analysis flag will upload recorded traffic
to UP9 cloud for further analysis and enriched presentation options.
`
@@ -44,7 +44,6 @@ var tapCmd = &cobra.Command{
Long: `Record the ingoing traffic of a kubernetes pod.
Supported protocols are HTTP and gRPC.`,
RunE: func(cmd *cobra.Command, args []string) error {
go mizu.ReportRun("tap", mizuTapOptions)
RunMizuTap(regex, mizuTapOptions)
return nil
},

View File

@@ -10,20 +10,20 @@ import (
)
type MizuVersionOptions struct {
DebugInfo bool
DebugInfo bool
}
var mizuVersionOptions = &MizuVersionOptions{}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version info",
RunE: func(cmd *cobra.Command, args []string) error {
go mizu.ReportRun("version", mizuVersionOptions)
if mizuVersionOptions.DebugInfo {
timeStampInt, _ := strconv.ParseInt(mizu.BuildTimestamp, 10, 0)
fmt.Printf("Version: %s \nBranch: %s (%s) \n", mizu.SemVer, mizu.Branch, mizu.GitCommitHash)
fmt.Printf("Build Time: %s (%s)\n", mizu.BuildTimestamp, time.Unix(timeStampInt, 0))
fmt.Printf("Build Time: %s (%s)\n", mizu.BuildTimestamp, time.Unix(timeStampInt, 0))
} else {
fmt.Printf("Version: %s (%s)\n", mizu.SemVer, mizu.Branch)

View File

@@ -2,11 +2,10 @@ package cmd
import (
"github.com/spf13/cobra"
"github.com/up9inc/mizu/cli/mizu"
)
type MizuViewOptions struct {
GuiPort uint16
GuiPort uint16
}
var mizuViewOptions = &MizuViewOptions{}
@@ -15,12 +14,6 @@ var viewCmd = &cobra.Command{
Use: "view",
Short: "Open GUI in browser",
RunE: func(cmd *cobra.Command, args []string) error {
go mizu.ReportRun("view", mizuFetchOptions)
if isCompatible, err := mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort); err != nil {
return err
} else if !isCompatible {
return nil
}
runMizuView(mizuViewOptions)
return nil
},

View File

@@ -1,30 +0,0 @@
package mizu
import (
"bytes"
"encoding/json"
"fmt"
"github.com/romana/rlog"
"net/http"
)
const telemetryUrl = "https://us-east4-up9-prod.cloudfunctions.net/mizu-telemetry"
func ReportRun(cmd string, args interface{}) {
if Branch != "main" {
rlog.Debugf("reporting only on main branch")
return
}
argsBytes, _ := json.Marshal(args)
argsMap := map[string]string{"telemetry_type": "mizu_execution", "cmd": cmd, "args": string(argsBytes), "component": "mizu_cli"}
argsMap["message"] = fmt.Sprintf("mizu %v - %v", argsMap["cmd"], string(argsBytes))
jsonValue, _ := json.Marshal(argsMap)
if resp, err := http.Post(telemetryUrl, "application/json", bytes.NewBuffer(jsonValue)); err != nil {
rlog.Debugf("error sending telemtry err: %v, response %v", err, resp)
} else {
rlog.Debugf("Successfully reported telemetry")
}
}

View File

@@ -1,46 +0,0 @@
package mizu
import (
"encoding/json"
"fmt"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/shared/semver"
"net/http"
"net/url"
)
func getApiVersion(port uint16) (string, error) {
versionUrl, _ := url.Parse(fmt.Sprintf("http://localhost:%d/mizu/metadata/version", port))
req := &http.Request{
Method: http.MethodGet,
URL: versionUrl,
}
statusResp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
defer statusResp.Body.Close()
versionResponse := &shared.VersionResponse{}
if err := json.NewDecoder(statusResp.Body).Decode(&versionResponse); err != nil {
return "", err
}
return versionResponse.SemVer, nil
}
func CheckVersionCompatibility(port uint16) (bool, error) {
apiSemVer, err := getApiVersion(port)
if err != nil {
return false, err
}
if semver.SemVersion(apiSemVer).Major() == semver.SemVersion(SemVer).Major() &&
semver.SemVersion(apiSemVer).Minor() == semver.SemVersion(SemVer).Minor() {
return true, nil
}
fmt.Printf(Red, fmt.Sprintf("cli version (%s) is not compatible with api version (%s)\n", SemVer, apiSemVer))
return false, nil
}

View File

@@ -61,8 +61,3 @@ type TrafficFilteringOptions struct {
PlainTextMaskingRegexes []*SerializableRegexp
HideHealthChecks bool
}
type VersionResponse struct {
SemVer string `json:"semver"`
}

View File

@@ -1,11 +1,9 @@
package tap
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
@@ -48,27 +46,12 @@ type HarFile struct {
}
func NewEntry(request *http.Request, requestTime time.Time, response *http.Response, responseTime time.Time) (*har.Entry, error) {
harRequest, err := har.NewRequest(request, false)
harRequest, err := har.NewRequest(request, true)
if err != nil {
SilentError("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
return nil, errors.New("Failed converting request to HAR")
}
// For requests with multipart/form-data or application/x-www-form-urlencoded Content-Type,
// martian/har will parse the request body and place the parameters in harRequest.PostData.Params
// instead of harRequest.PostData.Text (as the HAR spec requires it).
// Mizu currently only looks at PostData.Text. Therefore, instead of letting martian/har set the content of
// PostData, always copy the request body to PostData.Text.
if (request.ContentLength > 0) {
reqBody, err := ioutil.ReadAll(request.Body)
if err != nil {
SilentError("read-request-body", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
return nil, errors.New("Failed reading request body")
}
request.Body = ioutil.NopCloser(bytes.NewReader(reqBody))
harRequest.PostData.Text = string(reqBody)
}
harResponse, err := har.NewResponse(response, true)
if err != nil {
SilentError("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)