Commit 260914a9 authored by Kamil Trzciński's avatar Kamil Trzciński

Strip sensitive data from URL

parent 1d0b5aaf
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/archives" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/archives"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/url"
) )
type CacheArchiverCommand struct { type CacheArchiverCommand struct {
...@@ -22,7 +23,7 @@ type CacheArchiverCommand struct { ...@@ -22,7 +23,7 @@ type CacheArchiverCommand struct {
} }
func (c *CacheArchiverCommand) upload() (bool, error) { func (c *CacheArchiverCommand) upload() (bool, error) {
logrus.Infoln("Uploading", filepath.Base(c.File), "to", c.URL) logrus.Infoln("Uploading", filepath.Base(c.File), "to", url_helpers.CleanURL(c.URL))
file, err := os.Open(c.File) file, err := os.Open(c.File)
if err != nil { if err != nil {
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/archives" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/archives"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/formatter" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/formatter"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/url"
) )
type CacheExtractorCommand struct { type CacheExtractorCommand struct {
...@@ -54,7 +55,7 @@ func (c *CacheExtractorCommand) download() (bool, error) { ...@@ -54,7 +55,7 @@ func (c *CacheExtractorCommand) download() (bool, error) {
return false, nil return false, nil
} }
logrus.Infoln("Downloading", filepath.Base(c.File), "from", c.URL) logrus.Infoln("Downloading", filepath.Base(c.File), "from", url_helpers.CleanURL(c.URL))
_, err = io.Copy(file, resp.Body) _, err = io.Copy(file, resp.Body)
if err != nil { if err != nil {
return true, err return true, err
......
...@@ -2,7 +2,8 @@ package common ...@@ -2,7 +2,8 @@ package common
import ( import (
"io" "io"
"net/url"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/url"
) )
type UpdateState int type UpdateState int
...@@ -90,14 +91,8 @@ type GetBuildResponse struct { ...@@ -90,14 +91,8 @@ type GetBuildResponse struct {
TLSCAChain string `json:"-"` TLSCAChain string `json:"-"`
} }
func (b *GetBuildResponse) RepoCleanURL() string { func (b *GetBuildResponse) RepoCleanURL() (ret string) {
repoURL, err := url.Parse(b.RepoURL) return url_helpers.CleanURL(b.RepoURL)
if err != nil {
return err.Error()
}
repoURL.User = nil
return repoURL.String()
} }
type RegisterRunnerRequest struct { type RegisterRunnerRequest struct {
......
package url_helpers
import "net/url"
func CleanURL(value string) (ret string) {
u, err := url.Parse(value)
if err != nil {
return
}
u.User = nil
u.RawQuery = ""
u.Fragment = ""
return u.String()
}
package url_helpers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRemovingAllSensitiveData(t *testing.T) {
url := CleanURL("https://user:password@gitlab.com/gitlab?key=value#fragment")
assert.Equal(t, "https://gitlab.com/gitlab", url)
}
func TestInvalidURL(t *testing.T) {
assert.Empty(t, CleanURL("://invalid URL"))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment