| 1 | package cmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 5 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 6 | |
| 7 | intotoscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/ "github.com/in-toto/in-toto-golang/in_totoscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/" |
| 8 | "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/" |
| 9 | ) |
| 10 | |
| 11 | var ( |
| 12 | stepNamescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/stepName. string |
| 13 | runDirscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runDir. string |
| 14 | materialsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/materialsPaths. []string |
| 15 | productsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/productsPaths. []string |
| 16 | noCommandscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/noCommand. bool |
| 17 | ) |
| 18 | |
| 19 | var runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd. = &cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#{ |
| 20 | Usescip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Use.: "run", |
| 21 | Shortscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Short.: "Executes the passed command and records paths and hashes of 'materials'", |
| 22 | Longscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Long.: `Executes the passed command and records paths and hashes of 'materials' (i.e. |
| 23 | files before command execution) and 'products' (i.e. files after command |
| 24 | execution) and stores them together with other information (executed command, |
| 25 | return value, stdout, stderr, ...) to a link metadata file, which is signed |
| 26 | with the passed key. Returns nonzero value on failure and zero otherwise.`, |
| 27 | Argsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Args.: cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.MinimumNArgsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/MinimumNArgs().(0), |
| 28 | PreRunEscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#PreRunE.: getKeyCertscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/getKeyCert()., |
| 29 | RunEscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#RunE.: runscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/run()., |
| 30 | } |
| 31 | |
| 32 | func initscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/init().() { |
| 33 | rootCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/rootCmd..AddCommandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#AddCommand().(runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd.) |
| 34 | |
| 35 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVarP().( |
| 36 | &stepNamescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/stepName., |
| 37 | "name", |
| 38 | "n", |
| 39 | "", |
| 40 | `Name used to associate the resulting link metadata |
| 41 | with the corresponding step defined in an in-toto layout.`, |
| 42 | ) |
| 43 | |
| 44 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVarP().( |
| 45 | &runDirscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runDir., |
| 46 | "run-dir", |
| 47 | "r", |
| 48 | "", |
| 49 | `runDir specifies the working directory of the command. |
| 50 | If runDir is the empty string, the command will run in the |
| 51 | calling process's current directory. The runDir directory must |
| 52 | exist, be writable, and not be a symlink.`, |
| 53 | ) |
| 54 | |
| 55 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVarP().( |
| 56 | &keyPathscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/keyPath., |
| 57 | "key", |
| 58 | "k", |
| 59 | "", |
| 60 | `Path to a PEM formatted private key file used to sign |
| 61 | the resulting link metadata.`, |
| 62 | ) |
| 63 | |
| 64 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVarP().( |
| 65 | &certPathscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/certPath., |
| 66 | "cert", |
| 67 | "c", |
| 68 | "", |
| 69 | `Path to a PEM formatted certificate that corresponds with |
| 70 | the provided key.`, |
| 71 | ) |
| 72 | |
| 73 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringArrayVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringArrayVarP().( |
| 74 | &materialsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/materialsPaths., |
| 75 | "materials", |
| 76 | "m", |
| 77 | []string{}, |
| 78 | `Paths to files or directories, whose paths and hashes |
| 79 | are stored in the resulting link metadata before the |
| 80 | command is executed. Symlinks are followed.`, |
| 81 | ) |
| 82 | |
| 83 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringArrayVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringArrayVarP().( |
| 84 | &productsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/productsPaths., |
| 85 | "products", |
| 86 | "p", |
| 87 | []string{}, |
| 88 | `Paths to files or directories, whose paths and hashes |
| 89 | are stored in the resulting link metadata after the |
| 90 | command is executed. Symlinks are followed.`, |
| 91 | ) |
| 92 | |
| 93 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVarP().( |
| 94 | &outDirscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/outDir., |
| 95 | "metadata-directory", |
| 96 | "d", |
| 97 | "./", |
| 98 | `Directory to store link metadata`, |
| 99 | ) |
| 100 | |
| 101 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringArrayVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringArrayVarP().( |
| 102 | &lStripPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/lStripPaths., |
| 103 | "lstrip-paths", |
| 104 | "l", |
| 105 | []string{}, |
| 106 | `Path prefixes used to left-strip artifact paths before storing |
| 107 | them to the resulting link metadata. If multiple prefixes |
| 108 | are specified, only a single prefix can match the path of |
| 109 | any artifact and that is then left-stripped. All prefixes |
| 110 | are checked to ensure none of them are a left substring |
| 111 | of another.`, |
| 112 | ) |
| 113 | |
| 114 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringArrayVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringArrayVarP().( |
| 115 | &excludescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/exclude., |
| 116 | "exclude", |
| 117 | "e", |
| 118 | []string{}, |
| 119 | `Path patterns to match paths that should not be recorded as 0 |
| 120 | ‘materials’ or ‘products’. Passed patterns override patterns defined |
| 121 | in environment variables or config files. See Config docs for details.`, |
| 122 | ) |
| 123 | |
| 124 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..MarkFlagRequiredscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#MarkFlagRequired().("name") |
| 125 | |
| 126 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#BoolVar().( |
| 127 | &lineNormalizationscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/lineNormalization., |
| 128 | "normalize-line-endings", |
| 129 | false, |
| 130 | `Enable line normalization in order to support different |
| 131 | operating systems. It is done by replacing all line separators |
| 132 | with a new line character.`, |
| 133 | ) |
| 134 | |
| 135 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#BoolVarP().( |
| 136 | &noCommandscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/noCommand., |
| 137 | "no-command", |
| 138 | "x", |
| 139 | false, |
| 140 | `Indicate that there is no command to be executed for the step.`, |
| 141 | ) |
| 142 | |
| 143 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..PersistentFlagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#PersistentFlags().().BoolVarscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#BoolVar().( |
| 144 | &followSymlinkDirsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/followSymlinkDirs., |
| 145 | "follow-symlink-dirs", |
| 146 | false, |
| 147 | `Follow symlinked directories to their targets. Note: this parameter |
| 148 | toggles following linked directories only, linked files are always |
| 149 | recorded independently of this parameter.`, |
| 150 | ) |
| 151 | |
| 152 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..PersistentFlagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#PersistentFlags().().BoolVarscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#BoolVar().( |
| 153 | &useDSSEscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/useDSSE., |
| 154 | "use-dsse", |
| 155 | false, |
| 156 | "Create metadata using DSSE instead of the legacy signature wrapper.", |
| 157 | ) |
| 158 | |
| 159 | runCmdscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runCmd..Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringVarscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringVar().( |
| 160 | &spiffeUDSscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/spiffeUDS., |
| 161 | "spiffe-workload-api-path", |
| 162 | "", |
| 163 | "UDS path for SPIFFE workload API", |
| 164 | ) |
| 165 | |
| 166 | } |
| 167 | |
| 168 | func runscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/run().(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#, args []string) error { |
| 169 | if noCommandscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/noCommand. && len(args) > 0 { |
| 170 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("command arguments passed with --no-command/-x flag") |
| 171 | } |
| 172 | |
| 173 | if !noCommandscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/noCommand. && len(args) == 0 { |
| 174 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("no command arguments passed, please specify or use --no-command option") |
| 175 | } |
| 176 | |
| 177 | metadata, err := intotoscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/.InTotoRunscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/InTotoRun().(stepNamescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/stepName., runDirscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/runDir., materialsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/materialsPaths., productsPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/productsPaths., args, keyscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/key., []string{"sha256"}, excludescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/exclude., lStripPathsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/lStripPaths., lineNormalizationscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/lineNormalization., followSymlinkDirsscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/followSymlinkDirs., useDSSEscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/useDSSE.) |
| 178 | if err != nil { |
| 179 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to create link metadata: %w", err) |
| 180 | } |
| 181 | |
| 182 | link, ok := metadata.GetPayloadscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/Metadata#GetPayload.().(intotoscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/.Linkscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/Link#) |
| 183 | if !ok { |
| 184 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("metadata must be link") |
| 185 | } |
| 186 | linkName := fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(intotoscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/.LinkNameFormatscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/LinkNameFormat., link.Namescip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/Link#Name., keyscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/key..KeyIDscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/Key#KeyID.) |
| 187 | |
| 188 | linkPath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(outDirscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/cmd`/outDir., linkName) |
| 189 | err = metadata.Dumpscip-go gomod github.com/in-toto/in-toto-golang . `github.com/in-toto/in-toto-golang/in_toto`/Metadata#Dump.(linkPath) |
| 190 | if err != nil { |
| 191 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to write link metadata to %s: %w", linkPath, err) |
| 192 | } |
| 193 | |
| 194 | return nil |
| 195 | } |