Documentation
¶
Overview ¶
Package reimage provides tools for processing/updating the images listed in k8s manifests.
Package reimage provides tools for processing/updating the images listed in k8s manifests
Package reimage provides tools for processing/updating the images listed in k8s manifests.
Index ¶
- Variables
- func ProcessK8s(w io.Writer, r io.Reader, u Updater) error
- func ProcessRawYAML(w io.Writer, r io.Reader, u Updater) error
- type EnsureRemapper
- type GCPBinAuthzConcisePayload
- type GCPBinAuthzPayload
- type GrafeasAttester
- type GrafeasClient
- type GrafeasVulnGetter
- type History
- type IgnoreRemapper
- type ImageCheckError
- type ImageSetters
- type ImageVulnerability
- type ImagesFinder
- type JSONImageFinderConfig
- type KMS
- type KMSClient
- type Keyer
- type Logger
- type MultiRemapper
- type QualifiedImage
- type RawYAML
- type RecorderRemapper
- type Remapper
- type RenameRemapper
- type RenameUpdater
- type RepoTemplateInput
- type Setter
- type StaticRemapper
- type TrivyVulnGetter
- type Updater
- type VulnCheckResult
- type VulnChecker
- type VulnGetter
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTemplateStr is a sensible default for importing images. DefaultTemplateStr = `{{ .RemotePath }}/{{ .Registry }}/{{ .Repository }}:{{ .DigestHex }}` // DefaultRulesConfig is a set of additional, non-core rules for known existing image // locations. DefaultRulesConfig = []JSONImageFinderConfig{ { Kind: "^Prometheus$", APIVersion: `^monitoring\.coreos\.com/v1$`, ImageJSONP: []string{"$.spec.image"}, }, } // ErrDiscoveryNotFound is returned when no Vulnerability checking Discovery is associated with an image. ErrDiscoveryNotFound = errors.New("discovery not found in response") // ErrDiscoverNotFinished is returned when Vulnerability checking did not complete in time. ErrDiscoverNotFinished = errors.New("vulnerability checking not completed") // ErrAttestationNotFound is return if no attestations are present for a given image digest. ErrAttestationNotFound = errors.New("attestation not found in response") )
var DefaultLogger = Logger(slog.Default())
DefaultLogger is a quick shortcut to the slog default logger.
var ErrSkip = errors.New("skip further processing")
ErrSkip if this is returned by ReMap then MultiRemapper will ignore this image and skip further processing.
Functions ¶
func ProcessK8s ¶ added in v0.9.0
ProcessK8s runs the Updater for each kubernetes resource found in the file. Unknown field are converted to.
Types ¶
type EnsureRemapper ¶ added in v0.2.0
type EnsureRemapper struct {
Logger
NoClobber bool // If true, we'll refuse to overwrite remote images
DryRun bool // If true, don't perform the any actual copies
}
EnsureRemapper is a mapper that will copy the original image reference to the latest, possibly remote, reference.
func (*EnsureRemapper) ReMap ¶ added in v0.2.0
func (t *EnsureRemapper) ReMap(h *History) error
ReMap copies the original reference to the latest, potentially remote reference.
type GCPBinAuthzConcisePayload ¶ added in v0.2.0
GCPBinAuthzConcisePayload is a convenient wrapper around GCPBinAuthzPayload it with json.Marshal to a GCPBinAuthzPayload with correctly set Type.
func (*GCPBinAuthzConcisePayload) MarshalJSON ¶ added in v0.2.0
func (pl *GCPBinAuthzConcisePayload) MarshalJSON() ([]byte, error)
MarshalJSON marshals the provided type to JSON, but conforming to the structure of a GCPBinAuthzPayload.
type GCPBinAuthzPayload ¶ added in v0.2.0
type GCPBinAuthzPayload struct {
Critical struct {
Identity struct {
DockerReference string `json:"docker-reference"`
} `json:"identitiy"`
Image struct {
DockerManifestDigest string `json:"docker-manifest-digest"`
} `json:"image"`
Type string `json:"type"`
} `json:"critical"`
}
GCPBinAuthzPayload is the mandated attestation note for signing Docker/OCI images for Google's Binauthz implementation.
type GrafeasAttester ¶ added in v0.2.0
type GrafeasAttester struct {
Grafeas GrafeasClient
Keys Keyer
Logger
Parent string
NoteRef string
}
GrafeasAttester implements attestation creation and checking using Grafaes.
func (*GrafeasAttester) Attest ¶ added in v0.2.0
Attest creates a NoteRef attestation for digest. It will skip this if one already exist.
type GrafeasClient ¶ added in v0.2.0
type GrafeasClient interface {
ListOccurrences(ctx context.Context, req *grafeaspb.ListOccurrencesRequest, opts ...gax.CallOption) *grafeas.OccurrenceIterator
CreateOccurrence(ctx context.Context, req *grafeaspb.CreateOccurrenceRequest, opts ...gax.CallOption) (*grafeaspb.Occurrence, error)
}
GrafeasClient still isn't mockable, need to wrap it.
type GrafeasVulnGetter ¶ added in v0.7.0
type GrafeasVulnGetter struct {
Grafeas GrafeasClient
Logger
Parent string
RetryMax int
RetryDelay time.Duration
}
GrafeasVulnGetter checks that images have been scanned, and checks that they do not contain unexpected vulnerabilities.
func (*GrafeasVulnGetter) GetVulnerabilities ¶ added in v0.7.0
func (vc *GrafeasVulnGetter) GetVulnerabilities(ctx context.Context, dig name.Digest) ([]ImageVulnerability, error)
GetVulnerabilities waits for a completed vulnerability discovery, and then check that an image has no CVEs that violate the configured policy.
type History ¶
History is the full set of updates performed so far.
func NewHistory ¶
NewHistory starts a history for a given reference.
func (*History) AddDigest ¶ added in v0.2.0
AddDigest sets the known image digest for the image being tracked by this history.
func (*History) LatestDigest ¶ added in v0.2.0
LatestDigest constructs a digest name for the latest reference, and the original digest.
type IgnoreRemapper ¶ added in v0.6.0
IgnoreRemapper will return ErrSkip for any image name that natches the Ignore regexp.
func (*IgnoreRemapper) ReMap ¶ added in v0.6.0
func (t *IgnoreRemapper) ReMap(h *History) error
ReMap will return ErrSkip for any image name that natches the Ignore regexp.
type ImageCheckError ¶ added in v0.2.0
ImageCheckError is returned by Check if unwanted vulnerabilities are found.
func (*ImageCheckError) Error ¶ added in v0.2.0
func (ice *ImageCheckError) Error() string
type ImageSetters ¶
type ImageSetters []Setter
ImageSetters is list of one of more Setters.
func (ImageSetters) Set ¶
func (ss ImageSetters) Set(img string)
Set all the image setters in the list to the provided image.
type ImageVulnerability ¶ added in v0.7.0
ImageVulnerability describes a given CVE by ID and score.
type ImagesFinder ¶
type ImagesFinder interface {
FindImages(obj any) (map[string]ImageSetters, error)
FindK8sImages(obj *unstructured.Unstructured) (map[string]ImageSetters, error)
}
ImagesFinder specifies any mechanism for finding images within any k8s Unstructured data. Each entry in the map is an image name that was found. Calling the Set method on the map values will replace the discovered image name with a replacement.
func CompileJSONImageFinders ¶
func CompileJSONImageFinders(jmCfgs []JSONImageFinderConfig) (ImagesFinder, error)
CompileJSONImageFinders builds an ImagesFinder than can find image configuration strings from arbitrary unstructured K8S JSON objects, using JSONP queries.
type JSONImageFinderConfig ¶
type JSONImageFinderConfig struct {
Kind string `json:"kind" yaml:"kind"` // regexp to match k8s kind
APIVersion string `json:"apiVersion" yaml:"apiVersion"` // regexp to match k8s apiVersion
ImageJSONP []string `json:"imageJSONP" yaml:"imageJSONP"` // jsonP queries to find individual image fields
}
JSONImageFinderConfig describes the settings for finding arbitrary image fields in K8S types.
type KMS ¶ added in v0.2.0
KMS uses Google Cloud KMS to sign and verify data. Only EC_SIGN_P256_SHA256 are supported at this time.
type KMSClient ¶ added in v0.2.0
type KMSClient interface {
AsymmetricSign(ctx context.Context, req *kmspb.AsymmetricSignRequest, opts ...gax.CallOption) (*kmspb.AsymmetricSignResponse, error)
GetPublicKey(ctx context.Context, req *kmspb.GetPublicKeyRequest, opts ...gax.CallOption) (*kmspb.PublicKey, error)
}
KMSClient describes all the methods we require for a Google compatible signing service.
type Keyer ¶ added in v0.2.0
type Keyer interface {
Sign(ctx context.Context, bs []byte) ([]byte, string, error)
Verify(ctx context.Context, bs, sig []byte) error
}
Keyer is an interface to a private key, for signing and verifying blobs.
type MultiRemapper ¶
type MultiRemapper []Remapper
MultiRemapper applies each remapper, passing results from one to the next.
func (MultiRemapper) ReMap ¶
func (t MultiRemapper) ReMap(h *History) error
ReMap applies each remapper, passing results from one to the next. An error is returned as soon as any remapper fails.
type QualifiedImage ¶ added in v0.2.0
type QualifiedImage struct {
Tag string `json:"tag"`
Digest string `json:"digest"`
IgnoredCVEs []string `json:"ignoredCVEs,omitempty"`
FoundCVEs []string `json:"foundCVEs,omitempty"`
}
QualifiedImage describes an image tag, at a specific digest.
type RawYAML ¶ added in v0.9.0
type RawYAML struct {
Object any
}
RawYAML is intended to wrap objects that are return from raw YAML unmarshaling the Update method of RenameUpdater will process these by looking for images using FindImages (rather than FindK8sImages). By default this will be any rules that were compiled with "Kind: Raw".
type RecorderRemapper ¶ added in v0.2.0
type RecorderRemapper struct {
// contains filtered or unexported fields
}
RecorderRemapper records all remappings up as they are seen.
func (*RecorderRemapper) Mappings ¶ added in v0.2.0
func (r *RecorderRemapper) Mappings() (map[string]QualifiedImage, error)
Mappings returns the set of image original to final performed by all the remappers.
func (*RecorderRemapper) ReMap ¶ added in v0.2.0
func (r *RecorderRemapper) ReMap(h *History) error
ReMap records all remappings so far, should usuually be used as the final remapper.
type RenameRemapper ¶ added in v0.2.0
type RenameRemapper struct {
Logger
Ignore *regexp.Regexp
RemoteTmpl *template.Template
RemotePath string
// contains filtered or unexported fields
}
RenameRemapper is a Remapper implementation that can rename an image to a remote registry/repository path. The new path is built using RemoteTmpl, and the copy is performed using crane.Copy. reimage will then optionally copy the image to the new location.
func (*RenameRemapper) ReMap ¶ added in v0.2.0
func (t *RenameRemapper) ReMap(h *History) error
ReMap copies an image from the original registry to a given new destination registry.
type RenameUpdater ¶ added in v0.2.0
type RenameUpdater struct {
Ignore *regexp.Regexp // Completely ignore images strings matching this regexp
ImagesFinder ImagesFinder
Remapper Remapper
ForceDigests bool
}
RenameUpdater applies the Remapper to all images found in object passed to Update. For Objects of unknown types the UnstructuredImagesFinder is used. TODO(tcm): rename this thinger.
func (*RenameUpdater) Update ¶ added in v0.2.0
func (s *RenameUpdater) Update(obj any) error
Update applies the Remapper to all found images in the object.
type RepoTemplateInput ¶
type RepoTemplateInput struct {
RemotePath string // The request remote repository and registry prefix.
Digest string // The digest of the image.
DigestAlgo string // The hash algorithm of the image digest.
DigestHex string // The hex string of the digest hash.
Tag string // The image tag (TODO(tcm): not used at the moment).
Registry string // The image registry.
Repository string // The image repository.
}
RepoTemplateInput is the input provied to the RemoteTmpl of the RepoRemapper.
type Setter ¶
type Setter func(img string)
A Setter is used for setting the string description of an image.
type StaticRemapper ¶ added in v0.2.0
type StaticRemapper struct {
Mappings map[string]QualifiedImage
AllowMissing bool
}
StaticRemapper is a Remapper implementation that allows statically mapping incoming images to a pre-existing set of known target image names and digests.
func NewStaticRemapper ¶ added in v0.2.0
func NewStaticRemapper(mps map[string]QualifiedImage, confirmDigest bool) (*StaticRemapper, error)
NewStaticRemapper creates a StaticRemapper. If confirmDigest is true, the constructor will check that all target image tags still map to the currently referenced digest.
func (*StaticRemapper) ReMap ¶ added in v0.2.0
func (s *StaticRemapper) ReMap(h *History) error
ReMap looks up the incoming image in the provided mappings. If AllowMissing is false, attempts to look up images not in the static mappings will fail (if true, ReMap is a no-op).
type TrivyVulnGetter ¶ added in v0.7.0
type TrivyVulnGetter struct {
Command []string
}
func (*TrivyVulnGetter) GetVulnerabilities ¶ added in v0.7.0
func (vc *TrivyVulnGetter) GetVulnerabilities(ctx context.Context, dig name.Digest) ([]ImageVulnerability, error)
type VulnCheckResult ¶ added in v0.7.0
type VulnCheckResult struct {
Ignored []string // CVEs that were present, but explicitly ignored by the checker.
Found []string // CVEs that were present, but under the max requested CVSS.
}
VulnCheckResult is the result of a vulnerability check.
type VulnChecker ¶ added in v0.7.0
type VulnChecker struct {
Getter VulnGetter
Logger
IgnoreImages *regexp.Regexp
CVEIgnoreList []string
sync.Mutex
MaxCVSS float32
// contains filtered or unexported fields
}
VulnChecker checks that images have been scanned, and checks that they do not contain unexpected vulnerabilities.
func (*VulnChecker) Check ¶ added in v0.7.0
func (vc *VulnChecker) Check(ctx context.Context, dig name.Digest) (*VulnCheckResult, error)
Check waits for a completed vulnerability discovery, and then check that an image has no CVEs that violate the configured policy.
type VulnGetter ¶ added in v0.7.0
type VulnGetter interface {
GetVulnerabilities(ctx context.Context, dig name.Digest) ([]ImageVulnerability, error)
}
VulnGetter is an interface to any tool that can retrieve vulnerabilities for a given docker image digest.