Skip to content

Commit

Permalink
Fix fleetctl Windows issues (#40)
Browse files Browse the repository at this point in the history
- Properly set the path for the config file on Windows.
- Check for appropriate settings for TLS config.

Fixes #39
  • Loading branch information
zwass authored Nov 18, 2020
1 parent ecf6fd1 commit ab94d94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
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

0 comments on commit ab94d94

Please sign in to comment.