-
Notifications
You must be signed in to change notification settings - Fork 131
feat(remote-tasks): gate remote annotation URLs #2745
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,23 @@ data: | |
| # Allow fetching remote tasks | ||
| remote-tasks: "true" | ||
|
|
||
| # Optional comma-separated host allowlist for remote annotation URLs. Bare | ||
| # hosts and https:// hosts allow HTTPS fetches. HTTP fetches are disabled | ||
| # unless the host is explicitly listed with http://. | ||
| # Wildcards such as "*.example.com" match host suffixes; broad patterns such | ||
| # as "*.com" are allowed but risky. | ||
| remote-tasks-url-allowlist: "" | ||
|
|
||
| # Optional comma-separated CIDRs to block in addition to built-in unsafe | ||
| # ranges such as loopback, link-local, private, multicast, and shared address | ||
| # space. These built-in checks block typical Kubernetes service targets when | ||
| # they resolve to private cluster IPs. Use this to block additional | ||
| # cluster-specific service and pod CIDRs. | ||
| remote-tasks-url-blocked-cidrs: "" | ||
|
|
||
| # Maximum response size, in bytes, for remote annotation fetches. | ||
| remote-tasks-url-max-response-size: "1048576" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like exposing low level stuff as configuration but if for whatever reason someone has a task/prun bigger than 1mb to fetch then we let them fetch it |
||
|
|
||
| # Using the URL of the Tekton dashboard, Pipelines-as-Code generates a URL to the | ||
| # PipelineRun on the Tekton dashboard | ||
| tekton-dashboard-url: "" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/hub" | ||||||||||
| hubtypes "github.com/openshift-pipelines/pipelines-as-code/pkg/hub/vars" | ||||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/params" | ||||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/params/clients" | ||||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" | ||||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings" | ||||||||||
| "github.com/openshift-pipelines/pipelines-as-code/pkg/provider" | ||||||||||
|
|
@@ -34,6 +35,19 @@ type RemoteTasks struct { | |||||||||
| DeprecatedHubResources []string // tracks resources resolved from deprecated tektonhub catalogs | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (rt RemoteTasks) remoteResourceFetchOptions() clients.RemoteResourceFetchOptions { | ||||||||||
| if rt.Run == nil || rt.Run.Info.Pac == nil { | ||||||||||
| return clients.RemoteResourceFetchOptions{ | ||||||||||
| MaxResponseBytes: clients.DefaultRemoteResourceMaxResponseBytes, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return clients.RemoteResourceFetchOptions{ | ||||||||||
| AllowedHosts: rt.Run.Info.Pac.RemoteTasksURLAllowlist, | ||||||||||
| BlockedCIDRs: rt.Run.Info.Pac.RemoteTasksURLBlockedCIDRs, | ||||||||||
| MaxResponseBytes: int64(rt.Run.Info.Pac.RemoteTasksURLMaxResponseSize), | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // nolint: dupl | ||||||||||
| func (rt *RemoteTasks) convertToPipeline(ctx context.Context, uri, data string) (*tektonv1.Pipeline, error) { | ||||||||||
| decoder := k8scheme.Codecs.UniversalDeserializer() | ||||||||||
|
|
@@ -101,20 +115,43 @@ func (rt *RemoteTasks) convertTotask(ctx context.Context, uri, data string) (*te | |||||||||
|
|
||||||||||
| func (rt *RemoteTasks) getRemote(ctx context.Context, uri string, fromHub bool, kind string) (string, error) { | ||||||||||
| rt.Logger.Debugf("getRemote: uri=%s kind=%s fromHub=%t", uri, kind, fromHub) | ||||||||||
| if fetchedFromURIFromProvider, task, err := rt.ProviderInterface.GetTaskURI(ctx, rt.Event, uri); fetchedFromURIFromProvider { | ||||||||||
| rt.Logger.Debugf("getRemote: fetched %s via provider hook for uri=%s", kind, uri) | ||||||||||
| return task, err | ||||||||||
| } | ||||||||||
| fetchOptions := rt.remoteResourceFetchOptions() | ||||||||||
| loweredURI := strings.ToLower(uri) | ||||||||||
|
|
||||||||||
| switch { | ||||||||||
| case strings.HasPrefix(uri, "https://"), strings.HasPrefix(uri, "http://"): // if it starts with http(s)://, it is a remote resource | ||||||||||
| if strings.HasPrefix(loweredURI, "http://") || strings.HasPrefix(loweredURI, "https://") { | ||||||||||
| if err := clients.ValidateRemoteResourceProviderURL(uri, fetchOptions); err != nil { | ||||||||||
| return "", err | ||||||||||
| } | ||||||||||
| if fetchedFromURIFromProvider, task, err := rt.ProviderInterface.GetTaskURI(ctx, rt.Event, uri); fetchedFromURIFromProvider { | ||||||||||
| rt.Logger.Debugf("getRemote: fetched %s via provider hook for uri=%s", kind, uri) | ||||||||||
| if err != nil { | ||||||||||
| return task, err | ||||||||||
| } | ||||||||||
|
Comment on lines
+127
to
+129
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||||||||||
| if err := clients.CheckRemoteResourceResponseSize(int64(len(task)), fetchOptions); err != nil { | ||||||||||
| return "", err | ||||||||||
| } | ||||||||||
| return task, nil | ||||||||||
| } | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| rt.Logger.Debugf("getRemote: fetching %s from http(s) url", kind) | ||||||||||
| data, err := rt.Run.Clients.GetURL(ctx, uri) | ||||||||||
| data, err := rt.Run.Clients.GetRemoteResourceURL(ctx, uri, fetchOptions) | ||||||||||
| if err != nil { | ||||||||||
| return "", err | ||||||||||
| } | ||||||||||
| rt.Logger.Infof("successfully fetched %s from remote HTTPS URL", uri) | ||||||||||
| rt.Logger.Infof("successfully fetched %s from remote URL", uri) | ||||||||||
| return string(data), nil | ||||||||||
| } | ||||||||||
| if fetchedFromURIFromProvider, task, err := rt.ProviderInterface.GetTaskURI(ctx, rt.Event, uri); fetchedFromURIFromProvider { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||||||||||
| rt.Logger.Debugf("getRemote: fetched %s via provider hook for uri=%s", kind, uri) | ||||||||||
| if err != nil { | ||||||||||
| return task, err | ||||||||||
| } | ||||||||||
| if err := clients.CheckRemoteResourceResponseSize(int64(len(task)), fetchOptions); err != nil { | ||||||||||
| return "", err | ||||||||||
| } | ||||||||||
| return task, nil | ||||||||||
| } | ||||||||||
|
Comment on lines
+121
to
+152
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not create the policy as part of |
||||||||||
|
|
||||||||||
| switch { | ||||||||||
| case fromHub && strings.Contains(uri, "://"): // if it contains ://, it is a remote custom catalog | ||||||||||
| split := strings.Split(uri, "://") | ||||||||||
| catalogID := split[0] | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.