mirror of
https://github.com/containers/skopeo.git
synced 2026-01-31 14:29:03 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e079f9d61b | ||
|
|
ceabc0a404 | ||
|
|
523b8b44a2 | ||
|
|
d2d1796eb5 | ||
|
|
c67e5f7425 | ||
|
|
1b8686d044 | ||
|
|
a4de1428f9 | ||
|
|
524f6c0682 | ||
|
|
fa18fce7e8 | ||
|
|
96be1bb155 | ||
|
|
23c6b42b26 | ||
|
|
6307635b5f | ||
|
|
47e7cda4e9 | ||
|
|
5dd3b2bffd | ||
|
|
12f0e24519 | ||
|
|
b137741385 | ||
|
|
233804fedc | ||
|
|
0c90e57eaf | ||
|
|
8fb4ab3d92 | ||
|
|
8c9e250801 | ||
|
|
04aee56a36 | ||
|
|
4f1fabc2a4 | ||
|
|
43bc356337 |
@@ -10,6 +10,7 @@ RUN dnf -y update && dnf install -y make git golang golang-github-cpuguy83-go-md
|
||||
gnupg \
|
||||
# OpenShift deps
|
||||
which tar wget hostname util-linux bsdtar socat ethtool device-mapper iptables tree findutils nmap-ncat e2fsprogs xfsprogs lsof docker iproute \
|
||||
bats jq podman \
|
||||
&& dnf clean all
|
||||
|
||||
# Install two versions of the registry. The first is an older version that
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM ubuntu:18.10
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
golang \
|
||||
btrfs-tools \
|
||||
libbtrfs-dev \
|
||||
git-core \
|
||||
libdevmapper-dev \
|
||||
libgpgme11-dev \
|
||||
|
||||
13
Makefile
13
Makefile
@@ -138,12 +138,23 @@ install-completions:
|
||||
shell: build-container
|
||||
$(CONTAINER_RUN) bash
|
||||
|
||||
check: validate test-unit test-integration
|
||||
check: validate test-unit test-integration test-system
|
||||
|
||||
# The tests can run out of entropy and block in containers, so replace /dev/random.
|
||||
test-integration: build-container
|
||||
$(CONTAINER_RUN) bash -c 'rm -f /dev/random; ln -sf /dev/urandom /dev/random; SKOPEO_CONTAINER_TESTS=1 BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-integration'
|
||||
|
||||
# complicated set of options needed to run podman-in-podman
|
||||
test-system: build-container
|
||||
DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \
|
||||
$(CONTAINER_CMD) --privileged --net=host \
|
||||
-v $$DTEMP:/var/lib/containers:Z \
|
||||
"$(IMAGE)" \
|
||||
bash -c 'BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-system'; \
|
||||
rc=$$?; \
|
||||
$(RM) -rf $$DTEMP; \
|
||||
exit $$rc
|
||||
|
||||
test-unit: build-container
|
||||
# Just call (make test unit-local) here instead of worrying about environment differences, e.g. GO15VENDOREXPERIMENT.
|
||||
$(CONTAINER_RUN) make test-unit-local BUILDTAGS='$(BUILDTAGS)'
|
||||
|
||||
@@ -172,7 +172,7 @@ Building without a container requires a bit more manual work and setup in your e
|
||||
Install the necessary dependencies:
|
||||
```sh
|
||||
Fedora$ sudo dnf install gpgme-devel libassuan-devel btrfs-progs-devel device-mapper-devel ostree-devel
|
||||
Ubuntu$ sudo apt install libgpgme-dev libassuan-dev btrfs-progs libdevmapper-dev libostree-dev
|
||||
Ubuntu$ sudo apt install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev libostree-dev
|
||||
macOS$ brew install gpgme
|
||||
```
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ func maybeReexec() error {
|
||||
func reexecIfNecessaryForImages(imageNames ...string) error {
|
||||
// Check if container-storage are used before doing unshare
|
||||
for _, imageName := range imageNames {
|
||||
if alltransports.TransportFromImageName(imageName).Name() == storage.Transport.Name() {
|
||||
transport := alltransports.TransportFromImageName(imageName)
|
||||
if transport != nil && transport.Name() == storage.Transport.Name() {
|
||||
return maybeReexec()
|
||||
}
|
||||
}
|
||||
|
||||
18
hack/make/test-system
Executable file
18
hack/make/test-system
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Before running podman for the first time, make sure
|
||||
# to set storage to vfs (not overlay): podman-in-podman
|
||||
# doesn't work with overlay. And, disable mountopt,
|
||||
# which causes error with vfs.
|
||||
sed -i \
|
||||
-e 's/^driver\s*=.*/driver = "vfs"/' \
|
||||
-e 's/^mountopt/#mountopt/' \
|
||||
/etc/containers/storage.conf
|
||||
|
||||
# Build skopeo, install into /usr/bin
|
||||
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
|
||||
make install
|
||||
|
||||
# Run tests
|
||||
SKOPEO_BINARY=/usr/bin/skopeo bats --tap systemtest
|
||||
@@ -87,3 +87,7 @@ func (s *SkopeoSuite) TestNoNeedAuthToPrivateRegistryV2ImageNotFound(c *check.C)
|
||||
wanted = ".*unauthorized: authentication required.*"
|
||||
c.Assert(string(out), check.Not(check.Matches), "(?s)"+wanted) // (?s) : '.' will also match newlines
|
||||
}
|
||||
|
||||
func (s *SkopeoSuite) TestInspectFailsWhenReferenceIsInvalid(c *check.C) {
|
||||
assertSkopeoFails(c, `.*Invalid image name.*`, "inspect", "unknown")
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/containers/image/signature"
|
||||
"github.com/go-check/check"
|
||||
"github.com/opencontainers/go-digest"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/opencontainers/image-tools/image"
|
||||
)
|
||||
@@ -64,7 +64,7 @@ func (s *CopySuite) SetUpSuite(c *check.C) {
|
||||
os.Setenv("GNUPGHOME", s.gpgHome)
|
||||
|
||||
for _, key := range []string{"personal", "official"} {
|
||||
batchInput := fmt.Sprintf("Key-Type: RSA\nName-Real: Test key - %s\nName-email: %s@example.com\n%%commit\n",
|
||||
batchInput := fmt.Sprintf("Key-Type: RSA\nName-Real: Test key - %s\nName-email: %s@example.com\n%%no-protection\n%%commit\n",
|
||||
key, key)
|
||||
runCommandWithInput(c, batchInput, gpgBinary, "--batch", "--gen-key")
|
||||
|
||||
@@ -696,3 +696,7 @@ func (s *SkopeoSuite) TestFailureCopySrcWithMirrorAndPrefixUnavailable(c *check.
|
||||
assertSkopeoFails(c, ".*no such host.*", "--registries-conf="+regConfFixture, "copy",
|
||||
"docker://gcr.invalid/wrong/prefix/busybox", "dir:"+dir)
|
||||
}
|
||||
|
||||
func (s *CopySuite) TestCopyFailsWhenReferenceIsInvalid(c *check.C) {
|
||||
assertSkopeoFails(c, `.*Invalid image name.*`, "copy", "unknown:transport", "unknown:test")
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (s *SigningSuite) SetUpSuite(c *check.C) {
|
||||
c.Assert(err, check.IsNil)
|
||||
os.Setenv("GNUPGHOME", s.gpgHome)
|
||||
|
||||
runCommandWithInput(c, "Key-Type: RSA\nName-Real: Testing user\n%commit\n", gpgBinary, "--homedir", s.gpgHome, "--batch", "--gen-key")
|
||||
runCommandWithInput(c, "Key-Type: RSA\nName-Real: Testing user\n%no-protection\n%commit\n", gpgBinary, "--homedir", s.gpgHome, "--batch", "--gen-key")
|
||||
|
||||
lines, err := exec.Command(gpgBinary, "--homedir", s.gpgHome, "--with-colons", "--no-permission-warning", "--fingerprint").Output()
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
19
systemtest/001-basic.bats
Normal file
19
systemtest/001-basic.bats
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Simplest set of skopeo tests. If any of these fail, we have serious problems.
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
# Override standard setup! We don't yet trust anything
|
||||
function setup() {
|
||||
:
|
||||
}
|
||||
|
||||
@test "skopeo version emits reasonable output" {
|
||||
run_skopeo --version
|
||||
|
||||
expect_output --substring "skopeo version [0-9.]+"
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
67
systemtest/010-inspect.bats
Normal file
67
systemtest/010-inspect.bats
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Simplest test for skopeo inspect
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
@test "inspect: basic" {
|
||||
workdir=$TESTDIR/inspect
|
||||
|
||||
remote_image=docker://quay.io/libpod/alpine_labels:latest
|
||||
# Inspect remote source, then pull it. There's a small race condition
|
||||
# in which the remote image can get updated between the inspect and
|
||||
# the copy; let's just not worry about it.
|
||||
run_skopeo inspect $remote_image
|
||||
inspect_remote=$output
|
||||
|
||||
# Now pull it into a directory
|
||||
run_skopeo copy $remote_image dir:$workdir
|
||||
expect_output --substring "Getting image source signatures"
|
||||
expect_output --substring "Writing manifest to image destination"
|
||||
|
||||
# Unpacked contents must include a manifest and version
|
||||
[ -e $workdir/manifest.json ]
|
||||
[ -e $workdir/version ]
|
||||
|
||||
# Now run inspect locally
|
||||
run_skopeo inspect dir:$workdir
|
||||
inspect_local=$output
|
||||
|
||||
# Each SHA-named file must be listed in the output of 'inspect'
|
||||
for sha in $(find $workdir -type f | xargs -l1 basename | egrep '^[0-9a-f]{64}$'); do
|
||||
expect_output --from="$inspect_local" --substring "sha256:$sha" \
|
||||
"Locally-extracted SHA file is present in 'inspect'"
|
||||
done
|
||||
|
||||
# Simple sanity check on 'inspect' output.
|
||||
# For each of the given keys (LHS of the table below):
|
||||
# 1) Get local and remote values
|
||||
# 2) Sanity-check local value using simple expression
|
||||
# 3) Confirm that local and remote values match.
|
||||
#
|
||||
# The reason for (2) is to make sure that we don't compare bad results
|
||||
#
|
||||
# The reason for a hardcoded list, instead of 'jq keys', is that RepoTags
|
||||
# is always empty locally, but a list remotely.
|
||||
while read key expect; do
|
||||
local=$(echo "$inspect_local" | jq -r ".$key")
|
||||
remote=$(echo "$inspect_remote" | jq -r ".$key")
|
||||
|
||||
expect_output --from="$local" --substring "$expect" \
|
||||
"local $key is sane"
|
||||
|
||||
expect_output --from="$remote" "$local" \
|
||||
"local $key matches remote"
|
||||
done <<END_EXPECT
|
||||
Architecture amd64
|
||||
Created [0-9-]+T[0-9:]+\.[0-9]+Z
|
||||
Digest sha256:[0-9a-f]{64}
|
||||
DockerVersion [0-9]+\.[0-9][0-9.-]+
|
||||
Labels \\\{.*PODMAN.*podman.*\\\}
|
||||
Layers \\\[.*sha256:.*\\\]
|
||||
Os linux
|
||||
END_EXPECT
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
79
systemtest/020-copy.bats
Normal file
79
systemtest/020-copy.bats
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Copy tests
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
function setup() {
|
||||
standard_setup
|
||||
|
||||
start_registry reg
|
||||
}
|
||||
|
||||
# From remote, to dir1, to local, to dir2;
|
||||
# compare dir1 and dir2, expect no changes
|
||||
@test "copy: dir, round trip" {
|
||||
local remote_image=docker://busybox:latest
|
||||
local localimg=docker://localhost:5000/busybox:unsigned
|
||||
|
||||
local dir1=$TESTDIR/dir1
|
||||
local dir2=$TESTDIR/dir2
|
||||
|
||||
run_skopeo copy $remote_image dir:$dir1
|
||||
run_skopeo copy --dest-tls-verify=false dir:$dir1 $localimg
|
||||
run_skopeo copy --src-tls-verify=false $localimg dir:$dir2
|
||||
|
||||
# Both extracted copies must be identical
|
||||
diff -urN $dir1 $dir2
|
||||
}
|
||||
|
||||
# Same as above, but using 'oci:' instead of 'dir:' and with a :latest tag
|
||||
@test "copy: oci, round trip" {
|
||||
local remote_image=docker://busybox:latest
|
||||
local localimg=docker://localhost:5000/busybox:unsigned
|
||||
|
||||
local dir1=$TESTDIR/oci1
|
||||
local dir2=$TESTDIR/oci2
|
||||
|
||||
run_skopeo copy $remote_image oci:$dir1:latest
|
||||
run_skopeo copy --dest-tls-verify=false oci:$dir1:latest $localimg
|
||||
run_skopeo copy --src-tls-verify=false $localimg oci:$dir2:latest
|
||||
|
||||
# Both extracted copies must be identical
|
||||
diff -urN $dir1 $dir2
|
||||
}
|
||||
|
||||
# Same image, extracted once with :tag and once without
|
||||
@test "copy: oci w/ and w/o tags" {
|
||||
local remote_image=docker://busybox:latest
|
||||
|
||||
local dir1=$TESTDIR/dir1
|
||||
local dir2=$TESTDIR/dir2
|
||||
|
||||
run_skopeo copy $remote_image oci:$dir1
|
||||
run_skopeo copy $remote_image oci:$dir2:withtag
|
||||
|
||||
# Both extracted copies must be identical, except for index.json
|
||||
diff -urN --exclude=index.json $dir1 $dir2
|
||||
|
||||
# ...which should differ only in the tag. (But that's too hard to check)
|
||||
grep '"org.opencontainers.image.ref.name":"withtag"' $dir2/index.json
|
||||
}
|
||||
|
||||
# This one seems unlikely to get fixed
|
||||
@test "copy: bug 651" {
|
||||
skip "Enable this once skopeo issue #651 has been fixed"
|
||||
|
||||
run_skopeo copy --dest-tls-verify=false \
|
||||
docker://quay.io/libpod/alpine_labels:latest \
|
||||
docker://localhost:5000/foo
|
||||
}
|
||||
|
||||
teardown() {
|
||||
podman rm -f reg
|
||||
|
||||
standard_teardown
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
32
systemtest/030-local-registry-tls.bats
Normal file
32
systemtest/030-local-registry-tls.bats
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Confirm that skopeo will push to and pull from a local
|
||||
# registry with locally-created TLS certificates.
|
||||
#
|
||||
load helpers
|
||||
|
||||
function setup() {
|
||||
standard_setup
|
||||
|
||||
start_registry --with-cert reg
|
||||
}
|
||||
|
||||
@test "local registry, with cert" {
|
||||
# Push to local registry...
|
||||
run_skopeo copy --dest-cert-dir=$TESTDIR/client-auth \
|
||||
docker://busybox:latest \
|
||||
docker://localhost:5000/busybox:unsigned
|
||||
|
||||
# ...and pull it back out
|
||||
run_skopeo copy --src-cert-dir=$TESTDIR/client-auth \
|
||||
docker://localhost:5000/busybox:unsigned \
|
||||
dir:$TESTDIR/extracted
|
||||
}
|
||||
|
||||
teardown() {
|
||||
podman rm -f reg
|
||||
|
||||
standard_teardown
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
78
systemtest/040-local-registry-auth.bats
Normal file
78
systemtest/040-local-registry-auth.bats
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Tests with a local registry with auth
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
function setup() {
|
||||
standard_setup
|
||||
|
||||
# Remove old/stale cred file
|
||||
_cred_dir=$TESTDIR/credentials
|
||||
export XDG_RUNTIME_DIR=$_cred_dir
|
||||
mkdir -p $_cred_dir/containers
|
||||
rm -f $_cred_dir/containers/auth.json
|
||||
|
||||
# Start authenticated registry with random password
|
||||
testuser=testuser
|
||||
testpassword=$(random_string 15)
|
||||
|
||||
start_registry --testuser=testuser --testpassword=$testpassword reg
|
||||
}
|
||||
|
||||
@test "auth: credentials on command line" {
|
||||
# No creds
|
||||
run_skopeo 1 inspect --tls-verify=false docker://localhost:5000/nonesuch
|
||||
expect_output --substring "unauthorized: authentication required"
|
||||
|
||||
# Wrong user
|
||||
run_skopeo 1 inspect --tls-verify=false --creds=baduser:badpassword \
|
||||
docker://localhost:5000/nonesuch
|
||||
expect_output --substring "unauthorized: authentication required"
|
||||
|
||||
# Wrong password
|
||||
run_skopeo 1 inspect --tls-verify=false --creds=$testuser:badpassword \
|
||||
docker://localhost:5000/nonesuch
|
||||
expect_output --substring "unauthorized: authentication required"
|
||||
|
||||
# Correct creds, but no such image
|
||||
run_skopeo 1 inspect --tls-verify=false --creds=$testuser:$testpassword \
|
||||
docker://localhost:5000/nonesuch
|
||||
expect_output --substring "manifest unknown: manifest unknown"
|
||||
|
||||
# These should pass
|
||||
run_skopeo copy --dest-tls-verify=false --dcreds=$testuser:$testpassword \
|
||||
docker://busybox:latest docker://localhost:5000/busybox:mine
|
||||
run_skopeo inspect --tls-verify=false --creds=$testuser:$testpassword \
|
||||
docker://localhost:5000/busybox:mine
|
||||
expect_output --substring "localhost:5000/busybox"
|
||||
}
|
||||
|
||||
@test "auth: credentials via podman login" {
|
||||
# Logged in: skopeo should work
|
||||
podman login --tls-verify=false -u $testuser -p $testpassword localhost:5000
|
||||
|
||||
run_skopeo copy --dest-tls-verify=false \
|
||||
docker://busybox:latest docker://localhost:5000/busybox:mine
|
||||
run_skopeo inspect --tls-verify=false docker://localhost:5000/busybox:mine
|
||||
expect_output --substring "localhost:5000/busybox"
|
||||
|
||||
# Logged out: should fail
|
||||
podman logout localhost:5000
|
||||
|
||||
run_skopeo 1 inspect --tls-verify=false docker://localhost:5000/busybox:mine
|
||||
expect_output --substring "unauthorized: authentication required"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
podman rm -f reg
|
||||
|
||||
if [[ -n $_cred_dir ]]; then
|
||||
rm -rf $_cred_dir
|
||||
fi
|
||||
|
||||
standard_teardown
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
151
systemtest/050-signing.bats
Normal file
151
systemtest/050-signing.bats
Normal file
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# Tests with gpg signing
|
||||
#
|
||||
|
||||
load helpers
|
||||
|
||||
function setup() {
|
||||
standard_setup
|
||||
|
||||
# Create dummy gpg keys
|
||||
export GNUPGHOME=$TESTDIR/skopeo-gpg
|
||||
mkdir --mode=0700 $GNUPGHOME
|
||||
|
||||
# gpg on f30 needs this, otherwise:
|
||||
# gpg: agent_genkey failed: Inappropriate ioctl for device
|
||||
# ...but gpg on f29 (and, probably, Ubuntu) doesn't grok this
|
||||
GPGOPTS='--pinentry-mode loopback'
|
||||
if gpg --pinentry-mode asdf 2>&1 | grep -qi 'Invalid option'; then
|
||||
GPGOPTS=
|
||||
fi
|
||||
|
||||
for k in alice bob;do
|
||||
gpg --batch $GPGOPTS --gen-key --passphrase '' <<END_GPG
|
||||
Key-Type: RSA
|
||||
Name-Real: Test key - $k
|
||||
Name-email: $k@test.redhat.com
|
||||
%commit
|
||||
END_GPG
|
||||
|
||||
gpg --armor --export $k@test.redhat.com >$GNUPGHOME/pubkey-$k.gpg
|
||||
done
|
||||
|
||||
# Registries. The important part here seems to be sigstore,
|
||||
# because (I guess?) the registry itself has no mechanism
|
||||
# for storing or validating signatures.
|
||||
REGISTRIES_D=$TESTDIR/registries.d
|
||||
mkdir $REGISTRIES_D $TESTDIR/sigstore
|
||||
cat >$REGISTRIES_D/registries.yaml <<EOF
|
||||
docker:
|
||||
localhost:5000:
|
||||
sigstore: file://$TESTDIR/sigstore
|
||||
EOF
|
||||
|
||||
# Policy file. Basically, require /myns/alice and /myns/bob
|
||||
# to be signed; allow /open; and reject anything else.
|
||||
POLICY_JSON=$TESTDIR/policy.json
|
||||
cat >$POLICY_JSON <<END_POLICY_JSON
|
||||
{
|
||||
"default": [
|
||||
{
|
||||
"type": "reject"
|
||||
}
|
||||
],
|
||||
"transports": {
|
||||
"docker": {
|
||||
"localhost:5000/myns/alice": [
|
||||
{
|
||||
"type": "signedBy",
|
||||
"keyType": "GPGKeys",
|
||||
"keyPath": "$GNUPGHOME/pubkey-alice.gpg"
|
||||
}
|
||||
],
|
||||
"localhost:5000/myns/bob": [
|
||||
{
|
||||
"type": "signedBy",
|
||||
"keyType": "GPGKeys",
|
||||
"keyPath": "$GNUPGHOME/pubkey-bob.gpg"
|
||||
}
|
||||
],
|
||||
"localhost:5000/open": [
|
||||
{
|
||||
"type": "insecureAcceptAnything"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
END_POLICY_JSON
|
||||
|
||||
start_registry reg
|
||||
}
|
||||
|
||||
@test "signing" {
|
||||
run_skopeo '?' standalone-sign /dev/null busybox alice@test.redhat.com -o /dev/null
|
||||
if [[ "$output" =~ 'signing is not supported' ]]; then
|
||||
skip "skopeo built without support for creating signatures"
|
||||
return 1
|
||||
fi
|
||||
if [ "$status" -ne 0 ]; then
|
||||
die "exit code is $status; expected $expected_rc"
|
||||
fi
|
||||
|
||||
# Cache local copy
|
||||
run_skopeo copy docker://busybox:latest dir:$TESTDIR/busybox
|
||||
|
||||
# Push a bunch of images. Do so *without* --policy flag; this lets us
|
||||
# sign or not, creating images that will or won't conform to policy.
|
||||
while read path sig comments; do
|
||||
local sign_opt=
|
||||
if [[ $sig != '-' ]]; then
|
||||
sign_opt="--sign-by=${sig}@test.redhat.com"
|
||||
fi
|
||||
run_skopeo --registries.d $REGISTRIES_D \
|
||||
copy --dest-tls-verify=false \
|
||||
$sign_opt \
|
||||
dir:$TESTDIR/busybox \
|
||||
docker://localhost:5000$path
|
||||
done <<END_PUSH
|
||||
/myns/alice:signed alice # Properly-signed image
|
||||
/myns/alice:unsigned - # Unsigned image to path that requires signature
|
||||
/myns/bob:signedbyalice alice # Bad signature: image under /bob
|
||||
/myns/carol:latest - # No signature
|
||||
/open/forall:latest - # No signature, but none needed
|
||||
END_PUSH
|
||||
|
||||
# Done pushing. Now try to fetch. From here on we use the --policy option.
|
||||
# The table below lists the paths to fetch, and the expected errors (or
|
||||
# none, if we expect them to pass).
|
||||
while read path expected_error; do
|
||||
expected_rc=
|
||||
if [[ -n $expected_error ]]; then
|
||||
expected_rc=1
|
||||
fi
|
||||
|
||||
rm -rf $TESTDIR/d
|
||||
run_skopeo $expected_rc \
|
||||
--registries.d $REGISTRIES_D \
|
||||
--policy $POLICY_JSON \
|
||||
copy --src-tls-verify=false \
|
||||
docker://localhost:5000$path \
|
||||
dir:$TESTDIR/d
|
||||
if [[ -n $expected_error ]]; then
|
||||
expect_output --substring "Source image rejected: $expected_error"
|
||||
fi
|
||||
done <<END_TESTS
|
||||
/myns/alice:signed
|
||||
/myns/bob:signedbyalice Invalid GPG signature
|
||||
/myns/alice:unsigned Signature for identity localhost:5000/myns/alice:signed is not accepted
|
||||
/myns/carol:latest Running image docker://localhost:5000/myns/carol:latest is rejected by policy.
|
||||
/open/forall:latest
|
||||
END_TESTS
|
||||
}
|
||||
|
||||
teardown() {
|
||||
podman rm -f reg
|
||||
|
||||
standard_teardown
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
344
systemtest/helpers.bash
Normal file
344
systemtest/helpers.bash
Normal file
@@ -0,0 +1,344 @@
|
||||
#!/bin/bash
|
||||
|
||||
SKOPEO_BINARY=${SKOPEO_BINARY:-$(dirname ${BASH_SOURCE})/../skopeo}
|
||||
|
||||
# Default timeout for a skopeo command.
|
||||
SKOPEO_TIMEOUT=${SKOPEO_TIMEOUT:-300}
|
||||
|
||||
###############################################################################
|
||||
# BEGIN setup/teardown
|
||||
|
||||
# Provide common setup and teardown functions, but do not name them such!
|
||||
# That way individual tests can override with their own setup/teardown,
|
||||
# while retaining the ability to include these if they so desire.
|
||||
|
||||
function standard_setup() {
|
||||
# Argh. Although BATS provides $BATS_TMPDIR, it's just /tmp!
|
||||
# That's bloody worthless. Let's make our own, in which subtests
|
||||
# can write whatever they like and trust that it'll be deleted
|
||||
# on cleanup.
|
||||
TESTDIR=$(mktemp -d --tmpdir=${BATS_TMPDIR:-/tmp} skopeo_bats.XXXXXX)
|
||||
}
|
||||
|
||||
function standard_teardown() {
|
||||
if [[ -n $TESTDIR ]]; then
|
||||
rm -rf $TESTDIR
|
||||
fi
|
||||
}
|
||||
|
||||
# Individual .bats files may override or extend these
|
||||
function setup() {
|
||||
standard_setup
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
standard_teardown
|
||||
}
|
||||
|
||||
# END setup/teardown
|
||||
###############################################################################
|
||||
# BEGIN standard helpers for running skopeo and testing results
|
||||
|
||||
#################
|
||||
# run_skopeo # Invoke skopeo, with timeout, using BATS 'run'
|
||||
#################
|
||||
#
|
||||
# This is the preferred mechanism for invoking skopeo:
|
||||
#
|
||||
# * we use 'timeout' to abort (with a diagnostic) if something
|
||||
# takes too long; this is preferable to a CI hang.
|
||||
# * we log the command run and its output. This doesn't normally
|
||||
# appear in BATS output, but it will if there's an error.
|
||||
# * we check exit status. Since the normal desired code is 0,
|
||||
# that's the default; but the first argument can override:
|
||||
#
|
||||
# run_skopeo 125 nonexistent-subcommand
|
||||
# run_skopeo '?' some-other-command # let our caller check status
|
||||
#
|
||||
# Since we use the BATS 'run' mechanism, $output and $status will be
|
||||
# defined for our caller.
|
||||
#
|
||||
function run_skopeo() {
|
||||
# Number as first argument = expected exit code; default 0
|
||||
expected_rc=0
|
||||
case "$1" in
|
||||
[0-9]) expected_rc=$1; shift;;
|
||||
[1-9][0-9]) expected_rc=$1; shift;;
|
||||
[12][0-9][0-9]) expected_rc=$1; shift;;
|
||||
'?') expected_rc= ; shift;; # ignore exit code
|
||||
esac
|
||||
|
||||
# Remember command args, for possible use in later diagnostic messages
|
||||
MOST_RECENT_SKOPEO_COMMAND="skopeo $*"
|
||||
|
||||
# stdout is only emitted upon error; this echo is to help a debugger
|
||||
echo "\$ $SKOPEO_BINARY $*"
|
||||
run timeout --foreground --kill=10 $SKOPEO_TIMEOUT ${SKOPEO_BINARY} "$@"
|
||||
# without "quotes", multiple lines are glommed together into one
|
||||
if [ -n "$output" ]; then
|
||||
echo "$output"
|
||||
fi
|
||||
if [ "$status" -ne 0 ]; then
|
||||
echo -n "[ rc=$status ";
|
||||
if [ -n "$expected_rc" ]; then
|
||||
if [ "$status" -eq "$expected_rc" ]; then
|
||||
echo -n "(expected) ";
|
||||
else
|
||||
echo -n "(** EXPECTED $expected_rc **) ";
|
||||
fi
|
||||
fi
|
||||
echo "]"
|
||||
fi
|
||||
|
||||
if [ "$status" -eq 124 -o "$status" -eq 137 ]; then
|
||||
# FIXME: 'timeout -v' requires coreutils-8.29; travis seems to have
|
||||
# an older version. If/when travis updates, please add -v
|
||||
# to the 'timeout' command above, and un-comment this out:
|
||||
# if expr "$output" : ".*timeout: sending" >/dev/null; then
|
||||
echo "*** TIMED OUT ***"
|
||||
false
|
||||
fi
|
||||
|
||||
if [ -n "$expected_rc" ]; then
|
||||
if [ "$status" -ne "$expected_rc" ]; then
|
||||
die "exit code is $status; expected $expected_rc"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#########
|
||||
# die # Abort with helpful message
|
||||
#########
|
||||
function die() {
|
||||
echo "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" >&2
|
||||
echo "#| FAIL: $*" >&2
|
||||
echo "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >&2
|
||||
false
|
||||
}
|
||||
|
||||
###################
|
||||
# expect_output # Compare actual vs expected string; fail if mismatch
|
||||
###################
|
||||
#
|
||||
# Compares $output against the given string argument. Optional second
|
||||
# argument is descriptive text to show as the error message (default:
|
||||
# the command most recently run by 'run_skopeo'). This text can be
|
||||
# useful to isolate a failure when there are multiple identical
|
||||
# run_skopeo invocations, and the difference is solely in the
|
||||
# config or setup; see, e.g., run.bats:run-cmd().
|
||||
#
|
||||
# By default we run an exact string comparison; use --substring to
|
||||
# look for the given string anywhere in $output.
|
||||
#
|
||||
# By default we look in "$output", which is set in run_skopeo().
|
||||
# To override, use --from="some-other-string" (e.g. "${lines[0]}")
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# expect_output "this is exactly what we expect"
|
||||
# expect_output "foo=bar" "description of this particular test"
|
||||
# expect_output --from="${lines[0]}" "expected first line"
|
||||
#
|
||||
function expect_output() {
|
||||
# By default we examine $output, the result of run_skopeo
|
||||
local actual="$output"
|
||||
local check_substring=
|
||||
|
||||
# option processing: recognize --from="...", --substring
|
||||
local opt
|
||||
for opt; do
|
||||
local value=$(expr "$opt" : '[^=]*=\(.*\)')
|
||||
case "$opt" in
|
||||
--from=*) actual="$value"; shift;;
|
||||
--substring) check_substring=1; shift;;
|
||||
--) shift; break;;
|
||||
-*) die "Invalid option '$opt'" ;;
|
||||
*) break;;
|
||||
esac
|
||||
done
|
||||
|
||||
local expect="$1"
|
||||
local testname="${2:-${MOST_RECENT_SKOPEO_COMMAND:-[no test name given]}}"
|
||||
|
||||
if [ -z "$expect" ]; then
|
||||
if [ -z "$actual" ]; then
|
||||
return
|
||||
fi
|
||||
expect='[no output]'
|
||||
elif [ "$actual" = "$expect" ]; then
|
||||
return
|
||||
elif [ -n "$check_substring" ]; then
|
||||
if [[ "$actual" =~ $expect ]]; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# This is a multi-line message, which may in turn contain multi-line
|
||||
# output, so let's format it ourself, readably
|
||||
local -a actual_split
|
||||
readarray -t actual_split <<<"$actual"
|
||||
printf "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" >&2
|
||||
printf "#| FAIL: $testname\n" >&2
|
||||
printf "#| expected: '%s'\n" "$expect" >&2
|
||||
printf "#| actual: '%s'\n" "${actual_split[0]}" >&2
|
||||
local line
|
||||
for line in "${actual_split[@]:1}"; do
|
||||
printf "#| > '%s'\n" "$line" >&2
|
||||
done
|
||||
printf "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" >&2
|
||||
false
|
||||
}
|
||||
|
||||
#######################
|
||||
# expect_line_count # Check the expected number of output lines
|
||||
#######################
|
||||
#
|
||||
# ...from the most recent run_skopeo command
|
||||
#
|
||||
function expect_line_count() {
|
||||
local expect="$1"
|
||||
local testname="${2:-${MOST_RECENT_SKOPEO_COMMAND:-[no test name given]}}"
|
||||
|
||||
local actual="${#lines[@]}"
|
||||
if [ "$actual" -eq "$expect" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
printf "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" >&2
|
||||
printf "#| FAIL: $testname\n" >&2
|
||||
printf "#| Expected %d lines of output, got %d\n" $expect $actual >&2
|
||||
printf "#| Output was:\n" >&2
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
printf "#| >%s\n" "$line" >&2
|
||||
done
|
||||
printf "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" >&2
|
||||
false
|
||||
}
|
||||
|
||||
# END standard helpers for running skopeo and testing results
|
||||
###############################################################################
|
||||
# BEGIN helpers for starting/stopping registries
|
||||
|
||||
####################
|
||||
# start_registry # Run a local registry container
|
||||
####################
|
||||
#
|
||||
# Usage: start_registry [OPTIONS] NAME
|
||||
#
|
||||
# OPTIONS
|
||||
# --port=NNNN Port to listen on (default: 5000)
|
||||
# --testuser=XXX Require authentication; this is the username
|
||||
# --testpassword=XXX ...and the password (these two go together)
|
||||
# --with-cert Create a cert for running with TLS (not working)
|
||||
#
|
||||
# NAME is the container name to assign.
|
||||
#
|
||||
start_registry() {
|
||||
local port=5000
|
||||
local testuser=
|
||||
local testpassword=
|
||||
local create_cert=
|
||||
|
||||
# option processing: recognize options for running the registry
|
||||
# in different modes.
|
||||
local opt
|
||||
for opt; do
|
||||
local value=$(expr "$opt" : '[^=]*=\(.*\)')
|
||||
case "$opt" in
|
||||
--port=*) port="$value"; shift;;
|
||||
--testuser=*) testuser="$value"; shift;;
|
||||
--testpassword=*) testpassword="$value"; shift;;
|
||||
--with-cert) create_cert=1; shift;;
|
||||
-*) die "Invalid option '$opt'" ;;
|
||||
*) break;;
|
||||
esac
|
||||
done
|
||||
|
||||
local name=${1?start_registry() invoked without a NAME}
|
||||
|
||||
# Temp directory must be defined and must exist
|
||||
[[ -n $TESTDIR && -d $TESTDIR ]]
|
||||
|
||||
AUTHDIR=$TESTDIR/auth
|
||||
mkdir -p $AUTHDIR
|
||||
|
||||
local -a reg_args=(-v $AUTHDIR:/auth:Z -p $port:5000)
|
||||
|
||||
# cgroup option necessary under podman-in-podman (CI tests),
|
||||
# and doesn't seem to do any harm otherwise.
|
||||
PODMAN="podman --cgroup-manager=cgroupfs"
|
||||
|
||||
# Called with --testuser? Create an htpasswd file
|
||||
if [[ -n $testuser ]]; then
|
||||
if [[ -z $testpassword ]]; then
|
||||
die "start_registry() invoked with testuser but no testpassword"
|
||||
fi
|
||||
|
||||
if ! egrep -q "^$testuser:" $AUTHDIR/htpasswd; then
|
||||
$PODMAN run --rm --entrypoint htpasswd registry:2 \
|
||||
-Bbn $testuser $testpassword >> $AUTHDIR/htpasswd
|
||||
fi
|
||||
|
||||
reg_args+=(
|
||||
-e REGISTRY_AUTH=htpasswd
|
||||
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
|
||||
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"
|
||||
)
|
||||
fi
|
||||
|
||||
# Called with --with-cert? Create certificates.
|
||||
if [[ -n $create_cert ]]; then
|
||||
CERT=$AUTHDIR/domain.crt
|
||||
if [ ! -e $CERT ]; then
|
||||
openssl req -newkey rsa:4096 -nodes -sha256 \
|
||||
-keyout $AUTHDIR/domain.key -x509 -days 2 \
|
||||
-out $CERT \
|
||||
-subj "/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=localhost"
|
||||
fi
|
||||
|
||||
reg_args+=(
|
||||
-e REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt
|
||||
-e REGISTRY_HTTP_TLS_KEY=/auth/domain.key
|
||||
)
|
||||
|
||||
# Copy .crt file to a directory *without* the .key one, so we can
|
||||
# test the client. (If client sees a matching .key file, it fails)
|
||||
# Thanks to Miloslav Trmac for this hint.
|
||||
mkdir -p $TESTDIR/client-auth
|
||||
cp $CERT $TESTDIR/client-auth/
|
||||
fi
|
||||
|
||||
$PODMAN run -d --name $name "${reg_args[@]}" registry:2
|
||||
|
||||
# Wait for registry to actually come up
|
||||
timeout=10
|
||||
while [[ $timeout -ge 1 ]]; do
|
||||
if curl localhost:$port/; then
|
||||
return
|
||||
fi
|
||||
|
||||
timeout=$(expr $timeout - 1)
|
||||
sleep 1
|
||||
done
|
||||
die "Timed out waiting for registry container to respond on :$port"
|
||||
}
|
||||
|
||||
# END helpers for starting/stopping registries
|
||||
###############################################################################
|
||||
# BEGIN miscellaneous tools
|
||||
|
||||
###################
|
||||
# random_string # Returns a pseudorandom human-readable string
|
||||
###################
|
||||
#
|
||||
# Numeric argument, if present, is desired length of string
|
||||
#
|
||||
function random_string() {
|
||||
local length=${1:-10}
|
||||
|
||||
head /dev/urandom | tr -dc a-zA-Z0-9 | head -c$length
|
||||
}
|
||||
|
||||
# END miscellaneous tools
|
||||
###############################################################################
|
||||
16
systemtest/run-tests
Executable file
16
systemtest/run-tests
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# run-tests - simple wrapper allowing shortcuts on invocation
|
||||
#
|
||||
|
||||
TEST_DIR=$(dirname $0)
|
||||
TESTS=$TEST_DIR
|
||||
|
||||
for i; do
|
||||
case "$i" in
|
||||
*.bats) TESTS=$i ;;
|
||||
*) TESTS=$(echo $TEST_DIR/*$i*.bats) ;;
|
||||
esac
|
||||
done
|
||||
|
||||
bats $TESTS
|
||||
@@ -2,14 +2,14 @@
|
||||
github.com/urfave/cli v1.20.0
|
||||
github.com/kr/pretty v0.1.0
|
||||
github.com/kr/text v0.1.0
|
||||
github.com/containers/image 2c0349c99af7d90694b3faa0e9bde404d407b145
|
||||
github.com/containers/buildah 810efa340ab43753034e2ed08ec290e4abab7e72
|
||||
github.com/containers/image v2.0.0
|
||||
github.com/containers/buildah v1.8.4
|
||||
github.com/vbauerster/mpb v3.3.4
|
||||
github.com/mattn/go-isatty v0.0.4
|
||||
github.com/VividCortex/ewma v1.1.1
|
||||
golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e
|
||||
github.com/opencontainers/go-digest c9281466c8b2f606084ac71339773efd177436e7
|
||||
github.com/containers/storage v1.12.3
|
||||
github.com/containers/storage v1.12.10
|
||||
github.com/sirupsen/logrus v1.0.0
|
||||
github.com/go-check/check v1
|
||||
github.com/stretchr/testify v1.1.3
|
||||
|
||||
13
vendor/github.com/containers/buildah/pkg/unshare/unshare.c
generated
vendored
13
vendor/github.com/containers/buildah/pkg/unshare/unshare.c
generated
vendored
@@ -3,7 +3,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/memfd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <sched.h>
|
||||
@@ -14,6 +14,17 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Open Source projects like conda-forge, want to package podman and are based
|
||||
off of centos:6, Conda-force has minimal libc requirements and is lacking
|
||||
the memfd.h file, so we use mmam.h
|
||||
*/
|
||||
#ifndef MFD_ALLOW_SEALING
|
||||
#define MFD_ALLOW_SEALING 2U
|
||||
#endif
|
||||
#ifndef MFD_CLOEXEC
|
||||
#define MFD_CLOEXEC 1U
|
||||
#endif
|
||||
|
||||
#ifndef F_LINUX_SPECIFIC_BASE
|
||||
#define F_LINUX_SPECIFIC_BASE 1024
|
||||
#endif
|
||||
|
||||
45
vendor/github.com/containers/buildah/pkg/unshare/unshare.go
generated
vendored
45
vendor/github.com/containers/buildah/pkg/unshare/unshare.go
generated
vendored
@@ -64,6 +64,7 @@ func (c *Cmd) Start() error {
|
||||
if os.Geteuid() != 0 {
|
||||
c.Env = append(c.Env, "_CONTAINERS_USERNS_CONFIGURED=done")
|
||||
c.Env = append(c.Env, fmt.Sprintf("_CONTAINERS_ROOTLESS_UID=%d", os.Geteuid()))
|
||||
c.Env = append(c.Env, fmt.Sprintf("_CONTAINERS_ROOTLESS_GID=%d", os.Getegid()))
|
||||
}
|
||||
|
||||
// Create the pipe for reading the child's PID.
|
||||
@@ -183,6 +184,7 @@ func (c *Cmd) Start() error {
|
||||
for _, m := range c.GidMappings {
|
||||
fmt.Fprintf(g, "%d %d %d\n", m.ContainerID, m.HostID, m.Size)
|
||||
}
|
||||
gidmapSet := false
|
||||
// Set the GID map.
|
||||
if c.UseNewgidmap {
|
||||
cmd := exec.Command("newgidmap", append([]string{pidString}, strings.Fields(strings.Replace(g.String(), "\n", " ", -1))...)...)
|
||||
@@ -190,11 +192,28 @@ func (c *Cmd) Start() error {
|
||||
cmd.Stdout = g
|
||||
cmd.Stderr = g
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Fprintf(continueWrite, "error running newgidmap: %v: %s", err, g.String())
|
||||
return errors.Wrapf(err, "error running newgidmap: %s", g.String())
|
||||
if err == nil {
|
||||
gidmapSet = true
|
||||
} else {
|
||||
logrus.Warnf("error running newgidmap: %v: %s", err, g.String())
|
||||
logrus.Warnf("falling back to single mapping")
|
||||
g.Reset()
|
||||
g.Write([]byte(fmt.Sprintf("0 %d 1\n", os.Getegid())))
|
||||
}
|
||||
}
|
||||
if !gidmapSet {
|
||||
if c.UseNewgidmap {
|
||||
setgroups, err := os.OpenFile(fmt.Sprintf("/proc/%s/setgroups", pidString), os.O_TRUNC|os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
fmt.Fprintf(continueWrite, "error opening /proc/%s/setgroups: %v", pidString, err)
|
||||
return errors.Wrapf(err, "error opening /proc/%s/setgroups", pidString)
|
||||
}
|
||||
defer setgroups.Close()
|
||||
if _, err := fmt.Fprintf(setgroups, "deny"); err != nil {
|
||||
fmt.Fprintf(continueWrite, "error writing 'deny' to /proc/%s/setgroups: %v", pidString, err)
|
||||
return errors.Wrapf(err, "error writing 'deny' to /proc/%s/setgroups", pidString)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gidmap, err := os.OpenFile(fmt.Sprintf("/proc/%s/gid_map", pidString), os.O_TRUNC|os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
fmt.Fprintf(continueWrite, "error opening /proc/%s/gid_map: %v", pidString, err)
|
||||
@@ -214,6 +233,7 @@ func (c *Cmd) Start() error {
|
||||
for _, m := range c.UidMappings {
|
||||
fmt.Fprintf(u, "%d %d %d\n", m.ContainerID, m.HostID, m.Size)
|
||||
}
|
||||
uidmapSet := false
|
||||
// Set the GID map.
|
||||
if c.UseNewuidmap {
|
||||
cmd := exec.Command("newuidmap", append([]string{pidString}, strings.Fields(strings.Replace(u.String(), "\n", " ", -1))...)...)
|
||||
@@ -221,11 +241,16 @@ func (c *Cmd) Start() error {
|
||||
cmd.Stdout = u
|
||||
cmd.Stderr = u
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Fprintf(continueWrite, "error running newuidmap: %v: %s", err, u.String())
|
||||
return errors.Wrapf(err, "error running newuidmap: %s", u.String())
|
||||
if err == nil {
|
||||
uidmapSet = true
|
||||
} else {
|
||||
logrus.Warnf("error running newuidmap: %v: %s", err, u.String())
|
||||
logrus.Warnf("falling back to single mapping")
|
||||
u.Reset()
|
||||
u.Write([]byte(fmt.Sprintf("0 %d 1\n", os.Geteuid())))
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if !uidmapSet {
|
||||
uidmap, err := os.OpenFile(fmt.Sprintf("/proc/%s/uid_map", pidString), os.O_TRUNC|os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
fmt.Fprintf(continueWrite, "error opening /proc/%s/uid_map: %v", pidString, err)
|
||||
@@ -354,7 +379,9 @@ func MaybeReexecUsingUserNamespace(evenForRoot bool) {
|
||||
// range in /etc/subuid and /etc/subgid file is a starting host
|
||||
// ID and a range size.
|
||||
uidmap, gidmap, err = GetSubIDMappings(me.Username, me.Username)
|
||||
bailOnError(err, "error reading allowed ID mappings")
|
||||
if err != nil {
|
||||
logrus.Warnf("error reading allowed ID mappings: %v", err)
|
||||
}
|
||||
if len(uidmap) == 0 {
|
||||
logrus.Warnf("Found no UID ranges set aside for user %q in /etc/subuid.", me.Username)
|
||||
}
|
||||
|
||||
7
vendor/github.com/containers/buildah/vendor.conf
generated
vendored
7
vendor/github.com/containers/buildah/vendor.conf
generated
vendored
@@ -3,12 +3,12 @@ github.com/blang/semver v3.5.0
|
||||
github.com/BurntSushi/toml v0.2.0
|
||||
github.com/containerd/continuity 004b46473808b3e7a4a3049c20e4376c91eb966d
|
||||
github.com/containernetworking/cni v0.7.0-rc2
|
||||
github.com/containers/image f52cf78ebfa1916da406f8b6210d8f7764ec1185
|
||||
github.com/containers/image v2.0.0
|
||||
github.com/cyphar/filepath-securejoin v0.2.1
|
||||
github.com/vbauerster/mpb v3.3.4
|
||||
github.com/mattn/go-isatty v0.0.4
|
||||
github.com/VividCortex/ewma v1.1.1
|
||||
github.com/boltdb/bolt v1.3.1
|
||||
github.com/containers/storage v1.12.2
|
||||
github.com/containers/storage v1.12.10
|
||||
github.com/docker/distribution 5f6282db7d65e6d72ad7c2cc66310724a57be716
|
||||
github.com/docker/docker 54dddadc7d5d89fe0be88f76979f6f6ab0dede83
|
||||
github.com/docker/docker-credential-helpers v0.6.1
|
||||
@@ -66,3 +66,4 @@ github.com/onsi/gomega v1.4.3
|
||||
github.com/spf13/cobra v0.0.3
|
||||
github.com/spf13/pflag v1.0.3
|
||||
github.com/ishidawataru/sctp 07191f837fedd2f13d1ec7b5f885f0f3ec54b1cb
|
||||
github.com/etcd-io/bbolt v1.3.2
|
||||
|
||||
61
vendor/github.com/containers/image/docker/docker_image_src.go
generated
vendored
61
vendor/github.com/containers/image/docker/docker_image_src.go
generated
vendored
@@ -29,44 +29,16 @@ type dockerImageSource struct {
|
||||
cachedManifestMIMEType string // Only valid if cachedManifest != nil
|
||||
}
|
||||
|
||||
// newImageSource creates a new `ImageSource` for the specified image reference
|
||||
// `ref`.
|
||||
//
|
||||
// The following steps will be done during the instance creation:
|
||||
//
|
||||
// - Lookup the registry within the configured location in
|
||||
// `sys.SystemRegistriesConfPath`. If there is no configured registry available,
|
||||
// we fallback to the provided docker reference `ref`.
|
||||
//
|
||||
// - References which contain a configured prefix will be automatically rewritten
|
||||
// to the correct target reference. For example, if the configured
|
||||
// `prefix = "example.com/foo"`, `location = "example.com"` and the image will be
|
||||
// pulled from the ref `example.com/foo/image`, then the resulting pull will
|
||||
// effectively point to `example.com/image`.
|
||||
//
|
||||
// - If the rewritten reference succeeds, it will be used as the `dockerRef`
|
||||
// in the client. If the rewrite fails, the function immediately returns an error.
|
||||
//
|
||||
// - Each mirror will be used (in the configured order) to test the
|
||||
// availability of the image manifest on the remote location. For example,
|
||||
// if the manifest is not reachable due to connectivity issues, then the next
|
||||
// mirror will be tested instead. If no mirror is configured or contains the
|
||||
// target manifest, then the initial `ref` will be tested as fallback. The
|
||||
// creation of the new `dockerImageSource` only succeeds if a remote
|
||||
// location with the available manifest was found.
|
||||
//
|
||||
// A cleanup call to `.Close()` is needed if the caller is done using the returned
|
||||
// `ImageSource`.
|
||||
// newImageSource creates a new ImageSource for the specified image reference.
|
||||
// The caller must call .Close() on the returned ImageSource.
|
||||
func newImageSource(ctx context.Context, sys *types.SystemContext, ref dockerReference) (*dockerImageSource, error) {
|
||||
registry, err := sysregistriesv2.FindRegistry(sys, ref.ref.Name())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error loading registries configuration")
|
||||
}
|
||||
|
||||
if registry == nil {
|
||||
// No configuration was found for the provided reference, so we create
|
||||
// a fallback registry by hand to make the client creation below work
|
||||
// as intended.
|
||||
// No configuration was found for the provided reference, so use the
|
||||
// equivalent of a default configuration.
|
||||
registry = &sysregistriesv2.Registry{
|
||||
Endpoint: sysregistriesv2.Endpoint{
|
||||
Location: ref.ref.String(),
|
||||
@@ -76,18 +48,19 @@ func newImageSource(ctx context.Context, sys *types.SystemContext, ref dockerRef
|
||||
}
|
||||
|
||||
primaryDomain := reference.Domain(ref.ref)
|
||||
// Found the registry within the sysregistriesv2 configuration. Now we test
|
||||
// all endpoints for the manifest availability. If a working image source
|
||||
// was found, it will be used for all future pull actions.
|
||||
// Check all endpoints for the manifest availability. If we find one that does
|
||||
// contain the image, it will be used for all future pull actions. Always try the
|
||||
// non-mirror original location last; this both transparently handles the case
|
||||
// of no mirrors configured, and ensures we return the error encountered when
|
||||
// acessing the upstream location if all endpoints fail.
|
||||
manifestLoadErr := errors.New("Internal error: newImageSource returned without trying any endpoint")
|
||||
for _, endpoint := range append(registry.Mirrors, registry.Endpoint) {
|
||||
logrus.Debugf("Trying to pull %q from endpoint %q", ref.ref, endpoint.Location)
|
||||
|
||||
newRef, err := endpoint.RewriteReference(ref.ref, registry.Prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dockerRef, err := newReference(newRef)
|
||||
pullSources, err := registry.PullSourcesFromReference(ref.ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, pullSource := range pullSources {
|
||||
logrus.Debugf("Trying to pull %q", pullSource.Reference)
|
||||
dockerRef, err := newReference(pullSource.Reference)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -104,7 +77,7 @@ func newImageSource(ctx context.Context, sys *types.SystemContext, ref dockerRef
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.tlsClientConfig.InsecureSkipVerify = endpoint.Insecure
|
||||
client.tlsClientConfig.InsecureSkipVerify = pullSource.Endpoint.Insecure
|
||||
|
||||
testImageSource := &dockerImageSource{
|
||||
ref: dockerRef,
|
||||
|
||||
2
vendor/github.com/containers/image/docker/reference/README.md
generated
vendored
2
vendor/github.com/containers/image/docker/reference/README.md
generated
vendored
@@ -1,2 +1,2 @@
|
||||
This is a copy of github.com/docker/distribution/reference as of commit fb0bebc4b64e3881cc52a2478d749845ed76d2a8,
|
||||
This is a copy of github.com/docker/distribution/reference as of commit 3226863cbcba6dbc2f6c83a37b28126c934af3f8,
|
||||
except that ParseAnyReferenceWithSet has been removed to drop the dependency on github.com/docker/distribution/digestset.
|
||||
29
vendor/github.com/containers/image/docker/reference/normalize.go
generated
vendored
29
vendor/github.com/containers/image/docker/reference/normalize.go
generated
vendored
@@ -55,6 +55,35 @@ func ParseNormalizedNamed(s string) (Named, error) {
|
||||
return named, nil
|
||||
}
|
||||
|
||||
// ParseDockerRef normalizes the image reference following the docker convention. This is added
|
||||
// mainly for backward compatibility.
|
||||
// The reference returned can only be either tagged or digested. For reference contains both tag
|
||||
// and digest, the function returns digested reference, e.g. docker.io/library/busybox:latest@
|
||||
// sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa will be returned as
|
||||
// docker.io/library/busybox@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa.
|
||||
func ParseDockerRef(ref string) (Named, error) {
|
||||
named, err := ParseNormalizedNamed(ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := named.(NamedTagged); ok {
|
||||
if canonical, ok := named.(Canonical); ok {
|
||||
// The reference is both tagged and digested, only
|
||||
// return digested.
|
||||
newNamed, err := WithName(canonical.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newCanonical, err := WithDigest(newNamed, canonical.Digest())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newCanonical, nil
|
||||
}
|
||||
}
|
||||
return TagNameOnly(named), nil
|
||||
}
|
||||
|
||||
// splitDockerDomain splits a repository name to domain and remotename string.
|
||||
// If no valid domain is found, the default domain is used. Repository name
|
||||
// needs to be already validated before.
|
||||
|
||||
4
vendor/github.com/containers/image/docker/reference/reference.go
generated
vendored
4
vendor/github.com/containers/image/docker/reference/reference.go
generated
vendored
@@ -15,7 +15,7 @@
|
||||
// tag := /[\w][\w.-]{0,127}/
|
||||
//
|
||||
// digest := digest-algorithm ":" digest-hex
|
||||
// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]
|
||||
// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]*
|
||||
// digest-algorithm-separator := /[+.-_]/
|
||||
// digest-algorithm-component := /[A-Za-z][A-Za-z0-9]*/
|
||||
// digest-hex := /[0-9a-fA-F]{32,}/ ; At least 128 bit digest value
|
||||
@@ -205,7 +205,7 @@ func Parse(s string) (Reference, error) {
|
||||
var repo repository
|
||||
|
||||
nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1])
|
||||
if nameMatch != nil && len(nameMatch) == 3 {
|
||||
if len(nameMatch) == 3 {
|
||||
repo.domain = nameMatch[1]
|
||||
repo.path = nameMatch[2]
|
||||
} else {
|
||||
|
||||
10
vendor/github.com/containers/image/docker/reference/regexp.go
generated
vendored
10
vendor/github.com/containers/image/docker/reference/regexp.go
generated
vendored
@@ -20,15 +20,15 @@ var (
|
||||
optional(repeated(separatorRegexp, alphaNumericRegexp)))
|
||||
|
||||
// domainComponentRegexp restricts the registry domain component of a
|
||||
// repository name to start with a component as defined by domainRegexp
|
||||
// repository name to start with a component as defined by DomainRegexp
|
||||
// and followed by an optional port.
|
||||
domainComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`)
|
||||
|
||||
// domainRegexp defines the structure of potential domain components
|
||||
// DomainRegexp defines the structure of potential domain components
|
||||
// that may be part of image names. This is purposely a subset of what is
|
||||
// allowed by DNS to ensure backwards compatibility with Docker image
|
||||
// names.
|
||||
domainRegexp = expression(
|
||||
DomainRegexp = expression(
|
||||
domainComponentRegexp,
|
||||
optional(repeated(literal(`.`), domainComponentRegexp)),
|
||||
optional(literal(`:`), match(`[0-9]+`)))
|
||||
@@ -51,14 +51,14 @@ var (
|
||||
// regexp has capturing groups for the domain and name part omitting
|
||||
// the separating forward slash from either.
|
||||
NameRegexp = expression(
|
||||
optional(domainRegexp, literal(`/`)),
|
||||
optional(DomainRegexp, literal(`/`)),
|
||||
nameComponentRegexp,
|
||||
optional(repeated(literal(`/`), nameComponentRegexp)))
|
||||
|
||||
// anchoredNameRegexp is used to parse a name value, capturing the
|
||||
// domain and trailing components.
|
||||
anchoredNameRegexp = anchored(
|
||||
optional(capture(domainRegexp), literal(`/`)),
|
||||
optional(capture(DomainRegexp), literal(`/`)),
|
||||
capture(nameComponentRegexp,
|
||||
optional(repeated(literal(`/`), nameComponentRegexp))))
|
||||
|
||||
|
||||
148
vendor/github.com/containers/image/docs/containers-registries.conf.5.md
generated
vendored
148
vendor/github.com/containers/image/docs/containers-registries.conf.5.md
generated
vendored
@@ -18,57 +18,127 @@ VERSION 2 is the latest format of the `registries.conf` and is currently in
|
||||
beta. This means in general VERSION 1 should be used in production environments
|
||||
for now.
|
||||
|
||||
Every registry can have its own mirrors configured. The mirrors will be tested
|
||||
in order for the availability of the remote manifest. This happens currently
|
||||
only during an image pull. If the manifest is not reachable due to connectivity
|
||||
issues or the unavailability of the remote manifest, then the next mirror will
|
||||
be tested instead. If no mirror is configured or contains the manifest to be
|
||||
pulled, then the initially provided reference will be used as fallback. It is
|
||||
possible to set the `insecure` option per mirror, too.
|
||||
### GLOBAL SETTINGS
|
||||
|
||||
Furthermore it is possible to specify a `prefix` for a registry. The `prefix`
|
||||
is used to find the relevant target registry from where the image has to be
|
||||
pulled. During the test for the availability of the image, the prefixed
|
||||
location will be rewritten to the correct remote location. This applies to
|
||||
mirrors as well as the fallback `location`. If no prefix is specified, it
|
||||
defaults to the specified `location`. For example, if
|
||||
`prefix = "example.com/foo"`, `location = "example.com"` and the image will be
|
||||
pulled from `example.com/foo/image`, then the resulting pull will be effectively
|
||||
point to `example.com/image`.
|
||||
`unqualified-search-registries`
|
||||
: An array of _host_[`:`_port_] registries to try when pulling an unqualified image, in order.
|
||||
|
||||
By default container runtimes use TLS when retrieving images from a registry.
|
||||
If the registry is not setup with TLS, then the container runtime will fail to
|
||||
pull images from the registry. If you set `insecure = true` for a registry or a
|
||||
mirror you overwrite the `insecure` flag for that specific entry. This means
|
||||
that the container runtime will attempt use unencrypted HTTP to pull the image.
|
||||
It also allows you to pull from a registry with self-signed certificates.
|
||||
### NAMESPACED `[[registry]]` SETTINGS
|
||||
|
||||
If you set the `unqualified-search = true` for the registry, then it is possible
|
||||
to omit the registry hostname when pulling images. This feature does not work
|
||||
together with a specified `prefix`.
|
||||
The bulk of the configuration is represented as an array of `[[registry]]`
|
||||
TOML tables; the settings may therefore differ among different registries
|
||||
as well as among different namespaces/repositories within a registry.
|
||||
|
||||
If `blocked = true` then it is not allowed to pull images from that registry.
|
||||
#### Choosing a `[[registry]]` TOML table
|
||||
|
||||
Given an image name, a single `[[registry]]` TOML table is chosen based on its `prefix` field.
|
||||
|
||||
`prefix`
|
||||
: A prefix of the user-specified image name, i.e. using one of the following formats:
|
||||
- _host_[`:`_port_]
|
||||
- _host_[`:`_port_]`/`_namespace_[`/`_namespace_…]
|
||||
- _host_[`:`_port_]`/`_namespace_[`/`_namespace_…]`/`_repo_
|
||||
- _host_[`:`_port_]`/`_namespace_[`/`_namespace_…]`/`_repo_(`:`_tag|`@`_digest_)
|
||||
|
||||
The user-specified image name must start with the specified `prefix` (and continue
|
||||
with the appropriate separator) for a particular `[[registry]]` TOML table to be
|
||||
considered; (only) the TOML table with the longest match is used.
|
||||
|
||||
As a special case, the `prefix` field can be missing; if so, it defaults to the value
|
||||
of the `location` field (described below).
|
||||
|
||||
#### Per-namespace settings
|
||||
|
||||
`insecure`
|
||||
: `true` or `false`.
|
||||
By default, container runtimes require TLS when retrieving images from a registry.
|
||||
If `insecure` is set to `true`, unencrypted HTTP as well as TLS connections with untrusted
|
||||
certificates are allowed.
|
||||
|
||||
`blocked`
|
||||
: `true` or `false`.
|
||||
If `true`, pulling images with matching names is forbidden.
|
||||
|
||||
#### Remapping and mirroring registries
|
||||
|
||||
The user-specified image reference is, primarily, a "logical" image name, always used for naming
|
||||
the image. By default, the image reference also directly specifies the registry and repository
|
||||
to use, but the following options can be used to redirect the underlying accesses
|
||||
to different registry servers or locations (e.g. to support configurations with no access to the
|
||||
internet without having to change `Dockerfile`s, or to add redundancy).
|
||||
|
||||
`location`
|
||||
: Accepts the same format as the `prefix` field, and specifies the physical location
|
||||
of the `prefix`-rooted namespace.
|
||||
|
||||
By default, this equal to `prefix` (in which case `prefix` can be omitted and the
|
||||
`[[registry]]` TOML table can only specify `location`).
|
||||
|
||||
Example: Given
|
||||
```
|
||||
prefix = "example.com/foo"
|
||||
location = "internal-registry-for-example.net/bar"
|
||||
```
|
||||
requests for the image `example.com/foo/myimage:latest` will actually work with the
|
||||
`internal-registry-for-example.net/bar/myimage:latest` image.
|
||||
|
||||
`mirror`
|
||||
: An array of TOML tables specifiying (possibly-partial) mirrors for the
|
||||
`prefix`-rooted namespace.
|
||||
|
||||
The mirrors are attempted in the specified order; the first one that can be
|
||||
contacted and contains the image will be used (and if none of the mirrors contains the image,
|
||||
the primary location specified by the `registry.location` field, or using the unmodified
|
||||
user-specified reference, is tried last).
|
||||
|
||||
Each TOML table in the `mirror` array can contain the following fields, with the same semantics
|
||||
as if specified in the `[[registry]]` TOML table directly:
|
||||
- `location`
|
||||
- `insecure`
|
||||
|
||||
`mirror-by-digest-only`
|
||||
: `true` or `false`.
|
||||
If `true`, mirrors will only be used during pulling if the image reference includes a digest.
|
||||
Referencing an image by digest ensures that the same is always used
|
||||
(whereas referencing an image by a tag may cause different registries to return
|
||||
different images if the tag mapping is out of sync).
|
||||
|
||||
Note that if this is `true`, images referenced by a tag will only use the primary
|
||||
registry, failing if that registry is not accessible.
|
||||
|
||||
*Note*: Redirection and mirrors are currently processed only when reading images, not when pushing
|
||||
to a registry; that may change in the future.
|
||||
|
||||
### EXAMPLE
|
||||
|
||||
```
|
||||
unqualified-search-registries = ["example.com"]
|
||||
|
||||
[[registry]]
|
||||
location = "example.com"
|
||||
insecure = false
|
||||
prefix = "example.com/foo"
|
||||
unqualified-search = false
|
||||
insecure = false
|
||||
blocked = false
|
||||
mirror = [
|
||||
{ location = "example-mirror-0.local", insecure = false },
|
||||
{ location = "example-mirror-1.local", insecure = true }
|
||||
]
|
||||
location = "internal-registry-for-example.com/bar"
|
||||
|
||||
[[registry.mirror]]
|
||||
location = "example-mirror-0.local/mirror-for-foo"
|
||||
|
||||
[[registry.mirror]]
|
||||
location = "example-mirror-1.local/mirrors/foo"
|
||||
insecure = true
|
||||
```
|
||||
Given the above, a pull of `example.com/foo/image:latest` will try:
|
||||
1. `example-mirror-0.local/mirror-for-foo/image:latest`
|
||||
2. `example-mirror-1.local/mirrors/foo/image:latest`
|
||||
3. `internal-registry-for-example.net/bar/myimage:latest`
|
||||
|
||||
in order, and use the first one that exists.
|
||||
|
||||
## VERSION 1
|
||||
VERSION 1 can be used as alternative to the VERSION 2, but it is not capable in
|
||||
using registry mirrors or a prefix.
|
||||
VERSION 1 can be used as alternative to the VERSION 2, but it does not support
|
||||
using registry mirrors, longest-prefix matches, or location rewriting.
|
||||
|
||||
The TOML_format is used to build a simple list for registries under three
|
||||
The TOML format is used to build a simple list of registries under three
|
||||
categories: `registries.search`, `registries.insecure`, and `registries.block`.
|
||||
You can list multiple registries using a comma separated list.
|
||||
|
||||
@@ -76,11 +146,11 @@ Search registries are used when the caller of a container runtime does not fully
|
||||
container image that they want to execute. These registries are prepended onto the front
|
||||
of the specified container image until the named image is found at a registry.
|
||||
|
||||
Note insecure registries can be used for any registry, not just the registries listed
|
||||
Note that insecure registries can be used for any registry, not just the registries listed
|
||||
under search.
|
||||
|
||||
The fields `registries.insecure` and `registries.block` work as like as the
|
||||
`insecure` and `blocked` from VERSION 2.
|
||||
The `registries.insecure` and `registries.block` lists have the same meaning as the
|
||||
`insecure` and `blocked` fields in VERSION 2.
|
||||
|
||||
### EXAMPLE
|
||||
The following example configuration defines two searchable registries, one
|
||||
|
||||
224
vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go
generated
vendored
224
vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go
generated
vendored
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -35,10 +36,10 @@ type Endpoint struct {
|
||||
Insecure bool `toml:"insecure"`
|
||||
}
|
||||
|
||||
// RewriteReference will substitute the provided reference `prefix` to the
|
||||
// rewriteReference will substitute the provided reference `prefix` to the
|
||||
// endpoints `location` from the `ref` and creates a new named reference from it.
|
||||
// The function errors if the newly created reference is not parsable.
|
||||
func (e *Endpoint) RewriteReference(ref reference.Named, prefix string) (reference.Named, error) {
|
||||
func (e *Endpoint) rewriteReference(ref reference.Named, prefix string) (reference.Named, error) {
|
||||
refString := ref.String()
|
||||
if !refMatchesPrefix(refString, prefix) {
|
||||
return nil, fmt.Errorf("invalid prefix '%v' for reference '%v'", prefix, refString)
|
||||
@@ -61,8 +62,10 @@ type Registry struct {
|
||||
Mirrors []Endpoint `toml:"mirror"`
|
||||
// If true, pulling from the registry will be blocked.
|
||||
Blocked bool `toml:"blocked"`
|
||||
// If true, the registry can be used when pulling an unqualified image.
|
||||
Search bool `toml:"unqualified-search"`
|
||||
// If true, mirrors will only be used for digest pulls. Pulling images by
|
||||
// tag can potentially yield different images, depending on which endpoint
|
||||
// we pull from. Forcing digest-pulls for mirrors avoids that issue.
|
||||
MirrorByDigestOnly bool `toml:"mirror-by-digest-only"`
|
||||
// Prefix is used for matching images, and to translate one namespace to
|
||||
// another. If `Prefix="example.com/bar"`, `location="example.com/foo/bar"`
|
||||
// and we pull from "example.com/bar/myimage:latest", the image will
|
||||
@@ -71,6 +74,41 @@ type Registry struct {
|
||||
Prefix string `toml:"prefix"`
|
||||
}
|
||||
|
||||
// PullSource consists of an Endpoint and a Reference. Note that the reference is
|
||||
// rewritten according to the registries prefix and the Endpoint's location.
|
||||
type PullSource struct {
|
||||
Endpoint Endpoint
|
||||
Reference reference.Named
|
||||
}
|
||||
|
||||
// PullSourcesFromReference returns a slice of PullSource's based on the passed
|
||||
// reference.
|
||||
func (r *Registry) PullSourcesFromReference(ref reference.Named) ([]PullSource, error) {
|
||||
var endpoints []Endpoint
|
||||
|
||||
if r.MirrorByDigestOnly {
|
||||
// Only use mirrors when the reference is a digest one.
|
||||
if _, isDigested := ref.(reference.Canonical); isDigested {
|
||||
endpoints = append(r.Mirrors, r.Endpoint)
|
||||
} else {
|
||||
endpoints = []Endpoint{r.Endpoint}
|
||||
}
|
||||
} else {
|
||||
endpoints = append(r.Mirrors, r.Endpoint)
|
||||
}
|
||||
|
||||
sources := []PullSource{}
|
||||
for _, ep := range endpoints {
|
||||
rewritten, err := ep.rewriteReference(ref, r.Prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sources = append(sources, PullSource{Endpoint: ep, Reference: rewritten})
|
||||
}
|
||||
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
// V1TOMLregistries is for backwards compatibility to sysregistries v1
|
||||
type V1TOMLregistries struct {
|
||||
Registries []string `toml:"registries"`
|
||||
@@ -83,11 +121,35 @@ type V1TOMLConfig struct {
|
||||
Block V1TOMLregistries `toml:"block"`
|
||||
}
|
||||
|
||||
// V1RegistriesConf is the sysregistries v1 configuration format.
|
||||
type V1RegistriesConf struct {
|
||||
V1TOMLConfig `toml:"registries"`
|
||||
}
|
||||
|
||||
// Nonempty returns true if config contains at least one configuration entry.
|
||||
func (config *V1RegistriesConf) Nonempty() bool {
|
||||
return (len(config.V1TOMLConfig.Search.Registries) != 0 ||
|
||||
len(config.V1TOMLConfig.Insecure.Registries) != 0 ||
|
||||
len(config.V1TOMLConfig.Block.Registries) != 0)
|
||||
}
|
||||
|
||||
// V2RegistriesConf is the sysregistries v2 configuration format.
|
||||
type V2RegistriesConf struct {
|
||||
Registries []Registry `toml:"registry"`
|
||||
// An array of host[:port] (not prefix!) entries to use for resolving unqualified image references
|
||||
UnqualifiedSearchRegistries []string `toml:"unqualified-search-registries"`
|
||||
}
|
||||
|
||||
// Nonempty returns true if config contains at least one configuration entry.
|
||||
func (config *V2RegistriesConf) Nonempty() bool {
|
||||
return (len(config.Registries) != 0 ||
|
||||
len(config.UnqualifiedSearchRegistries) != 0)
|
||||
}
|
||||
|
||||
// tomlConfig is the data type used to unmarshal the toml config.
|
||||
type tomlConfig struct {
|
||||
Registries []Registry `toml:"registry"`
|
||||
// backwards compatability to sysregistries v1
|
||||
V1TOMLConfig `toml:"registries"`
|
||||
V2RegistriesConf
|
||||
V1RegistriesConf // for backwards compatibility with sysregistries v1
|
||||
}
|
||||
|
||||
// InvalidRegistries represents an invalid registry configurations. An example
|
||||
@@ -120,12 +182,10 @@ func parseLocation(input string) (string, error) {
|
||||
return trimmed, nil
|
||||
}
|
||||
|
||||
// getV1Registries transforms v1 registries in the config into an array of v2
|
||||
// registries of type Registry.
|
||||
func getV1Registries(config *tomlConfig) ([]Registry, error) {
|
||||
// ConvertToV2 returns a v2 config corresponding to a v1 one.
|
||||
func (config *V1RegistriesConf) ConvertToV2() (*V2RegistriesConf, error) {
|
||||
regMap := make(map[string]*Registry)
|
||||
// We must preserve the order of config.V1Registries.Search.Registries at least. The order of the
|
||||
// other registries is not really important, but make it deterministic (the same for the same config file)
|
||||
// The order of the registries is not really important, but make it deterministic (the same for the same config file)
|
||||
// to minimize behavior inconsistency and not contribute to difficult-to-reproduce situations.
|
||||
registryOrder := []string{}
|
||||
|
||||
@@ -148,15 +208,6 @@ func getV1Registries(config *tomlConfig) ([]Registry, error) {
|
||||
return reg, nil
|
||||
}
|
||||
|
||||
// Note: config.V1Registries.Search needs to be processed first to ensure registryOrder is populated in the right order
|
||||
// if one of the search registries is also in one of the other lists.
|
||||
for _, search := range config.V1TOMLConfig.Search.Registries {
|
||||
reg, err := getRegistry(search)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reg.Search = true
|
||||
}
|
||||
for _, blocked := range config.V1TOMLConfig.Block.Registries {
|
||||
reg, err := getRegistry(blocked)
|
||||
if err != nil {
|
||||
@@ -172,28 +223,31 @@ func getV1Registries(config *tomlConfig) ([]Registry, error) {
|
||||
reg.Insecure = true
|
||||
}
|
||||
|
||||
registries := []Registry{}
|
||||
res := &V2RegistriesConf{
|
||||
UnqualifiedSearchRegistries: config.V1TOMLConfig.Search.Registries,
|
||||
}
|
||||
for _, location := range registryOrder {
|
||||
reg := regMap[location]
|
||||
registries = append(registries, *reg)
|
||||
res.Registries = append(res.Registries, *reg)
|
||||
}
|
||||
return registries, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// postProcessRegistries checks the consistency of all registries (e.g., set
|
||||
// the Prefix to Location if not set) and applies conflict checks. It returns an
|
||||
// array of cleaned registries and error in case of conflicts.
|
||||
func postProcessRegistries(regs []Registry) ([]Registry, error) {
|
||||
var registries []Registry
|
||||
regMap := make(map[string][]Registry)
|
||||
// anchoredDomainRegexp is an internal implementation detail of postProcess, defining the valid values of elements of UnqualifiedSearchRegistries.
|
||||
var anchoredDomainRegexp = regexp.MustCompile("^" + reference.DomainRegexp.String() + "$")
|
||||
|
||||
for _, reg := range regs {
|
||||
var err error
|
||||
// postProcess checks the consistency of all the configuration, looks for conflicts,
|
||||
// and normalizes the configuration (e.g., sets the Prefix to Location if not set).
|
||||
func (config *V2RegistriesConf) postProcess() error {
|
||||
regMap := make(map[string][]*Registry)
|
||||
|
||||
for i := range config.Registries {
|
||||
reg := &config.Registries[i]
|
||||
// make sure Location and Prefix are valid
|
||||
var err error
|
||||
reg.Location, err = parseLocation(reg.Location)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if reg.Prefix == "" {
|
||||
@@ -201,7 +255,7 @@ func postProcessRegistries(regs []Registry) ([]Registry, error) {
|
||||
} else {
|
||||
reg.Prefix, err = parseLocation(reg.Prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,10 +263,9 @@ func postProcessRegistries(regs []Registry) ([]Registry, error) {
|
||||
for _, mir := range reg.Mirrors {
|
||||
mir.Location, err = parseLocation(mir.Location)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
registries = append(registries, reg)
|
||||
regMap[reg.Location] = append(regMap[reg.Location], reg)
|
||||
}
|
||||
|
||||
@@ -222,22 +275,32 @@ func postProcessRegistries(regs []Registry) ([]Registry, error) {
|
||||
//
|
||||
// Note: we need to iterate over the registries array to ensure a
|
||||
// deterministic behavior which is not guaranteed by maps.
|
||||
for _, reg := range registries {
|
||||
for _, reg := range config.Registries {
|
||||
others, _ := regMap[reg.Location]
|
||||
for _, other := range others {
|
||||
if reg.Insecure != other.Insecure {
|
||||
msg := fmt.Sprintf("registry '%s' is defined multiple times with conflicting 'insecure' setting", reg.Location)
|
||||
|
||||
return nil, &InvalidRegistries{s: msg}
|
||||
return &InvalidRegistries{s: msg}
|
||||
}
|
||||
if reg.Blocked != other.Blocked {
|
||||
msg := fmt.Sprintf("registry '%s' is defined multiple times with conflicting 'blocked' setting", reg.Location)
|
||||
return nil, &InvalidRegistries{s: msg}
|
||||
return &InvalidRegistries{s: msg}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return registries, nil
|
||||
for i := range config.UnqualifiedSearchRegistries {
|
||||
registry, err := parseLocation(config.UnqualifiedSearchRegistries[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !anchoredDomainRegexp.MatchString(registry) {
|
||||
return &InvalidRegistries{fmt.Sprintf("Invalid unqualified-search-registries entry %#v", registry)}
|
||||
}
|
||||
config.UnqualifiedSearchRegistries[i] = registry
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getConfigPath returns the system-registries config path if specified.
|
||||
@@ -260,7 +323,7 @@ var configMutex = sync.Mutex{}
|
||||
// configCache caches already loaded configs with config paths as keys and is
|
||||
// used to avoid redudantly parsing configs. Concurrent accesses to the cache
|
||||
// are synchronized via configMutex.
|
||||
var configCache = make(map[string][]Registry)
|
||||
var configCache = make(map[string]*V2RegistriesConf)
|
||||
|
||||
// InvalidateCache invalidates the registry cache. This function is meant to be
|
||||
// used for long-running processes that need to reload potential changes made to
|
||||
@@ -268,20 +331,18 @@ var configCache = make(map[string][]Registry)
|
||||
func InvalidateCache() {
|
||||
configMutex.Lock()
|
||||
defer configMutex.Unlock()
|
||||
configCache = make(map[string][]Registry)
|
||||
configCache = make(map[string]*V2RegistriesConf)
|
||||
}
|
||||
|
||||
// GetRegistries loads and returns the registries specified in the config.
|
||||
// Note the parsed content of registry config files is cached. For reloading,
|
||||
// use `InvalidateCache` and re-call `GetRegistries`.
|
||||
func GetRegistries(ctx *types.SystemContext) ([]Registry, error) {
|
||||
// getConfig returns the config object corresponding to ctx, loading it if it is not yet cached.
|
||||
func getConfig(ctx *types.SystemContext) (*V2RegistriesConf, error) {
|
||||
configPath := getConfigPath(ctx)
|
||||
|
||||
configMutex.Lock()
|
||||
defer configMutex.Unlock()
|
||||
// if the config has already been loaded, return the cached registries
|
||||
if registries, inCache := configCache[configPath]; inCache {
|
||||
return registries, nil
|
||||
if config, inCache := configCache[configPath]; inCache {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// load the config
|
||||
@@ -292,51 +353,53 @@ func GetRegistries(ctx *types.SystemContext) ([]Registry, error) {
|
||||
// isn't set. Note: if ctx.SystemRegistriesConfPath points to
|
||||
// the default config, we will still return an error.
|
||||
if os.IsNotExist(err) && (ctx == nil || ctx.SystemRegistriesConfPath == "") {
|
||||
return []Registry{}, nil
|
||||
return &V2RegistriesConf{Registries: []Registry{}}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
registries := config.Registries
|
||||
v2Config := &config.V2RegistriesConf
|
||||
|
||||
// backwards compatibility for v1 configs
|
||||
v1Registries, err := getV1Registries(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(v1Registries) > 0 {
|
||||
if len(registries) > 0 {
|
||||
if config.V1RegistriesConf.Nonempty() {
|
||||
if config.V2RegistriesConf.Nonempty() {
|
||||
return nil, &InvalidRegistries{s: "mixing sysregistry v1/v2 is not supported"}
|
||||
}
|
||||
registries = v1Registries
|
||||
v2, err := config.V1RegistriesConf.ConvertToV2()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v2Config = v2
|
||||
}
|
||||
|
||||
registries, err = postProcessRegistries(registries)
|
||||
if err != nil {
|
||||
if err := v2Config.postProcess(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// populate the cache
|
||||
configCache[configPath] = registries
|
||||
|
||||
return registries, err
|
||||
configCache[configPath] = v2Config
|
||||
return v2Config, nil
|
||||
}
|
||||
|
||||
// FindUnqualifiedSearchRegistries returns all registries that are configured
|
||||
// for unqualified image search (i.e., with Registry.Search == true).
|
||||
func FindUnqualifiedSearchRegistries(ctx *types.SystemContext) ([]Registry, error) {
|
||||
registries, err := GetRegistries(ctx)
|
||||
// GetRegistries loads and returns the registries specified in the config.
|
||||
// Note the parsed content of registry config files is cached. For reloading,
|
||||
// use `InvalidateCache` and re-call `GetRegistries`.
|
||||
func GetRegistries(ctx *types.SystemContext) ([]Registry, error) {
|
||||
config, err := getConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config.Registries, nil
|
||||
}
|
||||
|
||||
unqualified := []Registry{}
|
||||
for _, reg := range registries {
|
||||
if reg.Search {
|
||||
unqualified = append(unqualified, reg)
|
||||
}
|
||||
// UnqualifiedSearchRegistries returns a list of host[:port] entries to try
|
||||
// for unqualified image search, in the returned order)
|
||||
func UnqualifiedSearchRegistries(ctx *types.SystemContext) ([]string, error) {
|
||||
config, err := getConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return unqualified, nil
|
||||
return config.UnqualifiedSearchRegistries, nil
|
||||
}
|
||||
|
||||
// refMatchesPrefix returns true iff ref,
|
||||
@@ -371,14 +434,14 @@ func refMatchesPrefix(ref, prefix string) bool {
|
||||
// — note that this requires the name to start with an explicit hostname!).
|
||||
// If no Registry prefixes the image, nil is returned.
|
||||
func FindRegistry(ctx *types.SystemContext, ref string) (*Registry, error) {
|
||||
registries, err := GetRegistries(ctx)
|
||||
config, err := getConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reg := Registry{}
|
||||
prefixLen := 0
|
||||
for _, r := range registries {
|
||||
for _, r := range config.Registries {
|
||||
if refMatchesPrefix(ref, r.Prefix) {
|
||||
length := len(r.Prefix)
|
||||
if length > prefixLen {
|
||||
@@ -393,21 +456,12 @@ func FindRegistry(ctx *types.SystemContext, ref string) (*Registry, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Reads the global registry file from the filesystem. Returns a byte array.
|
||||
func readRegistryConf(configPath string) ([]byte, error) {
|
||||
configBytes, err := ioutil.ReadFile(configPath)
|
||||
return configBytes, err
|
||||
}
|
||||
|
||||
// Used in unittests to parse custom configs without a types.SystemContext.
|
||||
var readConf = readRegistryConf
|
||||
|
||||
// Loads the registry configuration file from the filesystem and then unmarshals
|
||||
// it. Returns the unmarshalled object.
|
||||
func loadRegistryConf(configPath string) (*tomlConfig, error) {
|
||||
config := &tomlConfig{}
|
||||
|
||||
configBytes, err := readConf(configPath)
|
||||
configBytes, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
73
vendor/github.com/containers/image/registries.conf
generated
vendored
73
vendor/github.com/containers/image/registries.conf
generated
vendored
@@ -29,37 +29,54 @@ registries = []
|
||||
# The second version of the configuration format allows to specify registry
|
||||
# mirrors:
|
||||
#
|
||||
# # An array of host[:port] registries to try when pulling an unqualified image, in order.
|
||||
# unqualified-search-registries = ["example.com"]
|
||||
#
|
||||
# [[registry]]
|
||||
# # The main location of the registry
|
||||
# location = "example.com"
|
||||
#
|
||||
# # If true, certs verification will be skipped and HTTP (non-TLS) connections
|
||||
# # will be allowed.
|
||||
# insecure = false
|
||||
#
|
||||
# # Prefix is used for matching images, and to translate one namespace to
|
||||
# # another. If `prefix = "example.com/foo"`, `location = "example.com"` and
|
||||
# # we pull from "example.com/foo/myimage:latest", the image will effectively be
|
||||
# # pulled from "example.com/myimage:latest". If no Prefix is specified,
|
||||
# # it defaults to the specified `location`. When a prefix is used, then a pull
|
||||
# # without specifying the prefix is not possible any more.
|
||||
# # The "prefix" field is used to choose the relevant [[registry]] TOML table;
|
||||
# # (only) the TOML table with the longest match for the input image name
|
||||
# # (taking into account namespace/repo/tag/digest separators) is used.
|
||||
# #
|
||||
# # If the prefix field is missing, it defaults to be the same as the "location" field.
|
||||
# prefix = "example.com/foo"
|
||||
#
|
||||
# # If true, the registry can be used when pulling an unqualified image. If a
|
||||
# # prefix is specified, unqualified pull is not possible any more.
|
||||
# unqualified-search = false
|
||||
# # If true, unencrypted HTTP as well as TLS connections with untrusted
|
||||
# # certificates are allowed.
|
||||
# insecure = false
|
||||
#
|
||||
# # If true, pulling from the registry will be blocked.
|
||||
# # If true, pulling images with matching names is forbidden.
|
||||
# blocked = false
|
||||
#
|
||||
# # All available mirrors of the registry. The mirrors will be evaluated in
|
||||
# # order during an image pull. Furthermore it is possible to specify the
|
||||
# # `insecure` flag per registry mirror, too.
|
||||
# mirror = [
|
||||
# { location = "example-mirror-0.local", insecure = false },
|
||||
# { location = "example-mirror-1.local", insecure = true },
|
||||
# # It is also possible to specify an additional path within the `location`.
|
||||
# # A pull to `example.com/foo/image:latest` will then result in
|
||||
# # `example-mirror-2.local/path/image:latest`.
|
||||
# { location = "example-mirror-2.local/path" },
|
||||
# ]
|
||||
# # The physical location of the "prefix"-rooted namespace.
|
||||
# #
|
||||
# # By default, this equal to "prefix" (in which case "prefix" can be omitted
|
||||
# # and the [[registry]] TOML table can only specify "location").
|
||||
# #
|
||||
# # Example: Given
|
||||
# # prefix = "example.com/foo"
|
||||
# # location = "internal-registry-for-example.net/bar"
|
||||
# # requests for the image example.com/foo/myimage:latest will actually work with the
|
||||
# # internal-registry-for-example.net/bar/myimage:latest image.
|
||||
# location = internal-registry-for-example.com/bar"
|
||||
#
|
||||
# # (Possibly-partial) mirrors for the "prefix"-rooted namespace.
|
||||
# #
|
||||
# # The mirrors are attempted in the specified order; the first one that can be
|
||||
# # contacted and contains the image will be used (and if none of the mirrors contains the image,
|
||||
# # the primary location specified by the "registry.location" field, or using the unmodified
|
||||
# # user-specified reference, is tried last).
|
||||
# #
|
||||
# # Each TOML table in the "mirror" array can contain the following fields, with the same semantics
|
||||
# # as if specified in the [[registry]] TOML table directly:
|
||||
# # - location
|
||||
# # - insecure
|
||||
# [[registry.mirror]]
|
||||
# location = "example-mirror-0.local/mirror-for-foo"
|
||||
# [[registry.mirror]]
|
||||
# location = "example-mirror-1.local/mirrors/foo"
|
||||
# insecure = true
|
||||
# # Given the above, a pull of example.com/foo/image:latest will try:
|
||||
# # 1. example-mirror-0.local/mirror-for-foo/image:latest
|
||||
# # 2. example-mirror-1.local/mirrors/foo/image:latest
|
||||
# # 3. internal-registry-for-example.net/bar/myimage:latest
|
||||
# # in order, and use the first one that exists.
|
||||
|
||||
6
vendor/github.com/containers/image/version/version.go
generated
vendored
6
vendor/github.com/containers/image/version/version.go
generated
vendored
@@ -4,14 +4,14 @@ import "fmt"
|
||||
|
||||
const (
|
||||
// VersionMajor is for an API incompatible changes
|
||||
VersionMajor = 1
|
||||
VersionMajor = 2
|
||||
// VersionMinor is for functionality in a backwards-compatible manner
|
||||
VersionMinor = 7
|
||||
VersionMinor = 0
|
||||
// VersionPatch is for backwards-compatible bug fixes
|
||||
VersionPatch = 0
|
||||
|
||||
// VersionDev indicates development branch. Releases will be empty string.
|
||||
VersionDev = "-dev"
|
||||
VersionDev = ""
|
||||
)
|
||||
|
||||
// Version is the specification version that the package types support.
|
||||
|
||||
4
vendor/github.com/containers/storage/containers.go
generated
vendored
4
vendor/github.com/containers/storage/containers.go
generated
vendored
@@ -572,6 +572,10 @@ func (r *containerStore) Lock() {
|
||||
r.lockfile.Lock()
|
||||
}
|
||||
|
||||
func (r *containerStore) RecursiveLock() {
|
||||
r.lockfile.RecursiveLock()
|
||||
}
|
||||
|
||||
func (r *containerStore) RLock() {
|
||||
r.lockfile.RLock()
|
||||
}
|
||||
|
||||
3
vendor/github.com/containers/storage/drivers/aufs/aufs.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/aufs/aufs.go
generated
vendored
@@ -255,6 +255,9 @@ func (a *Driver) AdditionalImageStores() []string {
|
||||
|
||||
// CreateFromTemplate creates a layer with the same contents and parent as another layer.
|
||||
func (a *Driver) CreateFromTemplate(id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *graphdriver.CreateOpts, readWrite bool) error {
|
||||
if opts == nil {
|
||||
opts = &graphdriver.CreateOpts{}
|
||||
}
|
||||
return graphdriver.NaiveCreateFromTemplate(a, id, template, templateIDMappings, parent, parentIDMappings, opts, readWrite)
|
||||
}
|
||||
|
||||
|
||||
3
vendor/github.com/containers/storage/drivers/chown.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/chown.go
generated
vendored
@@ -55,6 +55,9 @@ func chownByMapsMain() {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error walking to %q: %v", path, err)
|
||||
}
|
||||
if path == "." {
|
||||
return nil
|
||||
}
|
||||
return platformLChown(path, info, toHost, toContainer)
|
||||
}
|
||||
if err := filepath.Walk(".", chown); err != nil {
|
||||
|
||||
1
vendor/github.com/containers/storage/drivers/driver.go
generated
vendored
1
vendor/github.com/containers/storage/drivers/driver.go
generated
vendored
@@ -40,6 +40,7 @@ var (
|
||||
type CreateOpts struct {
|
||||
MountLabel string
|
||||
StorageOpt map[string]string
|
||||
*idtools.IDMappings
|
||||
}
|
||||
|
||||
// MountOpts contains optional arguments for LayerStope.Mount() methods.
|
||||
|
||||
77
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
77
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
@@ -16,7 +16,7 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/containers/storage/drivers"
|
||||
graphdriver "github.com/containers/storage/drivers"
|
||||
"github.com/containers/storage/drivers/overlayutils"
|
||||
"github.com/containers/storage/drivers/quota"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
@@ -320,6 +320,8 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
|
||||
mergedDir := filepath.Join(layerDir, "merged")
|
||||
lower1Dir := filepath.Join(layerDir, "lower1")
|
||||
lower2Dir := filepath.Join(layerDir, "lower2")
|
||||
upperDir := filepath.Join(layerDir, "upper")
|
||||
workDir := filepath.Join(layerDir, "work")
|
||||
defer func() {
|
||||
// Permitted to fail, since the various subdirectories
|
||||
// can be empty or not even there, and the home might
|
||||
@@ -331,7 +333,9 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
|
||||
_ = idtools.MkdirAs(mergedDir, 0700, rootUID, rootGID)
|
||||
_ = idtools.MkdirAs(lower1Dir, 0700, rootUID, rootGID)
|
||||
_ = idtools.MkdirAs(lower2Dir, 0700, rootUID, rootGID)
|
||||
flags := fmt.Sprintf("lowerdir=%s:%s", lower1Dir, lower2Dir)
|
||||
_ = idtools.MkdirAs(upperDir, 0700, rootUID, rootGID)
|
||||
_ = idtools.MkdirAs(workDir, 0700, rootUID, rootGID)
|
||||
flags := fmt.Sprintf("lowerdir=%s:%s,upperdir=%s,workdir=%s", lower1Dir, lower2Dir, upperDir, workDir)
|
||||
if len(flags) < unix.Getpagesize() {
|
||||
err := mountFrom(filepath.Dir(home), "overlay", mergedDir, "overlay", 0, flags)
|
||||
if err == nil {
|
||||
@@ -341,7 +345,7 @@ func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGI
|
||||
logrus.Debugf("overlay test mount with multiple lowers failed %v", err)
|
||||
}
|
||||
}
|
||||
flags = fmt.Sprintf("lowerdir=%s", lower1Dir)
|
||||
flags = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lower1Dir, upperDir, workDir)
|
||||
if len(flags) < unix.Getpagesize() {
|
||||
err := mountFrom(filepath.Dir(home), "overlay", mergedDir, "overlay", 0, flags)
|
||||
if err == nil {
|
||||
@@ -470,10 +474,22 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr
|
||||
func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts) (retErr error) {
|
||||
dir := d.dir(id)
|
||||
|
||||
rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
|
||||
uidMaps := d.uidMaps
|
||||
gidMaps := d.gidMaps
|
||||
|
||||
if opts != nil && opts.IDMappings != nil {
|
||||
uidMaps = opts.IDMappings.UIDs()
|
||||
gidMaps = opts.IDMappings.GIDs()
|
||||
}
|
||||
|
||||
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Make the link directory if it does not exist
|
||||
if err := idtools.MkdirAllAs(path.Join(d.home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) {
|
||||
return err
|
||||
}
|
||||
if err := idtools.MkdirAllAs(path.Dir(dir), 0700, rootUID, rootGID); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -677,6 +693,48 @@ func (d *Driver) Remove(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// recreateSymlinks goes through the driver's home directory and checks if the diff directory
|
||||
// under each layer has a symlink created for it under the linkDir. If the symlink does not
|
||||
// exist, it creates them
|
||||
func (d *Driver) recreateSymlinks() error {
|
||||
// List all the directories under the home directory
|
||||
dirs, err := ioutil.ReadDir(d.home)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading driver home directory %q: %v", d.home, err)
|
||||
}
|
||||
// This makes the link directory if it doesn't exist
|
||||
rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := idtools.MkdirAllAs(path.Join(d.home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) {
|
||||
return err
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
// Skip over the linkDir and anything that is not a directory
|
||||
if dir.Name() == linkDir || !dir.Mode().IsDir() {
|
||||
continue
|
||||
}
|
||||
// Read the "link" file under each layer to get the name of the symlink
|
||||
data, err := ioutil.ReadFile(path.Join(d.dir(dir.Name()), "link"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading name of symlink for %q: %v", dir, err)
|
||||
}
|
||||
linkPath := path.Join(d.home, linkDir, strings.Trim(string(data), "\n"))
|
||||
// Check if the symlink exists, and if it doesn't create it again with the name we
|
||||
// got from the "link" file
|
||||
_, err = os.Stat(linkPath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
if err := os.Symlink(path.Join("..", dir.Name(), "diff"), linkPath); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("error trying to stat %q: %v", linkPath, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get creates and mounts the required file system for the given id and returns the mount path.
|
||||
func (d *Driver) Get(id string, options graphdriver.MountOpts) (_ string, retErr error) {
|
||||
return d.get(id, false, options)
|
||||
@@ -732,7 +790,16 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
|
||||
}
|
||||
lower = ""
|
||||
}
|
||||
if lower == "" {
|
||||
// if it is a "not found" error, that means the symlinks were lost in a sudden reboot
|
||||
// so call the recreateSymlinks function to go through all the layer dirs and recreate
|
||||
// the symlinks with the name from their respective "link" files
|
||||
if lower == "" && os.IsNotExist(err) {
|
||||
logrus.Warnf("Can't stat lower layer %q because it does not exist. Going through storage to recreate the missing symlinks.", newpath)
|
||||
if err := d.recreateSymlinks(); err != nil {
|
||||
return "", fmt.Errorf("error recreating the missing symlinks: %v", err)
|
||||
}
|
||||
lower = newpath
|
||||
} else if lower == "" {
|
||||
return "", fmt.Errorf("Can't stat lower layer %q: %v", newpath, err)
|
||||
}
|
||||
} else {
|
||||
|
||||
7
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
7
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
@@ -123,8 +123,13 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool
|
||||
return fmt.Errorf("--storage-opt is not supported for vfs")
|
||||
}
|
||||
|
||||
idMappings := d.idMappings
|
||||
if opts != nil && opts.IDMappings != nil {
|
||||
idMappings = opts.IDMappings
|
||||
}
|
||||
|
||||
dir := d.dir(id)
|
||||
rootIDs := d.idMappings.RootPair()
|
||||
rootIDs := idMappings.RootPair()
|
||||
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
9
vendor/github.com/containers/storage/images.go
generated
vendored
9
vendor/github.com/containers/storage/images.go
generated
vendored
@@ -82,6 +82,9 @@ type Image struct {
|
||||
// is set before using it.
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
|
||||
// ReadOnly is true if this image resides in a read-only layer store.
|
||||
ReadOnly bool `json:"-"`
|
||||
|
||||
Flags map[string]interface{} `json:"flags,omitempty"`
|
||||
}
|
||||
|
||||
@@ -159,6 +162,7 @@ func copyImage(i *Image) *Image {
|
||||
BigDataSizes: copyStringInt64Map(i.BigDataSizes),
|
||||
BigDataDigests: copyStringDigestMap(i.BigDataDigests),
|
||||
Created: i.Created,
|
||||
ReadOnly: i.ReadOnly,
|
||||
Flags: copyStringInterfaceMap(i.Flags),
|
||||
}
|
||||
}
|
||||
@@ -269,6 +273,7 @@ func (r *imageStore) Load() error {
|
||||
list := digests[digest]
|
||||
digests[digest] = append(list, image)
|
||||
}
|
||||
image.ReadOnly = !r.IsReadWrite()
|
||||
}
|
||||
}
|
||||
if shouldSave && (!r.IsReadWrite() || !r.Locked()) {
|
||||
@@ -739,6 +744,10 @@ func (r *imageStore) Lock() {
|
||||
r.lockfile.Lock()
|
||||
}
|
||||
|
||||
func (r *imageStore) RecursiveLock() {
|
||||
r.lockfile.RecursiveLock()
|
||||
}
|
||||
|
||||
func (r *imageStore) RLock() {
|
||||
r.lockfile.RLock()
|
||||
}
|
||||
|
||||
14
vendor/github.com/containers/storage/layers.go
generated
vendored
14
vendor/github.com/containers/storage/layers.go
generated
vendored
@@ -103,6 +103,9 @@ type Layer struct {
|
||||
// for use inside of a user namespace where UID mapping is being used.
|
||||
UIDMap []idtools.IDMap `json:"uidmap,omitempty"`
|
||||
GIDMap []idtools.IDMap `json:"gidmap,omitempty"`
|
||||
|
||||
// ReadOnly is true if this layer resides in a read-only layer store.
|
||||
ReadOnly bool `json:"-"`
|
||||
}
|
||||
|
||||
type layerMountPoint struct {
|
||||
@@ -259,6 +262,7 @@ func copyLayer(l *Layer) *Layer {
|
||||
UncompressedDigest: l.UncompressedDigest,
|
||||
UncompressedSize: l.UncompressedSize,
|
||||
CompressionType: l.CompressionType,
|
||||
ReadOnly: l.ReadOnly,
|
||||
Flags: copyStringInterfaceMap(l.Flags),
|
||||
UIDMap: copyIDMap(l.UIDMap),
|
||||
GIDMap: copyIDMap(l.GIDMap),
|
||||
@@ -318,6 +322,7 @@ func (r *layerStore) Load() error {
|
||||
if layer.MountLabel != "" {
|
||||
label.ReserveLabel(layer.MountLabel)
|
||||
}
|
||||
layer.ReadOnly = !r.IsReadWrite()
|
||||
}
|
||||
err = nil
|
||||
}
|
||||
@@ -402,12 +407,10 @@ func (r *layerStore) Save() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Touch()
|
||||
if err := ioutils.AtomicWriteFile(rpath, jldata, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
if !r.IsReadWrite() {
|
||||
return nil
|
||||
}
|
||||
r.mountsLockfile.Lock()
|
||||
defer r.mountsLockfile.Unlock()
|
||||
defer r.mountsLockfile.Touch()
|
||||
@@ -614,6 +617,7 @@ func (r *layerStore) Put(id string, parentLayer *Layer, names []string, mountLab
|
||||
opts := drivers.CreateOpts{
|
||||
MountLabel: mountLabel,
|
||||
StorageOpt: options,
|
||||
IDMappings: idMappings,
|
||||
}
|
||||
if moreOptions.TemplateLayer != "" {
|
||||
if err = r.driver.CreateFromTemplate(id, moreOptions.TemplateLayer, templateIDMappings, parent, parentMappings, &opts, writeable); err != nil {
|
||||
@@ -1305,6 +1309,10 @@ func (r *layerStore) Lock() {
|
||||
r.lockfile.Lock()
|
||||
}
|
||||
|
||||
func (r *layerStore) RecursiveLock() {
|
||||
r.lockfile.RecursiveLock()
|
||||
}
|
||||
|
||||
func (r *layerStore) RLock() {
|
||||
r.lockfile.RLock()
|
||||
}
|
||||
|
||||
4
vendor/github.com/containers/storage/lockfile.go
generated
vendored
4
vendor/github.com/containers/storage/lockfile.go
generated
vendored
@@ -15,6 +15,10 @@ type Locker interface {
|
||||
// Acquire a writer lock.
|
||||
Lock()
|
||||
|
||||
// Acquire a writer lock recursively, allowing for recursive acquisitions
|
||||
// within the same process space.
|
||||
RecursiveLock()
|
||||
|
||||
// Unlock the lock.
|
||||
Unlock()
|
||||
|
||||
|
||||
20
vendor/github.com/containers/storage/lockfile_linux.go
generated
vendored
20
vendor/github.com/containers/storage/lockfile_linux.go
generated
vendored
@@ -1,20 +0,0 @@
|
||||
// +build linux solaris
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// TouchedSince indicates if the lock file has been touched since the specified time
|
||||
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||
st := unix.Stat_t{}
|
||||
err := unix.Fstat(int(l.fd), &st)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
touched := time.Unix(st.Mtim.Unix())
|
||||
return when.Before(touched)
|
||||
}
|
||||
19
vendor/github.com/containers/storage/lockfile_otherunix.go
generated
vendored
19
vendor/github.com/containers/storage/lockfile_otherunix.go
generated
vendored
@@ -1,19 +0,0 @@
|
||||
// +build darwin freebsd
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||
st := unix.Stat_t{}
|
||||
err := unix.Fstat(int(l.fd), &st)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
touched := time.Unix(st.Mtimespec.Unix())
|
||||
return when.Before(touched)
|
||||
}
|
||||
41
vendor/github.com/containers/storage/lockfile_unix.go
generated
vendored
41
vendor/github.com/containers/storage/lockfile_unix.go
generated
vendored
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
"github.com/containers/storage/pkg/system"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -25,6 +26,7 @@ type lockfile struct {
|
||||
locktype int16
|
||||
locked bool
|
||||
ro bool
|
||||
recursive bool
|
||||
}
|
||||
|
||||
// openLock opens the file at path and returns the corresponding file
|
||||
@@ -75,7 +77,7 @@ func createLockerForPath(path string, ro bool) (Locker, error) {
|
||||
|
||||
// lock locks the lockfile via FCTNL(2) based on the specified type and
|
||||
// command.
|
||||
func (l *lockfile) lock(l_type int16) {
|
||||
func (l *lockfile) lock(l_type int16, recursive bool) {
|
||||
lk := unix.Flock_t{
|
||||
Type: l_type,
|
||||
Whence: int16(os.SEEK_SET),
|
||||
@@ -86,7 +88,13 @@ func (l *lockfile) lock(l_type int16) {
|
||||
case unix.F_RDLCK:
|
||||
l.rwMutex.RLock()
|
||||
case unix.F_WRLCK:
|
||||
l.rwMutex.Lock()
|
||||
if recursive {
|
||||
// NOTE: that's okay as recursive is only set in RecursiveLock(), so
|
||||
// there's no need to protect against hypothetical RDLCK cases.
|
||||
l.rwMutex.RLock()
|
||||
} else {
|
||||
l.rwMutex.Lock()
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("attempted to acquire a file lock of unrecognized type %d", l_type))
|
||||
}
|
||||
@@ -110,6 +118,7 @@ func (l *lockfile) lock(l_type int16) {
|
||||
}
|
||||
l.locktype = l_type
|
||||
l.locked = true
|
||||
l.recursive = recursive
|
||||
l.counter++
|
||||
}
|
||||
|
||||
@@ -119,13 +128,24 @@ func (l *lockfile) Lock() {
|
||||
if l.ro {
|
||||
l.RLock()
|
||||
} else {
|
||||
l.lock(unix.F_WRLCK)
|
||||
l.lock(unix.F_WRLCK, false)
|
||||
}
|
||||
}
|
||||
|
||||
// RecursiveLock locks the lockfile as a writer but allows for recursive
|
||||
// acquisitions within the same process space. Note that RLock() will be called
|
||||
// if it's a lockTypReader lock.
|
||||
func (l *lockfile) RecursiveLock() {
|
||||
if l.ro {
|
||||
l.RLock()
|
||||
} else {
|
||||
l.lock(unix.F_WRLCK, true)
|
||||
}
|
||||
}
|
||||
|
||||
// LockRead locks the lockfile as a reader.
|
||||
func (l *lockfile) RLock() {
|
||||
l.lock(unix.F_RDLCK)
|
||||
l.lock(unix.F_RDLCK, false)
|
||||
}
|
||||
|
||||
// Unlock unlocks the lockfile.
|
||||
@@ -161,7 +181,7 @@ func (l *lockfile) Unlock() {
|
||||
// Close the file descriptor on the last unlock.
|
||||
unix.Close(int(l.fd))
|
||||
}
|
||||
if l.locktype == unix.F_RDLCK {
|
||||
if l.locktype == unix.F_RDLCK || l.recursive {
|
||||
l.rwMutex.RUnlock()
|
||||
} else {
|
||||
l.rwMutex.Unlock()
|
||||
@@ -232,3 +252,14 @@ func (l *lockfile) Modified() (bool, error) {
|
||||
func (l *lockfile) IsReadWrite() bool {
|
||||
return !l.ro
|
||||
}
|
||||
|
||||
// TouchedSince indicates if the lock file has been touched since the specified time
|
||||
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||
st, err := system.Fstat(int(l.fd))
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
mtim := st.Mtim()
|
||||
touched := time.Unix(mtim.Unix())
|
||||
return when.Before(touched)
|
||||
}
|
||||
|
||||
6
vendor/github.com/containers/storage/lockfile_windows.go
generated
vendored
6
vendor/github.com/containers/storage/lockfile_windows.go
generated
vendored
@@ -36,6 +36,12 @@ func (l *lockfile) Lock() {
|
||||
l.locked = true
|
||||
}
|
||||
|
||||
func (l *lockfile) RecursiveLock() {
|
||||
// We don't support Windows but a recursive writer-lock in one process-space
|
||||
// is really a writer lock, so just panic.
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (l *lockfile) RLock() {
|
||||
l.mu.Lock()
|
||||
l.locked = true
|
||||
|
||||
36
vendor/github.com/containers/storage/pkg/chrootarchive/archive.go
generated
vendored
36
vendor/github.com/containers/storage/pkg/chrootarchive/archive.go
generated
vendored
@@ -1,7 +1,7 @@
|
||||
package chrootarchive
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
stdtar "archive/tar"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -34,18 +34,34 @@ func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.
|
||||
// The archive may be compressed with one of the following algorithms:
|
||||
// identity (uncompressed), gzip, bzip2, xz.
|
||||
func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error {
|
||||
return untarHandler(tarArchive, dest, options, true)
|
||||
return untarHandler(tarArchive, dest, options, true, dest)
|
||||
}
|
||||
|
||||
// UntarWithRoot is the same as `Untar`, but allows you to pass in a root directory
|
||||
// The root directory is the directory that will be chrooted to.
|
||||
// `dest` must be a path within `root`, if it is not an error will be returned.
|
||||
//
|
||||
// `root` should set to a directory which is not controlled by any potentially
|
||||
// malicious process.
|
||||
//
|
||||
// This should be used to prevent a potential attacker from manipulating `dest`
|
||||
// such that it would provide access to files outside of `dest` through things
|
||||
// like symlinks. Normally `ResolveSymlinksInScope` would handle this, however
|
||||
// sanitizing symlinks in this manner is inherrently racey:
|
||||
// ref: CVE-2018-15664
|
||||
func UntarWithRoot(tarArchive io.Reader, dest string, options *archive.TarOptions, root string) error {
|
||||
return untarHandler(tarArchive, dest, options, true, root)
|
||||
}
|
||||
|
||||
// UntarUncompressed reads a stream of bytes from `archive`, parses it as a tar archive,
|
||||
// and unpacks it into the directory at `dest`.
|
||||
// The archive must be an uncompressed stream.
|
||||
func UntarUncompressed(tarArchive io.Reader, dest string, options *archive.TarOptions) error {
|
||||
return untarHandler(tarArchive, dest, options, false)
|
||||
return untarHandler(tarArchive, dest, options, false, dest)
|
||||
}
|
||||
|
||||
// Handler for teasing out the automatic decompression
|
||||
func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool) error {
|
||||
func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool, root string) error {
|
||||
if tarArchive == nil {
|
||||
return fmt.Errorf("Empty archive")
|
||||
}
|
||||
@@ -77,7 +93,15 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
|
||||
r = decompressedArchive
|
||||
}
|
||||
|
||||
return invokeUnpack(r, dest, options)
|
||||
return invokeUnpack(r, dest, options, root)
|
||||
}
|
||||
|
||||
// Tar tars the requested path while chrooted to the specified root.
|
||||
func Tar(srcPath string, options *archive.TarOptions, root string) (io.ReadCloser, error) {
|
||||
if options == nil {
|
||||
options = &archive.TarOptions{}
|
||||
}
|
||||
return invokePack(srcPath, options, root)
|
||||
}
|
||||
|
||||
// CopyFileWithTarAndChown returns a function which copies a single file from outside
|
||||
@@ -99,7 +123,7 @@ func CopyFileWithTarAndChown(chownOpts *idtools.IDPair, hasher io.Writer, uidmap
|
||||
var hashWorker sync.WaitGroup
|
||||
hashWorker.Add(1)
|
||||
go func() {
|
||||
t := tar.NewReader(contentReader)
|
||||
t := stdtar.NewReader(contentReader)
|
||||
_, err := t.Next()
|
||||
if err != nil {
|
||||
hashError = err
|
||||
|
||||
130
vendor/github.com/containers/storage/pkg/chrootarchive/archive_unix.go
generated
vendored
130
vendor/github.com/containers/storage/pkg/chrootarchive/archive_unix.go
generated
vendored
@@ -10,10 +10,13 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/containers/storage/pkg/reexec"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// untar is the entry-point for storage-untar on re-exec. This is not used on
|
||||
@@ -23,18 +26,28 @@ func untar() {
|
||||
runtime.LockOSThread()
|
||||
flag.Parse()
|
||||
|
||||
var options *archive.TarOptions
|
||||
var options archive.TarOptions
|
||||
|
||||
//read the options from the pipe "ExtraFiles"
|
||||
if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
if err := chroot(flag.Arg(0)); err != nil {
|
||||
dst := flag.Arg(0)
|
||||
var root string
|
||||
if len(flag.Args()) > 1 {
|
||||
root = flag.Arg(1)
|
||||
}
|
||||
|
||||
if root == "" {
|
||||
root = dst
|
||||
}
|
||||
|
||||
if err := chroot(root); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
if err := archive.Unpack(os.Stdin, "/", options); err != nil {
|
||||
if err := archive.Unpack(os.Stdin, dst, &options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
// fully consume stdin in case it is zero padded
|
||||
@@ -45,7 +58,10 @@ func untar() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.TarOptions) error {
|
||||
func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.TarOptions, root string) error {
|
||||
if root == "" {
|
||||
return errors.New("must specify a root to chroot to")
|
||||
}
|
||||
|
||||
// We can't pass a potentially large exclude list directly via cmd line
|
||||
// because we easily overrun the kernel's max argument/environment size
|
||||
@@ -57,7 +73,21 @@ func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.T
|
||||
return fmt.Errorf("Untar pipe failure: %v", err)
|
||||
}
|
||||
|
||||
cmd := reexec.Command("storage-untar", dest)
|
||||
if root != "" {
|
||||
relDest, err := filepath.Rel(root, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if relDest == "." {
|
||||
relDest = "/"
|
||||
}
|
||||
if relDest[0] != '/' {
|
||||
relDest = "/" + relDest
|
||||
}
|
||||
dest = relDest
|
||||
}
|
||||
|
||||
cmd := reexec.Command("storage-untar", dest, root)
|
||||
cmd.Stdin = decompressedArchive
|
||||
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, r)
|
||||
@@ -68,6 +98,7 @@ func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.T
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Errorf("Untar error on re-exec cmd: %v", err)
|
||||
}
|
||||
|
||||
//write the options to the pipe for the untar exec to read
|
||||
if err := json.NewEncoder(w).Encode(options); err != nil {
|
||||
return fmt.Errorf("Untar json encode to pipe failed: %v", err)
|
||||
@@ -84,3 +115,92 @@ func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.T
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tar() {
|
||||
runtime.LockOSThread()
|
||||
flag.Parse()
|
||||
|
||||
src := flag.Arg(0)
|
||||
var root string
|
||||
if len(flag.Args()) > 1 {
|
||||
root = flag.Arg(1)
|
||||
}
|
||||
|
||||
if root == "" {
|
||||
root = src
|
||||
}
|
||||
|
||||
if err := realChroot(root); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
var options archive.TarOptions
|
||||
if err := json.NewDecoder(os.Stdin).Decode(&options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
rdr, err := archive.TarWithOptions(src, &options)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
defer rdr.Close()
|
||||
|
||||
if _, err := io.Copy(os.Stdout, rdr); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func invokePack(srcPath string, options *archive.TarOptions, root string) (io.ReadCloser, error) {
|
||||
if root == "" {
|
||||
return nil, errors.New("root path must not be empty")
|
||||
}
|
||||
|
||||
relSrc, err := filepath.Rel(root, srcPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if relSrc == "." {
|
||||
relSrc = "/"
|
||||
}
|
||||
if relSrc[0] != '/' {
|
||||
relSrc = "/" + relSrc
|
||||
}
|
||||
|
||||
// make sure we didn't trim a trailing slash with the call to `Rel`
|
||||
if strings.HasSuffix(srcPath, "/") && !strings.HasSuffix(relSrc, "/") {
|
||||
relSrc += "/"
|
||||
}
|
||||
|
||||
cmd := reexec.Command("storage-tar", relSrc, root)
|
||||
|
||||
errBuff := bytes.NewBuffer(nil)
|
||||
cmd.Stderr = errBuff
|
||||
|
||||
tarR, tarW := io.Pipe()
|
||||
cmd.Stdout = tarW
|
||||
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error getting options pipe for tar process")
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, errors.Wrap(err, "tar error on re-exec cmd")
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := cmd.Wait()
|
||||
err = errors.Wrapf(err, "error processing tar file: %s", errBuff)
|
||||
tarW.CloseWithError(err)
|
||||
}()
|
||||
|
||||
if err := json.NewEncoder(stdin).Encode(options); err != nil {
|
||||
stdin.Close()
|
||||
return nil, errors.Wrap(err, "tar json encode to pipe failed")
|
||||
}
|
||||
stdin.Close()
|
||||
|
||||
return tarR, nil
|
||||
}
|
||||
|
||||
9
vendor/github.com/containers/storage/pkg/chrootarchive/archive_windows.go
generated
vendored
9
vendor/github.com/containers/storage/pkg/chrootarchive/archive_windows.go
generated
vendored
@@ -14,9 +14,16 @@ func chroot(path string) error {
|
||||
|
||||
func invokeUnpack(decompressedArchive io.ReadCloser,
|
||||
dest string,
|
||||
options *archive.TarOptions) error {
|
||||
options *archive.TarOptions, root string) error {
|
||||
// Windows is different to Linux here because Windows does not support
|
||||
// chroot. Hence there is no point sandboxing a chrooted process to
|
||||
// do the unpack. We call inline instead within the daemon process.
|
||||
return archive.Unpack(decompressedArchive, longpath.AddPrefix(dest), options)
|
||||
}
|
||||
|
||||
func invokePack(srcPath string, options *archive.TarOptions, root string) (io.ReadCloser, error) {
|
||||
// Windows is different to Linux here because Windows does not support
|
||||
// chroot. Hence there is no point sandboxing a chrooted process to
|
||||
// do the pack. We call inline instead within the daemon process.
|
||||
return archive.TarWithOptions(srcPath, options)
|
||||
}
|
||||
|
||||
6
vendor/github.com/containers/storage/pkg/chrootarchive/chroot_unix.go
generated
vendored
6
vendor/github.com/containers/storage/pkg/chrootarchive/chroot_unix.go
generated
vendored
@@ -4,9 +4,13 @@ package chrootarchive
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func chroot(path string) error {
|
||||
func realChroot(path string) error {
|
||||
if err := unix.Chroot(path); err != nil {
|
||||
return err
|
||||
}
|
||||
return unix.Chdir("/")
|
||||
}
|
||||
|
||||
func chroot(path string) error {
|
||||
return realChroot(path)
|
||||
}
|
||||
|
||||
1
vendor/github.com/containers/storage/pkg/chrootarchive/init_unix.go
generated
vendored
1
vendor/github.com/containers/storage/pkg/chrootarchive/init_unix.go
generated
vendored
@@ -14,6 +14,7 @@ import (
|
||||
func init() {
|
||||
reexec.Register("storage-applyLayer", applyLayer)
|
||||
reexec.Register("storage-untar", untar)
|
||||
reexec.Register("storage-tar", tar)
|
||||
}
|
||||
|
||||
func fatal(err error) {
|
||||
|
||||
12
vendor/github.com/containers/storage/pkg/system/stat_unix.go
generated
vendored
12
vendor/github.com/containers/storage/pkg/system/stat_unix.go
generated
vendored
@@ -58,3 +58,15 @@ func Stat(path string) (*StatT, error) {
|
||||
}
|
||||
return fromStatT(s)
|
||||
}
|
||||
|
||||
// Fstat takes an open file descriptor and returns
|
||||
// a system.StatT type pertaining to that file.
|
||||
//
|
||||
// Throws an error if the file descriptor is invalid
|
||||
func Fstat(fd int) (*StatT, error) {
|
||||
s := &syscall.Stat_t{}
|
||||
if err := syscall.Fstat(fd, s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fromStatT(s)
|
||||
}
|
||||
|
||||
34
vendor/github.com/containers/storage/store.go
generated
vendored
34
vendor/github.com/containers/storage/store.go
generated
vendored
@@ -1197,18 +1197,20 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
|
||||
}
|
||||
imageID = cimage.ID
|
||||
|
||||
createMappedLayer := imageHomeStore == istore
|
||||
if cimage.TopLayer != "" {
|
||||
createMappedLayer := imageHomeStore == istore
|
||||
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, createMappedLayer, rlstore, lstores, idMappingsOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imageTopLayer = ilayer
|
||||
|
||||
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, createMappedLayer, rlstore, lstores, idMappingsOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imageTopLayer = ilayer
|
||||
if !options.HostUIDMapping && len(options.UIDMap) == 0 {
|
||||
uidMap = ilayer.UIDMap
|
||||
}
|
||||
if !options.HostGIDMapping && len(options.GIDMap) == 0 {
|
||||
gidMap = ilayer.GIDMap
|
||||
if !options.HostUIDMapping && len(options.UIDMap) == 0 {
|
||||
uidMap = ilayer.UIDMap
|
||||
}
|
||||
if !options.HostGIDMapping && len(options.GIDMap) == 0 {
|
||||
gidMap = ilayer.GIDMap
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rlstore.Lock()
|
||||
@@ -3396,12 +3398,18 @@ func init() {
|
||||
ReloadConfigurationFile(defaultConfigFile, &defaultStoreOptions)
|
||||
}
|
||||
|
||||
// GetDefaultMountOptions returns the default mountoptions defined in container/storage
|
||||
func GetDefaultMountOptions() ([]string, error) {
|
||||
return GetMountOptions(defaultStoreOptions.GraphDriverName, defaultStoreOptions.GraphDriverOptions)
|
||||
}
|
||||
|
||||
// GetMountOptions returns the mountoptions for the specified driver and graphDriverOptions
|
||||
func GetMountOptions(driver string, graphDriverOptions []string) ([]string, error) {
|
||||
mountOpts := []string{
|
||||
".mountopt",
|
||||
fmt.Sprintf("%s.mountopt", defaultStoreOptions.GraphDriverName),
|
||||
fmt.Sprintf("%s.mountopt", driver),
|
||||
}
|
||||
for _, option := range defaultStoreOptions.GraphDriverOptions {
|
||||
for _, option := range graphDriverOptions {
|
||||
key, val, err := parsers.ParseKeyValueOpt(option)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
16
vendor/github.com/containers/storage/utils.go
generated
vendored
16
vendor/github.com/containers/storage/utils.go
generated
vendored
@@ -71,14 +71,16 @@ func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap stri
|
||||
// GetRootlessRuntimeDir returns the runtime directory when running as non root
|
||||
func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
|
||||
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if runtimeDir == "" {
|
||||
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid)
|
||||
st, err := system.Stat(tmpDir)
|
||||
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
|
||||
return tmpDir, nil
|
||||
}
|
||||
|
||||
if runtimeDir != "" {
|
||||
return runtimeDir, nil
|
||||
}
|
||||
tmpDir := fmt.Sprintf("%s/%d", os.TempDir(), rootlessUid)
|
||||
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid)
|
||||
st, err := system.Stat(tmpDir)
|
||||
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
|
||||
return tmpDir, nil
|
||||
}
|
||||
tmpDir = fmt.Sprintf("%s/%d", os.TempDir(), rootlessUid)
|
||||
if err := os.MkdirAll(tmpDir, 0700); err != nil {
|
||||
logrus.Errorf("failed to create %s: %v", tmpDir, err)
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package version
|
||||
|
||||
// Version is the version of the build.
|
||||
const Version = "0.1.36"
|
||||
const Version = "0.1.37"
|
||||
|
||||
Reference in New Issue
Block a user