-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support different verification options per image
Different images will require different verification options. This commit adds configuration that allows you to define different 'verifiers' for specific image references, or image reference patterns. At the moment it supports verification by public key, or the existing options, but should be expanded to include all supported options. Also modifies the response from the provider to include an error per-image checked, rather than returning any error as a 'system' error. I've also removed the _invalid suffix from the key returned in the response when there's an error. The presence of the 'error' field indicates this better, I think. Signed-off-by: Rob Best <[email protected]>
- Loading branch information
1 parent
f26799b
commit 7307a7b
Showing
7 changed files
with
638 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
// DefaultOptions are the default verification options | ||
DefaultOptions = &CheckOptions{ | ||
RekorURL: "https://rekor.sigstore.dev", | ||
} | ||
|
||
// DefaultConfig is the configuration used when none is provided | ||
DefaultConfig = &Config{ | ||
Verifiers: []Verifier{ | ||
{ | ||
Options: DefaultOptions, | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
// LoadConfig loads configuration from a file. If a file isn't provided then it | ||
// returns the default configuration. | ||
func LoadConfig(confFile string) (*Config, error) { | ||
if confFile == "" { | ||
return DefaultConfig, nil | ||
} | ||
|
||
var c *Config | ||
|
||
yamlReader, err := os.Open(confFile) | ||
if err != nil { | ||
return c, fmt.Errorf("error reading config file: %s", err) | ||
} | ||
defer yamlReader.Close() | ||
decoder := yaml.NewDecoder(yamlReader) | ||
decoder.KnownFields(true) | ||
|
||
if err = decoder.Decode(&c); err != nil { | ||
return c, fmt.Errorf("error parsing config file: %s", err) | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
// Config configures the provider | ||
type Config struct { | ||
// Verifiers is a list of verifiers. The validator will iterate over | ||
// this list until it finds a verifier that matches the image its | ||
// validating. | ||
Verifiers []Verifier `yaml:"verifiers"` | ||
} | ||
|
||
// Verifier verifies an image | ||
type Verifier struct { | ||
// Image is an image reference, either to a specific image or a pattern. | ||
// Supports '*' and '?' in the pattern string. | ||
Image string `yaml:"image,omitempty"` | ||
|
||
// Options defines verification options | ||
Options *CheckOptions `yaml:"options,omitempty"` | ||
} | ||
|
||
// UnmarshalYAML sets default options for the verifier config when they aren't | ||
// provided | ||
func (v *Verifier) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
type rawVerifier Verifier | ||
var raw rawVerifier | ||
if err := unmarshal(&raw); err != nil { | ||
return err | ||
} | ||
|
||
if raw.Options == nil { | ||
raw.Options = DefaultOptions | ||
} | ||
|
||
*v = Verifier(raw) | ||
|
||
return nil | ||
} | ||
|
||
// CheckOptions are the options used to verify the signature of an image | ||
type CheckOptions struct { | ||
// Key is a path to a public key file, KMS URI or Kubernetes Secret | ||
Key string `yaml:"key,omitempty"` | ||
|
||
// RekorURL is the address of a rekor STL server | ||
RekorURL string `yaml:"rekorURL,omitempty"` | ||
} |
Oops, something went wrong.