core

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2018 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunPerceptor added in v0.0.10

func RunPerceptor()

Types

type Container added in v0.0.5

type Container struct {
	Image Image
	Name  string
}

func NewContainer added in v0.0.5

func NewContainer(image Image, name string) *Container

type DockerImageSha added in v0.0.5

type DockerImageSha string

type HTTPResponder

type HTTPResponder struct {
	AddPodChannel                 chan Pod
	UpdatePodChannel              chan Pod
	DeletePodChannel              chan string
	AddImageChannel               chan Image
	AllPodsChannel                chan []Pod
	AllImagesChannel              chan []Image
	PostNextImageChannel          chan func(*Image)
	PostFinishScanJobChannel      chan api.FinishedScanClientJob
	SetConcurrentScanLimitChannel chan int
	GetModelChannel               chan func(json string)
	GetScanResultsChannel         chan func(scanResults api.ScanResults)
}

HTTPResponder ...

func NewHTTPResponder

func NewHTTPResponder() *HTTPResponder

func (*HTTPResponder) AddImage

func (hr *HTTPResponder) AddImage(apiImage api.Image)

func (*HTTPResponder) AddPod

func (hr *HTTPResponder) AddPod(apiPod api.Pod)

func (*HTTPResponder) DeletePod

func (hr *HTTPResponder) DeletePod(qualifiedName string)

func (*HTTPResponder) Error

func (hr *HTTPResponder) Error(w http.ResponseWriter, r *http.Request, err error, statusCode int)

func (*HTTPResponder) GetModel

func (hr *HTTPResponder) GetModel() string

func (*HTTPResponder) GetNextImage

func (hr *HTTPResponder) GetNextImage() api.NextImage

func (*HTTPResponder) GetScanResults

func (hr *HTTPResponder) GetScanResults() api.ScanResults

GetScanResults returns results for:

  • all images that have a scan status of complete
  • all pods for which all their images have a scan status of complete

func (*HTTPResponder) NotFound

func (hr *HTTPResponder) NotFound(w http.ResponseWriter, r *http.Request)

func (*HTTPResponder) PostFinishScan

func (hr *HTTPResponder) PostFinishScan(job api.FinishedScanClientJob)

func (*HTTPResponder) SetConcurrentScanLimit added in v0.0.7

func (hr *HTTPResponder) SetConcurrentScanLimit(limit api.SetConcurrentScanLimit)

func (*HTTPResponder) UpdateAllImages added in v0.0.7

func (hr *HTTPResponder) UpdateAllImages(allImages api.AllImages)

func (*HTTPResponder) UpdateAllPods

func (hr *HTTPResponder) UpdateAllPods(allPods api.AllPods)

func (*HTTPResponder) UpdatePod

func (hr *HTTPResponder) UpdatePod(apiPod api.Pod)

type HubImageScan

type HubImageScan struct {
	Sha  DockerImageSha
	Scan *hub.ImageScan
}

type Image added in v0.0.5

type Image struct {
	// Name combines Host, User, and Project
	Name string
	Sha  DockerImageSha
}

func NewImage added in v0.0.5

func NewImage(name string, sha DockerImageSha) *Image

func (Image) HubProjectName added in v0.0.5

func (image Image) HubProjectName() string

func (Image) HubProjectNameSearchString added in v0.0.7

func (image Image) HubProjectNameSearchString() string

func (Image) HubProjectVersionName added in v0.0.5

func (image Image) HubProjectVersionName() string

func (Image) HubProjectVersionNameSearchString added in v0.0.7

func (image Image) HubProjectVersionNameSearchString() string

func (Image) HubScanName added in v0.0.5

func (image Image) HubScanName() string

func (Image) HubScanNameSearchString added in v0.0.7

func (image Image) HubScanNameSearchString() string

func (*Image) HumanReadableName added in v0.0.5

func (image *Image) HumanReadableName() string

HumanReadableName returns a nice, easy to read string

func (*Image) PullSpec added in v0.0.5

func (image *Image) PullSpec() string

PullSpec combines Name with the image sha and should be pullable by Docker

type ImageInfo added in v0.0.5

