github.com/wangchanggan/helm@v0.0.0-20211020154240-11b1b7d5406d/cmd/helm/verify.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package main
    17  
    18  import (
    19  	"errors"
    20  	"io"
    21  
    22  	"github.com/spf13/cobra"
    23  
    24  	"k8s.io/helm/pkg/downloader"
    25  )
    26  
    27  const verifyDesc = `
    28  Verify that the given chart has a valid provenance file.
    29  
    30  Provenance files provide cryptographic verification that a chart has not been
    31  tampered with, and was packaged by a trusted provider.
    32  
    33  This command can be used to verify a local chart. Several other commands provide
    34  '--verify' flags that run the same validation. To generate a signed package, use
    35  the 'helm package --sign' command.
    36  `
    37  
    38  type verifyCmd struct {
    39  	keyring   string
    40  	chartfile string
    41  
    42  	out io.Writer
    43  }
    44  
    45  func newVerifyCmd(out io.Writer) *cobra.Command {
    46  	vc := &verifyCmd{out: out}
    47  
    48  	cmd := &cobra.Command{
    49  		Use:   "verify [flags] PATH",
    50  		Short: "Verify that a chart at the given path has been signed and is valid",
    51  		Long:  verifyDesc,
    52  		RunE: func(cmd *cobra.Command, args []string) error {
    53  			if len(args) == 0 {
    54  				return errors.New("a path to a package file is required")
    55  			}
    56  			vc.chartfile = args[0]
    57  			return vc.run()
    58  		},
    59  	}
    60  
    61  	f := cmd.Flags()
    62  	f.StringVar(&vc.keyring, "keyring", defaultKeyring(), "Keyring containing public keys")
    63  
    64  	return cmd
    65  }
    66  
    67  func (v *verifyCmd) run() error {
    68  	_, err := downloader.VerifyChart(v.chartfile, v.keyring)
    69  	return err
    70  }