diff --git a/README.md b/README.md index 5703f7291a55..beb7d7ee64ac 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Your feedback is always welcome. - Callum Styan's March 2019 DevOpsDays Vancouver talk "[Grafana Loki: Log Aggregation for Incident Investigations][devopsdays19-talk]". - Grafana Labs blog post "[How We Designed Loki to Work Easily Both as Microservices and as Monoliths][architecture-blog]". - Julien Garcia Gonzalez' March 2019 blog post "[Grafana Logging using Loki][giant-swarm-blog]". -- Tom Wilkie's early-2019 CNCF Paris/FODEM talk "[Grafana Loki: like Prometheus, but for logs][fosdem19-talk]" ([slides][fosdem19-slides], [video][fosdem19-video]). +- Tom Wilkie's early-2019 CNCF Paris/FOSDEM talk "[Grafana Loki: like Prometheus, but for logs][fosdem19-talk]" ([slides][fosdem19-slides], [video][fosdem19-video]). - David Kaltschmidt's KubeCon 2018 talk "[On the OSS Path to Full Observability with Grafana][kccna18-event]" ([slides][kccna18-slides], [video][kccna18-video]) on how Loki fits into a cloud-native environment. - Goutham Veeramachaneni's blog post "[Loki: Prometheus-inspired, open source logging for cloud natives](https://grafana.com/blog/2018/12/12/loki-prometheus-inspired-open-source-logging-for-cloud-natives/)" on details of the Loki architectire. - David Kaltschmidt's blog post "[Closer look at Grafana's user interface for Loki](https://grafana.com/blog/2019/01/02/closer-look-at-grafanas-user-interface-for-loki/)" on the ideas that went into the logging user interface. diff --git a/cmd/logcli/client.go b/cmd/logcli/client.go index 9e31353ee69b..59b5754f914b 100644 --- a/cmd/logcli/client.go +++ b/cmd/logcli/client.go @@ -12,6 +12,7 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/prometheus/common/config" "github.com/grafana/loki/pkg/logproto" ) @@ -60,9 +61,25 @@ func doRequest(path string, out interface{}) error { if err != nil { return err } + req.SetBasicAuth(*username, *password) - resp, err := http.DefaultClient.Do(req) + clientConfig := config.HTTPClientConfig{ + TLSConfig: config.TLSConfig{ + CAFile: *tlsCACertPath, + CertFile: *tlsClientCertPath, + KeyFile: *tlsClientCertKeyPath, + ServerName: url, + InsecureSkipVerify: *tlsSkipVerify, + }, + } + + client, err := config.NewClientFromConfig(clientConfig, "logcli") + if err != nil { + return err + } + + resp, err := client.Do(req) if err != nil { return err } @@ -86,6 +103,18 @@ func liveTailQueryConn() (*websocket.Conn, error) { } func wsConnect(path string) (*websocket.Conn, error) { + + tlsConfig, err := config.NewTLSConfig(&config.TLSConfig{ + CAFile: *tlsCACertPath, + CertFile: *tlsClientCertPath, + KeyFile: *tlsClientCertKeyPath, + ServerName: *addr, + InsecureSkipVerify: *tlsSkipVerify, + }) + if err != nil { + return nil, err + } + url := *addr + path if strings.HasPrefix(url, "https") { url = strings.Replace(url, "https", "wss", 1) @@ -95,7 +124,12 @@ func wsConnect(path string) (*websocket.Conn, error) { log.Println(url) h := http.Header{"Authorization": {"Basic " + base64.StdEncoding.EncodeToString([]byte(*username+":"+*password))}} - c, resp, err := websocket.DefaultDialer.Dial(url, h) + + ws := websocket.Dialer{ + TLSClientConfig: tlsConfig, + } + + c, resp, err := ws.Dial(url, h) if err != nil { if resp == nil { diff --git a/cmd/logcli/main.go b/cmd/logcli/main.go index 42861a2d1b24..d37074bc18ab 100644 --- a/cmd/logcli/main.go +++ b/cmd/logcli/main.go @@ -14,6 +14,11 @@ var ( username = app.Flag("username", "Username for HTTP basic auth.").Default("").Envar("GRAFANA_USERNAME").String() password = app.Flag("password", "Password for HTTP basic auth.").Default("").Envar("GRAFANA_PASSWORD").String() + tlsCACertPath = app.Flag("ca-cert", "Path to the server Certificate Authority.").Default("").Envar("LOKI_CA_CERT_PATH").String() + tlsSkipVerify = app.Flag("tls-skip-verify", "Server certificate TLS skip verify.").Default("false").Bool() + tlsClientCertPath = app.Flag("cert", "Path to the client certificate.").Default("").Envar("LOKI_CLIENT_CERT_PATH").String() + tlsClientCertKeyPath = app.Flag("key", "Path to the client certificate key.").Default("").Envar("LOKI_CLIENT_KEY_PATH").String() + queryCmd = app.Command("query", "Run a LogQL query.") queryStr = queryCmd.Arg("query", "eg '{foo=\"bar\",baz=\"blip\"}'").Required().String() regexpStr = queryCmd.Arg("regex", "").String() diff --git a/docs/logcli.md b/docs/logcli.md index b72727867bb6..678fb37b8817 100644 --- a/docs/logcli.md +++ b/docs/logcli.md @@ -44,8 +44,8 @@ Common labels: {job="cortex-ops/consul", namespace="cortex-ops"} ### Configuration - Configuration values are considered in the following order (lowest to highest): + - environment value - command line @@ -53,17 +53,22 @@ The URLs of the requests are printed to help with integration work. ### Details -``` +```console $ logcli help usage: logcli [] [ ...] A command-line for loki. Flags: - --help Show context-sensitive help (also try --help-long and --help-man). - --addr="" Server address, need to specify. - --username="" Username for HTTP basic auth. - --password="" Password for HTTP basic auth. + --help Show context-sensitive help (also try --help-long and --help-man). + --addr="https://logs-us-west1.grafana.net" + Server address. + --username="" Username for HTTP basic auth. + --password="" Password for HTTP basic auth. + --ca-cert="" Path to the server Certificate Authority. + --tls-skip-verify Server certificate TLS skip verify. + --cert="" Path to the client certificate. + --key="" Path to the client certificate key. Commands: help [...] @@ -72,7 +77,7 @@ Commands: query [] [] Run a LogQL query. - labels