type ImageInfo struct {
	ScanStatus             ScanStatus
	TimeOfLastStatusChange time.Time
	ScanResults            *hub.ImageScan
	ImageSha               DockerImageSha
	ImageNames             []string
}

func NewImageInfo added in v0.0.5

func NewImageInfo(sha DockerImageSha, imageName string) *ImageInfo

type Model

type Model struct {
	// Pods is a map of "<namespace>/<name>" to pod
	Pods                map[string]Pod
	Images              map[DockerImageSha]*ImageInfo
	ImageScanQueue      []Image
	ImageHubCheckQueue  []Image
	ConcurrentScanLimit int
	Config              PerceptorConfig
	HubVersion          string
}

Model is the root of the core model

func NewModel

func NewModel(config PerceptorConfig, hubVersion string) *Model

func (*Model) AddImage

func (model *Model) AddImage(image Image)

AddImage adds an image to the model, sets its status to NotScanned, and adds it to the queue for hub checking.

func (*Model) AddPod

func (model *Model) AddPod(newPod Pod)

AddPod adds a pod and all the images in a pod to the model. If the pod is already present in the model, it will be removed and a new one created in its place. The key is the combination of the pod's namespace and name. It extract the containers and images from the pod, adding them into the cache.

func (*Model) DeletePod

func (model *Model) DeletePod(podName string)

DeletePod removes the record of a pod, but does not affect images.

type ModelMetrics added in v0.0.8

type ModelMetrics struct {
	ScanStatusCounts    map[ScanStatus]int
	NumberOfPods        int
	NumberOfImages      int
	ContainerCounts     map[int]int
	ImageCountHistogram map[int]int
}

type Perceptor

type Perceptor struct {
	// contains filtered or unexported fields
}

Perceptor ties together: a cluster, scan clients, and a hub. It listens to the cluster to learn about new pods. It keeps track of pods, containers, images, and scan results in a model. It has the hub scan images that have never been seen before. It grabs the scan results from the hub and adds them to its model. It publishes vulnerabilities that the cluster can find out about.

func NewMockedPerceptor

func NewMockedPerceptor() (*Perceptor, error)

NewMockedPerceptor creates a Perceptor which uses a mock hub

func NewPerceptor

func NewPerceptor(config PerceptorConfig) (*Perceptor, error)

NewPerceptor creates a Perceptor using a real hub client.

type PerceptorConfig

type PerceptorConfig struct {
	HubHost             string
	HubUser             string
	HubUserPassword     string
	ConcurrentScanLimit int
	UseMockMode         bool
	Port                int
}

PerceptorConfig contains all configuration for Perceptor

func GetPerceptorConfig

func GetPerceptorConfig() (*PerceptorConfig, error)

GetPerceptorConfig returns a configuration object to configure Perceptor

func (*PerceptorConfig) StartWatch

func (p *PerceptorConfig) StartWatch(handler func(fsnotify.Event))

StartWatch will start watching the Perceptor configuration file and call the passed handler function when the configuration file has changed

type Pod added in v0.0.5

type Pod struct {
	Name       string
	UID        string
	Namespace  string
	Containers []Container
}

func NewPod added in v0.0.5

func NewPod(name string, uid string, namespace string, containers []Container) *Pod

func (*Pod) QualifiedName added in v0.0.5

func (pod *Pod) QualifiedName() string

type ScanStatus

type ScanStatus int

ScanStatus describes the state of an image in perceptor

const (
	ScanStatusUnknown           ScanStatus = iota
	ScanStatusInHubCheckQueue   ScanStatus = iota
	ScanStatusCheckingHub       ScanStatus = iota
	ScanStatusInQueue           ScanStatus = iota
	ScanStatusRunningScanClient ScanStatus = iota
	ScanStatusRunningHubScan    ScanStatus = iota
	ScanStatusComplete          ScanStatus = iota
	ScanStatusError             ScanStatus = iota
)

func (ScanStatus) MarshalJSON added in v0.0.8

func (s ScanStatus) MarshalJSON() ([]byte, error)

func (ScanStatus) MarshalText added in v0.0.8

func (s ScanStatus) MarshalText() (text []byte, err error)

func (ScanStatus) String

func (status ScanStatus) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL