definition: Add Source.SkipVerification

This allows for the source verification to be skipped if needed.

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
Thomas Hipp 2018-07-02 17:37:31 +02:00
parent 91598f1fa2
commit fb39a671f7
No known key found for this signature in database
GPG Key ID: 993408D1137B7D51
7 changed files with 50 additions and 32 deletions

View File

@ -51,6 +51,7 @@ type DefinitionSource struct {
SameAs string `yaml:"same_as,omitempty"`
AptSources string `yaml:"apt_sources,omitempty"`
IgnoreRelease bool `yaml:"ignore_release,omitempty"`
SkipVerification bool `yaml:"skip_verification,omitempty"`
}
// A DefinitionTargetLXCConfig represents the config part of the metadata.

View File

@ -56,17 +56,22 @@ func (s *AlpineLinuxHTTP) Run(definition shared.Definition, rootfsDir string) er
return err
}
if url.Scheme != "https" && len(definition.Source.Keys) == 0 {
if !definition.Source.SkipVerification && url.Scheme != "https" &&
len(definition.Source.Keys) == 0 {
return errors.New("GPG keys are required if downloading from HTTP")
}
if definition.Source.SkipVerification {
err = shared.DownloadSha256(tarball, "")
} else {
err = shared.DownloadSha256(tarball, tarball+".sha256")
}
if err != nil {
return err
}
// Force gpg checks when using http
if url.Scheme != "https" {
if !definition.Source.SkipVerification && url.Scheme != "https" {
shared.DownloadSha256(tarball+".asc", "")
valid, err := shared.VerifyFile(
filepath.Join(os.TempDir(), fname),

View File

@ -33,7 +33,8 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
return err
}
if url.Scheme != "https" && len(definition.Source.Keys) == 0 {
if !definition.Source.SkipVerification && url.Scheme != "https" &&
len(definition.Source.Keys) == 0 {
return errors.New("GPG keys are required if downloading from HTTP")
}
@ -43,7 +44,7 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
}
// Force gpg checks when using http
if url.Scheme != "https" {
if !definition.Source.SkipVerification && url.Scheme != "https" {
shared.DownloadSha256(tarball+".sig", "")
valid, err := shared.VerifyFile(

View File

@ -45,13 +45,14 @@ func (s *CentOSHTTP) Run(definition shared.Definition, rootfsDir string) error {
}
checksumFile := ""
if !definition.Source.SkipVerification {
// Force gpg checks when using http
if url.Scheme != "https" {
if len(definition.Source.Keys) == 0 {
return errors.New("GPG keys are required if downloading from HTTP")
}
checksumFile = "sha256sum.txt.asc"
checksumFile = "sha256sum.txt"
shared.DownloadSha256(baseURL+checksumFile, "")
valid, err := shared.VerifyFile(filepath.Join(os.TempDir(), checksumFile), "",
definition.Source.Keys, definition.Source.Keyserver)
@ -62,6 +63,7 @@ func (s *CentOSHTTP) Run(definition shared.Definition, rootfsDir string) error {
return errors.New("Failed to verify tarball")
}
}
}
err = shared.DownloadSha256(baseURL+s.fname, checksumFile)
if err != nil {

View File

@ -33,6 +33,10 @@ func (s *Debootstrap) Run(definition shared.Definition, rootfsDir string) error
args = append(args, "--arch", definition.Image.ArchitectureMapped)
}
if definition.Source.SkipVerification {
args = append(args, "--no-check-gpg")
}
if len(definition.Source.Keys) > 0 {
keyring, err := shared.CreateGPGKeyring(definition.Source.Keyserver, definition.Source.Keys)
if err != nil {

View File

@ -44,17 +44,22 @@ func (s *GentooHTTP) Run(definition shared.Definition, rootfsDir string) error {
return err
}
if url.Scheme != "https" && len(definition.Source.Keys) == 0 {
if !definition.Source.SkipVerification && url.Scheme != "https" &&
len(definition.Source.Keys) == 0 {
return errors.New("GPG keys are required if downloading from HTTP")
}
if definition.Source.SkipVerification {
err = shared.DownloadSha512(tarball, "")
} else {
err = shared.DownloadSha512(tarball, tarball+".DIGESTS")
}
if err != nil {
return err
}
// Force gpg checks when using http
if url.Scheme != "https" {
if !definition.Source.SkipVerification && url.Scheme != "https" {
shared.DownloadSha512(tarball+".DIGESTS.asc", "")
valid, err := shared.VerifyFile(
filepath.Join(os.TempDir(), fname+".DIGESTS.asc"),

View File

@ -51,7 +51,7 @@ func (s *UbuntuHTTP) Run(definition shared.Definition, rootfsDir string) error {
checksumFile := ""
// Force gpg checks when using http
if url.Scheme != "https" {
if !definition.Source.SkipVerification && url.Scheme != "https" {
if len(definition.Source.Keys) == 0 {
return errors.New("GPG keys are required if downloading from HTTP")
}