Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ go:
- 1.8

install:
- go get -v github.com/Masterminds/glide
- cd $GOPATH/src/github.com/Masterminds/glide && git checkout tags/v0.12.3 && go install && cd -
- glide install -v
- go get -u github.com/jteeuwen/go-bindata/...

addons:
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG CLAIRCTL_VERSION=${CLAIRCTL_VERSION:-master}
ARG CLAIRCTL_COMMIT=

RUN apk add --update curl \
&& apk add --virtual build-dependencies go gcc build-base glide git \
&& apk add --virtual build-dependencies go gcc build-base git \
&& adduser clairctl -D \
&& mkdir -p /reports \
&& chown -R clairctl:clairctl /reports /tmp \
Expand All @@ -22,12 +22,10 @@ RUN apk add --update curl \
&& rm -f clairctl.zip \
&& mv ${GOPATH}/src/github.com/jgsqware/clairctl-* ${GOPATH}/src/github.com/jgsqware/clairctl \
&& cd ${GOPATH}/src/github.com/jgsqware/clairctl \
&& glide install -v \
&& go generate ./clair \
&& go build -o /usr/local/bin/clairctl -ldflags "-X github.com/jgsqware/clairctl/cmd.version=${CLAIRCTL_VERSION}-${CLAIRCTL_COMMIT}" \
&& apk del build-dependencies \
&& rm -rf /var/cache/apk/* \
&& rm -rf /root/.glide/ \
&& rm -rf /go \
&& echo $'clair:\n\
port: 6060\n\
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ clair:

**clairctl** requires Go 1.8+.

Install Glide:
```
curl https://glide.sh/get | sh
```

Clone and build:
```
git clone git@github.com:jgsqware/clairctl.git $GOPATH/src/github.com/jgsqware/clairctl
cd $GOPATH/src/github.com/jgsqware/clairctl
glide install -v
go generate ./clair
go build
```
Expand Down
2 changes: 1 addition & 1 deletion clair/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
)

//Analyze return Clair Image analysis
Expand Down
2 changes: 1 addition & 1 deletion clair/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
)

func Delete(image reference.NamedTagged, manifest distribution.Manifest) error {
Expand Down
15 changes: 8 additions & 7 deletions clair/layering.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"strings"

"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/coreos/clair/api/v1"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
"github.com/jgsqware/clairctl/config"
"github.com/jgsqware/clairctl/docker/dockerdist"
"github.com/jgsqware/clairctl/xstrings"
Expand Down Expand Up @@ -50,18 +50,19 @@ func (layers *layering) pushAll() error {

lUID := xstrings.Substr(digest, 0, 12)
log.Infof("Pushing Layer %d/%d [%v]", index+1, layerCount, lUID)
insertRegistryMapping(digest, layers.image.Hostname())
u, _ := dockerdist.GetPushURL(layers.image.Hostname())
domain := reference.Domain(layers.image)
insertRegistryMapping(digest, domain)
u, _ := dockerdist.GetPushURL(domain)
payload := v1.LayerEnvelope{Layer: &v1.Layer{
Name: digest,
Path: blobsURI(u.String(), layers.image.RemoteName(), digest),
Path: blobsURI(u.String(), reference.Path(layers.image), digest),
ParentName: layers.parentID,
Format: "Docker",
}}

//FIXME Update to TLS
if config.IsLocal {
local := layers.hURL + "/" + layers.image.Hostname()
local := layers.hURL + "/" + domain
payload.Layer.Path = strings.Replace(payload.Layer.Path, u.String(), local, 1)
payload.Layer.Path += "/layer.tar"
}
Expand Down Expand Up @@ -98,7 +99,7 @@ func (layers *layering) analyzeAll() ImageAnalysis {
}
}
return ImageAnalysis{
Registry: xstrings.TrimPrefixSuffix(layers.image.Hostname(), "http://", "/v2"),
Registry: xstrings.TrimPrefixSuffix(reference.Domain(layers.image), "http://", "/v2"),
ImageName: layers.image.Name(),
Tag: layers.image.Tag(),
Layers: res,
Expand Down
2 changes: 1 addition & 1 deletion clair/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
"github.com/jgsqware/clairctl/config"
"github.com/jgsqware/clairctl/docker/dockerdist"
"github.com/spf13/viper"
Expand Down
26 changes: 13 additions & 13 deletions clair/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"text/template"

"github.com/coreos/clair/api/v1"
"github.com/coreos/clair/utils/types"
"github.com/coreos/clair/database"
)

//execute go generate ./clair
Expand Down Expand Up @@ -45,10 +45,10 @@ func ReportAsHTML(analyzes ImageAnalysis) (string, error) {
return doc.String(), nil
}

func invertedPriorities() []types.Priority {
ip := make([]types.Priority, len(types.Priorities))
for i, j := 0, len(types.Priorities)-1; i <= j; i, j = i+1, j-1 {
ip[i], ip[j] = types.Priorities[j], types.Priorities[i]
func invertedPriorities() []database.Severity {
ip := make([]database.Severity, len(database.Severities))
for i, j := 0, len(database.Severities)-1; i <= j; i, j = i+1, j-1 {
ip[i], ip[j] = database.Severities[j], database.Severities[i]
}
return ip

Expand All @@ -60,7 +60,7 @@ type vulnerabilityWithFeature struct {
}

//VulnerabiliesCounts Total count of vulnerabilities by type
type vulnerabiliesCounts map[types.Priority]int
type vulnerabiliesCounts map[database.Severity]int

//Total return to total of Vulnerabilities
func (v vulnerabiliesCounts) Total() int {
Expand All @@ -73,12 +73,12 @@ func (v vulnerabiliesCounts) Total() int {

//Count return count of severities in Vulnerabilities
func (v vulnerabiliesCounts) Count(severity string) int {
return v[types.Priority(severity)]
return v[database.Severity(severity)]
}

//RelativeCount get the percentage of vulnerabilities of a severity
func (v vulnerabiliesCounts) RelativeCount(severity string) float64 {
count := v[types.Priority(severity)]
count := v[database.Severity(severity)]
result := float64(count) / float64(v.Total()) * 100
return math.Ceil(result*100) / 100
}
Expand All @@ -92,23 +92,23 @@ func allVulnerabilities(imageAnalysis ImageAnalysis) vulnerabiliesCounts {
for _, f := range l.Layer.Features {

for _, v := range f.Vulnerabilities {
result[types.Priority(v.Severity)]++
result[database.Severity(v.Severity)]++
}
}

return result
}

//Vulnerabilities return a list a vulnerabilities
func vulnerabilities(imageAnalysis ImageAnalysis) map[types.Priority][]vulnerabilityWithFeature {
func vulnerabilities(imageAnalysis ImageAnalysis) map[database.Severity][]vulnerabilityWithFeature {

result := make(map[types.Priority][]vulnerabilityWithFeature)
result := make(map[database.Severity][]vulnerabilityWithFeature)

l := imageAnalysis.MostRecentLayer()
for _, f := range l.Layer.Features {
for _, v := range f.Vulnerabilities {

result[types.Priority(v.Severity)] = append(result[types.Priority(v.Severity)], vulnerabilityWithFeature{Vulnerability: v, Feature: f.Name + ":" + f.Version})
result[database.Severity(v.Severity)] = append(result[database.Severity(v.Severity)], vulnerabilityWithFeature{Vulnerability: v, Feature: f.Name + ":" + f.Version})
}
}

Expand All @@ -126,7 +126,7 @@ func sortedVulnerabilities(imageAnalysis ImageAnalysis) []v1.Feature {
vulnerabilities := []v1.Vulnerability{}
for _, p := range invertedPriorities() {
for _, v := range f.Vulnerabilities {
if types.Priority(v.Severity) == p {
if database.Severity(v.Severity) == p {
vulnerabilities = append(vulnerabilities, v)
}
}
Expand Down
4 changes: 2 additions & 2 deletions clair/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/coreos/clair/utils/types"
"github.com/coreos/clair/database"
)

func TestReportAsHtml(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestReportAsHtml(t *testing.T) {
}

func TestInvertedPriorities(t *testing.T) {
expected := []types.Priority{types.Defcon1, types.Critical, types.High, types.Medium, types.Low, types.Negligible, types.Unknown}
expected := []database.Severity{database.Defcon1Severity, database.CriticalSeverity, database.HighSeverity, database.MediumSeverity, database.LowSeverity, database.NegligibleSeverity, database.UnknownSeverity}
ip := invertedPriorities()
for i, v := range ip {
if v != expected[i] {
Expand Down
37 changes: 19 additions & 18 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/coreos/clair/api/v1"
"github.com/coreos/clair/utils/types"
"github.com/coreos/clair/database"
"github.com/fatih/color"
"github.com/jgsqware/clairctl/clair"
"github.com/jgsqware/clairctl/config"
Expand Down Expand Up @@ -75,26 +75,26 @@ var analyzeCmd = &cobra.Command{
}

type PriorityCount struct {
Priority types.Priority
Priority database.Severity
Count int
}

func colorized(p PriorityCount) string {
switch p.Priority {

case types.Unknown:
case database.UnknownSeverity:
return color.WhiteString("%v: %v", p.Priority, p.Count)
case types.Negligible:
case database.NegligibleSeverity:
return color.HiWhiteString("%v: %v", p.Priority, p.Count)
case types.Low:
case database.LowSeverity:
return color.YellowString("%v: %v", p.Priority, p.Count)
case types.Medium:
case database.MediumSeverity:
return color.HiYellowString("%v: %v", p.Priority, p.Count)
case types.High:
case database.HighSeverity:
return color.MagentaString("%v: %v", p.Priority, p.Count)
case types.Critical:
case database.CriticalSeverity:
return color.RedString("%v: %v", p.Priority, p.Count)
case types.Defcon1:
case database.Defcon1Severity:
return color.HiRedString("%v: %v", p.Priority, p.Count)
default:
return color.WhiteString("%v: %v", p.Priority, p.Count)
Expand All @@ -111,11 +111,12 @@ func isValid(l v1.LayerEnvelope) bool {
return true
}

func getPrioritiesFromArgs() []types.Priority {
f := []types.Priority{}
func getPrioritiesFromArgs() []database.Severity {
f := []database.Severity{}
for _, aa := range strings.Split(filters, ",") {
if types.Priority(aa).IsValid() {
f = append(f, types.Priority(aa))
s, err := database.NewSeverity(aa)
if err == nil {
f = append(f, s)
}
}
return f
Expand All @@ -125,23 +126,23 @@ func CountVulnerabilities(l v1.LayerEnvelope) []PriorityCount {
filtersS := getPrioritiesFromArgs()

if len(filtersS) == 0 {
filtersS = types.Priorities
filtersS = database.Severities
}
r := make(map[types.Priority]int)
r := make(map[database.Severity]int)
for _, v := range filtersS {
r[v] = 0
}

for _, f := range l.Layer.Features {
for _, v := range f.Vulnerabilities {
if _, ok := r[types.Priority(v.Severity)]; ok {
r[types.Priority(v.Severity)]++
if _, ok := r[database.Severity(v.Severity)]; ok {
r[database.Severity(v.Severity)]++
}
}
}

result := []PriorityCount{}
for _, p := range types.Priorities {
for _, p := range database.Severities {
if pp, ok := r[p]; ok {
result = append(result, PriorityCount{p, pp})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/jgsqware/clairctl/clair"
"github.com/jgsqware/clairctl/config"
"github.com/jgsqware/clairctl/docker"
Expand Down
2 changes: 1 addition & 1 deletion cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"html/template"
"os"

"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
"github.com/jgsqware/clairctl/config"
"github.com/jgsqware/clairctl/docker"
"github.com/opencontainers/go-digest"
Expand Down
2 changes: 1 addition & 1 deletion docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
"github.com/jgsqware/clairctl/config"
"github.com/jgsqware/clairctl/docker/dockercli"
"github.com/jgsqware/clairctl/docker/dockerdist"
Expand Down
8 changes: 6 additions & 2 deletions docker/dockercli/dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/reference"
"github.com/docker/distribution/reference"
"github.com/jgsqware/clairctl/config"
"github.com/opencontainers/go-digest"
)
Expand All @@ -35,7 +35,11 @@ func GetLocalManifest(imageName string, withExport bool) (reference.NamedTagged,
}
var image reference.NamedTagged
if reference.IsNameOnly(n) {
image = reference.WithDefaultTag(n).(reference.NamedTagged)
r, err := reference.WithTag(n, "latest")
if err != nil {
return nil, nil, err
}
image = r.(reference.NamedTagged)
} else {
image = n.(reference.NamedTagged)
}
Expand Down
Loading