From c84179088cf3abd15160ddead9da000482a580e1 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Tue, 29 Mar 2022 23:11:02 +0100 Subject: [PATCH 1/2] Fixes regression accessing GitLab public repositories Some git servers are more accommodating than others. Gitlab will try to validate credentials when they are provided, even if they are empty and the target repository is public, leading to a failed authentication error. Signed-off-by: Paulo Gomes --- pkg/git/gogit/transport.go | 13 +++++++++---- pkg/git/gogit/transport_test.go | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/git/gogit/transport.go b/pkg/git/gogit/transport.go index 0ab3fbd6..cd59110d 100644 --- a/pkg/git/gogit/transport.go +++ b/pkg/git/gogit/transport.go @@ -36,10 +36,15 @@ func transportAuth(opts *git.AuthOptions) (transport.AuthMethod, error) { } switch opts.Transport { case git.HTTPS, git.HTTP: - return &http.BasicAuth{ - Username: opts.Username, - Password: opts.Password, - }, nil + // Some providers (i.e. GitLab) will reject empty credentials for + // public repositories. + if opts.Username != "" || opts.Password != "" { + return &http.BasicAuth{ + Username: opts.Username, + Password: opts.Password, + }, nil + } + return nil, nil case git.SSH: if len(opts.Identity) > 0 { pk, err := ssh.NewPublicKeys(opts.Username, opts.Identity, opts.Password) diff --git a/pkg/git/gogit/transport_test.go b/pkg/git/gogit/transport_test.go index 93ea279d..43577d9b 100644 --- a/pkg/git/gogit/transport_test.go +++ b/pkg/git/gogit/transport_test.go @@ -74,6 +74,24 @@ func Test_transportAuth(t *testing.T) { wantFunc func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) wantErr error }{ + { + name: "Public HTTP Repositories", + opts: &git.AuthOptions{ + Transport: git.HTTP, + }, + wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) { + g.Expect(t).To(BeNil()) + }, + }, + { + name: "Public HTTPS Repositories", + opts: &git.AuthOptions{ + Transport: git.HTTP, + }, + wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) { + g.Expect(t).To(BeNil()) + }, + }, { name: "HTTP basic auth", opts: &git.AuthOptions{ From da91e470360467385e5dc619af3e9c5cb517cd04 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Tue, 29 Mar 2022 23:12:07 +0100 Subject: [PATCH 2/2] Improve documentation on Debugging source controller Expands on the current documentation to help contributors debug the controller regardless of all its existing dependencies. Signed-off-by: Paulo Gomes --- DEVELOPMENT.md | 28 ++++++++++++++++++++++++++++ Makefile | 19 +++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 99097f7e..ab958a44 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -128,3 +128,31 @@ Deploy `source-controller` into the cluster that is configured in the local kube ```sh make deploy ``` + +### Debugging controller with VSCode + +Create a `.vscode/launch.json` file: +```json +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "envFile": "${workspaceFolder}/build/.env", + "program": "${workspaceFolder}/main.go" + } + ] +} +``` + +Create the environment file containing details on how to load +`libgit2` dependencies: +```bash +make env +``` + +Start debugging by either clicking `Run` > `Start Debugging` or using +the relevant shortcut. diff --git a/Makefile b/Makefile index da627197..70468ad5 100644 --- a/Makefile +++ b/Makefile @@ -241,19 +241,30 @@ endef # Build fuzzers fuzz-build: $(LIBGIT2) - rm -rf $(shell pwd)/build/fuzz/ - mkdir -p $(shell pwd)/build/fuzz/out/ + rm -rf $(BUILD_DIR)/fuzz/ + mkdir -p $(BUILD_DIR)/fuzz/out/ docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder docker run --rm \ -e FUZZING_LANGUAGE=go -e SANITIZER=address \ -e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \ - -v "$(shell pwd)/build/fuzz/out":/out \ + -v "$(BUILD_DIR)/fuzz/out":/out \ local-fuzzing:latest fuzz-smoketest: fuzz-build docker run --rm \ - -v "$(shell pwd)/build/fuzz/out":/out \ + -v "$(BUILD_DIR)/fuzz/out":/out \ -v "$(shell pwd)/tests/fuzz/oss_fuzz_run.sh":/runner.sh \ local-fuzzing:latest \ bash -c "/runner.sh" + +# Creates an env file that can be used to load all source-controller's dependencies +# this is handy when you want to run adhoc debug sessions on tests or start the +# controller in a new debug session. +env: $(LIBGIT2) + echo 'GO_ENABLED="1"' > $(BUILD_DIR)/.env + echo 'PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"' >> $(BUILD_DIR)/.env + echo 'LIBRARY_PATH="$(LIBRARY_PATH)"' >> $(BUILD_DIR)/.env + echo 'CGO_CFLAGS="$(CGO_CFLAGS)"' >> $(BUILD_DIR)/.env + echo 'CGO_LDFLAGS="$(CGO_LDFLAGS)"' >> $(BUILD_DIR)/.env + echo 'KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)' >> $(BUILD_DIR)/.env