mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 21:51:33 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d344625847 | ||
|
|
496c2748cf | ||
|
|
ee8504bc5a | ||
|
|
994e4a1c69 | ||
|
|
0de96a8163 | ||
|
|
c8fc8768b6 | ||
|
|
f2008c5359 | ||
|
|
acf1720b3f | ||
|
|
0e9a7bc3ce | ||
|
|
313a1b7620 | ||
|
|
62d83404b5 | ||
|
|
aef842e7df | ||
|
|
e629e255d8 | ||
|
|
134f8e6b47 | ||
|
|
1cd89729d5 | ||
|
|
566146bc13 | ||
|
|
1ebafeb635 | ||
|
|
18193ae0a3 | ||
|
|
cd745d5c6e | ||
|
|
6f514d28c0 | ||
|
|
39fa2faad2 | ||
|
|
324953d74a | ||
|
|
b256616589 | ||
|
|
409f65bfd1 | ||
|
|
87f59e3802 | ||
|
|
c650d17a26 | ||
|
|
5e2d02ab73 | ||
|
|
eb3738347a | ||
|
|
6152460c1e | ||
|
|
1527979e87 | ||
|
|
04175d0763 | ||
|
|
a111eea20c | ||
|
|
ea361c0476 | ||
|
|
967f80f3cc | ||
|
|
8d90b0faf8 | ||
|
|
3ac6394b80 | ||
|
|
0357b26c1b | ||
|
|
1d4a82365b | ||
|
|
3ab5251f56 | ||
|
|
d51a02091c | ||
|
|
0573b17b24 | ||
|
|
c9379eb3fb | ||
|
|
662ca4114d | ||
|
|
1d1b813d25 | ||
|
|
fd9c2ae27d | ||
|
|
09c38a8d43 | ||
|
|
86292adbd9 | ||
|
|
c78b920e01 |
@@ -1,5 +1,35 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.3.3 (2014-12-11)
|
||||||
|
|
||||||
|
#### Security
|
||||||
|
- Fix path traversal vulnerability in processing of absolute symbolic links (CVE-2014-9356)
|
||||||
|
- Fix decompression of xz image archives, preventing privilege escalation (CVE-2014-9357)
|
||||||
|
- Validate image IDs (CVE-2014-9358)
|
||||||
|
|
||||||
|
#### Runtime
|
||||||
|
- Fix an issue when image archives are being read slowly
|
||||||
|
|
||||||
|
#### Client
|
||||||
|
- Fix a regression related to stdin redirection
|
||||||
|
- Fix a regression with `docker cp` when destination is the current directory
|
||||||
|
|
||||||
|
## 1.3.2 (2014-11-20)
|
||||||
|
|
||||||
|
#### Security
|
||||||
|
- Fix tar breakout vulnerability
|
||||||
|
* Extractions are now sandboxed chroot
|
||||||
|
- Security options are no longer committed to images
|
||||||
|
|
||||||
|
#### Runtime
|
||||||
|
- Fix deadlock in `docker ps -f exited=1`
|
||||||
|
- Fix a bug when `--volumes-from` references a container that failed to start
|
||||||
|
|
||||||
|
#### Registry
|
||||||
|
+ `--insecure-registry` now accepts CIDR notation such as 10.1.0.0/16
|
||||||
|
* Private registries whose IPs fall in the 127.0.0.0/8 range do no need the `--insecure-registry` flag
|
||||||
|
- Skip the experimental registry v2 API when mirroring is enabled
|
||||||
|
|
||||||
## 1.3.1 (2014-10-28)
|
## 1.3.1 (2014-10-28)
|
||||||
|
|
||||||
#### Security
|
#### Security
|
||||||
|
|||||||
+2
-2
@@ -75,10 +75,10 @@ ENV GOARM 5
|
|||||||
RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'
|
RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'
|
||||||
|
|
||||||
# Grab Go's cover tool for dead-simple code coverage testing
|
# Grab Go's cover tool for dead-simple code coverage testing
|
||||||
RUN go get code.google.com/p/go.tools/cmd/cover
|
RUN go get golang.org/x/tools/cmd/cover
|
||||||
|
|
||||||
# TODO replace FPM with some very minimal debhelper stuff
|
# TODO replace FPM with some very minimal debhelper stuff
|
||||||
RUN gem install --no-rdoc --no-ri fpm --version 1.0.2
|
RUN gem install --no-rdoc --no-ri fpm --version 1.3.2
|
||||||
|
|
||||||
# Install man page generator
|
# Install man page generator
|
||||||
RUN mkdir -p /go/src/github.com/cpuguy83 \
|
RUN mkdir -p /go/src/github.com/cpuguy83 \
|
||||||
|
|||||||
+98
-7
@@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
@@ -19,9 +21,99 @@ import (
|
|||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type tlsClientCon struct {
|
||||||
|
*tls.Conn
|
||||||
|
rawConn net.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tlsClientCon) CloseWrite() error {
|
||||||
|
// Go standard tls.Conn doesn't provide the CloseWrite() method so we do it
|
||||||
|
// on its underlying connection.
|
||||||
|
if cwc, ok := c.rawConn.(interface {
|
||||||
|
CloseWrite() error
|
||||||
|
}); ok {
|
||||||
|
return cwc.CloseWrite()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func tlsDial(network, addr string, config *tls.Config) (net.Conn, error) {
|
||||||
|
return tlsDialWithDialer(new(net.Dialer), network, addr, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to copy Go's implementation of tls.Dial (pkg/cryptor/tls/tls.go) in
|
||||||
|
// order to return our custom tlsClientCon struct which holds both the tls.Conn
|
||||||
|
// object _and_ its underlying raw connection. The rationale for this is that
|
||||||
|
// we need to be able to close the write end of the connection when attaching,
|
||||||
|
// which tls.Conn does not provide.
|
||||||
|
func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Config) (net.Conn, error) {
|
||||||
|
// We want the Timeout and Deadline values from dialer to cover the
|
||||||
|
// whole process: TCP connection and TLS handshake. This means that we
|
||||||
|
// also need to start our own timers now.
|
||||||
|
timeout := dialer.Timeout
|
||||||
|
|
||||||
|
if !dialer.Deadline.IsZero() {
|
||||||
|
deadlineTimeout := dialer.Deadline.Sub(time.Now())
|
||||||
|
if timeout == 0 || deadlineTimeout < timeout {
|
||||||
|
timeout = deadlineTimeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errChannel chan error
|
||||||
|
|
||||||
|
if timeout != 0 {
|
||||||
|
errChannel = make(chan error, 2)
|
||||||
|
time.AfterFunc(timeout, func() {
|
||||||
|
errChannel <- errors.New("")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
rawConn, err := dialer.Dial(network, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
colonPos := strings.LastIndex(addr, ":")
|
||||||
|
if colonPos == -1 {
|
||||||
|
colonPos = len(addr)
|
||||||
|
}
|
||||||
|
hostname := addr[:colonPos]
|
||||||
|
|
||||||
|
// If no ServerName is set, infer the ServerName
|
||||||
|
// from the hostname we're connecting to.
|
||||||
|
if config.ServerName == "" {
|
||||||
|
// Make a copy to avoid polluting argument or default.
|
||||||
|
c := *config
|
||||||
|
c.ServerName = hostname
|
||||||
|
config = &c
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := tls.Client(rawConn, config)
|
||||||
|
|
||||||
|
if timeout == 0 {
|
||||||
|
err = conn.Handshake()
|
||||||
|
} else {
|
||||||
|
go func() {
|
||||||
|
errChannel <- conn.Handshake()
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = <-errChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
rawConn.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is Docker difference with standard's crypto/tls package: returned a
|
||||||
|
// wrapper which holds both the TLS and raw connections.
|
||||||
|
return &tlsClientCon{conn, rawConn}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) dial() (net.Conn, error) {
|
func (cli *DockerCli) dial() (net.Conn, error) {
|
||||||
if cli.tlsConfig != nil && cli.proto != "unix" {
|
if cli.tlsConfig != nil && cli.proto != "unix" {
|
||||||
return tls.Dial(cli.proto, cli.addr, cli.tlsConfig)
|
// Notice this isn't Go standard's tls.Dial function
|
||||||
|
return tlsDial(cli.proto, cli.addr, cli.tlsConfig)
|
||||||
}
|
}
|
||||||
return net.Dial(cli.proto, cli.addr)
|
return net.Dial(cli.proto, cli.addr)
|
||||||
}
|
}
|
||||||
@@ -109,12 +201,11 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
|
|||||||
io.Copy(rwc, in)
|
io.Copy(rwc, in)
|
||||||
log.Debugf("[hijack] End of stdin")
|
log.Debugf("[hijack] End of stdin")
|
||||||
}
|
}
|
||||||
if tcpc, ok := rwc.(*net.TCPConn); ok {
|
|
||||||
if err := tcpc.CloseWrite(); err != nil {
|
if conn, ok := rwc.(interface {
|
||||||
log.Debugf("Couldn't send EOF: %s", err)
|
CloseWrite() error
|
||||||
}
|
}); ok {
|
||||||
} else if unixc, ok := rwc.(*net.UnixConn); ok {
|
if err := conn.CloseWrite(); err != nil {
|
||||||
if err := unixc.CloseWrite(); err != nil {
|
|
||||||
log.Debugf("Couldn't send EOF: %s", err)
|
log.Debugf("Couldn't send EOF: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
imagepkg "github.com/docker/docker/image"
|
imagepkg "github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/pkg/promise"
|
"github.com/docker/docker/pkg/promise"
|
||||||
@@ -46,7 +47,8 @@ func (b *Builder) readContext(context io.Reader) error {
|
|||||||
if b.context, err = tarsum.NewTarSum(decompressedStream, true, tarsum.Version0); err != nil {
|
if b.context, err = tarsum.NewTarSum(decompressedStream, true, tarsum.Version0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := archive.Untar(b.context, tmpdirPath, nil); err != nil {
|
|
||||||
|
if err := chrootarchive.Untar(b.context, tmpdirPath, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,7 +622,7 @@ func (b *Builder) addContext(container *daemon.Container, orig, dest string, dec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to successfully untar the orig
|
// try to successfully untar the orig
|
||||||
if err := archive.UntarPath(origPath, tarDest); err == nil {
|
if err := chrootarchive.UntarPath(origPath, tarDest); err == nil {
|
||||||
return nil
|
return nil
|
||||||
} else if err != io.EOF {
|
} else if err != io.EOF {
|
||||||
log.Debugf("Couldn't untar %s to %s: %s", origPath, tarDest, err)
|
log.Debugf("Couldn't untar %s to %s: %s", origPath, tarDest, err)
|
||||||
@@ -630,7 +632,7 @@ func (b *Builder) addContext(container *daemon.Container, orig, dest string, dec
|
|||||||
if err := os.MkdirAll(path.Dir(destPath), 0755); err != nil {
|
if err := os.MkdirAll(path.Dir(destPath), 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := archive.CopyWithTar(origPath, destPath); err != nil {
|
if err := chrootarchive.CopyWithTar(origPath, destPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,7 +645,7 @@ func (b *Builder) addContext(container *daemon.Container, orig, dest string, dec
|
|||||||
}
|
}
|
||||||
|
|
||||||
func copyAsDirectory(source, destination string, destinationExists bool) error {
|
func copyAsDirectory(source, destination string, destinationExists bool) error {
|
||||||
if err := archive.CopyWithTar(source, destination); err != nil {
|
if err := chrootarchive.CopyWithTar(source, destination); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ ENV GOARM 5
|
|||||||
RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'
|
RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'
|
||||||
|
|
||||||
# Grab Go's cover tool for dead-simple code coverage testing
|
# Grab Go's cover tool for dead-simple code coverage testing
|
||||||
RUN go get code.google.com/p/go.tools/cmd/cover
|
RUN go get golang.org/x/tools/cmd/cover
|
||||||
|
|
||||||
# TODO replace FPM with some very minimal debhelper stuff
|
# TODO replace FPM with some very minimal debhelper stuff
|
||||||
RUN gem install --no-rdoc --no-ri fpm --version 1.0.2
|
RUN gem install --no-rdoc --no-ri fpm --version 1.0.2
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
(env "DOCKER_CROSSPLATFORMS" "linux/386 linux/arm darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 freebsd/arm")
|
(env "DOCKER_CROSSPLATFORMS" "linux/386 linux/arm darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 freebsd/arm")
|
||||||
(env "GOARM" "5")
|
(env "GOARM" "5")
|
||||||
(run "cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'")
|
(run "cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'")
|
||||||
(run "go get code.google.com/p/go.tools/cmd/cover")
|
(run "go get golang.org/x/tools/cmd/cover")
|
||||||
(run "gem install --no-rdoc --no-ri fpm --version 1.0.2")
|
(run "gem install --no-rdoc --no-ri fpm --version 1.0.2")
|
||||||
(run "git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox")
|
(run "git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox")
|
||||||
(run "/bin/echo -e '[default]\\naccess_key=$AWS_ACCESS_KEY\\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg")
|
(run "/bin/echo -e '[default]\\naccess_key=$AWS_ACCESS_KEY\\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg")
|
||||||
|
|||||||
+9
-1
@@ -56,7 +56,7 @@ func (config *Config) InstallFlags() {
|
|||||||
flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
|
flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
|
||||||
flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
|
flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
|
||||||
flag.StringVar(&config.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)\nthis subnet must be nested in the bridge subnet (which is defined by -b or --bip)")
|
flag.StringVar(&config.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)\nthis subnet must be nested in the bridge subnet (which is defined by -b or --bip)")
|
||||||
opts.ListVar(&config.InsecureRegistries, []string{"-insecure-registry"}, "Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback)")
|
opts.ListVar(&config.InsecureRegistries, []string{"-insecure-registry"}, "Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)")
|
||||||
flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
||||||
flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
|
flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
|
||||||
flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
|
flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
|
||||||
@@ -68,6 +68,14 @@ func (config *Config) InstallFlags() {
|
|||||||
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
|
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
|
||||||
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
|
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
|
||||||
opts.MirrorListVar(&config.Mirrors, []string{"-registry-mirror"}, "Specify a preferred Docker registry mirror")
|
opts.MirrorListVar(&config.Mirrors, []string{"-registry-mirror"}, "Specify a preferred Docker registry mirror")
|
||||||
|
|
||||||
|
// Localhost is by default considered as an insecure registry
|
||||||
|
// This is a stop-gap for people who are running a private registry on localhost (especially on Boot2docker).
|
||||||
|
//
|
||||||
|
// TODO: should we deprecate this once it is easier for people to set up a TLS registry or change
|
||||||
|
// daemon flags on boot2docker?
|
||||||
|
// If so, do not forget to check the TODO in TestIsSecure
|
||||||
|
config.InsecureRegistries = append(config.InsecureRegistries, "127.0.0.0/8")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultNetworkMtu() int {
|
func GetDefaultNetworkMtu() int {
|
||||||
|
|||||||
+5
-6
@@ -528,10 +528,10 @@ func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint, configCmd []string)
|
|||||||
return entrypoint, args
|
return entrypoint, args
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
|
||||||
var (
|
var (
|
||||||
label_opts []string
|
labelOpts []string
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, opt := range config.SecurityOpt {
|
for _, opt := range config.SecurityOpt {
|
||||||
@@ -541,7 +541,7 @@ func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
|||||||
}
|
}
|
||||||
switch con[0] {
|
switch con[0] {
|
||||||
case "label":
|
case "label":
|
||||||
label_opts = append(label_opts, con[1])
|
labelOpts = append(labelOpts, con[1])
|
||||||
case "apparmor":
|
case "apparmor":
|
||||||
container.AppArmorProfile = con[1]
|
container.AppArmorProfile = con[1]
|
||||||
default:
|
default:
|
||||||
@@ -549,7 +549,7 @@ func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
container.ProcessLabel, container.MountLabel, err = label.InitLabels(label_opts)
|
container.ProcessLabel, container.MountLabel, err = label.InitLabels(labelOpts)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,7 +583,6 @@ func (daemon *Daemon) newContainer(name string, config *runconfig.Config, img *i
|
|||||||
execCommands: newExecStore(),
|
execCommands: newExecStore(),
|
||||||
}
|
}
|
||||||
container.root = daemon.containerRoot(container.ID)
|
container.root = daemon.containerRoot(container.ID)
|
||||||
err = parseSecurityOpt(container, config)
|
|
||||||
return container, err
|
return container, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestParseSecurityOpt(t *testing.T) {
|
func TestParseSecurityOpt(t *testing.T) {
|
||||||
container := &Container{}
|
container := &Container{}
|
||||||
config := &runconfig.Config{}
|
config := &runconfig.HostConfig{}
|
||||||
|
|
||||||
// test apparmor
|
// test apparmor
|
||||||
config.SecurityOpt = []string{"apparmor:test_profile"}
|
config.SecurityOpt = []string{"apparmor:test_profile"}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/libcontainer/netlink"
|
"github.com/docker/libcontainer/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/libcontainer"
|
"github.com/docker/libcontainer"
|
||||||
"github.com/docker/libcontainer/namespaces"
|
"github.com/docker/libcontainer/namespaces"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/libcontainer"
|
"github.com/docker/libcontainer"
|
||||||
"github.com/docker/libcontainer/namespaces"
|
"github.com/docker/libcontainer/namespaces"
|
||||||
"github.com/docker/libcontainer/syncpipe"
|
"github.com/docker/libcontainer/syncpipe"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/docker/daemon/graphdriver"
|
"github.com/docker/docker/daemon/graphdriver"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
mountpk "github.com/docker/docker/pkg/mount"
|
mountpk "github.com/docker/docker/pkg/mount"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
@@ -304,7 +305,7 @@ func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Driver) applyDiff(id string, diff archive.ArchiveReader) error {
|
func (a *Driver) applyDiff(id string, diff archive.ArchiveReader) error {
|
||||||
return archive.Untar(diff, path.Join(a.rootPath(), "diff", id), nil)
|
return chrootarchive.Untar(diff, path.Join(a.rootPath(), "diff", id), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffSize calculates the changes between the specified id
|
// DiffSize calculates the changes between the specified id
|
||||||
|
|||||||
@@ -4,18 +4,24 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/docker/docker/daemon/graphdriver"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/daemon/graphdriver"
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tmp = path.Join(os.TempDir(), "aufs-tests", "aufs")
|
tmp = path.Join(os.TempDir(), "aufs-tests", "aufs")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reexec.Init()
|
||||||
|
}
|
||||||
|
|
||||||
func testInit(dir string, t *testing.T) graphdriver.Driver {
|
func testInit(dir string, t *testing.T) graphdriver.Driver {
|
||||||
d, err := Init(dir, nil)
|
d, err := Init(dir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
@@ -120,7 +121,7 @@ func (gdw *naiveDiffDriver) ApplyDiff(id, parent string, diff archive.ArchiveRea
|
|||||||
|
|
||||||
start := time.Now().UTC()
|
start := time.Now().UTC()
|
||||||
log.Debugf("Start untar layer")
|
log.Debugf("Start untar layer")
|
||||||
if err = archive.ApplyLayer(layerFs, diff); err != nil {
|
if err = chrootarchive.ApplyLayer(layerFs, diff); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("Untar time: %vs", time.Now().UTC().Sub(start).Seconds())
|
log.Debugf("Untar time: %vs", time.Now().UTC().Sub(start).Seconds())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/graphdriver"
|
"github.com/docker/docker/daemon/graphdriver"
|
||||||
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/libcontainer/label"
|
"github.com/docker/libcontainer/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,21 +47,6 @@ func isGNUcoreutils() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyDir(src, dst string) error {
|
|
||||||
argv := make([]string, 0, 4)
|
|
||||||
|
|
||||||
if isGNUcoreutils() {
|
|
||||||
argv = append(argv, "-aT", "--reflink=auto", src, dst)
|
|
||||||
} else {
|
|
||||||
argv = append(argv, "-a", src+"/.", dst+"/.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if output, err := exec.Command("cp", argv...).CombinedOutput(); err != nil {
|
|
||||||
return fmt.Errorf("Error VFS copying directory: %s (%s)", err, output)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Driver) Create(id, parent string) error {
|
func (d *Driver) Create(id, parent string) error {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
|
if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
|
||||||
@@ -80,7 +66,7 @@ func (d *Driver) Create(id, parent string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s: %s", parent, err)
|
return fmt.Errorf("%s: %s", parent, err)
|
||||||
}
|
}
|
||||||
if err := copyDir(parentDir, dir); err != nil {
|
if err := chrootarchive.CopyWithTar(parentDir, dir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
package vfs
|
package vfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/daemon/graphdriver/graphtest"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/daemon/graphdriver/graphtest"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reexec.Init()
|
||||||
|
}
|
||||||
|
|
||||||
// This avoids creating a new driver for each test if all tests are run
|
// This avoids creating a new driver for each test if all tests are run
|
||||||
// Make sure to put new tests between TestVfsSetup and TestVfsTeardown
|
// Make sure to put new tests between TestVfsSetup and TestVfsTeardown
|
||||||
func TestVfsSetup(t *testing.T) {
|
func TestVfsSetup(t *testing.T) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
|
|||||||
out.Set("ProcessLabel", container.ProcessLabel)
|
out.Set("ProcessLabel", container.ProcessLabel)
|
||||||
out.SetJson("Volumes", container.Volumes)
|
out.SetJson("Volumes", container.Volumes)
|
||||||
out.SetJson("VolumesRW", container.VolumesRW)
|
out.SetJson("VolumesRW", container.VolumesRW)
|
||||||
|
out.SetJson("AppArmorProfile", container.AppArmorProfile)
|
||||||
|
|
||||||
if children, err := daemon.Children(container.Name); err == nil {
|
if children, err := daemon.Children(container.Name); err == nil {
|
||||||
for linkAlias, child := range children {
|
for linkAlias, child := range children {
|
||||||
|
|||||||
+1
-1
@@ -93,7 +93,7 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
|
|||||||
if len(filt_exited) > 0 && !container.Running {
|
if len(filt_exited) > 0 && !container.Running {
|
||||||
should_skip := true
|
should_skip := true
|
||||||
for _, code := range filt_exited {
|
for _, code := range filt_exited {
|
||||||
if code == container.GetExitCode() {
|
if code == container.ExitCode {
|
||||||
should_skip = false
|
should_skip = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/proxy"
|
"github.com/docker/docker/pkg/proxy"
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
const userlandProxyCommandName = "docker-proxy"
|
const userlandProxyCommandName = "docker-proxy"
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
|
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
|
||||||
|
if err := parseSecurityOpt(container, hostConfig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// Validate the HostConfig binds. Make sure that:
|
// Validate the HostConfig binds. Make sure that:
|
||||||
// the source exists
|
// the source exists
|
||||||
for _, bind := range hostConfig.Binds {
|
for _, bind := range hostConfig.Binds {
|
||||||
|
|||||||
+9
-4
@@ -10,7 +10,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/pkg/symlink"
|
"github.com/docker/docker/pkg/symlink"
|
||||||
"github.com/docker/docker/volumes"
|
"github.com/docker/docker/volumes"
|
||||||
@@ -191,15 +191,20 @@ func parseBindMountSpec(spec string) (string, string, bool, error) {
|
|||||||
func (container *Container) applyVolumesFrom() error {
|
func (container *Container) applyVolumesFrom() error {
|
||||||
volumesFrom := container.hostConfig.VolumesFrom
|
volumesFrom := container.hostConfig.VolumesFrom
|
||||||
|
|
||||||
|
mountGroups := make([]map[string]*Mount, 0, len(volumesFrom))
|
||||||
|
|
||||||
for _, spec := range volumesFrom {
|
for _, spec := range volumesFrom {
|
||||||
mounts, err := parseVolumesFromSpec(container.daemon, spec)
|
mountGroup, err := parseVolumesFromSpec(container.daemon, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
mountGroups = append(mountGroups, mountGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, mounts := range mountGroups {
|
||||||
for _, mnt := range mounts {
|
for _, mnt := range mounts {
|
||||||
mnt.container = container
|
mnt.container = container
|
||||||
if err = mnt.initialize(); err != nil {
|
if err := mnt.initialize(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +307,7 @@ func copyExistingContents(source, destination string) error {
|
|||||||
|
|
||||||
if len(srcList) == 0 {
|
if len(srcList) == 0 {
|
||||||
// If the source volume is empty copy files from the root into the volume
|
// If the source volume is empty copy files from the root into the volume
|
||||||
if err := archive.CopyWithTar(source, destination); err != nil {
|
if err := chrootarchive.CopyWithTar(source, destination); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
_ "github.com/docker/docker/daemon/execdriver/lxc"
|
_ "github.com/docker/docker/daemon/execdriver/lxc"
|
||||||
_ "github.com/docker/docker/daemon/execdriver/native"
|
_ "github.com/docker/docker/daemon/execdriver/native"
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ expect an integer, and they can only be specified once.
|
|||||||
-g, --graph="/var/lib/docker" Path to use as the root of the Docker runtime
|
-g, --graph="/var/lib/docker" Path to use as the root of the Docker runtime
|
||||||
-H, --host=[] The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
|
-H, --host=[] The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
|
||||||
--icc=true Enable inter-container communication
|
--icc=true Enable inter-container communication
|
||||||
--insecure-registry=[] Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback)
|
--insecure-registry=[] Enable insecure communication with specified registries (disables certificate verification for HTTPS and enables HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)
|
||||||
--ip=0.0.0.0 Default IP address to use when binding container ports
|
--ip=0.0.0.0 Default IP address to use when binding container ports
|
||||||
--ip-forward=true Enable net.ipv4.ip_forward
|
--ip-forward=true Enable net.ipv4.ip_forward
|
||||||
--ip-masq=true Enable IP masquerading for bridge's IP range
|
--ip-masq=true Enable IP masquerading for bridge's IP range
|
||||||
@@ -193,24 +193,44 @@ To set the DNS server for all Docker containers, use
|
|||||||
To set the DNS search domain for all Docker containers, use
|
To set the DNS search domain for all Docker containers, use
|
||||||
`docker -d --dns-search example.com`.
|
`docker -d --dns-search example.com`.
|
||||||
|
|
||||||
|
### Insecure registries
|
||||||
|
|
||||||
|
Docker considers a private registry either secure or insecure.
|
||||||
|
In the rest of this section, *registry* is used for *private registry*, and `myregistry:5000`
|
||||||
|
is a placeholder example for a private registry.
|
||||||
|
|
||||||
|
A secure registry uses TLS and a copy of its CA certificate is placed on the Docker host at
|
||||||
|
`/etc/docker/certs.d/myregistry:5000/ca.crt`.
|
||||||
|
An insecure registry is either not using TLS (i.e., listening on plain text HTTP), or is using
|
||||||
|
TLS with a CA certificate not known by the Docker daemon. The latter can happen when the
|
||||||
|
certificate was not found under `/etc/docker/certs.d/myregistry:5000/`, or if the certificate
|
||||||
|
verification failed (i.e., wrong CA).
|
||||||
|
|
||||||
|
By default, Docker assumes all, but local (see local registries below), registries are secure.
|
||||||
|
Communicating with an insecure registry is not possible if Docker assumes that registry is secure.
|
||||||
|
In order to communicate with an insecure registry, the Docker daemon requires `--insecure-registry`
|
||||||
|
in one of the following two forms:
|
||||||
|
|
||||||
|
* `--insecure-registry myregistry:5000` tells the Docker daemon that myregistry:5000 should be considered insecure.
|
||||||
|
* `--insecure-registry 10.1.0.0/16` tells the Docker daemon that all registries whose domain resolve to an IP address is part
|
||||||
|
of the subnet described by the CIDR syntax, should be considered insecure.
|
||||||
|
|
||||||
|
The flag can be used multiple times to allow multiple registries to be marked as insecure.
|
||||||
|
|
||||||
|
If an insecure registry is not marked as insecure, `docker pull`, `docker push`, and `docker search`
|
||||||
|
will result in an error message prompting the user to either secure or pass the `--insecure-registry`
|
||||||
|
flag to the Docker daemon as described above.
|
||||||
|
|
||||||
|
Local registries, whose IP address falls in the 127.0.0.0/8 range, are automatically marked as insecure
|
||||||
|
as of Docker 1.3.2. It is not recommended to rely on this, as it may change in the future.
|
||||||
|
|
||||||
|
|
||||||
### Miscellaneous options
|
### Miscellaneous options
|
||||||
|
|
||||||
IP masquerading uses address translation to allow containers without a public IP to talk
|
IP masquerading uses address translation to allow containers without a public IP to talk
|
||||||
to other machines on the Internet. This may interfere with some network topologies and
|
to other machines on the Internet. This may interfere with some network topologies and
|
||||||
can be disabled with --ip-masq=false.
|
can be disabled with --ip-masq=false.
|
||||||
|
|
||||||
|
|
||||||
By default, Docker will assume all registries are secured via TLS with certificate verification
|
|
||||||
enabled. Prior versions of Docker used an auto fallback if a registry did not support TLS
|
|
||||||
(or if the TLS connection failed). This introduced the opportunity for Man In The Middle (MITM)
|
|
||||||
attacks, so as of Docker 1.3.1, the user must now specify the `--insecure-registry` daemon flag
|
|
||||||
for each insecure registry. An insecure registry is either not using TLS (i.e. plain text HTTP),
|
|
||||||
or is using TLS with a CA certificate not known by the Docker daemon (i.e. certification
|
|
||||||
verification disabled). For example, if there is a registry listening for HTTP at 127.0.0.1:5000,
|
|
||||||
as of Docker 1.3.1 you are required to specify `--insecure-registry 127.0.0.1:5000` when starting
|
|
||||||
the Docker daemon.
|
|
||||||
|
|
||||||
|
|
||||||
Docker supports softlinks for the Docker data directory
|
Docker supports softlinks for the Docker data directory
|
||||||
(`/var/lib/docker`) and for `/var/lib/docker/tmp`. The `DOCKER_TMPDIR` and the data directory can be set like this:
|
(`/var/lib/docker`) and for `/var/lib/docker/tmp`. The `DOCKER_TMPDIR` and the data directory can be set like this:
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,69 @@ understanding, release
|
|||||||
|
|
||||||
#Release Notes
|
#Release Notes
|
||||||
|
|
||||||
|
##Version 1.3.3
|
||||||
|
(2014-12-11)
|
||||||
|
|
||||||
|
This release fixes several security issues. In order to encourage immediate
|
||||||
|
upgrading, this release also patches some critical bugs. All users are highly
|
||||||
|
encouraged to upgrade as soon as possible.
|
||||||
|
|
||||||
|
*Security fixes*
|
||||||
|
|
||||||
|
Patches and changes were made to address the following vulnerabilities:
|
||||||
|
|
||||||
|
* CVE-2014-9356: Path traversal during processing of absolute symlinks.
|
||||||
|
Absolute symlinks were not adequately checked for traversal which created a
|
||||||
|
vulnerability via image extraction and/or volume mounts.
|
||||||
|
* CVE-2014-9357: Escalation of privileges during decompression of LZMA (.xz)
|
||||||
|
archives. Docker 1.3.2 added `chroot` for archive extraction. This created a
|
||||||
|
vulnerability that could allow malicious images or builds to write files to the
|
||||||
|
host system and escape containerization, leading to privilege escalation.
|
||||||
|
* CVE-2014-9358: Path traversal and spoofing opportunities via image
|
||||||
|
identifiers. Image IDs passed either via `docker load` or registry communications
|
||||||
|
were not sufficiently validated. This created a vulnerability to path traversal
|
||||||
|
attacks wherein malicious images or repository spoofing could lead to graph
|
||||||
|
corruption and manipulation.
|
||||||
|
|
||||||
|
*Runtime fixes*
|
||||||
|
|
||||||
|
* Fixed an issue that cause image archives to be read slowly.
|
||||||
|
|
||||||
|
*Client fixes*
|
||||||
|
|
||||||
|
* Fixed a regression related to STDIN redirection.
|
||||||
|
* Fixed a regression involving `docker cp` when the current directory is the
|
||||||
|
destination.
|
||||||
|
|
||||||
|
##Version 1.3.2
|
||||||
|
(2014-11-24)
|
||||||
|
|
||||||
|
This release fixes some bugs and addresses some security issues. We have also
|
||||||
|
made improvements to aspects of `docker run`.
|
||||||
|
|
||||||
|
*Security fixes*
|
||||||
|
|
||||||
|
Patches and changes were made to address CVE-2014-6407 and CVE-2014-6408.
|
||||||
|
Specifically, changes were made in order to:
|
||||||
|
|
||||||
|
* Prevent host privilege escalation from an image extraction vulnerability (CVE-2014-6407).
|
||||||
|
|
||||||
|
* Prevent container escalation from malicious security options applied to images (CVE-2014-6408).
|
||||||
|
|
||||||
|
*Daemon fixes*
|
||||||
|
|
||||||
|
The `--insecure-registry` flag of the `docker run` command has undergone
|
||||||
|
several refinements and additions. For details, please see the
|
||||||
|
[command-line reference](http://docs.docker.com/reference/commandline/cli/#run).
|
||||||
|
|
||||||
|
* You can now specify a sub-net in order to set a range of registries which the Docker daemon will consider insecure.
|
||||||
|
|
||||||
|
* By default, Docker now defines `localhost` as an insecure registry.
|
||||||
|
|
||||||
|
* Registries can now be referenced using the Classless Inter-Domain Routing (CIDR) format.
|
||||||
|
|
||||||
|
* When mirroring is enabled, the experimental registry v2 API is skipped.
|
||||||
|
|
||||||
##Version 1.3.1
|
##Version 1.3.1
|
||||||
(2014-10-28)
|
(2014-10-28)
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -10,7 +10,9 @@ import (
|
|||||||
"github.com/docker/docker/engine"
|
"github.com/docker/docker/engine"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/chrootarchive"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Loads a set of images into the repository. This is the complementary of ImageExport.
|
// Loads a set of images into the repository. This is the complementary of ImageExport.
|
||||||
@@ -53,7 +55,7 @@ func (s *TagStore) CmdLoad(job *engine.Job) engine.Status {
|
|||||||
excludes[i] = k
|
excludes[i] = k
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
if err := archive.Untar(repoFile, repoDir, &archive.TarOptions{Excludes: excludes}); err != nil {
|
if err := chrootarchive.Untar(repoFile, repoDir, &archive.TarOptions{Excludes: excludes}); err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +113,10 @@ func (s *TagStore) recursiveLoad(eng *engine.Engine, address, tmpImageDir string
|
|||||||
log.Debugf("Error unmarshalling json", err)
|
log.Debugf("Error unmarshalling json", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := utils.ValidateID(img.ID); err != nil {
|
||||||
|
log.Debugf("Error validating ID: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
if img.Parent != "" {
|
if img.Parent != "" {
|
||||||
if !s.graph.Exists(img.Parent) {
|
if !s.graph.Exists(img.Parent) {
|
||||||
if err := s.recursiveLoad(eng, img.Parent, tmpImageDir); err != nil {
|
if err := s.recursiveLoad(eng, img.Parent, tmpImageDir); err != nil {
|
||||||
|
|||||||
+9
-1
@@ -1,6 +1,14 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reexec.Init()
|
||||||
|
}
|
||||||
|
|
||||||
func TestPools(t *testing.T) {
|
func TestPools(t *testing.T) {
|
||||||
s := &TagStore{
|
s := &TagStore{
|
||||||
|
|||||||
+2
-4
@@ -113,9 +113,7 @@ func (s *TagStore) CmdPull(job *engine.Job) engine.Status {
|
|||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secure := registry.IsSecure(hostname, s.insecureRegistries)
|
endpoint, err := registry.NewEndpoint(hostname, s.insecureRegistries)
|
||||||
|
|
||||||
endpoint, err := registry.NewEndpoint(hostname, secure)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
@@ -139,7 +137,7 @@ func (s *TagStore) CmdPull(job *engine.Job) engine.Status {
|
|||||||
mirrors = s.mirrors
|
mirrors = s.mirrors
|
||||||
}
|
}
|
||||||
|
|
||||||
if isOfficial || endpoint.Version == registry.APIVersion2 {
|
if len(mirrors) == 0 && (isOfficial || endpoint.Version == registry.APIVersion2) {
|
||||||
j := job.Eng.Job("trust_update_base")
|
j := job.Eng.Job("trust_update_base")
|
||||||
if err = j.Run(); err != nil {
|
if err = j.Run(); err != nil {
|
||||||
return job.Errorf("error updating trust base graph: %s", err)
|
return job.Errorf("error updating trust base graph: %s", err)
|
||||||
|
|||||||
+1
-3
@@ -214,9 +214,7 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status {
|
|||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secure := registry.IsSecure(hostname, s.insecureRegistries)
|
endpoint, err := registry.NewEndpoint(hostname, s.insecureRegistries)
|
||||||
|
|
||||||
endpoint, err := registry.NewEndpoint(hostname, secure)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
testImageName = "myapp"
|
testImageName = "myapp"
|
||||||
testImageID = "foo"
|
testImageID = "1a2d3c4d4e5fa2d2a21acea242a5e2345d3aefc3e7dfa2a2a2a21a2a2ad2d234"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fakeTar() (io.Reader, error) {
|
func fakeTar() (io.Reader, error) {
|
||||||
|
|||||||
@@ -1167,6 +1167,133 @@ func TestBuildCopyDisallowRemote(t *testing.T) {
|
|||||||
logDone("build - copy - disallow copy from remote")
|
logDone("build - copy - disallow copy from remote")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildAddBadLinks(t *testing.T) {
|
||||||
|
const (
|
||||||
|
dockerfile = `
|
||||||
|
FROM scratch
|
||||||
|
ADD links.tar /
|
||||||
|
ADD foo.txt /symlink/
|
||||||
|
`
|
||||||
|
targetFile = "foo.txt"
|
||||||
|
)
|
||||||
|
var (
|
||||||
|
name = "test-link-absolute"
|
||||||
|
)
|
||||||
|
defer deleteImages(name)
|
||||||
|
ctx, err := fakeContext(dockerfile, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
tempDir, err := ioutil.TempDir("", "test-link-absolute-temp-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temporary directory: %s", tempDir)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
symlinkTarget := fmt.Sprintf("/../../../../../../../../../../../..%s", tempDir)
|
||||||
|
tarPath := filepath.Join(ctx.Dir, "links.tar")
|
||||||
|
nonExistingFile := filepath.Join(tempDir, targetFile)
|
||||||
|
fooPath := filepath.Join(ctx.Dir, targetFile)
|
||||||
|
|
||||||
|
tarOut, err := os.Create(tarPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tarWriter := tar.NewWriter(tarOut)
|
||||||
|
|
||||||
|
header := &tar.Header{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: symlinkTarget,
|
||||||
|
Mode: 0755,
|
||||||
|
Uid: 0,
|
||||||
|
Gid: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tarWriter.WriteHeader(header)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tarWriter.Close()
|
||||||
|
tarOut.Close()
|
||||||
|
|
||||||
|
foo, err := os.Create(fooPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer foo.Close()
|
||||||
|
|
||||||
|
if _, err := foo.WriteString("test"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - ADD must add files in container")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildAddBadLinksVolume(t *testing.T) {
|
||||||
|
const (
|
||||||
|
dockerfileTemplate = `
|
||||||
|
FROM busybox
|
||||||
|
RUN ln -s /../../../../../../../../%s /x
|
||||||
|
VOLUME /x
|
||||||
|
ADD foo.txt /x/`
|
||||||
|
targetFile = "foo.txt"
|
||||||
|
)
|
||||||
|
var (
|
||||||
|
name = "test-link-absolute-volume"
|
||||||
|
dockerfile = ""
|
||||||
|
)
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create temporary directory: %s", tempDir)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir)
|
||||||
|
nonExistingFile := filepath.Join(tempDir, targetFile)
|
||||||
|
|
||||||
|
ctx, err := fakeContext(dockerfile, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
fooPath := filepath.Join(ctx.Dir, targetFile)
|
||||||
|
|
||||||
|
foo, err := os.Create(fooPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer foo.Close()
|
||||||
|
|
||||||
|
if _, err := foo.WriteString("test"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - ADD should add files in volume")
|
||||||
|
}
|
||||||
|
|
||||||
// Issue #5270 - ensure we throw a better error than "unexpected EOF"
|
// Issue #5270 - ensure we throw a better error than "unexpected EOF"
|
||||||
// when we can't access files in the context.
|
// when we can't access files in the context.
|
||||||
func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
|
func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
|
||||||
@@ -2867,6 +2994,118 @@ RUN cat /existing-directory-trailing-slash/test/foo | grep Hi`
|
|||||||
logDone("build - ADD tar")
|
logDone("build - ADD tar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildAddTarXz(t *testing.T) {
|
||||||
|
name := "testbuildaddtarxz"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
ctx := func() *FakeContext {
|
||||||
|
dockerfile := `
|
||||||
|
FROM busybox
|
||||||
|
ADD test.tar.xz /
|
||||||
|
RUN cat /test/foo | grep Hi`
|
||||||
|
tmpDir, err := ioutil.TempDir("", "fake-context")
|
||||||
|
testTar, err := os.Create(filepath.Join(tmpDir, "test.tar"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create test.tar archive: %v", err)
|
||||||
|
}
|
||||||
|
defer testTar.Close()
|
||||||
|
|
||||||
|
tw := tar.NewWriter(testTar)
|
||||||
|
|
||||||
|
if err := tw.WriteHeader(&tar.Header{
|
||||||
|
Name: "test/foo",
|
||||||
|
Size: 2,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("failed to write tar file header: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := tw.Write([]byte("Hi")); err != nil {
|
||||||
|
t.Fatalf("failed to write tar file content: %v", err)
|
||||||
|
}
|
||||||
|
if err := tw.Close(); err != nil {
|
||||||
|
t.Fatalf("failed to close tar archive: %v", err)
|
||||||
|
}
|
||||||
|
xzCompressCmd := exec.Command("xz", "test.tar")
|
||||||
|
xzCompressCmd.Dir = tmpDir
|
||||||
|
out, _, err := runCommandWithOutput(xzCompressCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
||||||
|
t.Fatalf("failed to open destination dockerfile: %v", err)
|
||||||
|
}
|
||||||
|
return &FakeContext{Dir: tmpDir}
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - ADD tar.xz")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildAddTarXzGz(t *testing.T) {
|
||||||
|
name := "testbuildaddtarxzgz"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
ctx := func() *FakeContext {
|
||||||
|
dockerfile := `
|
||||||
|
FROM busybox
|
||||||
|
ADD test.tar.xz.gz /
|
||||||
|
RUN ls /test.tar.xz.gz`
|
||||||
|
tmpDir, err := ioutil.TempDir("", "fake-context")
|
||||||
|
testTar, err := os.Create(filepath.Join(tmpDir, "test.tar"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create test.tar archive: %v", err)
|
||||||
|
}
|
||||||
|
defer testTar.Close()
|
||||||
|
|
||||||
|
tw := tar.NewWriter(testTar)
|
||||||
|
|
||||||
|
if err := tw.WriteHeader(&tar.Header{
|
||||||
|
Name: "test/foo",
|
||||||
|
Size: 2,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("failed to write tar file header: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := tw.Write([]byte("Hi")); err != nil {
|
||||||
|
t.Fatalf("failed to write tar file content: %v", err)
|
||||||
|
}
|
||||||
|
if err := tw.Close(); err != nil {
|
||||||
|
t.Fatalf("failed to close tar archive: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
xzCompressCmd := exec.Command("xz", "test.tar")
|
||||||
|
xzCompressCmd.Dir = tmpDir
|
||||||
|
out, _, err := runCommandWithOutput(xzCompressCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
gzipCompressCmd := exec.Command("gzip", "test.tar.xz")
|
||||||
|
gzipCompressCmd.Dir = tmpDir
|
||||||
|
out, _, err = runCommandWithOutput(gzipCompressCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
||||||
|
t.Fatalf("failed to open destination dockerfile: %v", err)
|
||||||
|
}
|
||||||
|
return &FakeContext{Dir: tmpDir}
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - ADD tar.xz.gz")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildFromGIT(t *testing.T) {
|
func TestBuildFromGIT(t *testing.T) {
|
||||||
name := "testbuildfromgit"
|
name := "testbuildfromgit"
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
@@ -3175,3 +3414,86 @@ func TestBuildExoticShellInterpolation(t *testing.T) {
|
|||||||
|
|
||||||
logDone("build - exotic shell interpolation")
|
logDone("build - exotic shell interpolation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildSymlinkBreakout(t *testing.T) {
|
||||||
|
name := "testbuildsymlinkbreakout"
|
||||||
|
tmpdir, err := ioutil.TempDir("", name)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
ctx := filepath.Join(tmpdir, "context")
|
||||||
|
if err := os.MkdirAll(ctx, 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(ctx, "Dockerfile"), []byte(`
|
||||||
|
from busybox
|
||||||
|
add symlink.tar /
|
||||||
|
add inject /symlink/
|
||||||
|
`), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
inject := filepath.Join(ctx, "inject")
|
||||||
|
if err := ioutil.WriteFile(inject, nil, 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f, err := os.Create(filepath.Join(ctx, "symlink.tar"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
w := tar.NewWriter(f)
|
||||||
|
w.WriteHeader(&tar.Header{
|
||||||
|
Name: "symlink2",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "/../../../../../../../../../../../../../../",
|
||||||
|
Uid: os.Getuid(),
|
||||||
|
Gid: os.Getgid(),
|
||||||
|
})
|
||||||
|
w.WriteHeader(&tar.Header{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: filepath.Join("symlink2", tmpdir),
|
||||||
|
Uid: os.Getuid(),
|
||||||
|
Gid: os.Getgid(),
|
||||||
|
})
|
||||||
|
w.Close()
|
||||||
|
f.Close()
|
||||||
|
if _, err := buildImageFromContext(name, &FakeContext{Dir: ctx}, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Lstat(filepath.Join(tmpdir, "inject")); err == nil {
|
||||||
|
t.Fatal("symlink breakout - inject")
|
||||||
|
} else if !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
logDone("build - symlink breakout")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildXZHost(t *testing.T) {
|
||||||
|
name := "testbuildxzhost"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
ctx, err := fakeContext(`
|
||||||
|
FROM busybox
|
||||||
|
ADD xz /usr/local/sbin/
|
||||||
|
RUN chmod 755 /usr/local/sbin/xz
|
||||||
|
ADD test.xz /
|
||||||
|
RUN [ ! -e /injected ]`,
|
||||||
|
map[string]string{
|
||||||
|
"test.xz": "\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00" +
|
||||||
|
"\x21\x01\x16\x00\x00\x00\x74\x2f\xe5\xa3\x01\x00\x3f\xfd" +
|
||||||
|
"\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00\x21",
|
||||||
|
"xz": "#!/bin/sh\ntouch /injected",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - xz host is being used")
|
||||||
|
}
|
||||||
|
|||||||
@@ -371,3 +371,41 @@ func TestCpUnprivilegedUser(t *testing.T) {
|
|||||||
|
|
||||||
logDone("cp - unprivileged user")
|
logDone("cp - unprivileged user")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCpToDot(t *testing.T) {
|
||||||
|
out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
t.Fatal("failed to create a container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
|
defer deleteContainer(cleanedContainerID)
|
||||||
|
|
||||||
|
out, _, err = dockerCmd(t, "wait", cleanedContainerID)
|
||||||
|
if err != nil || stripTrailingCharacters(out) != "0" {
|
||||||
|
t.Fatal("failed to set up container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "docker-integration")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Chdir(cwd)
|
||||||
|
if err := os.Chdir(tmpdir); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, _, err = dockerCmd(t, "cp", cleanedContainerID+":/test", ".")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("couldn't docker cp to \".\" path: %s", err)
|
||||||
|
}
|
||||||
|
content, err := ioutil.ReadFile("./test")
|
||||||
|
if string(content) != "lololol\n" {
|
||||||
|
t.Fatal("Wrong content in copied file %q, should be %q", content, "lololol\n")
|
||||||
|
}
|
||||||
|
logDone("cp - to dot path")
|
||||||
|
}
|
||||||
|
|||||||
@@ -282,3 +282,81 @@ func TestPsListContainersFilterStatus(t *testing.T) {
|
|||||||
|
|
||||||
logDone("ps - test ps filter status")
|
logDone("ps - test ps filter status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPsListContainersFilterExited(t *testing.T) {
|
||||||
|
deleteAllContainers()
|
||||||
|
defer deleteAllContainers()
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
firstZero, err := getIDByName("zero1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
secondZero, err := getIDByName("zero2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Should fail.", out, err)
|
||||||
|
}
|
||||||
|
firstNonZero, err := getIDByName("nonzero1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Should fail.", out, err)
|
||||||
|
}
|
||||||
|
secondNonZero, err := getIDByName("nonzero2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter containers by exited=0
|
||||||
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
ids := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
if len(ids) != 2 {
|
||||||
|
t.Fatalf("Should be 2 zero exited containerst got %d", len(ids))
|
||||||
|
}
|
||||||
|
if ids[0] != secondZero {
|
||||||
|
t.Fatalf("First in list should be %q, got %q", secondZero, ids[0])
|
||||||
|
}
|
||||||
|
if ids[1] != firstZero {
|
||||||
|
t.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
ids = strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
if len(ids) != 2 {
|
||||||
|
t.Fatalf("Should be 2 zero exited containerst got %d", len(ids))
|
||||||
|
}
|
||||||
|
if ids[0] != secondNonZero {
|
||||||
|
t.Fatalf("First in list should be %q, got %q", secondNonZero, ids[0])
|
||||||
|
}
|
||||||
|
if ids[1] != firstNonZero {
|
||||||
|
t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
|
||||||
|
}
|
||||||
|
logDone("ps - test ps filter exited")
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,6 +62,140 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
|
|||||||
logDone("load - load a repo using stdout")
|
logDone("load - load a repo using stdout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save a repo using gz compression and try to load it using stdout
|
||||||
|
func TestSaveXzAndLoadRepoStdout(t *testing.T) {
|
||||||
|
tempDir, err := ioutil.TempDir("", "test-save-xz-gz-load-repo-stdout")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
tarballPath := filepath.Join(tempDir, "foobar-save-load-test.tar.xz.gz")
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create a container: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
repoName := "foobar-save-load-test-xz-gz"
|
||||||
|
|
||||||
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
||||||
|
out, _, err = runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
||||||
|
out, _, err = runCommandWithOutput(commitCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to commit container: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
|
before, _, err := runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist before saving it: %v %v", before, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
saveCmdTemplate := `%v save %v | xz -c | gzip -c > %s`
|
||||||
|
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName, tarballPath)
|
||||||
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
|
out, _, err = runCommandWithOutput(saveCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to save repo: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
loadCmdFinal := fmt.Sprintf(`cat %s | docker load`, tarballPath)
|
||||||
|
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
||||||
|
out, _, err = runCommandWithOutput(loadCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
|
after, _, err := runCommandWithOutput(inspectCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("the repo should not exist: %v", after)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteContainer(cleanedContainerID)
|
||||||
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
logDone("load - save a repo with xz compression & load it using stdout")
|
||||||
|
}
|
||||||
|
|
||||||
|
// save a repo using xz+gz compression and try to load it using stdout
|
||||||
|
func TestSaveXzGzAndLoadRepoStdout(t *testing.T) {
|
||||||
|
tempDir, err := ioutil.TempDir("", "test-save-xz-gz-load-repo-stdout")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
tarballPath := filepath.Join(tempDir, "foobar-save-load-test.tar.xz.gz")
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create a container: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
repoName := "foobar-save-load-test-xz-gz"
|
||||||
|
|
||||||
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
||||||
|
out, _, err = runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
||||||
|
out, _, err = runCommandWithOutput(commitCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to commit container: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
|
before, _, err := runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist before saving it: %v %v", before, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
saveCmdTemplate := `%v save %v | xz -c | gzip -c > %s`
|
||||||
|
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName, tarballPath)
|
||||||
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
|
out, _, err = runCommandWithOutput(saveCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to save repo: %v %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
loadCmdFinal := fmt.Sprintf(`cat %s | docker load`, tarballPath)
|
||||||
|
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
||||||
|
out, _, err = runCommandWithOutput(loadCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
|
after, _, err := runCommandWithOutput(inspectCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("the repo should not exist: %v", after)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteContainer(cleanedContainerID)
|
||||||
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
logDone("load - save a repo with xz+gz compression & load it using stdout")
|
||||||
|
}
|
||||||
|
|
||||||
func TestSaveSingleTag(t *testing.T) {
|
func TestSaveSingleTag(t *testing.T) {
|
||||||
repoName := "foobar-save-single-tag-test"
|
repoName := "foobar-save-single-tag-test"
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -36,3 +37,31 @@ func TestStartAttachReturnsOnError(t *testing.T) {
|
|||||||
|
|
||||||
logDone("start - error on start with attach exits")
|
logDone("start - error on start with attach exits")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh#8726: a failed Start() breaks --volumes-from on subsequent Start()'s
|
||||||
|
func TestStartVolumesFromFailsCleanly(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
// Create the first data volume
|
||||||
|
cmd(t, "run", "-d", "--name", "data_before", "-v", "/foo", "busybox")
|
||||||
|
|
||||||
|
// Expect this to fail because the data test after contaienr doesn't exist yet
|
||||||
|
if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "consumer", "--volumes-from", "data_before", "--volumes-from", "data_after", "busybox")); err == nil {
|
||||||
|
t.Fatal("Expected error but got none")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the second data volume
|
||||||
|
cmd(t, "run", "-d", "--name", "data_after", "-v", "/bar", "busybox")
|
||||||
|
|
||||||
|
// Now, all the volumes should be there
|
||||||
|
cmd(t, "start", "consumer")
|
||||||
|
|
||||||
|
// Check that we have the volumes we want
|
||||||
|
out, _, _ := cmd(t, "inspect", "--format='{{ len .Volumes }}'", "consumer")
|
||||||
|
n_volumes := strings.Trim(out, " \r\n'")
|
||||||
|
if n_volumes != "2" {
|
||||||
|
t.Fatalf("Missing volumes: expected 2, got %s", n_volumes)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("start - missing containers in --volumes-from did not affect subsequent runs")
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/docker/docker/nat"
|
"github.com/docker/docker/nat"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|||||||
+99
-51
@@ -35,10 +35,22 @@ type (
|
|||||||
Compression Compression
|
Compression Compression
|
||||||
NoLchown bool
|
NoLchown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Archiver allows the reuse of most utility functions of this package
|
||||||
|
// with a pluggable Untar function.
|
||||||
|
Archiver struct {
|
||||||
|
Untar func(io.Reader, string, *TarOptions) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// breakoutError is used to differentiate errors related to breaking out
|
||||||
|
// When testing archive breakout in the unit tests, this error is expected
|
||||||
|
// in order for the test to pass.
|
||||||
|
breakoutError error
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNotImplemented = errors.New("Function not implemented")
|
ErrNotImplemented = errors.New("Function not implemented")
|
||||||
|
defaultArchiver = &Archiver{Untar}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -263,11 +275,25 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
|
|||||||
}
|
}
|
||||||
|
|
||||||
case tar.TypeLink:
|
case tar.TypeLink:
|
||||||
if err := os.Link(filepath.Join(extractDir, hdr.Linkname), path); err != nil {
|
targetPath := filepath.Join(extractDir, hdr.Linkname)
|
||||||
|
// check for hardlink breakout
|
||||||
|
if !strings.HasPrefix(targetPath, extractDir) {
|
||||||
|
return breakoutError(fmt.Errorf("invalid hardlink %q -> %q", targetPath, hdr.Linkname))
|
||||||
|
}
|
||||||
|
if err := os.Link(targetPath, path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
case tar.TypeSymlink:
|
case tar.TypeSymlink:
|
||||||
|
// path -> hdr.Linkname = targetPath
|
||||||
|
// e.g. /extractDir/path/to/symlink -> ../2/file = /extractDir/path/2/file
|
||||||
|
targetPath := filepath.Join(filepath.Dir(path), hdr.Linkname)
|
||||||
|
|
||||||
|
// the reason we don't need to check symlinks in the path (with FollowSymlinkInScope) is because
|
||||||
|
// that symlink would first have to be created, which would be caught earlier, at this very check:
|
||||||
|
if !strings.HasPrefix(targetPath, extractDir) {
|
||||||
|
return breakoutError(fmt.Errorf("invalid symlink %q -> %q", path, hdr.Linkname))
|
||||||
|
}
|
||||||
if err := os.Symlink(hdr.Linkname, path); err != nil {
|
if err := os.Symlink(hdr.Linkname, path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -406,30 +432,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
|
|||||||
return pipeReader, nil
|
return pipeReader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Untar reads a stream of bytes from `archive`, parses it as a tar archive,
|
func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error {
|
||||||
// and unpacks it into the directory at `path`.
|
|
||||||
// The archive may be compressed with one of the following algorithms:
|
|
||||||
// identity (uncompressed), gzip, bzip2, xz.
|
|
||||||
// FIXME: specify behavior when target path exists vs. doesn't exist.
|
|
||||||
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
|
||||||
if options == nil {
|
|
||||||
options = &TarOptions{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if archive == nil {
|
|
||||||
return fmt.Errorf("Empty archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.Excludes == nil {
|
|
||||||
options.Excludes = []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
decompressedArchive, err := DecompressStream(archive)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer decompressedArchive.Close()
|
|
||||||
|
|
||||||
tr := tar.NewReader(decompressedArchive)
|
tr := tar.NewReader(decompressedArchive)
|
||||||
trBuf := pools.BufioReader32KPool.Get(nil)
|
trBuf := pools.BufioReader32KPool.Get(nil)
|
||||||
defer pools.BufioReader32KPool.Put(trBuf)
|
defer pools.BufioReader32KPool.Put(trBuf)
|
||||||
@@ -449,6 +452,7 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normalize name, for safety and for a simple is-root check
|
// Normalize name, for safety and for a simple is-root check
|
||||||
|
// This keeps "../" as-is, but normalizes "/../" to "/"
|
||||||
hdr.Name = filepath.Clean(hdr.Name)
|
hdr.Name = filepath.Clean(hdr.Name)
|
||||||
|
|
||||||
for _, exclude := range options.Excludes {
|
for _, exclude := range options.Excludes {
|
||||||
@@ -470,6 +474,13 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(dest, hdr.Name)
|
path := filepath.Join(dest, hdr.Name)
|
||||||
|
rel, err := filepath.Rel(dest, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(rel, "..") {
|
||||||
|
return breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest))
|
||||||
|
}
|
||||||
|
|
||||||
// If path exits we almost always just want to remove and replace it
|
// If path exits we almost always just want to remove and replace it
|
||||||
// The only exception is when it is a directory *and* the file from
|
// The only exception is when it is a directory *and* the file from
|
||||||
@@ -504,49 +515,74 @@ loop:
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TarUntar is a convenience function which calls Tar and Untar, with
|
// Untar reads a stream of bytes from `archive`, parses it as a tar archive,
|
||||||
// the output of one piped into the other. If either Tar or Untar fails,
|
// and unpacks it into the directory at `dest`.
|
||||||
// TarUntar aborts and returns the error.
|
// The archive may be compressed with one of the following algorithms:
|
||||||
func TarUntar(src string, dst string) error {
|
// identity (uncompressed), gzip, bzip2, xz.
|
||||||
|
// FIXME: specify behavior when target path exists vs. doesn't exist.
|
||||||
|
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
|
if archive == nil {
|
||||||
|
return fmt.Errorf("Empty archive")
|
||||||
|
}
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
if options == nil {
|
||||||
|
options = &TarOptions{}
|
||||||
|
}
|
||||||
|
if options.Excludes == nil {
|
||||||
|
options.Excludes = []string{}
|
||||||
|
}
|
||||||
|
decompressedArchive, err := DecompressStream(archive)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer decompressedArchive.Close()
|
||||||
|
return Unpack(decompressedArchive, dest, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (archiver *Archiver) TarUntar(src, dst string) error {
|
||||||
log.Debugf("TarUntar(%s %s)", src, dst)
|
log.Debugf("TarUntar(%s %s)", src, dst)
|
||||||
archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed})
|
archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer archive.Close()
|
defer archive.Close()
|
||||||
return Untar(archive, dst, nil)
|
return archiver.Untar(archive, dst, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UntarPath is a convenience function which looks for an archive
|
// TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other.
|
||||||
// at filesystem path `src`, and unpacks it at `dst`.
|
// If either Tar or Untar fails, TarUntar aborts and returns the error.
|
||||||
func UntarPath(src, dst string) error {
|
func TarUntar(src, dst string) error {
|
||||||
|
return defaultArchiver.TarUntar(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (archiver *Archiver) UntarPath(src, dst string) error {
|
||||||
archive, err := os.Open(src)
|
archive, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer archive.Close()
|
defer archive.Close()
|
||||||
if err := Untar(archive, dst, nil); err != nil {
|
if err := archiver.Untar(archive, dst, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyWithTar creates a tar archive of filesystem path `src`, and
|
// UntarPath is a convenience function which looks for an archive
|
||||||
// unpacks it at filesystem path `dst`.
|
// at filesystem path `src`, and unpacks it at `dst`.
|
||||||
// The archive is streamed directly with fixed buffering and no
|
func UntarPath(src, dst string) error {
|
||||||
// intermediary disk IO.
|
return defaultArchiver.UntarPath(src, dst)
|
||||||
//
|
}
|
||||||
func CopyWithTar(src, dst string) error {
|
|
||||||
|
func (archiver *Archiver) CopyWithTar(src, dst string) error {
|
||||||
srcSt, err := os.Stat(src)
|
srcSt, err := os.Stat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !srcSt.IsDir() {
|
if !srcSt.IsDir() {
|
||||||
return CopyFileWithTar(src, dst)
|
return archiver.CopyFileWithTar(src, dst)
|
||||||
}
|
}
|
||||||
// Create dst, copy src's content into it
|
// Create dst, copy src's content into it
|
||||||
log.Debugf("Creating dest directory: %s", dst)
|
log.Debugf("Creating dest directory: %s", dst)
|
||||||
@@ -554,16 +590,18 @@ func CopyWithTar(src, dst string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("Calling TarUntar(%s, %s)", src, dst)
|
log.Debugf("Calling TarUntar(%s, %s)", src, dst)
|
||||||
return TarUntar(src, dst)
|
return archiver.TarUntar(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyFileWithTar emulates the behavior of the 'cp' command-line
|
// CopyWithTar creates a tar archive of filesystem path `src`, and
|
||||||
// for a single file. It copies a regular file from path `src` to
|
// unpacks it at filesystem path `dst`.
|
||||||
// path `dst`, and preserves all its metadata.
|
// The archive is streamed directly with fixed buffering and no
|
||||||
//
|
// intermediary disk IO.
|
||||||
// If `dst` ends with a trailing slash '/', the final destination path
|
func CopyWithTar(src, dst string) error {
|
||||||
// will be `dst/base(src)`.
|
return defaultArchiver.CopyWithTar(src, dst)
|
||||||
func CopyFileWithTar(src, dst string) (err error) {
|
}
|
||||||
|
|
||||||
|
func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
|
||||||
log.Debugf("CopyFileWithTar(%s, %s)", src, dst)
|
log.Debugf("CopyFileWithTar(%s, %s)", src, dst)
|
||||||
srcSt, err := os.Stat(src)
|
srcSt, err := os.Stat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -611,7 +649,17 @@ func CopyFileWithTar(src, dst string) (err error) {
|
|||||||
err = er
|
err = er
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return Untar(r, filepath.Dir(dst), nil)
|
return archiver.Untar(r, filepath.Dir(dst), nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyFileWithTar emulates the behavior of the 'cp' command-line
|
||||||
|
// for a single file. It copies a regular file from path `src` to
|
||||||
|
// path `dst`, and preserves all its metadata.
|
||||||
|
//
|
||||||
|
// If `dst` ends with a trailing slash '/', the final destination path
|
||||||
|
// will be `dst/base(src)`.
|
||||||
|
func CopyFileWithTar(src, dst string) (err error) {
|
||||||
|
return defaultArchiver.CopyFileWithTar(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CmdStream executes a command, and returns its stdout as a stream.
|
// CmdStream executes a command, and returns its stdout as a stream.
|
||||||
|
|||||||
+205
-1
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -169,7 +170,12 @@ func TestTarWithOptions(t *testing.T) {
|
|||||||
// Failing prevents the archives from being uncompressed during ADD
|
// Failing prevents the archives from being uncompressed during ADD
|
||||||
func TestTypeXGlobalHeaderDoesNotFail(t *testing.T) {
|
func TestTypeXGlobalHeaderDoesNotFail(t *testing.T) {
|
||||||
hdr := tar.Header{Typeflag: tar.TypeXGlobalHeader}
|
hdr := tar.Header{Typeflag: tar.TypeXGlobalHeader}
|
||||||
err := createTarFile("pax_global_header", "some_dir", &hdr, nil, true)
|
tmpDir, err := ioutil.TempDir("", "docker-test-archive-pax-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
err = createTarFile(filepath.Join(tmpDir, "pax_global_header"), tmpDir, &hdr, nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -242,3 +248,201 @@ func BenchmarkTarUntar(b *testing.B) {
|
|||||||
os.RemoveAll(target)
|
os.RemoveAll(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUntarInvalidFilenames(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Name: "../victim/dotdot",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// Note the leading slash
|
||||||
|
Name: "/../victim/slash-dotdot",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("untar", "docker-TestUntarInvalidFilenames", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUntarInvalidHardlink(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{ // try reading victim/hello (../)
|
||||||
|
{
|
||||||
|
Name: "dotdot",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (/../)
|
||||||
|
{
|
||||||
|
Name: "slash-dotdot",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
// Note the leading slash
|
||||||
|
Linkname: "/../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try writing victim/file
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim/file",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (hardlink, symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // Try reading victim/hello (hardlink, hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "hardlink",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // Try removing victim directory (hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("untar", "docker-TestUntarInvalidHardlink", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUntarInvalidSymlink(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{ // try reading victim/hello (../)
|
||||||
|
{
|
||||||
|
Name: "dotdot",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (/../)
|
||||||
|
{
|
||||||
|
Name: "slash-dotdot",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
// Note the leading slash
|
||||||
|
Linkname: "/../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try writing victim/file
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim/file",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (symlink, symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (symlink, hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "hardlink",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try removing victim directory (symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try writing to victim/newdir/newfile with a symlink in the path
|
||||||
|
{
|
||||||
|
// this header needs to be before the next one, or else there is an error
|
||||||
|
Name: "dir/loophole",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "dir/loophole/newdir/newfile",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("untar", "docker-TestUntarInvalidSymlink", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+24
-13
@@ -21,18 +21,7 @@ func mkdev(major int64, minor int64) uint32 {
|
|||||||
return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff))
|
return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
func UnpackLayer(dest string, layer ArchiveReader) error {
|
||||||
// applies it to the directory `dest`.
|
|
||||||
func ApplyLayer(dest string, layer ArchiveReader) error {
|
|
||||||
// We need to be able to set any perms
|
|
||||||
oldmask := syscall.Umask(0)
|
|
||||||
defer syscall.Umask(oldmask)
|
|
||||||
|
|
||||||
layer, err := DecompressStream(layer)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tr := tar.NewReader(layer)
|
tr := tar.NewReader(layer)
|
||||||
trBuf := pools.BufioReader32KPool.Get(tr)
|
trBuf := pools.BufioReader32KPool.Get(tr)
|
||||||
defer pools.BufioReader32KPool.Put(trBuf)
|
defer pools.BufioReader32KPool.Put(trBuf)
|
||||||
@@ -92,7 +81,15 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(dest, hdr.Name)
|
path := filepath.Join(dest, hdr.Name)
|
||||||
|
rel, err := filepath.Rel(dest, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(rel, "..") {
|
||||||
|
return breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest))
|
||||||
|
}
|
||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
|
|
||||||
if strings.HasPrefix(base, ".wh.") {
|
if strings.HasPrefix(base, ".wh.") {
|
||||||
originalBase := base[len(".wh."):]
|
originalBase := base[len(".wh."):]
|
||||||
originalPath := filepath.Join(filepath.Dir(path), originalBase)
|
originalPath := filepath.Join(filepath.Dir(path), originalBase)
|
||||||
@@ -151,6 +148,20 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
||||||
|
// applies it to the directory `dest`.
|
||||||
|
func ApplyLayer(dest string, layer ArchiveReader) error {
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
// We need to be able to set any perms
|
||||||
|
oldmask := syscall.Umask(0)
|
||||||
|
defer syscall.Umask(oldmask)
|
||||||
|
|
||||||
|
layer, err := DecompressStream(layer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return UnpackLayer(dest, layer)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
package archive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApplyLayerInvalidFilenames(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Name: "../victim/dotdot",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// Note the leading slash
|
||||||
|
Name: "/../victim/slash-dotdot",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidFilenames", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyLayerInvalidHardlink(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{ // try reading victim/hello (../)
|
||||||
|
{
|
||||||
|
Name: "dotdot",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (/../)
|
||||||
|
{
|
||||||
|
Name: "slash-dotdot",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
// Note the leading slash
|
||||||
|
Linkname: "/../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try writing victim/file
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim/file",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (hardlink, symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // Try reading victim/hello (hardlink, hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "hardlink",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // Try removing victim directory (hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidHardlink", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyLayerInvalidSymlink(t *testing.T) {
|
||||||
|
for i, headers := range [][]*tar.Header{
|
||||||
|
{ // try reading victim/hello (../)
|
||||||
|
{
|
||||||
|
Name: "dotdot",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (/../)
|
||||||
|
{
|
||||||
|
Name: "slash-dotdot",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
// Note the leading slash
|
||||||
|
Linkname: "/../victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try writing victim/file
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim/file",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (symlink, symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "symlink",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try reading victim/hello (symlink, hardlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "hardlink",
|
||||||
|
Typeflag: tar.TypeLink,
|
||||||
|
Linkname: "loophole-victim/hello",
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ // try removing victim directory (symlink)
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeSymlink,
|
||||||
|
Linkname: "../victim",
|
||||||
|
Mode: 0755,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "loophole-victim",
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
Mode: 0644,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidSymlink", headers); err != nil {
|
||||||
|
t.Fatalf("i=%d. %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
package archive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||||
|
)
|
||||||
|
|
||||||
|
var testUntarFns = map[string]func(string, io.Reader) error{
|
||||||
|
"untar": func(dest string, r io.Reader) error {
|
||||||
|
return Untar(r, dest, nil)
|
||||||
|
},
|
||||||
|
"applylayer": func(dest string, r io.Reader) error {
|
||||||
|
return ApplyLayer(dest, ArchiveReader(r))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// testBreakout is a helper function that, within the provided `tmpdir` directory,
|
||||||
|
// creates a `victim` folder with a generated `hello` file in it.
|
||||||
|
// `untar` extracts to a directory named `dest`, the tar file created from `headers`.
|
||||||
|
//
|
||||||
|
// Here are the tested scenarios:
|
||||||
|
// - removed `victim` folder (write)
|
||||||
|
// - removed files from `victim` folder (write)
|
||||||
|
// - new files in `victim` folder (write)
|
||||||
|
// - modified files in `victim` folder (write)
|
||||||
|
// - file in `dest` with same content as `victim/hello` (read)
|
||||||
|
//
|
||||||
|
// When using testBreakout make sure you cover one of the scenarios listed above.
|
||||||
|
func testBreakout(untarFn string, tmpdir string, headers []*tar.Header) error {
|
||||||
|
tmpdir, err := ioutil.TempDir("", tmpdir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
dest := filepath.Join(tmpdir, "dest")
|
||||||
|
if err := os.Mkdir(dest, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
victim := filepath.Join(tmpdir, "victim")
|
||||||
|
if err := os.Mkdir(victim, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hello := filepath.Join(victim, "hello")
|
||||||
|
helloData, err := time.Now().MarshalText()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(hello, helloData, 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
helloStat, err := os.Stat(hello)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
reader, writer := io.Pipe()
|
||||||
|
go func() {
|
||||||
|
t := tar.NewWriter(writer)
|
||||||
|
for _, hdr := range headers {
|
||||||
|
t.WriteHeader(hdr)
|
||||||
|
}
|
||||||
|
t.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
untar := testUntarFns[untarFn]
|
||||||
|
if untar == nil {
|
||||||
|
return fmt.Errorf("could not find untar function %q in testUntarFns", untarFn)
|
||||||
|
}
|
||||||
|
if err := untar(dest, reader); err != nil {
|
||||||
|
if _, ok := err.(breakoutError); !ok {
|
||||||
|
// If untar returns an error unrelated to an archive breakout,
|
||||||
|
// then consider this an unexpected error and abort.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Here, untar detected the breakout.
|
||||||
|
// Let's move on verifying that indeed there was no breakout.
|
||||||
|
fmt.Printf("breakoutError: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check victim folder
|
||||||
|
f, err := os.Open(victim)
|
||||||
|
if err != nil {
|
||||||
|
// codepath taken if victim folder was removed
|
||||||
|
return fmt.Errorf("archive breakout: error reading %q: %v", victim, err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
// Check contents of victim folder
|
||||||
|
//
|
||||||
|
// We are only interested in getting 2 files from the victim folder, because if all is well
|
||||||
|
// we expect only one result, the `hello` file. If there is a second result, it cannot
|
||||||
|
// hold the same name `hello` and we assume that a new file got created in the victim folder.
|
||||||
|
// That is enough to detect an archive breakout.
|
||||||
|
names, err := f.Readdirnames(2)
|
||||||
|
if err != nil {
|
||||||
|
// codepath taken if victim is not a folder
|
||||||
|
return fmt.Errorf("archive breakout: error reading directory content of %q: %v", victim, err)
|
||||||
|
}
|
||||||
|
for _, name := range names {
|
||||||
|
if name != "hello" {
|
||||||
|
// codepath taken if new file was created in victim folder
|
||||||
|
return fmt.Errorf("archive breakout: new file %q", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check victim/hello
|
||||||
|
f, err = os.Open(hello)
|
||||||
|
if err != nil {
|
||||||
|
// codepath taken if read permissions were removed
|
||||||
|
return fmt.Errorf("archive breakout: could not lstat %q: %v", hello, err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
b, err := ioutil.ReadAll(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fi, err := f.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if helloStat.IsDir() != fi.IsDir() ||
|
||||||
|
// TODO: cannot check for fi.ModTime() change
|
||||||
|
helloStat.Mode() != fi.Mode() ||
|
||||||
|
helloStat.Size() != fi.Size() ||
|
||||||
|
!bytes.Equal(helloData, b) {
|
||||||
|
// codepath taken if hello has been modified
|
||||||
|
return fmt.Errorf("archive breakout: file %q has been modified. Contents: expected=%q, got=%q. FileInfo: expected=%#v, got=%#v.", hello, helloData, b, helloStat, fi)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that nothing in dest/ has the same content as victim/hello.
|
||||||
|
// Since victim/hello was generated with time.Now(), it is safe to assume
|
||||||
|
// that any file whose content matches exactly victim/hello, managed somehow
|
||||||
|
// to access victim/hello.
|
||||||
|
return filepath.Walk(dest, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if info.IsDir() {
|
||||||
|
if err != nil {
|
||||||
|
// skip directory if error
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
// enter directory
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
// skip file if error
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
b, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
// Houston, we have a problem. Aborting (space)walk.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if bytes.Equal(helloData, b) {
|
||||||
|
return fmt.Errorf("archive breakout: file %q has been accessed via %q", hello, path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
var chrootArchiver = &archive.Archiver{Untar}
|
||||||
|
|
||||||
|
func chroot(path string) error {
|
||||||
|
if err := syscall.Chroot(path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return syscall.Chdir("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func untar() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
flag.Parse()
|
||||||
|
if err := chroot(flag.Arg(0)); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
var options *archive.TarOptions
|
||||||
|
if err := json.NewDecoder(strings.NewReader(flag.Arg(1))).Decode(&options); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
if err := archive.Unpack(os.Stdin, "/", options); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
// fully consume stdin in case it is zero padded
|
||||||
|
flush(os.Stdin)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error {
|
||||||
|
if tarArchive == nil {
|
||||||
|
return fmt.Errorf("Empty archive")
|
||||||
|
}
|
||||||
|
if options == nil {
|
||||||
|
options = &archive.TarOptions{}
|
||||||
|
}
|
||||||
|
if options.Excludes == nil {
|
||||||
|
options.Excludes = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
buf bytes.Buffer
|
||||||
|
enc = json.NewEncoder(&buf)
|
||||||
|
)
|
||||||
|
if err := enc.Encode(options); err != nil {
|
||||||
|
return fmt.Errorf("Untar json encode: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(dest); os.IsNotExist(err) {
|
||||||
|
if err := os.MkdirAll(dest, 0777); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
decompressedArchive, err := archive.DecompressStream(tarArchive)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer decompressedArchive.Close()
|
||||||
|
|
||||||
|
cmd := reexec.Command("docker-untar", dest, buf.String())
|
||||||
|
cmd.Stdin = decompressedArchive
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Untar %s %s", err, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TarUntar(src, dst string) error {
|
||||||
|
return chrootArchiver.TarUntar(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyWithTar creates a tar archive of filesystem path `src`, and
|
||||||
|
// unpacks it at filesystem path `dst`.
|
||||||
|
// The archive is streamed directly with fixed buffering and no
|
||||||
|
// intermediary disk IO.
|
||||||
|
func CopyWithTar(src, dst string) error {
|
||||||
|
return chrootArchiver.CopyWithTar(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyFileWithTar emulates the behavior of the 'cp' command-line
|
||||||
|
// for a single file. It copies a regular file from path `src` to
|
||||||
|
// path `dst`, and preserves all its metadata.
|
||||||
|
//
|
||||||
|
// If `dst` ends with a trailing slash '/', the final destination path
|
||||||
|
// will be `dst/base(src)`.
|
||||||
|
func CopyFileWithTar(src, dst string) (err error) {
|
||||||
|
return chrootArchiver.CopyFileWithTar(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UntarPath is a convenience function which looks for an archive
|
||||||
|
// at filesystem path `src`, and unpacks it at `dst`.
|
||||||
|
func UntarPath(src, dst string) error {
|
||||||
|
return chrootArchiver.UntarPath(src, dst)
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reexec.Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChrootTarUntar(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
src := filepath.Join(tmpdir, "src")
|
||||||
|
if err := os.MkdirAll(src, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(src, "lolo"), []byte("hello lolo"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
stream, err := archive.Tar(src, archive.Uncompressed)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
dest := filepath.Join(tmpdir, "src")
|
||||||
|
if err := os.MkdirAll(dest, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := Untar(stream, dest, &archive.TarOptions{Excludes: []string{"lolo"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type slowEmptyTarReader struct {
|
||||||
|
size int
|
||||||
|
offset int
|
||||||
|
chunkSize int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read is a slow reader of an empty tar (like the output of "tar c --files-from /dev/null")
|
||||||
|
func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
count := s.chunkSize
|
||||||
|
if len(p) < s.chunkSize {
|
||||||
|
count = len(p)
|
||||||
|
}
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
p[i] = 0
|
||||||
|
}
|
||||||
|
s.offset += count
|
||||||
|
if s.offset > s.size {
|
||||||
|
return count, io.EOF
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchiveFromSlowReader")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
dest := filepath.Join(tmpdir, "dest")
|
||||||
|
if err := os.MkdirAll(dest, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024}
|
||||||
|
if err := Untar(stream, dest, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyEmptyArchiveFromSlowReader")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
dest := filepath.Join(tmpdir, "dest")
|
||||||
|
if err := os.MkdirAll(dest, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024}
|
||||||
|
if err := ApplyLayer(dest, stream); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func applyLayer() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if err := chroot(flag.Arg(0)); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
// We need to be able to set any perms
|
||||||
|
oldmask := syscall.Umask(0)
|
||||||
|
defer syscall.Umask(oldmask)
|
||||||
|
tmpDir, err := ioutil.TempDir("/", "temp-docker-extract")
|
||||||
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
os.Setenv("TMPDIR", tmpDir)
|
||||||
|
err = archive.UnpackLayer("/", os.Stdin)
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
flush(os.Stdin)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApplyLayer(dest string, layer archive.ArchiveReader) error {
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
decompressed, err := archive.DecompressStream(layer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if c, ok := decompressed.(io.Closer); ok {
|
||||||
|
c.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
cmd := reexec.Command("docker-applyLayer", dest)
|
||||||
|
cmd.Stdin = decompressed
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ApplyLayer %s %s", err, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reexec.Register("docker-untar", untar)
|
||||||
|
reexec.Register("docker-applyLayer", applyLayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func fatal(err error) {
|
||||||
|
fmt.Fprint(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// flush consumes all the bytes from the reader discarding
|
||||||
|
// any errors
|
||||||
|
func flush(r io.Reader) {
|
||||||
|
io.Copy(ioutil.Discard, r)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Michael Crosby <michael@docker.com> (@crosbymichael)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// +build linux
|
||||||
|
|
||||||
|
package reexec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Command(args ...string) *exec.Cmd {
|
||||||
|
return &exec.Cmd{
|
||||||
|
Path: Self(),
|
||||||
|
Args: args,
|
||||||
|
SysProcAttr: &syscall.SysProcAttr{
|
||||||
|
Pdeathsig: syscall.SIGTERM,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// +build !linux
|
||||||
|
|
||||||
|
package reexec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Command(args ...string) *exec.Cmd {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -27,19 +27,16 @@ func Init() bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Self returns the path to the current processes binary
|
// Self returns the path to the current processes binary
|
||||||
func Self() string {
|
func Self() string {
|
||||||
name := os.Args[0]
|
name := os.Args[0]
|
||||||
|
|
||||||
if filepath.Base(name) == name {
|
if filepath.Base(name) == name {
|
||||||
if lp, err := exec.LookPath(name); err == nil {
|
if lp, err := exec.LookPath(name); err == nil {
|
||||||
name = lp
|
name = lp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
Copyright 2014 Docker, Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
Copyright (c) 2014 The Docker & Go Authors. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
Michael Crosby <michael@crosbymichael.com> (@crosbymichael)
|
Tibor Vass <teabee89@gmail.com> (@tiborvass)
|
||||||
Victor Vieux <vieux@docker.com> (@vieux)
|
Cristian Staretu <cristian.staretu@gmail.com> (@unclejack)
|
||||||
|
Tianon Gravi <admwiggin@gmail.com> (@tianon)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Package symlink implements EvalSymlinksInScope which is an extension of filepath.EvalSymlinks
|
||||||
|
from the [Go standard library](https://golang.org/pkg/path/filepath).
|
||||||
|
|
||||||
|
The code from filepath.EvalSymlinks has been adapted in fs.go.
|
||||||
|
Please read the LICENSE.BSD file that governs fs.go and LICENSE.APACHE for fs_test.go.
|
||||||
+106
-60
@@ -1,85 +1,131 @@
|
|||||||
|
// Copyright 2012 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE.BSD file.
|
||||||
|
|
||||||
|
// This code is a modified version of path/filepath/symlink.go from the Go standard library.
|
||||||
|
|
||||||
package symlink
|
package symlink
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxLoopCounter = 100
|
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an absolute path
|
||||||
|
func FollowSymlinkInScope(path, root string) (string, error) {
|
||||||
// FollowSymlink will follow an existing link and scope it to the root
|
path, err := filepath.Abs(path)
|
||||||
// path provided.
|
|
||||||
func FollowSymlinkInScope(link, root string) (string, error) {
|
|
||||||
root, err := filepath.Abs(root)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
root, err = filepath.Abs(root)
|
||||||
link, err = filepath.Abs(link)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
return evalSymlinksInScope(path, root)
|
||||||
|
}
|
||||||
|
|
||||||
if link == root {
|
// evalSymlinksInScope will evaluate symlinks in `path` within a scope `root` and return
|
||||||
return root, nil
|
// a result guaranteed to be contained within the scope `root`, at the time of the call.
|
||||||
|
// Symlinks in `root` are not evaluated and left as-is.
|
||||||
|
// Errors encountered while attempting to evaluate symlinks in path will be returned.
|
||||||
|
// Non-existing paths are valid and do not constitute an error.
|
||||||
|
// `path` has to contain `root` as a prefix, or else an error will be returned.
|
||||||
|
// Trying to break out from `root` does not constitute an error.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// If /foo/bar -> /outside,
|
||||||
|
// FollowSymlinkInScope("/foo/bar", "/foo") == "/foo/outside" instead of "/oustide"
|
||||||
|
//
|
||||||
|
// IMPORTANT: it is the caller's responsibility to call evalSymlinksInScope *after* relevant symlinks
|
||||||
|
// are created and not to create subsequently, additional symlinks that could potentially make a
|
||||||
|
// previously-safe path, unsafe. Example: if /foo/bar does not exist, evalSymlinksInScope("/foo/bar", "/foo")
|
||||||
|
// would return "/foo/bar". If one makes /foo/bar a symlink to /baz subsequently, then "/foo/bar" should
|
||||||
|
// no longer be considered safely contained in "/foo".
|
||||||
|
func evalSymlinksInScope(path, root string) (string, error) {
|
||||||
|
root = filepath.Clean(root)
|
||||||
|
if path == root {
|
||||||
|
return path, nil
|
||||||
}
|
}
|
||||||
|
if !strings.HasPrefix(path, root) {
|
||||||
if !strings.HasPrefix(filepath.Dir(link), root) {
|
return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root)
|
||||||
return "", fmt.Errorf("%s is not within %s", link, root)
|
}
|
||||||
|
const maxIter = 255
|
||||||
|
originalPath := path
|
||||||
|
// given root of "/a" and path of "/a/b/../../c" we want path to be "/b/../../c"
|
||||||
|
path = path[len(root):]
|
||||||
|
if root == string(filepath.Separator) {
|
||||||
|
path = string(filepath.Separator) + path
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(path, string(filepath.Separator)) {
|
||||||
|
return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root)
|
||||||
}
|
}
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
// consume path by taking each frontmost path element,
|
||||||
|
// expanding it if it's a symlink, and appending it to b
|
||||||
|
var b bytes.Buffer
|
||||||
|
// b here will always be considered to be the "current absolute path inside
|
||||||
|
// root" when we append paths to it, we also append a slash and use
|
||||||
|
// filepath.Clean after the loop to trim the trailing slash
|
||||||
|
for n := 0; path != ""; n++ {
|
||||||
|
if n > maxIter {
|
||||||
|
return "", errors.New("evalSymlinksInScope: too many links in " + originalPath)
|
||||||
|
}
|
||||||
|
|
||||||
prev := "/"
|
// find next path component, p
|
||||||
|
i := strings.IndexRune(path, filepath.Separator)
|
||||||
|
var p string
|
||||||
|
if i == -1 {
|
||||||
|
p, path = path, ""
|
||||||
|
} else {
|
||||||
|
p, path = path[:i], path[i+1:]
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range strings.Split(link, "/") {
|
if p == "" {
|
||||||
prev = filepath.Join(prev, p)
|
continue
|
||||||
prev = filepath.Clean(prev)
|
}
|
||||||
|
|
||||||
loopCounter := 0
|
// this takes a b.String() like "b/../" and a p like "c" and turns it
|
||||||
for {
|
// into "/b/../c" which then gets filepath.Cleaned into "/c" and then
|
||||||
loopCounter++
|
// root gets prepended and we Clean again (to remove any trailing slash
|
||||||
|
// if the first Clean gave us just "/")
|
||||||
|
cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p)
|
||||||
|
if cleanP == string(filepath.Separator) {
|
||||||
|
// never Lstat "/" itself
|
||||||
|
b.Reset()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fullP := filepath.Clean(root + cleanP)
|
||||||
|
|
||||||
if loopCounter >= maxLoopCounter {
|
fi, err := os.Lstat(fullP)
|
||||||
return "", fmt.Errorf("loopCounter reached MAX: %v", loopCounter)
|
if os.IsNotExist(err) {
|
||||||
}
|
// if p does not exist, accept it
|
||||||
|
b.WriteString(p)
|
||||||
|
b.WriteRune(filepath.Separator)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if fi.Mode()&os.ModeSymlink == 0 {
|
||||||
|
b.WriteString(p + string(filepath.Separator))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(prev, root) {
|
// it's a symlink, put it at the front of path
|
||||||
// Don't resolve symlinks outside of root. For example,
|
dest, err := os.Readlink(fullP)
|
||||||
// we don't have to check /home in the below.
|
if err != nil {
|
||||||
//
|
return "", err
|
||||||
// /home -> usr/home
|
}
|
||||||
// FollowSymlinkInScope("/home/bob/foo/bar", "/home/bob/foo")
|
if filepath.IsAbs(dest) {
|
||||||
break
|
b.Reset()
|
||||||
}
|
|
||||||
|
|
||||||
stat, err := os.Lstat(prev)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if stat.Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
||||||
dest, err := os.Readlink(prev)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.IsAbs(dest) {
|
|
||||||
prev = filepath.Join(root, dest)
|
|
||||||
} else {
|
|
||||||
prev, _ = filepath.Abs(prev)
|
|
||||||
|
|
||||||
if prev = filepath.Clean(filepath.Join(filepath.Dir(prev), dest)); len(prev) < len(root) {
|
|
||||||
prev = filepath.Join(root, filepath.Base(dest))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
path = dest + string(filepath.Separator) + path
|
||||||
}
|
}
|
||||||
return prev, nil
|
|
||||||
|
// see note above on "fullP := ..." for why this is double-cleaned and
|
||||||
|
// what's happening here
|
||||||
|
return filepath.Clean(root + filepath.Clean(string(filepath.Separator)+b.String())), nil
|
||||||
}
|
}
|
||||||
|
|||||||
+345
-64
@@ -1,121 +1,402 @@
|
|||||||
|
// Licensed under the Apache License, Version 2.0; See LICENSE.APACHE
|
||||||
|
|
||||||
package symlink
|
package symlink
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func abs(t *testing.T, p string) string {
|
type dirOrLink struct {
|
||||||
o, err := filepath.Abs(p)
|
path string
|
||||||
if err != nil {
|
target string
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkNormal(t *testing.T) {
|
func makeFs(tmpdir string, fs []dirOrLink) error {
|
||||||
link := "testdata/fs/a/d/c/data"
|
for _, s := range fs {
|
||||||
|
s.path = filepath.Join(tmpdir, s.path)
|
||||||
|
if s.target == "" {
|
||||||
|
os.MkdirAll(s.path, 0755)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(filepath.Dir(s.path), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.Symlink(s.target, s.path); err != nil && !os.IsExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
func testSymlink(tmpdir, path, expected, scope string) error {
|
||||||
|
rewrite, err := FollowSymlinkInScope(filepath.Join(tmpdir, path), filepath.Join(tmpdir, scope))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
expected, err = filepath.Abs(filepath.Join(tmpdir, expected))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if expected != rewrite {
|
||||||
|
return fmt.Errorf("Expected %q got %q", expected, rewrite)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkAbsolute(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkAbsolute")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
if expected := abs(t, "testdata/b/c/data"); expected != rewrite {
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/d/c/data", "testdata/b/c/data", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkRelativePath(t *testing.T) {
|
func TestFollowSymlinkRelativePath(t *testing.T) {
|
||||||
link := "testdata/fs/i"
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativePath")
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
if expected := abs(t, "testdata/fs/a"); expected != rewrite {
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/i", target: "a"}}); err != nil {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/i", "testdata/fs/a", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkUnderLinkedDir(t *testing.T) {
|
func TestFollowSymlinkSkipSymlinksOutsideScope(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "docker-fs-test")
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkSkipSymlinksOutsideScope")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
os.Symlink("realdir", filepath.Join(dir, "linkdir"))
|
{path: "linkdir", target: "realdir"},
|
||||||
|
{path: "linkdir/foo/bar"},
|
||||||
linkDir := filepath.Join(dir, "linkdir", "foo")
|
}); err != nil {
|
||||||
dirUnderLinkDir := filepath.Join(dir, "linkdir", "foo", "bar")
|
|
||||||
os.MkdirAll(dirUnderLinkDir, 0700)
|
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(dirUnderLinkDir, linkDir)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err := testSymlink(tmpdir, "linkdir/foo/bar", "linkdir/foo/bar", "linkdir/foo"); err != nil {
|
||||||
if rewrite != dirUnderLinkDir {
|
t.Fatal(err)
|
||||||
t.Fatalf("Expected %s got %s", dirUnderLinkDir, rewrite)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkRandomString(t *testing.T) {
|
func TestFollowSymlinkInvalidScopePathPair(t *testing.T) {
|
||||||
if _, err := FollowSymlinkInScope("toto", "testdata"); err == nil {
|
if _, err := FollowSymlinkInScope("toto", "testdata"); err == nil {
|
||||||
t.Fatal("Random string should fail but didn't")
|
t.Fatal("expected an error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkLastLink(t *testing.T) {
|
func TestFollowSymlinkLastLink(t *testing.T) {
|
||||||
link := "testdata/fs/a/d"
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkLastLink")
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
if expected := abs(t, "testdata/b"); expected != rewrite {
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/d", "testdata/b", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkRelativeLink(t *testing.T) {
|
func TestFollowSymlinkRelativeLinkChangeScope(t *testing.T) {
|
||||||
link := "testdata/fs/a/e/c/data"
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativeLinkChangeScope")
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
if expected := abs(t, "testdata/fs/b/c/data"); expected != rewrite {
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/e", target: "../b"}}); err != nil {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/e/c/data", "testdata/fs/b/c/data", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// avoid letting allowing symlink e lead us to ../b
|
||||||
|
// normalize to the "testdata/fs/a"
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/e", "testdata/fs/a/b", "testdata/fs/a"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkRelativeLinkScope(t *testing.T) {
|
func TestFollowSymlinkDeepRelativeLinkChangeScope(t *testing.T) {
|
||||||
link := "testdata/fs/a/f"
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkDeepRelativeLinkChangeScope")
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
if expected := abs(t, "testdata/test"); expected != rewrite {
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/f", target: "../../../../test"}}); err != nil {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
|
||||||
}
|
|
||||||
|
|
||||||
link = "testdata/fs/b/h"
|
|
||||||
|
|
||||||
rewrite, err = FollowSymlinkInScope(link, "testdata")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// avoid letting symlink f lead us out of the "testdata" scope
|
||||||
|
// we don't normalize because symlink f is in scope and there is no
|
||||||
|
// information leak
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/f", "testdata/test", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// avoid letting symlink f lead us out of the "testdata/fs" scope
|
||||||
|
// we don't normalize because symlink f is in scope and there is no
|
||||||
|
// information leak
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/a/f", "testdata/fs/test", "testdata/fs"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if expected := abs(t, "testdata/root"); expected != rewrite {
|
func TestFollowSymlinkRelativeLinkChain(t *testing.T) {
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativeLinkChain")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
// avoid letting symlink g (pointed at by symlink h) take out of scope
|
||||||
|
// TODO: we should probably normalize to scope here because ../[....]/root
|
||||||
|
// is out of scope and we leak information
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "testdata/fs/b/h", target: "../g"},
|
||||||
|
{path: "testdata/fs/g", target: "../../../../../../../../../../../../root"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/b/h", "testdata/root", "testdata"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkBreakoutPath(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkBreakoutPath")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
// avoid letting symlink -> ../directory/file escape from scope
|
||||||
|
// normalize to "testdata/fs/j"
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/j/k", target: "../i/a"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "testdata/fs/j/k", "testdata/fs/j/i/a", "testdata/fs/j"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkToRoot(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkToRoot")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
// make sure we don't allow escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "/"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "foo", "", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkSlashDotdot(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkSlashDotdot")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
tmpdir = filepath.Join(tmpdir, "dir", "subdir")
|
||||||
|
|
||||||
|
// make sure we don't allow escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "/../../"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "foo", "", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkDotdot(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkDotdot")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
tmpdir = filepath.Join(tmpdir, "dir", "subdir")
|
||||||
|
|
||||||
|
// make sure we stay in scope without leaking information
|
||||||
|
// this also checks for escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "../../"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "foo", "", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkRelativePath2(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativePath2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "bar/foo", target: "baz/target"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "bar/foo", "bar/baz/target", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkScopeLink(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkScopeLink")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "root2"},
|
||||||
|
{path: "root", target: "root2"},
|
||||||
|
{path: "root2/foo", target: "../bar"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/foo", "root/bar", "root"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkRootScope(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRootScope")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
expected, err := filepath.EvalSymlinks(tmpdir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rewrite, err := FollowSymlinkInScope(tmpdir, "/")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if rewrite != expected {
|
||||||
|
t.Fatalf("expected %q got %q", expected, rewrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkEmpty(t *testing.T) {
|
||||||
|
res, err := FollowSymlinkInScope("", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if res != wd {
|
||||||
|
t.Fatal("expected %q got %q", wd, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkCircular(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkCircular")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{{path: "root/foo", target: "foo"}}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/foo", "", "root"); err == nil {
|
||||||
|
t.Fatal("expected an error for foo -> foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "root/bar", target: "baz"},
|
||||||
|
{path: "root/baz", target: "../bak"},
|
||||||
|
{path: "root/bak", target: "/bar"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/foo", "", "root"); err == nil {
|
||||||
|
t.Fatal("expected an error for bar -> baz -> bak -> bar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkComplexChainWithTargetPathsContainingLinks(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkComplexChainWithTargetPathsContainingLinks")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "root2"},
|
||||||
|
{path: "root", target: "root2"},
|
||||||
|
{path: "root/a", target: "r/s"},
|
||||||
|
{path: "root/r", target: "../root/t"},
|
||||||
|
{path: "root/root/t/s/b", target: "/../u"},
|
||||||
|
{path: "root/u/c", target: "."},
|
||||||
|
{path: "root/u/x/y", target: "../v"},
|
||||||
|
{path: "root/u/v", target: "/../w"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/a/b/c/x/y/z", "root/w/z", "root"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkBreakoutNonExistent(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkBreakoutNonExistent")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "root/slash", target: "/"},
|
||||||
|
{path: "root/sym", target: "/idontexist/../slash"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/sym/file", "root/file", "root"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFollowSymlinkNoLexicalCleaning(t *testing.T) {
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkNoLexicalCleaning")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
if err := makeFs(tmpdir, []dirOrLink{
|
||||||
|
{path: "root/sym", target: "/foo/bar"},
|
||||||
|
{path: "root/hello", target: "/sym/../baz"},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := testSymlink(tmpdir, "root/hello", "root/foo/baz", "root"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
/b
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
../b
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
../../../../test
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
../g
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
../../../../../../../../../../../../root
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
a
|
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -27,8 +28,17 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrConfigFileMissing = errors.New("The Auth config file is missing")
|
ErrConfigFileMissing = errors.New("The Auth config file is missing")
|
||||||
|
IndexServerURL *url.URL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
url, err := url.Parse(INDEXSERVER)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
IndexServerURL = url
|
||||||
|
}
|
||||||
|
|
||||||
type AuthConfig struct {
|
type AuthConfig struct {
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
|
|||||||
+88
-33
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,6 +12,9 @@ import (
|
|||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// for mocking in unit tests
|
||||||
|
var lookupIP = net.LookupIP
|
||||||
|
|
||||||
// scans string for api version in the URL path. returns the trimmed hostname, if version found, string and API version.
|
// scans string for api version in the URL path. returns the trimmed hostname, if version found, string and API version.
|
||||||
func scanForApiVersion(hostname string) (string, APIVersion) {
|
func scanForApiVersion(hostname string) (string, APIVersion) {
|
||||||
var (
|
var (
|
||||||
@@ -33,9 +37,40 @@ func scanForApiVersion(hostname string) (string, APIVersion) {
|
|||||||
return hostname, DefaultAPIVersion
|
return hostname, DefaultAPIVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEndpoint(hostname string, secure bool) (*Endpoint, error) {
|
func NewEndpoint(hostname string, insecureRegistries []string) (*Endpoint, error) {
|
||||||
|
endpoint, err := newEndpoint(hostname, insecureRegistries)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try HTTPS ping to registry
|
||||||
|
endpoint.URL.Scheme = "https"
|
||||||
|
if _, err := endpoint.Ping(); err != nil {
|
||||||
|
|
||||||
|
//TODO: triggering highland build can be done there without "failing"
|
||||||
|
|
||||||
|
if endpoint.secure {
|
||||||
|
// If registry is secure and HTTPS failed, show user the error and tell them about `--insecure-registry`
|
||||||
|
// in case that's what they need. DO NOT accept unknown CA certificates, and DO NOT fallback to HTTP.
|
||||||
|
return nil, fmt.Errorf("Invalid registry endpoint %s: %v. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry %s` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/%s/ca.crt", endpoint, err, endpoint.URL.Host, endpoint.URL.Host)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If registry is insecure and HTTPS failed, fallback to HTTP.
|
||||||
|
log.Debugf("Error from registry %q marked as insecure: %v. Insecurely falling back to HTTP", endpoint, err)
|
||||||
|
endpoint.URL.Scheme = "http"
|
||||||
|
_, err2 := endpoint.Ping()
|
||||||
|
if err2 == nil {
|
||||||
|
return endpoint, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("Invalid registry endpoint %q. HTTPS attempt: %v. HTTP attempt: %v", endpoint, err, err2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return endpoint, nil
|
||||||
|
}
|
||||||
|
func newEndpoint(hostname string, insecureRegistries []string) (*Endpoint, error) {
|
||||||
var (
|
var (
|
||||||
endpoint = Endpoint{secure: secure}
|
endpoint = Endpoint{}
|
||||||
trimmedHostname string
|
trimmedHostname string
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@@ -47,30 +82,10 @@ func NewEndpoint(hostname string, secure bool) (*Endpoint, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
endpoint.secure, err = isSecure(endpoint.URL.Host, insecureRegistries)
|
||||||
// Try HTTPS ping to registry
|
if err != nil {
|
||||||
endpoint.URL.Scheme = "https"
|
return nil, err
|
||||||
if _, err := endpoint.Ping(); err != nil {
|
|
||||||
|
|
||||||
//TODO: triggering highland build can be done there without "failing"
|
|
||||||
|
|
||||||
if secure {
|
|
||||||
// If registry is secure and HTTPS failed, show user the error and tell them about `--insecure-registry`
|
|
||||||
// in case that's what they need. DO NOT accept unknown CA certificates, and DO NOT fallback to HTTP.
|
|
||||||
return nil, fmt.Errorf("Invalid registry endpoint %s: %v. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry %s` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/%s/ca.crt", endpoint, err, endpoint.URL.Host, endpoint.URL.Host)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If registry is insecure and HTTPS failed, fallback to HTTP.
|
|
||||||
log.Debugf("Error from registry %q marked as insecure: %v. Insecurely falling back to HTTP", endpoint, err)
|
|
||||||
endpoint.URL.Scheme = "http"
|
|
||||||
_, err2 := endpoint.Ping()
|
|
||||||
if err2 == nil {
|
|
||||||
return &endpoint, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("Invalid registry endpoint %q. HTTPS attempt: %v. HTTP attempt: %v", endpoint, err, err2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &endpoint, nil
|
return &endpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,18 +156,58 @@ func (e Endpoint) Ping() (RegistryInfo, error) {
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSecure returns false if the provided hostname is part of the list of insecure registries.
|
// isSecure returns false if the provided hostname is part of the list of insecure registries.
|
||||||
// Insecure registries accept HTTP and/or accept HTTPS with certificates from unknown CAs.
|
// Insecure registries accept HTTP and/or accept HTTPS with certificates from unknown CAs.
|
||||||
func IsSecure(hostname string, insecureRegistries []string) bool {
|
//
|
||||||
if hostname == IndexServerAddress() {
|
// The list of insecure registries can contain an element with CIDR notation to specify a whole subnet.
|
||||||
return true
|
// If the subnet contains one of the IPs of the registry specified by hostname, the latter is considered
|
||||||
|
// insecure.
|
||||||
|
//
|
||||||
|
// hostname should be a URL.Host (`host:port` or `host`)
|
||||||
|
func isSecure(hostname string, insecureRegistries []string) (bool, error) {
|
||||||
|
if hostname == IndexServerURL.Host {
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, h := range insecureRegistries {
|
host, _, err := net.SplitHostPort(hostname)
|
||||||
if hostname == h {
|
if err != nil {
|
||||||
return false
|
// assume hostname is of the form `host` without the port and go on.
|
||||||
|
host = hostname
|
||||||
|
}
|
||||||
|
addrs, err := lookupIP(host)
|
||||||
|
if err != nil {
|
||||||
|
ip := net.ParseIP(host)
|
||||||
|
if ip == nil {
|
||||||
|
// if resolving `host` fails, error out, since host is to be net.Dial-ed anyway
|
||||||
|
return true, fmt.Errorf("issecure: could not resolve %q: %v", host, err)
|
||||||
|
}
|
||||||
|
addrs = []net.IP{ip}
|
||||||
|
}
|
||||||
|
if len(addrs) == 0 {
|
||||||
|
return true, fmt.Errorf("issecure: could not resolve %q", host)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, addr := range addrs {
|
||||||
|
for _, r := range insecureRegistries {
|
||||||
|
// hostname matches insecure registry
|
||||||
|
if hostname == r {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// now assume a CIDR was passed to --insecure-registry
|
||||||
|
_, ipnet, err := net.ParseCIDR(r)
|
||||||
|
if err != nil {
|
||||||
|
// if could not parse it as a CIDR, even after removing
|
||||||
|
// assume it's not a CIDR and go on with the next candidate
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the addr falls in the subnet
|
||||||
|
if ipnet.Contains(addr) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package registry
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestEndpointParse(t *testing.T) {
|
||||||
|
testData := []struct {
|
||||||
|
str string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{IndexServerAddress(), IndexServerAddress()},
|
||||||
|
{"http://0.0.0.0:5000", "http://0.0.0.0:5000/v1/"},
|
||||||
|
{"0.0.0.0:5000", "https://0.0.0.0:5000/v1/"},
|
||||||
|
}
|
||||||
|
for _, td := range testData {
|
||||||
|
e, err := newEndpoint(td.str, insecureRegistries)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%q: %s", td.str, err)
|
||||||
|
}
|
||||||
|
if e == nil {
|
||||||
|
t.Logf("something's fishy, endpoint for %q is nil", td.str)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if e.String() != td.expected {
|
||||||
|
t.Errorf("expected %q, got %q", td.expected, e.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,6 @@ var (
|
|||||||
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
||||||
ErrDoesNotExist = errors.New("Image does not exist")
|
ErrDoesNotExist = errors.New("Image does not exist")
|
||||||
errLoginRequired = errors.New("Authentication is required.")
|
errLoginRequired = errors.New("Authentication is required.")
|
||||||
validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
|
||||||
validNamespace = regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
|
validNamespace = regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
|
||||||
validRepo = regexp.MustCompile(`^([a-z0-9-_.]+)$`)
|
validRepo = regexp.MustCompile(`^([a-z0-9-_.]+)$`)
|
||||||
)
|
)
|
||||||
@@ -177,7 +176,8 @@ func validateRepositoryName(repositoryName string) error {
|
|||||||
namespace = "library"
|
namespace = "library"
|
||||||
name = nameParts[0]
|
name = nameParts[0]
|
||||||
|
|
||||||
if validHex.MatchString(name) {
|
// the repository name must not be a valid image ID
|
||||||
|
if err := utils.ValidateID(name); err == nil {
|
||||||
return fmt.Errorf("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings", name)
|
return fmt.Errorf("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings", name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package registry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -19,8 +21,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testHttpServer *httptest.Server
|
testHTTPServer *httptest.Server
|
||||||
testLayers = map[string]map[string]string{
|
insecureRegistries []string
|
||||||
|
testLayers = map[string]map[string]string{
|
||||||
"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20": {
|
"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20": {
|
||||||
"json": `{"id":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20",
|
"json": `{"id":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20",
|
||||||
"comment":"test base image","created":"2013-03-23T12:53:11.10432-07:00",
|
"comment":"test base image","created":"2013-03-23T12:53:11.10432-07:00",
|
||||||
@@ -79,6 +82,11 @@ var (
|
|||||||
"latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d",
|
"latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
mockHosts = map[string][]net.IP{
|
||||||
|
"": {net.ParseIP("0.0.0.0")},
|
||||||
|
"localhost": {net.ParseIP("127.0.0.1"), net.ParseIP("::1")},
|
||||||
|
"example.com": {net.ParseIP("42.42.42.42")},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -99,7 +107,31 @@ func init() {
|
|||||||
// /v2/
|
// /v2/
|
||||||
r.HandleFunc("/v2/version", handlerGetPing).Methods("GET")
|
r.HandleFunc("/v2/version", handlerGetPing).Methods("GET")
|
||||||
|
|
||||||
testHttpServer = httptest.NewServer(handlerAccessLog(r))
|
testHTTPServer = httptest.NewServer(handlerAccessLog(r))
|
||||||
|
URL, err := url.Parse(testHTTPServer.URL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
insecureRegistries = []string{URL.Host}
|
||||||
|
|
||||||
|
// override net.LookupIP
|
||||||
|
lookupIP = func(host string) ([]net.IP, error) {
|
||||||
|
if host == "127.0.0.1" {
|
||||||
|
// I believe in future Go versions this will fail, so let's fix it later
|
||||||
|
return net.LookupIP(host)
|
||||||
|
}
|
||||||
|
for h, addrs := range mockHosts {
|
||||||
|
if host == h {
|
||||||
|
return addrs, nil
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if addr.String() == host {
|
||||||
|
return []net.IP{addr}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("lookup: no such host")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerAccessLog(handler http.Handler) http.Handler {
|
func handlerAccessLog(handler http.Handler) http.Handler {
|
||||||
@@ -111,7 +143,7 @@ func handlerAccessLog(handler http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeURL(req string) string {
|
func makeURL(req string) string {
|
||||||
return testHttpServer.URL + req
|
return testHTTPServer.URL + req
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeHeaders(w http.ResponseWriter) {
|
func writeHeaders(w http.ResponseWriter) {
|
||||||
@@ -301,7 +333,7 @@ func handlerUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlerImages(w http.ResponseWriter, r *http.Request) {
|
func handlerImages(w http.ResponseWriter, r *http.Request) {
|
||||||
u, _ := url.Parse(testHttpServer.URL)
|
u, _ := url.Parse(testHTTPServer.URL)
|
||||||
w.Header().Add("X-Docker-Endpoints", fmt.Sprintf("%s , %s ", u.Host, "test.example.com"))
|
w.Header().Add("X-Docker-Endpoints", fmt.Sprintf("%s , %s ", u.Host, "test.example.com"))
|
||||||
w.Header().Add("X-Docker-Token", fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano()))
|
w.Header().Add("X-Docker-Token", fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano()))
|
||||||
if r.Method == "PUT" {
|
if r.Method == "PUT" {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var (
|
|||||||
|
|
||||||
func spawnTestRegistrySession(t *testing.T) *Session {
|
func spawnTestRegistrySession(t *testing.T) *Session {
|
||||||
authConfig := &AuthConfig{}
|
authConfig := &AuthConfig{}
|
||||||
endpoint, err := NewEndpoint(makeURL("/v1/"), false)
|
endpoint, err := NewEndpoint(makeURL("/v1/"), insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ func spawnTestRegistrySession(t *testing.T) *Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPingRegistryEndpoint(t *testing.T) {
|
func TestPingRegistryEndpoint(t *testing.T) {
|
||||||
ep, err := NewEndpoint(makeURL("/v1/"), false)
|
ep, err := NewEndpoint(makeURL("/v1/"), insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -316,3 +316,40 @@ func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsSecure(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
addr string
|
||||||
|
insecureRegistries []string
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{IndexServerURL.Host, nil, true},
|
||||||
|
{"example.com", []string{}, true},
|
||||||
|
{"example.com", []string{"example.com"}, false},
|
||||||
|
{"localhost", []string{"localhost:5000"}, false},
|
||||||
|
{"localhost:5000", []string{"localhost:5000"}, false},
|
||||||
|
{"localhost", []string{"example.com"}, false},
|
||||||
|
{"127.0.0.1:5000", []string{"127.0.0.1:5000"}, false},
|
||||||
|
{"localhost", nil, false},
|
||||||
|
{"localhost:5000", nil, false},
|
||||||
|
{"127.0.0.1", nil, false},
|
||||||
|
{"localhost", []string{"example.com"}, false},
|
||||||
|
{"127.0.0.1", []string{"example.com"}, false},
|
||||||
|
{"example.com", nil, true},
|
||||||
|
{"example.com", []string{"example.com"}, false},
|
||||||
|
{"127.0.0.1", []string{"example.com"}, false},
|
||||||
|
{"127.0.0.1:5000", []string{"example.com"}, false},
|
||||||
|
{"example.com:5000", []string{"42.42.0.0/16"}, false},
|
||||||
|
{"example.com", []string{"42.42.0.0/16"}, false},
|
||||||
|
{"example.com:5000", []string{"42.42.42.42/8"}, false},
|
||||||
|
{"127.0.0.1:5000", []string{"127.0.0.0/8"}, false},
|
||||||
|
{"42.42.42.42:5000", []string{"42.1.1.1/8"}, false},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
// TODO: remove this once we remove localhost insecure by default
|
||||||
|
insecureRegistries := append(tt.insecureRegistries, "127.0.0.0/8")
|
||||||
|
if sec, err := isSecure(tt.addr, insecureRegistries); err != nil || sec != tt.expected {
|
||||||
|
t.Fatalf("isSecure failed for %q %v, expected %v got %v. Error: %v", tt.addr, insecureRegistries, tt.expected, sec, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-4
@@ -40,7 +40,7 @@ func (s *Service) Auth(job *engine.Job) engine.Status {
|
|||||||
job.GetenvJson("authConfig", authConfig)
|
job.GetenvJson("authConfig", authConfig)
|
||||||
|
|
||||||
if addr := authConfig.ServerAddress; addr != "" && addr != IndexServerAddress() {
|
if addr := authConfig.ServerAddress; addr != "" && addr != IndexServerAddress() {
|
||||||
endpoint, err := NewEndpoint(addr, IsSecure(addr, s.insecureRegistries))
|
endpoint, err := NewEndpoint(addr, s.insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
@@ -92,9 +92,7 @@ func (s *Service) Search(job *engine.Job) engine.Status {
|
|||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secure := IsSecure(hostname, s.insecureRegistries)
|
endpoint, err := NewEndpoint(hostname, s.insecureRegistries)
|
||||||
|
|
||||||
endpoint, err := NewEndpoint(hostname, secure)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ type Config struct {
|
|||||||
Entrypoint []string
|
Entrypoint []string
|
||||||
NetworkDisabled bool
|
NetworkDisabled bool
|
||||||
OnBuild []string
|
OnBuild []string
|
||||||
SecurityOpt []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContainerConfigFromJob(job *engine.Job) *Config {
|
func ContainerConfigFromJob(job *engine.Job) *Config {
|
||||||
@@ -56,7 +55,6 @@ func ContainerConfigFromJob(job *engine.Job) *Config {
|
|||||||
}
|
}
|
||||||
job.GetenvJson("ExposedPorts", &config.ExposedPorts)
|
job.GetenvJson("ExposedPorts", &config.ExposedPorts)
|
||||||
job.GetenvJson("Volumes", &config.Volumes)
|
job.GetenvJson("Volumes", &config.Volumes)
|
||||||
config.SecurityOpt = job.GetenvList("SecurityOpt")
|
|
||||||
if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
|
if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
|
||||||
config.PortSpecs = PortSpecs
|
config.PortSpecs = PortSpecs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ type HostConfig struct {
|
|||||||
CapAdd []string
|
CapAdd []string
|
||||||
CapDrop []string
|
CapDrop []string
|
||||||
RestartPolicy RestartPolicy
|
RestartPolicy RestartPolicy
|
||||||
|
SecurityOpt []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is used by the create command when you want to set both the
|
// This is used by the create command when you want to set both the
|
||||||
@@ -90,6 +91,7 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
|||||||
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
||||||
job.GetenvJson("Devices", &hostConfig.Devices)
|
job.GetenvJson("Devices", &hostConfig.Devices)
|
||||||
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
|
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
|
||||||
|
hostConfig.SecurityOpt = job.GetenvList("SecurityOpt")
|
||||||
if Binds := job.GetenvList("Binds"); Binds != nil {
|
if Binds := job.GetenvList("Binds"); Binds != nil {
|
||||||
hostConfig.Binds = Binds
|
hostConfig.Binds = Binds
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -256,7 +256,6 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config,
|
|||||||
Volumes: flVolumes.GetMap(),
|
Volumes: flVolumes.GetMap(),
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
WorkingDir: *flWorkingDir,
|
WorkingDir: *flWorkingDir,
|
||||||
SecurityOpt: flSecurityOpt.GetAll(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
@@ -276,6 +275,7 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config,
|
|||||||
CapAdd: flCapAdd.GetAll(),
|
CapAdd: flCapAdd.GetAll(),
|
||||||
CapDrop: flCapDrop.GetAll(),
|
CapDrop: flCapDrop.GetAll(),
|
||||||
RestartPolicy: restartPolicy,
|
RestartPolicy: restartPolicy,
|
||||||
|
SecurityOpt: flSecurityOpt.GetAll(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
|
if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
|
||||||
|
|||||||
+7
-5
@@ -31,6 +31,10 @@ type KeyValuePair struct {
|
|||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
||||||
|
)
|
||||||
|
|
||||||
// Request a given URL and return an io.Reader
|
// Request a given URL and return an io.Reader
|
||||||
func Download(url string) (resp *http.Response, err error) {
|
func Download(url string) (resp *http.Response, err error) {
|
||||||
if resp, err = http.Get(url); err != nil {
|
if resp, err = http.Get(url); err != nil {
|
||||||
@@ -190,11 +194,9 @@ func GenerateRandomID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ValidateID(id string) error {
|
func ValidateID(id string) error {
|
||||||
if id == "" {
|
if ok := validHex.MatchString(id); !ok {
|
||||||
return fmt.Errorf("Id can't be empty")
|
err := fmt.Errorf("image ID '%s' is invalid", id)
|
||||||
}
|
return err
|
||||||
if strings.Contains(id, ":") {
|
|
||||||
return fmt.Errorf("Invalid character in id: ':'")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user