Skip to content
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
5 changes: 5 additions & 0 deletions cmd/fleetctl/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"runtime"

"github.com/fleetdm/fleet/server/service"
"github.com/pkg/errors"
Expand All @@ -27,6 +28,10 @@ func unauthenticatedClientFromCLI(c *cli.Context) (*service.Client, error) {
return nil, errors.New("set the Fleet API address with: fleetctl config set --address https://localhost:8080")
}

if runtime.GOOS == "windows" && cc.RootCA == "" && !cc.TLSSkipVerify {
return nil, errors.New("Windows clients must configure rootca (secure) or tls-skip-verify (insecure)")
}

fleet, err := service.NewClient(cc.Address, cc.TLSSkipVerify, cc.RootCA, cc.URLPrefix)
if err != nil {
return nil, errors.Wrap(err, "error creating Fleet API client handler")
Expand Down
8 changes: 6 additions & 2 deletions cmd/fleetctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"

"github.com/ghodss/yaml"
"github.com/kolide/kit/env"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
Expand All @@ -31,9 +30,14 @@ type Context struct {
}

func configFlag() cli.Flag {
homeDir, err := os.UserHomeDir()
if err != nil {
homeDir = "~"
}
defaultConfigPath := filepath.Join(homeDir, ".fleet", "config")
return cli.StringFlag{
Name: "config",
Value: fmt.Sprintf("%s/.fleet/config", env.String("HOME", "~/")),
Value: defaultConfigPath,
EnvVar: "CONFIG",
Usage: "Path to the Fleet config file",
}
Expand Down
17 changes: 8 additions & 9 deletions server/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,24 @@ func NewClient(addr string, insecureSkipVerify bool, rootCA, urlPrefix string) (
return nil, errors.Wrap(err, "parsing URL")
}

rootCAPool, err := x509.SystemCertPool()
if err != nil {
return nil, errors.Wrap(err, "loading system cert pool")
}

rootCAPool := x509.NewCertPool()
if rootCA != "" {
// set up empty cert pool
rootCAPool = x509.NewCertPool()

// read in the root cert file specified in the context
certs, err := ioutil.ReadFile(rootCA)
if err != nil {
return nil, errors.Wrap(err, "reading root CA")
}

// add certs to new cert pool
// add certs to pool
if ok := rootCAPool.AppendCertsFromPEM(certs); !ok {
return nil, errors.Wrap(err, "adding root CA")
}
} else if !insecureSkipVerify {
// Use only the system certs (doesn't work on Windows)
rootCAPool, err = x509.SystemCertPool()
if err != nil {
return nil, errors.Wrap(err, "loading system cert pool")
}
}

httpClient := &http.Client{
Expand Down