Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export GO15VENDOREXPERIMENT=1
PREFIX ?= ${DESTDIR}/usr
INSTALLDIR=${PREFIX}/bin
MANINSTALLDIR=${PREFIX}/share/man
CONTAINERSSYSCONFIGDIR=${DESTDIR}/etc/containers
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
GO_MD2MAN ?= /usr/bin/go-md2man

Expand Down Expand Up @@ -60,14 +61,13 @@ clean:
rm -f skopeo docs/*.1

install: install-binary install-docs install-completions
install -D -m 644 default-policy.json ${CONTAINERSSYSCONFIGDIR}/policy.json

install-binary: ./skopeo
install -d -m 0755 ${INSTALLDIR}
install -m 755 skopeo ${INSTALLDIR}
install -D -m 755 skopeo ${INSTALLDIR}/skopeo

install-docs: docs/skopeo.1
install -d -m 0755 ${MANINSTALLDIR}/man1
install -m 644 docs/skopeo.1 ${MANINSTALLDIR}/man1/
install -D -m 644 docs/skopeo.1 ${MANINSTALLDIR}/man1/skopeo.1

install-completions:
install -m 644 -T hack/make/bash_autocomplete ${BASHINSTALLDIR}/skopeo
Expand Down
21 changes: 16 additions & 5 deletions cmd/skopeo/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func copyHandler(context *cli.Context) error {
return errors.New("Usage: copy source destination")
}

policyContext, err := getPolicyContext(context)
if err != nil {
return fmt.Errorf("Error loading verification policy: %v", err)
}
defer policyContext.Destroy()

dest, err := parseImageDestination(context, context.Args()[1])
if err != nil {
return fmt.Errorf("Error initializing %s: %v", context.Args()[1], err)
Expand All @@ -93,11 +99,21 @@ func copyHandler(context *cli.Context) error {

signBy := context.String("sign-by")

// Please keep this policy check BEFORE reading any other information about the image.
if allowed, err := policyContext.IsRunningImageAllowed(src); !allowed || err != nil { // Be paranoid and fail if either return value indicates so.
return fmt.Errorf("Source image rejected: %v", err)
}

manifest, _, err := src.Manifest()
if err != nil {
return fmt.Errorf("Error reading manifest: %v", err)
}

sigs, err := src.Signatures()
if err != nil {
return fmt.Errorf("Error reading signatures: %v", err)
}

blobDigests, err := src.BlobDigests()
if err != nil {
return fmt.Errorf("Error parsing manifest: %v", err)
Expand Down Expand Up @@ -128,11 +144,6 @@ func copyHandler(context *cli.Context) error {
}
}

sigs, err := src.Signatures()
if err != nil {
return fmt.Errorf("Error reading signatures: %v", err)
}

if signBy != "" {
mech, err := signature.NewGPGSigningMechanism()
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions cmd/skopeo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/Sirupsen/logrus"
"github.com/containers/image/signature"
"github.com/projectatomic/skopeo/version"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -50,6 +51,11 @@ func createApp() *cli.App {
Name: "tls-verify",
Usage: "verify certificates",
},
cli.StringFlag{
Name: "policy",
Value: "",
Usage: "Path to a signature verification policy file",
},
}
app.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
Expand All @@ -75,3 +81,19 @@ func main() {
logrus.Fatal(err)
}
}

// getPolicyContext handles the global "policy" flag.
func getPolicyContext(c *cli.Context) (*signature.PolicyContext, error) {
policyPath := c.GlobalString("policy")
var policy *signature.Policy // This could be cached across calls, if we had an application context.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be contacted in a single var block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*compacted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OTOH it is easier to attach the “This could be cached” comment to the policy variable when it is on a separate line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's a somehow golang idiom, you can still add comments on top of each variable in a var block

var err error
if policyPath == "" {
policy, err = signature.DefaultPolicy(nil)
} else {
policy, err = signature.NewPolicyFromFile(policyPath)
}
if err != nil {
return nil, err
}
return signature.NewPolicyContext(policy)
}
7 changes: 7 additions & 0 deletions default-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"default": [
{
"type": "insecureAcceptAnything"
}
]
}
10 changes: 10 additions & 0 deletions docs/skopeo.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Most commands refer to container images, using a _transport_`:`_details_ format.

**--cert-path** _path_ Use certificates at _path_ (cert.pem, key.pem) to connect to the registry

**--policy** _path-to-policy_ Path to a policy.json file to use for verifying signatures and
deciding whether an image is accepted, instead of the default policy.

**--tls-verify** _bool-value_ Verify certificates

**--help**|**-h** Show help
Expand All @@ -56,6 +59,8 @@ Most commands refer to container images, using a _transport_`:`_details_ format.

Copy an image (manifest, filesystem layers, signatures) from one location to another.

Uses the system's signature verification policy to validate images, refuses to copy images rejected by the policy.

_source-image_ use the "image name" format described above

_destination-image_ use the "image name" format described above
Expand Down Expand Up @@ -128,6 +133,11 @@ Verify a signature using local files, digest will be printed on success.
## skopeo help
show help for `skopeo`

# FILES
**/etc/containers/policy.json**
Default signature verification policy file, if **--policy** is not specified.
The policy format is documented in https://github.com/containers/image/blob/master/docs/policy.json.md .

# EXAMPLES

## skopeo copy
Expand Down
2 changes: 1 addition & 1 deletion hack/make/test-integration
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bundle_test_integration() {
# subshell so that we can export PATH without breaking other things
(
make binary-local
make install-binary
make install
export GO15VENDOREXPERIMENT=1
bundle_test_integration
) 2>&1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.