From bd0781aec77d6419f7dc4bda63dd1a1b75bccd0b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:09:12 +0200 Subject: [PATCH 1/7] add makefile update build params --- .woodpecker.yml | 7 +++++-- Dockerfile | 2 +- Makefile | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/.woodpecker.yml b/.woodpecker.yml index 7292217..4e85361 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -12,8 +12,11 @@ pipeline: build: image: *golang volumes: *volumes + environments: + BUILD_DIR: build commands: - - go build -o /artifacts/capture + - mkdir $BUILD_DIR + - make push_release: image: plugins/gitea-release @@ -23,7 +26,7 @@ pipeline: from_secret: gitnet_api_key base_url: https://gitnet.fr note: ${CI_COMMIT_MESSAGE} - files: /artifacts/capture + files: build/* when: event: [tag] diff --git a/Dockerfile b/Dockerfile index 90fe3e9..f125ef2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /app/capture +RUN BUILD_DIR=/app make FROM debian:stable-slim diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8383bec --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +CGO_ENABLED = 0 +CC = go build +CFLAGS = -trimpath +LDFLAGS = all=-w -s +GCFLAGS = all= +ASMFLAGS = all= +GOARCH ?= amd64 + +BUILD_DIR ?= build +LINUX_BIN ?= capture +WIN_BIN ?= capture.exe + +all: build + +deps: + go install github.com/GeertJohan/go.rice/rice@latest + rice embed-go + +.PHONY: +build: deps + export CGO_ENABLED=$(CGO_ENABLED) + export GOARCH=$(GOARCH) + GOOS=linux $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LINUX_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" + GOOS=windows $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(WIN_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" From 3e6600113c8b042acabec3b9aee984e35d7bcce2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:12:52 +0200 Subject: [PATCH 2/7] fix ci build --- .woodpecker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 4e85361..b0f5366 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -12,10 +12,8 @@ pipeline: build: image: *golang volumes: *volumes - environments: - BUILD_DIR: build commands: - - mkdir $BUILD_DIR + - export BUILD_DIR=build - make push_release: From bcc4a9f4abe4ad0efce3aa2eb7284d11c045368d Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:14:01 +0200 Subject: [PATCH 3/7] fix ci build --- .woodpecker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index b0f5366..1507722 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -13,7 +13,6 @@ pipeline: image: *golang volumes: *volumes commands: - - export BUILD_DIR=build - make push_release: From 0afdce8c5fefa36602ff0f8b1934c3e145f6b2e6 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:15:08 +0200 Subject: [PATCH 4/7] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9273014..a8dcd12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +## v1.3.1 +### Added +- add makefile to manage build + ## v1.3.0 ### Added - add argument to define the configuration file From d6e0b063e0dee5e960d0254ad41976df4e598533 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:37:42 +0200 Subject: [PATCH 5/7] rename build binaries --- Dockerfile | 2 +- Makefile | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f125ef2..2ba558f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,6 @@ RUN BUILD_DIR=/app make FROM debian:stable-slim RUN apt-get update && apt-get install -y ca-certificates -COPY --from=builder /app/capture /usr/bin/capture +COPY --from=builder /app/capture-linux-amd64 /usr/bin/capture ENTRYPOINT ["/usr/bin/capture"] diff --git a/Makefile b/Makefile index 8383bec..961c529 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,11 @@ CFLAGS = -trimpath LDFLAGS = all=-w -s GCFLAGS = all= ASMFLAGS = all= -GOARCH ?= amd64 +GOARCH = amd64 BUILD_DIR ?= build -LINUX_BIN ?= capture -WIN_BIN ?= capture.exe +LINUX_BIN ?= capture-linux-amd64 +WIN_BIN ?= capture-window-amd64.exe all: build From 9993d9a8efe60bfd90169ad65b0f6840a6cc5a74 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:42:22 +0200 Subject: [PATCH 6/7] add option to skip TLS verification --- .gitignore | 6 +----- CHANGELOG.md | 6 ++++++ README.md | 16 +++++++++------- config.go | 5 +++++ main.go | 10 ++++++++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index b1ab026..796b96d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ -.idea -debug -debug.test -*.exe -capture +/build diff --git a/CHANGELOG.md b/CHANGELOG.md index a8dcd12..f09fbb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## [Unreleased] +## v1.4.0 +### Added +- add option to skil TLS verification +### Changed +- build binaries are nenamed + ## v1.3.1 ### Added - add makefile to manage build diff --git a/README.md b/README.md index 89957c7..909d932 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,14 @@ docker run -p 9000:9000 -p 9001:9001 deblan/capture -url=https://example.com/ -p #### Settings -| param | description | -| -------------- | ------------- | -| `-url` | **Required.** Set the url you want to proxy | -| `-port` | Set the proxy port. Default: *9000* | -| `-dashboard` | Set the dashboard port. Default: *9001* | -| `-captures` | Set how many captures to show in the dashboard. Default: *16* | -| `-config` | Set the configuration file. Default: *.capture.ini* | +| param | description | +| -------------- | ------------- | +| `-url` | **Required.** Set the url you want to proxy | +| `-port` | Set the proxy port. Default: *9000* | +| `-dashboard` | Set the dashboard port. Default: *9001* | +| `-captures` | Set how many captures to show in the dashboard. Default: *16* | +| `-tls-skip-verify` | Skip TLS vertificaton. Default: *false* | +| `-config` | Set the configuration file. Default: *.capture.ini* | You can create a file named `.capture.ini` and set the configuration inside: @@ -34,6 +35,7 @@ url = https://example.com/ port = 9000 dashboard = 9001 captures = 16 +tls_skip_verify = false ``` ## Using diff --git a/config.go b/config.go index 4344540..1d6ebe3 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,7 @@ type Config struct { TargetURL string ProxyPort string DashboardPort string + TLSSkipVerify bool MaxCaptures int } @@ -22,12 +23,14 @@ func ReadConfig() Config { defaultDashboardPort := "9001" defaultMaxCaptures := 16 defaultConfigFile := ".capture.ini" + defaultTLSSkipVerify := false targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy") configFile := flag.String("config", defaultConfigFile, "Set the configuration file") proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port") dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port") maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard") + TLSSkipVerify := flag.Bool("tls-skip-verify", defaultTLSSkipVerify, "Skip TLS vertification") flag.Parse() @@ -46,6 +49,7 @@ func ReadConfig() Config { ProxyPort: section.Key("port").MustString(*proxyPort), MaxCaptures: section.Key("captures").MustInt(*maxCaptures), DashboardPort: section.Key("dashboard").MustString(*dashboardPort), + TLSSkipVerify: section.Key("tls_skip_verify").MustBool(*TLSSkipVerify), } } @@ -54,5 +58,6 @@ func ReadConfig() Config { ProxyPort: *proxyPort, MaxCaptures: *maxCaptures, DashboardPort: *dashboardPort, + TLSSkipVerify: *TLSSkipVerify, } } diff --git a/main.go b/main.go index 520bce7..c2e27b2 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "compress/gzip" + "crypto/tls" _ "embed" "encoding/json" "fmt" @@ -36,7 +37,7 @@ func main() { fmt.Println() srv := NewCaptureService(cfg.MaxCaptures) - hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL))) + hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL, cfg.TLSSkipVerify))) go func() { fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg))) @@ -230,9 +231,14 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler } // NewProxyHandler is the reverse proxy handler. -func NewProxyHandler(URL string) http.HandlerFunc { +func NewProxyHandler(URL string, TLSSkipVerify bool) http.HandlerFunc { url, _ := url.Parse(URL) proxy := httputil.NewSingleHostReverseProxy(url) + insecureTransport := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: TLSSkipVerify}, + } + proxy.Transport = insecureTransport + proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) { fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL) rw.WriteHeader(StatusInternalProxyError) From 5fac42f17ba3a3ab453cd6b4b384ed963119dd3e Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 3 Aug 2023 15:44:38 +0200 Subject: [PATCH 7/7] fix tests --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 9227b83..eb93156 100644 --- a/main_test.go +++ b/main_test.go @@ -22,7 +22,7 @@ func TestProxyHandler(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { service := httptest.NewServer(http.HandlerFunc(tc.service)) - capture := httptest.NewServer(NewProxyHandler(service.URL)) + capture := httptest.NewServer(NewProxyHandler(service.URL, false)) // when resp := tc.request(capture.URL)