Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable for TLS check when pulling layers #331

Merged
merged 1 commit into from
Feb 27, 2017
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
8 changes: 8 additions & 0 deletions cmd/clair/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/coreos/clair"
"github.com/coreos/clair/api"
"github.com/coreos/clair/database"
"github.com/coreos/clair/ext/imagefmt"
"github.com/coreos/clair/pkg/stopper"

// Register database driver.
Expand Down Expand Up @@ -123,6 +124,7 @@ func main() {
flagConfigPath := flag.String("config", "/etc/clair/config.yaml", "Load configuration from the specified file.")
flagCPUProfilePath := flag.String("cpu-profile", "", "Write a CPU profile to the specified file before exiting.")
flagLogLevel := flag.String("log-level", "info", "Define the logging level.")
flagInsecureTLS := flag.Bool("insecure-tls", false, "Disable TLS server's certificate chain and hostname verification when pulling layers.")
flag.Parse()

// Check for dependencies.
Expand All @@ -149,5 +151,11 @@ func main() {
defer stopCPUProfiling(startCPUProfiling(*flagCPUProfilePath))
}

// Enable TLS server's certificate chain and hostname verification
// when pulling layers if specified
if *flagInsecureTLS {
imagefmt.SetInsecureTLS(*flagInsecureTLS)
}

Boot(config)
}
17 changes: 16 additions & 1 deletion ext/imagefmt/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package imagefmt

import (
"crypto/tls"
"fmt"
"io"
"math"
Expand All @@ -38,6 +39,10 @@ var (
// ErrCouldNotFindLayer is returned when we could not download or open the layer file.
ErrCouldNotFindLayer = commonerr.NewBadRequestError("could not find layer")

// insecureTLS controls whether TLS server's certificate chain and hostname are verified
// when pulling layers, verified in default.
insecureTLS = false

log = capnslog.NewPackageLogger("github.com/coreos/clair", "ext/imagefmt")

extractorsM sync.RWMutex
Expand Down Expand Up @@ -116,7 +121,11 @@ func Extract(format, path string, headers map[string]string, toExtract []string)
}

// Send the request and handle the response.
r, err := http.DefaultClient.Do(request)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureTLS},
}
client := &http.Client{Transport: tr}
r, err := client.Do(request)
if err != nil {
log.Warningf("could not download layer: %s", err)
return nil, ErrCouldNotFindLayer
Expand Down Expand Up @@ -148,3 +157,9 @@ func Extract(format, path string, headers map[string]string, toExtract []string)

return nil, commonerr.NewBadRequestError(fmt.Sprintf("unsupported image format '%s'", format))
}

// SetInsecureTLS sets the insecureTLS to control whether TLS server's certificate chain
// and hostname are verified when pulling layers.
func SetInsecureTLS(insecure bool) {
insecureTLS = insecure
}