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

adding proxy parameters to git pipeline resource #2215

Merged
merged 1 commit into from
Mar 18, 2020
Merged
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
32 changes: 32 additions & 0 deletions docs/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,38 @@ spec:
value: refs/pull/52525/head
```

#### Using HTTP/HTTPS Proxy

The `httpProxy` and `httpsProxy` parameter can be used to proxy non-SSL/SSL requests, for example to use an enterprise
proxy server for SSL requests:

```yaml
spec:
type: git
params:
- name: url
value: https://github.com/bobcatfish/wizzbang.git
- name: httpsProxy
value: "my-enterprise.proxy.com"
```

#### Using No Proxy

The `noProxy` parameter can be used to opt out of proxying, for example, to not proxy HTTP/HTTPS requests to
`no.proxy.com`:

```yaml
spec:
type: git
params:
- name: url
value: https://github.com/bobcatfish/wizzbang.git
- name: noProxy
value: "no.proxy.com"
```

Note: `httpProxy`, `httpsProxy`, and `noProxy` are all optional but no validation done if all three are specified.

### Pull Request Resource

The `pullRequest` resource represents a pull request event from a source control
Expand Down
55 changes: 55 additions & 0 deletions examples/v1alpha1/taskruns/git-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,58 @@ spec:
value: pull/2932/head
- name: url
value: https://github.com/GoogleContainerTools/skaffold

---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
generateName: git-resource-sslverify-
spec:
taskSpec:
inputs:
resources:
- name: skaffold
type: git
steps:
- image: ubuntu
script: cat skaffold/README.md
inputs:
resources:
- name: skaffold
resourceSpec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/GoogleContainerTools/skaffold
- name: sslVerify
value: "false"
---

apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
generateName: git-resource-no-proxy-
spec:
taskSpec:
inputs:
resources:
- name: skaffold
type: git
steps:
- image: ubuntu
script: cat skaffold/README.md
inputs:
resources:
- name: skaffold
resourceSpec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/GoogleContainerTools/skaffold
- name: noProxy
value: "google.com"
---
52 changes: 39 additions & 13 deletions pkg/apis/resource/v1alpha1/git/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ type Resource struct {
Revision string `json:"revision"`
Submodules bool `json:"submodules"`

Depth uint `json:"depth"`
SSLVerify bool `json:"sslVerify"`
GitImage string `json:"-"`
Depth uint `json:"depth"`
SSLVerify bool `json:"sslVerify"`
HTTPProxy string `json:"httpProxy"`
HTTPSProxy string `json:"httpsProxy"`
NOProxy string `json:"noProxy"`
GitImage string `json:"-"`
}

// NewResource creates a new git resource to pass to a Task
Expand Down Expand Up @@ -74,6 +77,12 @@ func NewResource(gitImage string, r *resource.PipelineResource) (*Resource, erro
gitResource.Depth = toUint(param.Value, 1)
case strings.EqualFold(param.Name, "SSLVerify"):
gitResource.SSLVerify = toBool(param.Value, true)
case strings.EqualFold(param.Name, "HTTPProxy"):
gitResource.HTTPProxy = param.Value
case strings.EqualFold(param.Name, "HTTPSProxy"):
gitResource.HTTPSProxy = param.Value
case strings.EqualFold(param.Name, "NOProxy"):
gitResource.NOProxy = param.Value
}
}
// default revision to master if nothing is provided
Expand Down Expand Up @@ -120,12 +129,15 @@ func (s *Resource) GetURL() string {
// Replacements is used for template replacement on a GitResource inside of a Taskrun.
func (s *Resource) Replacements() map[string]string {
return map[string]string{
"name": s.Name,
"type": s.Type,
"url": s.URL,
"revision": s.Revision,
"depth": strconv.FormatUint(uint64(s.Depth), 10),
"sslVerify": strconv.FormatBool(s.SSLVerify),
"name": s.Name,
"type": s.Type,
"url": s.URL,
"revision": s.Revision,
"depth": strconv.FormatUint(uint64(s.Depth), 10),
"sslVerify": strconv.FormatBool(s.SSLVerify),
"httpProxy": s.HTTPProxy,
"httpsProxy": s.HTTPSProxy,
"noProxy": s.NOProxy,
}
}

Expand All @@ -147,6 +159,23 @@ func (s *Resource) GetInputTaskModifier(_ *v1alpha1.TaskSpec, path string) (v1al
args = append(args, "-sslVerify=false")
}

env := []corev1.EnvVar{{
Name: "TEKTON_RESOURCE_NAME",
Value: s.Name,
}}

if len(s.HTTPProxy) != 0 {
env = append(env, corev1.EnvVar{Name: "HTTP_PROXY", Value: s.HTTPProxy})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that here, respective proxy env. variables are being set while creating a container instead of running git config --global like sslVerify in git.go

The reason for implementing this way is, for some reason, git proxy configuration was ignored and cloning a repo was not failing even after setting HTTPS_PROXY to an invalid server, see the failure test at
https://github.com/tektoncd/pipeline/pull/2215/files#diff-6e725a312c3f914d42e49f045db0bde5R185

}

if len(s.HTTPSProxy) != 0 {
env = append(env, corev1.EnvVar{Name: "HTTPS_PROXY", Value: s.HTTPSProxy})
}

if len(s.NOProxy) != 0 {
env = append(env, corev1.EnvVar{Name: "NO_PROXY", Value: s.NOProxy})
}

step := v1alpha1.Step{
Container: corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(gitSource + "-" + s.Name),
Expand All @@ -155,10 +184,7 @@ func (s *Resource) GetInputTaskModifier(_ *v1alpha1.TaskSpec, path string) (v1al
Args: args,
WorkingDir: pipeline.WorkspaceDir,
// This is used to populate the ResourceResult status.
Env: []corev1.EnvVar{{
Name: "TEKTON_RESOURCE_NAME",
Value: s.Name,
}},
Env: env,
},
}

Expand Down
Loading