Skip to content

Commit

Permalink
Update meta nodes to respect insecure skip verify
Browse files Browse the repository at this point in the history
  • Loading branch information
goller authored and lukevmorris committed Feb 14, 2018
1 parent bc864e4 commit 093fb7d
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.4.1.2
current_version = 1.4.1.3
files = README.md server/swagger.json
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(?P<release>\d+)
serialize = {major}.{minor}.{patch}.{release}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## v1.4.2.0 [unreleased]
### Features
### UI Improvements
### Bug Fixes

## v1.4.1.3 [2018-02-14]
### Bug Fixes
1. [#2818](https://github.com/influxdata/chronograf/pull/2818): Allow self-signed certificates for Enterprise InfluxDB Meta nodes

## v1.4.1.2 [2018-02-13]
### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ option.
## Versions

The most recent version of Chronograf is
[v1.4.1.2](https://www.influxdata.com/downloads/).
[v1.4.1.3](https://www.influxdata.com/downloads/).

Spotted a bug or have a feature request? Please open
[an issue](https://github.com/influxdata/chronograf/issues/new)!
Expand Down Expand Up @@ -178,7 +178,7 @@ By default, chronograf runs on port `8888`.
To get started right away with Docker, you can pull down our latest release:

```sh
docker pull chronograf:1.4.1.2
docker pull chronograf:1.4.1.3
```

### From Source
Expand Down
8 changes: 4 additions & 4 deletions enterprise/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type Client struct {
}

// NewClientWithTimeSeries initializes a Client with a known set of TimeSeries.
func NewClientWithTimeSeries(lg chronograf.Logger, mu string, authorizer influx.Authorizer, tls bool, series ...chronograf.TimeSeries) (*Client, error) {
func NewClientWithTimeSeries(lg chronograf.Logger, mu string, authorizer influx.Authorizer, tls, insecure bool, series ...chronograf.TimeSeries) (*Client, error) {
metaURL, err := parseMetaURL(mu, tls)
if err != nil {
return nil, err
}

ctrl := NewMetaClient(metaURL, authorizer)
ctrl := NewMetaClient(metaURL, insecure, authorizer)
c := &Client{
Ctrl: ctrl,
UsersStore: &UserStore{
Expand Down Expand Up @@ -85,13 +85,13 @@ func NewClientWithTimeSeries(lg chronograf.Logger, mu string, authorizer influx.
// varieties. TLS is used when the URL contains "https" or when the TLS
// parameter is set. authorizer will add the correct `Authorization` headers
// on the out-bound request.
func NewClientWithURL(mu string, authorizer influx.Authorizer, tls bool, lg chronograf.Logger) (*Client, error) {
func NewClientWithURL(mu string, authorizer influx.Authorizer, tls bool, insecure bool, lg chronograf.Logger) (*Client, error) {
metaURL, err := parseMetaURL(mu, tls)
if err != nil {
return nil, err
}

ctrl := NewMetaClient(metaURL, authorizer)
ctrl := NewMetaClient(metaURL, insecure, authorizer)
return &Client{
Ctrl: ctrl,
UsersStore: &UserStore{
Expand Down
70 changes: 51 additions & 19 deletions enterprise/enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func Test_Enterprise_AdvancesDataNodes(t *testing.T) {
Password: "thelake",
},
false,
false,
chronograf.TimeSeries(m1),
chronograf.TimeSeries(m2))
if err != nil {
Expand Down Expand Up @@ -114,23 +115,53 @@ func Test_Enterprise_NewClientWithURL(t *testing.T) {
t.Parallel()

urls := []struct {
url string
username string
password string
tls bool
shouldErr bool
name string
url string
username string
password string
tls bool
insecureSkipVerify bool
wantErr bool
}{
{"http://localhost:8086", "", "", false, false},
{"https://localhost:8086", "", "", false, false},
{"http://localhost:8086", "username", "password", false, false},

{"http://localhost:8086", "", "", true, false},
{"https://localhost:8086", "", "", true, false},

{"localhost:8086", "", "", false, false},
{"localhost:8086", "", "", true, false},

{":http", "", "", false, true},
{
name: "no tls should have no error",
url: "http://localhost:8086",
},
{
name: "tls sholuld have no error",
url: "https://localhost:8086",
},
{
name: "no tls but with basic auth",
url: "http://localhost:8086",
username: "username",
password: "password",
},
{
name: "tls request but url is not tls should not error",
url: "http://localhost:8086",
tls: true,
},
{
name: "https with tls and with insecureSkipVerify should not error",
url: "https://localhost:8086",
tls: true,
insecureSkipVerify: true,
},
{
name: "URL does not require http or https",
url: "localhost:8086",
},
{
name: "URL with TLS request should not error",
url: "localhost:8086",
tls: true,
},
{
name: "invalid URL causes error",
url: ":http",
wantErr: true,
},
}

for _, testURL := range urls {
Expand All @@ -141,10 +172,11 @@ func Test_Enterprise_NewClientWithURL(t *testing.T) {
Password: testURL.password,
},
testURL.tls,
testURL.insecureSkipVerify,
log.New(log.DebugLevel))
if err != nil && !testURL.shouldErr {
if err != nil && !testURL.wantErr {
t.Errorf("Unexpected error creating Client with URL %s and TLS preference %t. err: %s", testURL.url, testURL.tls, err.Error())
} else if err == nil && testURL.shouldErr {
} else if err == nil && testURL.wantErr {
t.Errorf("Expected error creating Client with URL %s and TLS preference %t", testURL.url, testURL.tls)
}
}
Expand All @@ -159,7 +191,7 @@ func Test_Enterprise_ComplainsIfNotOpened(t *testing.T) {
Username: "docbrown",
Password: "1.21 gigawatts",
},
false, chronograf.TimeSeries(m1))
false, false, chronograf.TimeSeries(m1))
if err != nil {
t.Error("Expected ErrUnitialized, but was this err:", err)
}
Expand Down
26 changes: 22 additions & 4 deletions enterprise/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package enterprise
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand All @@ -14,6 +15,14 @@ import (
"github.com/influxdata/chronograf/influx"
)

// Shared transports for all clients to prevent leaking connections
var (
skipVerifyTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
defaultTransport = &http.Transport{}
)

type client interface {
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
}
Expand All @@ -26,10 +35,12 @@ type MetaClient struct {
}

// NewMetaClient represents a meta node in an Influx Enterprise cluster
func NewMetaClient(url *url.URL, authorizer influx.Authorizer) *MetaClient {
func NewMetaClient(url *url.URL, InsecureSkipVerify bool, authorizer influx.Authorizer) *MetaClient {
return &MetaClient{
URL: url,
client: &defaultClient{},
URL: url,
client: &defaultClient{
InsecureSkipVerify: InsecureSkipVerify,
},
authorizer: authorizer,
}
}
Expand Down Expand Up @@ -399,7 +410,8 @@ func (m *MetaClient) Post(ctx context.Context, path string, action interface{},
}

type defaultClient struct {
Leader string
Leader string
InsecureSkipVerify bool
}

// Do is a helper function to interface with Influx Enterprise's Meta API
Expand Down Expand Up @@ -438,6 +450,12 @@ func (d *defaultClient) Do(URL *url.URL, path, method string, authorizer influx.
CheckRedirect: d.AuthedCheckRedirect,
}

if d.InsecureSkipVerify {
client.Transport = skipVerifyTransport
} else {
client.Transport = defaultTransport
}

res, err := client.Do(req)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion enterprise/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *UserStore) Delete(ctx context.Context, u *chronograf.User) error {
return c.Ctrl.DeleteUser(ctx, u.Name)
}

// Number of users in Influx
// Num of users in Influx
func (c *UserStore) Num(ctx context.Context) (int, error) {
all, err := c.All(ctx)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (c *InfluxClient) New(src chronograf.Source, logger chronograf.Logger) (chr
}
if src.Type == chronograf.InfluxEnterprise && src.MetaURL != "" {
tls := strings.Contains(src.MetaURL, "https")
return enterprise.NewClientWithTimeSeries(logger, src.MetaURL, influx.DefaultAuthorization(&src), tls, client)
insecure := src.InsecureSkipVerify
return enterprise.NewClientWithTimeSeries(logger, src.MetaURL, influx.DefaultAuthorization(&src), tls, insecure, client)
}
return client, nil
}
2 changes: 1 addition & 1 deletion server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Chronograf",
"description": "API endpoints for Chronograf",
"version": "1.4.1.2"
"version": "1.4.1.3"
},
"schemes": ["http"],
"basePath": "/chronograf/v1",
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chronograf-ui",
"version": "1.4.1-2",
"version": "1.4.1-3",
"private": false,
"license": "AGPL-3.0",
"description": "",
Expand Down

0 comments on commit 093fb7d

Please sign in to comment.