Skip to content

Commit 2e01150

Browse files
authored
feat: add insecure_skip_verify option to the builtin HTTP plugin (#178)
* feat: add insecure_skip_verify option to the builtin HTTP plugin * fix: use a string type for InsecureSkipVerify option * fix: use a copy of the htt.DefaultTransport * fix(plugin/http): create unsecure transport once and setup HTTP2 on it * chore: remove go1.12 from travis matrix and add go1.15 Signed-off-by: William Poussier <[email protected]>
1 parent efe2182 commit 2e01150

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ dist: bionic
44

55
language: go
66
go:
7+
- "1.15"
78
- "1.14"
89
- "1.13"
9-
- "1.12"
1010
- "master"
1111
go_import_path: github.com/ovh/utask
1212

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ require (
5656
github.com/wI2L/fizz v0.13.4
5757
github.com/ybriffa/deepcopy v0.0.0-20200601125345-88c31e59651d
5858
github.com/ziutek/mymysql v1.5.4 // indirect
59-
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
59+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
60+
golang.org/x/net v0.0.0-20200904194848-62affa334b73
6061
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
6162
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
6263
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPh
366366
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
367367
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
368368
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
369+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
370+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
369371
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
370372
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
371373
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -382,6 +384,8 @@ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCT
382384
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
383385
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
384386
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
387+
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
388+
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
385389
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
386390
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
387391
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

pkg/plugins/builtin/http/README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ This plugin permorms an HTTP request.
44

55
## Configuration
66

7-
|Fields|Description
8-
|---|---
9-
| `url` | destination for the http call, including host, path and query params; this all-in-one field conflicts with `host` and `path`
10-
| `host` | destination host for the http call; this field conflicts with the all-in-one field `url`
11-
| `path` | path for the http call; to use jointly with the `host` field; this field conflicts with the all-in-one field `url`
12-
| `method` | http method (`GET`, `POST`, `PUT`, `DELETE`, `PATCH`)
13-
| `body` | a string representing the payload to be sent with the request
14-
| `headers` | a list of headers, represented as (`name`, `value`) pairs
15-
| `timeout` | timeout expressed as a duration (e.g. `30s`)
16-
| `auth` | a single object composed of either a `basic` object with `user` and `password` fields to enable HTTP basic auth, or `bearer` field to enable Bearer Token Authorization
17-
| `follow_redirect` | if `true` (string) the plugin will follow up to 10 redirects (302, ...)
18-
| `query_parameters` | a list of query parameters, represented as (`name`, `value`) pairs; these will appended the query parameters present in the `url` field; parameters can be repeated (in either `url` or `query_parameters`) which will produce e.g. `?param=value1&param=value2`
19-
| `trim_prefix`| prefix in the response that must be removed before unmarshalling (optional)
7+
| Fields | Description |
8+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9+
| `url` | destination for the http call, including host, path and query params; this all-in-one field conflicts with `host` and `path` |
10+
| `host` | destination host for the http call; this field conflicts with the all-in-one field `url` |
11+
| `path` | path for the http call; to use jointly with the `host` field; this field conflicts with the all-in-one field `url` |
12+
| `method` | http method (`GET`, `POST`, `PUT`, `DELETE`, `PATCH`) |
13+
| `body` | a string representing the payload to be sent with the request |
14+
| `headers` | a list of headers, represented as (`name`, `value`) pairs |
15+
| `timeout` | timeout expressed as a duration (e.g. `30s`) |
16+
| `auth` | a single object composed of either a `basic` object with `user` and `password` fields to enable HTTP basic auth, or `bearer` field to enable Bearer Token Authorization |
17+
| `follow_redirect` | if `true` (string) the plugin will follow up to 10 redirects (302, ...) |
18+
| `query_parameters` | a list of query parameters, represented as (`name`, `value`) pairs; these will appended the query parameters present in the `url` field; parameters can be repeated (in either `url` or `query_parameters`) which will produce e.g. `?param=value1&param=value2` |
19+
| `trim_prefix` | prefix in the response that must be removed before unmarshalling (optional) |
20+
| `insecure_skip_verify` | If `true` (string), disables server's certificate chain and host verification. |
2021

2122
## Example
2223

pkg/plugins/builtin/http/http.go

+39-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pluginhttp
22

33
import (
44
"bytes"
5+
"crypto/tls"
56
"encoding/xml"
67
"errors"
78
"fmt"
@@ -16,6 +17,7 @@ import (
1617
"github.com/ovh/utask/pkg/plugins/builtin/httputil"
1718
"github.com/ovh/utask/pkg/plugins/taskplugin"
1819
"github.com/ovh/utask/pkg/utils"
20+
"golang.org/x/net/http2"
1921
)
2022

2123
// the HTTP plugin performs an HTTP call
@@ -26,24 +28,34 @@ var (
2628
)
2729
)
2830

31+
var defaultUnsecureTransport http.RoundTripper
32+
33+
func init() {
34+
tr := http.DefaultTransport.(*http.Transport).Clone()
35+
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
36+
_ = http2.ConfigureTransport(tr)
37+
defaultUnsecureTransport = tr
38+
}
39+
2940
const (
3041
// TimeoutDefault represents the default value that will be used for HTTP call, if not defined in configuration
3142
TimeoutDefault = "30s"
3243
)
3344

3445
// HTTPConfig is the configuration needed to perform an HTTP call
3546
type HTTPConfig struct {
36-
URL string `json:"url"`
37-
Host string `json:"host"`
38-
Path string `json:"path"`
39-
Method string `json:"method"`
40-
Body string `json:"body,omitempty"`
41-
Headers []parameter `json:"headers,omitempty"`
42-
Timeout string `json:"timeout,omitempty"`
43-
Auth auth `json:"auth,omitempty"`
44-
FollowRedirect string `json:"follow_redirect,omitempty"`
45-
QueryParameters []parameter `json:"query_parameters,omitempty"`
46-
TrimPrefix string `json:"trim_prefix,omitempty"`
47+
URL string `json:"url"`
48+
Host string `json:"host"`
49+
Path string `json:"path"`
50+
Method string `json:"method"`
51+
Body string `json:"body,omitempty"`
52+
Headers []parameter `json:"headers,omitempty"`
53+
Timeout string `json:"timeout,omitempty"`
54+
Auth auth `json:"auth,omitempty"`
55+
FollowRedirect string `json:"follow_redirect,omitempty"`
56+
QueryParameters []parameter `json:"query_parameters,omitempty"`
57+
TrimPrefix string `json:"trim_prefix,omitempty"`
58+
InsecureSkipVerify string `json:"insecure_skip_verify,omitempty"`
4759
}
4860

4961
// parameter represents either headers, query parameters, ...
@@ -193,10 +205,24 @@ func exec(stepName string, config interface{}, ctx interface{}) (interface{}, in
193205
if cfg.FollowRedirect != "" {
194206
fr, err = strconv.ParseBool(cfg.FollowRedirect)
195207
if err != nil {
196-
return nil, nil, fmt.Errorf("failed to parse allow redirect: %s", err)
208+
return nil, nil, fmt.Errorf("failed to parse follow_redirect: %s", err)
209+
}
210+
}
211+
var insecureSkipVerify bool
212+
if cfg.InsecureSkipVerify != "" {
213+
insecureSkipVerify, err = strconv.ParseBool(cfg.InsecureSkipVerify)
214+
if err != nil {
215+
return nil, nil, fmt.Errorf("failed to parse insecure_skip_verify: %s", err)
197216
}
198217
}
199-
httpClient := httputil.NewHTTPClient(httputil.HTTPClientConfig{Timeout: td, FollowRedirect: fr})
218+
httpClientConfig := httputil.HTTPClientConfig{
219+
Timeout: td,
220+
FollowRedirect: fr,
221+
}
222+
if insecureSkipVerify {
223+
httpClientConfig.Transport = defaultUnsecureTransport
224+
}
225+
httpClient := httputil.NewHTTPClient(httpClientConfig)
200226

201227
resp, err := httpClient.Do(req)
202228
if err != nil {

0 commit comments

Comments
 (0)