mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
linuxkit: allow user to configure a content trust passphrase command
Could be e.g.: ``` pkg: content-trust-passphrase-command: "lpass show <key> --password" ``` or ``` pkg: content-trust-passphrase-command: "gpg -d ~/.notary/passphrase.gpg" ``` Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
d3549b78f5
commit
dd8e3d49e8
@ -94,6 +94,11 @@ invoke the build like this (for LastPass):
|
|||||||
```
|
```
|
||||||
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=$(lpass show <key> --password) linuxkit pkg push «path-to-package»
|
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=$(lpass show <key> --password) linuxkit pkg push «path-to-package»
|
||||||
```
|
```
|
||||||
|
or alternatively you may add the command to `~/.moby/linuxkit/config.yml` e.g.:
|
||||||
|
```
|
||||||
|
pkg:
|
||||||
|
content-trust-passphrase-command: "lpass show <key> --password"
|
||||||
|
```
|
||||||
|
|
||||||
### Build packages as a developer
|
### Build packages as a developer
|
||||||
|
|
||||||
|
@ -3,12 +3,27 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GlobalConfig is the global tool configuration
|
||||||
|
type GlobalConfig struct {
|
||||||
|
Pkg PkgConfig `yaml:"pkg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PkgConfig is the config specific to the `pkg` subcommand
|
||||||
|
type PkgConfig struct {
|
||||||
|
// ContentTrustCommand is passed to `sh -c` and the stdout
|
||||||
|
// (including whitespace and \n) is set as the content trust
|
||||||
|
// passphrase. Can be used to execute a password manager.
|
||||||
|
ContentTrustCommand string `yaml:"content-trust-passphrase-command"`
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultLogFormatter = &log.TextFormatter{}
|
defaultLogFormatter = &log.TextFormatter{}
|
||||||
|
|
||||||
@ -17,6 +32,9 @@ var (
|
|||||||
|
|
||||||
// GitCommit hash, set at compile time
|
// GitCommit hash, set at compile time
|
||||||
GitCommit = "unknown"
|
GitCommit = "unknown"
|
||||||
|
|
||||||
|
// Config is the global tool configuration
|
||||||
|
Config = GlobalConfig{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// infoFormatter overrides the default format for Info() log events to
|
// infoFormatter overrides the default format for Info() log events to
|
||||||
@ -37,6 +55,22 @@ func version() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readConfig() {
|
||||||
|
cfgPath := filepath.Join(os.Getenv("HOME"), ".moby", "linuxkit", "config.yml")
|
||||||
|
cfgBytes, err := ioutil.ReadFile(cfgPath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("Failed to read %q\n", cfgPath)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if err := yaml.Unmarshal(cfgBytes, &Config); err != nil {
|
||||||
|
fmt.Printf("Failed to parse %q\n", cfgPath)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
|
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
|
||||||
@ -56,6 +90,8 @@ func main() {
|
|||||||
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
||||||
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
||||||
|
|
||||||
|
readConfig()
|
||||||
|
|
||||||
// Set up logging
|
// Set up logging
|
||||||
log.SetFormatter(new(infoFormatter))
|
log.SetFormatter(new(infoFormatter))
|
||||||
log.SetLevel(log.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,12 +20,37 @@ func pkgUsage() {
|
|||||||
fmt.Printf("See '%s pkg [command] --help' for details.\n\n", invoked)
|
fmt.Printf("See '%s pkg [command] --help' for details.\n\n", invoked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupContentTrust() {
|
||||||
|
// If it is already set there is nothing to do.
|
||||||
|
if _, ok := os.LookupEnv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"); ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// If it is not set but it is needed this is checked at time
|
||||||
|
// of use, not all commands need it.
|
||||||
|
if Config.Pkg.ContentTrustCommand == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the command and set the output as the passphrase
|
||||||
|
cmd := exec.Command("/bin/sh", "-c", Config.Pkg.ContentTrustCommand)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
v, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to run ContentTrustCommand: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Setenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE", string(v))
|
||||||
|
}
|
||||||
|
|
||||||
func pkg(args []string) {
|
func pkg(args []string) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
pkgUsage()
|
pkgUsage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupContentTrust()
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "build":
|
case "build":
|
||||||
pkgBuild(args[1:])
|
pkgBuild(args[1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user