mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 21:21:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
4e9bbfa900 | ||
|
|
e6efbd6596 | ||
|
|
9fc8b7f4e1 | ||
|
|
463297ffe9 | ||
|
|
2dac82eb82 | ||
|
|
7f8cdeb18b | ||
|
|
3d287811d7 | ||
|
|
21ab75afe0 | ||
|
|
66fba7c46e | ||
|
|
ff325bcb2f | ||
|
|
cf23053eb1 | ||
|
|
8caacb18f8 | ||
|
|
7d9ccc2636 | ||
|
|
ada9ac7b13 | ||
|
|
e134f1f74a | ||
|
|
f43e77fc12 | ||
|
|
c66196a9dc | ||
|
|
c0598aced0 | ||
|
|
f9b4bfa59b | ||
|
|
c78b920e01 |
@@ -1,5 +1,39 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
#### Security
|
||||||
|
* Prevent fallback to SSL protocols < TLS 1.0 for client, daemon and registry
|
||||||
|
+ Secure HTTPS connection to registries with certificate verification and without HTTP fallback unless `--insecure-registry` is specified
|
||||||
|
|
||||||
|
#### Runtime
|
||||||
|
- Fix issue where volumes would not be shared
|
||||||
|
|
||||||
|
#### Client
|
||||||
|
- Fix issue with `--iptables=false` not automatically setting `--ip-masq=false`
|
||||||
|
- Fix docker run output to non-TTY stdout
|
||||||
|
|
||||||
|
#### Builder
|
||||||
|
- Fix escaping `$` for environment variables
|
||||||
|
- Fix issue with lowercase `onbuild` Dockerfile instruction
|
||||||
|
- Restrict envrionment variable expansion to `ENV`, `ADD`, `COPY`, `WORKDIR`, `EXPOSE`, `VOLUME` and `USER`
|
||||||
|
|
||||||
## 1.3.0 (2014-10-14)
|
## 1.3.0 (2014-10-14)
|
||||||
|
|
||||||
#### Notable features since 1.2.0
|
#### Notable features since 1.2.0
|
||||||
|
|||||||
+1
-1
@@ -78,7 +78,7 @@ RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do
|
|||||||
RUN go get code.google.com/p/go.tools/cmd/cover
|
RUN go get code.google.com/p/go.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 \
|
||||||
|
|||||||
@@ -1986,6 +1986,10 @@ func (cli *DockerCli) CmdTag(args ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) pullImage(image string) error {
|
func (cli *DockerCli) pullImage(image string) error {
|
||||||
|
return cli.pullImageCustomOut(image, cli.out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
repos, tag := parsers.ParseRepositoryTag(image)
|
repos, tag := parsers.ParseRepositoryTag(image)
|
||||||
// pull only the image tagged 'latest' if no tag was specified
|
// pull only the image tagged 'latest' if no tag was specified
|
||||||
@@ -2014,7 +2018,7 @@ func (cli *DockerCli) pullImage(image string) error {
|
|||||||
registryAuthHeader := []string{
|
registryAuthHeader := []string{
|
||||||
base64.URLEncoding.EncodeToString(buf),
|
base64.URLEncoding.EncodeToString(buf),
|
||||||
}
|
}
|
||||||
if err = cli.stream("POST", "/images/create?"+v.Encode(), nil, cli.out, map[string][]string{"X-Registry-Auth": registryAuthHeader}); err != nil {
|
if err = cli.stream("POST", "/images/create?"+v.Encode(), nil, out, map[string][]string{"X-Registry-Auth": registryAuthHeader}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -2081,7 +2085,8 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
|
|||||||
if statusCode == 404 {
|
if statusCode == 404 {
|
||||||
fmt.Fprintf(cli.err, "Unable to find image '%s' locally\n", config.Image)
|
fmt.Fprintf(cli.err, "Unable to find image '%s' locally\n", config.Image)
|
||||||
|
|
||||||
if err = cli.pullImage(config.Image); err != nil {
|
// we don't want to write to stdout anything apart from container.ID
|
||||||
|
if err = cli.pullImageCustomOut(config.Image, cli.err); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Retry
|
// Retry
|
||||||
|
|||||||
@@ -1439,6 +1439,8 @@ func ListenAndServe(proto, addr string, job *engine.Job) error {
|
|||||||
tlsConfig := &tls.Config{
|
tlsConfig := &tls.Config{
|
||||||
NextProtos: []string{"http/1.1"},
|
NextProtos: []string{"http/1.1"},
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
|
// Avoid fallback on insecure SSL protocols
|
||||||
|
MinVersion: tls.VersionTLS10,
|
||||||
}
|
}
|
||||||
if job.GetenvBool("TlsVerify") {
|
if job.GetenvBool("TlsVerify") {
|
||||||
certPool := x509.NewCertPool()
|
certPool := x509.NewCertPool()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/nat"
|
"github.com/docker/docker/nat"
|
||||||
@@ -129,7 +130,7 @@ func onbuild(b *Builder, args []string, attributes map[string]bool, original str
|
|||||||
return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", triggerInstruction)
|
return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", triggerInstruction)
|
||||||
}
|
}
|
||||||
|
|
||||||
original = strings.TrimSpace(strings.TrimLeft(original, "ONBUILD"))
|
original = regexp.MustCompile(`(?i)^\s*ONBUILD\s*`).ReplaceAllString(original, "")
|
||||||
|
|
||||||
b.Config.OnBuild = append(b.Config.OnBuild, original)
|
b.Config.OnBuild = append(b.Config.OnBuild, original)
|
||||||
return b.commit("", b.Config.Cmd, fmt.Sprintf("ONBUILD %s", original))
|
return b.commit("", b.Config.Cmd, fmt.Sprintf("ONBUILD %s", original))
|
||||||
@@ -194,7 +195,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
|
|||||||
|
|
||||||
defer func(cmd []string) { b.Config.Cmd = cmd }(cmd)
|
defer func(cmd []string) { b.Config.Cmd = cmd }(cmd)
|
||||||
|
|
||||||
log.Debugf("Command to be executed: %v", b.Config.Cmd)
|
log.Debugf("[BUILDER] Command to be executed: %v", b.Config.Cmd)
|
||||||
|
|
||||||
hit, err := b.probeCache()
|
hit, err := b.probeCache()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -233,7 +234,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
|
|||||||
func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
|
func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||||
b.Config.Cmd = handleJsonArgs(args, attributes)
|
b.Config.Cmd = handleJsonArgs(args, attributes)
|
||||||
|
|
||||||
if !attributes["json"] && len(b.Config.Entrypoint) == 0 {
|
if !attributes["json"] {
|
||||||
b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
|
b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,14 +261,14 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
|
|||||||
parsed := handleJsonArgs(args, attributes)
|
parsed := handleJsonArgs(args, attributes)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case len(parsed) == 0:
|
|
||||||
// ENTYRPOINT []
|
|
||||||
b.Config.Entrypoint = nil
|
|
||||||
case attributes["json"]:
|
case attributes["json"]:
|
||||||
// ENTRYPOINT ["echo", "hi"]
|
// ENTRYPOINT ["echo", "hi"]
|
||||||
b.Config.Entrypoint = parsed
|
b.Config.Entrypoint = parsed
|
||||||
|
case len(parsed) == 0:
|
||||||
|
// ENTRYPOINT []
|
||||||
|
b.Config.Entrypoint = nil
|
||||||
default:
|
default:
|
||||||
// ENTYRPOINT echo hi
|
// ENTRYPOINT echo hi
|
||||||
b.Config.Entrypoint = []string{"/bin/sh", "-c", parsed[0]}
|
b.Config.Entrypoint = []string{"/bin/sh", "-c", parsed[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-3
@@ -41,6 +41,17 @@ var (
|
|||||||
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Environment variable interpolation will happen on these statements only.
|
||||||
|
var replaceEnvAllowed = map[string]struct{}{
|
||||||
|
"env": {},
|
||||||
|
"add": {},
|
||||||
|
"copy": {},
|
||||||
|
"workdir": {},
|
||||||
|
"expose": {},
|
||||||
|
"volume": {},
|
||||||
|
"user": {},
|
||||||
|
}
|
||||||
|
|
||||||
var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
|
var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -149,7 +160,7 @@ func (b *Builder) Run(context io.Reader) (string, error) {
|
|||||||
b.dockerfile = ast
|
b.dockerfile = ast
|
||||||
|
|
||||||
// some initializations that would not have been supplied by the caller.
|
// some initializations that would not have been supplied by the caller.
|
||||||
b.Config = &runconfig.Config{Entrypoint: []string{}, Cmd: nil}
|
b.Config = &runconfig.Config{}
|
||||||
b.TmpContainers = map[string]struct{}{}
|
b.TmpContainers = map[string]struct{}{}
|
||||||
|
|
||||||
for i, n := range b.dockerfile.Children {
|
for i, n := range b.dockerfile.Children {
|
||||||
@@ -196,13 +207,18 @@ func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
|
|||||||
|
|
||||||
if cmd == "onbuild" {
|
if cmd == "onbuild" {
|
||||||
ast = ast.Next.Children[0]
|
ast = ast.Next.Children[0]
|
||||||
strs = append(strs, b.replaceEnv(ast.Value))
|
strs = append(strs, ast.Value)
|
||||||
msg += " " + ast.Value
|
msg += " " + ast.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
for ast.Next != nil {
|
for ast.Next != nil {
|
||||||
ast = ast.Next
|
ast = ast.Next
|
||||||
strs = append(strs, b.replaceEnv(ast.Value))
|
var str string
|
||||||
|
str = ast.Value
|
||||||
|
if _, ok := replaceEnvAllowed[cmd]; ok {
|
||||||
|
str = b.replaceEnv(ast.Value)
|
||||||
|
}
|
||||||
|
strs = append(strs, str)
|
||||||
msg += " " + ast.Value
|
msg += " " + ast.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,10 +87,11 @@ func parseLine(line string) (string, *Node, error) {
|
|||||||
|
|
||||||
if sexp.Value != "" || sexp.Next != nil || sexp.Children != nil {
|
if sexp.Value != "" || sexp.Next != nil || sexp.Children != nil {
|
||||||
node.Next = sexp
|
node.Next = sexp
|
||||||
node.Attributes = attrs
|
|
||||||
node.Original = line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.Attributes = attrs
|
||||||
|
node.Original = line
|
||||||
|
|
||||||
return "", node, nil
|
return "", node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -10,13 +10,26 @@ var (
|
|||||||
// `\$` - match literal $
|
// `\$` - match literal $
|
||||||
// `[[:alnum:]_]+` - match things like `$SOME_VAR`
|
// `[[:alnum:]_]+` - match things like `$SOME_VAR`
|
||||||
// `{[[:alnum:]_]+}` - match things like `${SOME_VAR}`
|
// `{[[:alnum:]_]+}` - match things like `${SOME_VAR}`
|
||||||
tokenEnvInterpolation = regexp.MustCompile(`(\\\\+|[^\\]|\b|\A)\$([[:alnum:]_]+|{[[:alnum:]_]+})`)
|
tokenEnvInterpolation = regexp.MustCompile(`(\\|\\\\+|[^\\]|\b|\A)\$([[:alnum:]_]+|{[[:alnum:]_]+})`)
|
||||||
// this intentionally punts on more exotic interpolations like ${SOME_VAR%suffix} and lets the shell handle those directly
|
// this intentionally punts on more exotic interpolations like ${SOME_VAR%suffix} and lets the shell handle those directly
|
||||||
)
|
)
|
||||||
|
|
||||||
// handle environment replacement. Used in dispatcher.
|
// handle environment replacement. Used in dispatcher.
|
||||||
func (b *Builder) replaceEnv(str string) string {
|
func (b *Builder) replaceEnv(str string) string {
|
||||||
for _, match := range tokenEnvInterpolation.FindAllString(str, -1) {
|
for _, match := range tokenEnvInterpolation.FindAllString(str, -1) {
|
||||||
|
idx := strings.Index(match, "\\$")
|
||||||
|
if idx != -1 {
|
||||||
|
if idx+2 >= len(match) {
|
||||||
|
str = strings.Replace(str, match, "\\$", -1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := match[:idx]
|
||||||
|
stripped := match[idx+2:]
|
||||||
|
str = strings.Replace(str, match, prefix+"$"+stripped, -1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
match = match[strings.Index(match, "$"):]
|
match = match[strings.Index(match, "$"):]
|
||||||
matchKey := strings.Trim(match, "${}")
|
matchKey := strings.Trim(match, "${}")
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/docker/docker/engine"
|
"github.com/docker/docker/engine"
|
||||||
"github.com/docker/docker/events"
|
"github.com/docker/docker/events"
|
||||||
"github.com/docker/docker/pkg/parsers/kernel"
|
"github.com/docker/docker/pkg/parsers/kernel"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Register(eng *engine.Engine) error {
|
func Register(eng *engine.Engine) error {
|
||||||
@@ -26,7 +25,8 @@ func Register(eng *engine.Engine) error {
|
|||||||
if err := eng.Register("version", dockerVersion); err != nil {
|
if err := eng.Register("version", dockerVersion); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return registry.NewService().Install(eng)
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// remote: a RESTful api for cross-docker communication
|
// remote: a RESTful api for cross-docker communication
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Config struct {
|
|||||||
BridgeIface string
|
BridgeIface string
|
||||||
BridgeIP string
|
BridgeIP string
|
||||||
FixedCIDR string
|
FixedCIDR string
|
||||||
|
InsecureRegistries []string
|
||||||
InterContainerCommunication bool
|
InterContainerCommunication bool
|
||||||
GraphDriver string
|
GraphDriver string
|
||||||
GraphOptions []string
|
GraphOptions []string
|
||||||
@@ -55,6 +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) (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")
|
||||||
@@ -66,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 {
|
||||||
|
|||||||
+7
-8
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,7 +730,7 @@ func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error)
|
|||||||
return nil, fmt.Errorf("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
|
return nil, fmt.Errorf("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
|
||||||
}
|
}
|
||||||
if !config.EnableIptables && config.EnableIpMasq {
|
if !config.EnableIptables && config.EnableIpMasq {
|
||||||
return nil, fmt.Errorf("You specified --iptables=false with --ipmasq=true. IP masquerading uses iptables to function. Please set --ipmasq to false or --iptables to true.")
|
config.EnableIpMasq = false
|
||||||
}
|
}
|
||||||
config.DisableNetwork = config.BridgeIface == disableNetworkBridge
|
config.DisableNetwork = config.BridgeIface == disableNetworkBridge
|
||||||
|
|
||||||
@@ -831,7 +830,7 @@ func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Creating repository list")
|
log.Debugf("Creating repository list")
|
||||||
repositories, err := graph.NewTagStore(path.Join(config.Root, "repositories-"+driver.String()), g, config.Mirrors)
|
repositories, err := graph.NewTagStore(path.Join(config.Root, "repositories-"+driver.String()), g, config.Mirrors, config.InsecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
return nil, fmt.Errorf("Couldn't create Tag store: %s", 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 {
|
||||||
|
|||||||
+12
-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"
|
||||||
@@ -133,6 +133,7 @@ func (container *Container) parseVolumeMountConfig() (map[string]*Mount, error)
|
|||||||
// Get the rest of the volumes
|
// Get the rest of the volumes
|
||||||
for path := range container.Config.Volumes {
|
for path := range container.Config.Volumes {
|
||||||
// Check if this is already added as a bind-mount
|
// Check if this is already added as a bind-mount
|
||||||
|
path = filepath.Clean(path)
|
||||||
if _, exists := mounts[path]; exists {
|
if _, exists := mounts[path]; exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -182,21 +183,28 @@ func parseBindMountSpec(spec string) (string, string, bool, error) {
|
|||||||
return "", "", false, fmt.Errorf("cannot bind mount volume: %s volume paths must be absolute.", path)
|
return "", "", false, fmt.Errorf("cannot bind mount volume: %s volume paths must be absolute.", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
mountToPath = filepath.Clean(mountToPath)
|
||||||
return path, mountToPath, writable, nil
|
return path, mountToPath, writable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/docker/docker/engine"
|
"github.com/docker/docker/engine"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/signal"
|
"github.com/docker/docker/pkg/signal"
|
||||||
|
"github.com/docker/docker/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CanDaemon = true
|
const CanDaemon = true
|
||||||
@@ -33,11 +34,17 @@ func mainDaemon() {
|
|||||||
}
|
}
|
||||||
eng := engine.New()
|
eng := engine.New()
|
||||||
signal.Trap(eng.Shutdown)
|
signal.Trap(eng.Shutdown)
|
||||||
|
|
||||||
// Load builtins
|
// Load builtins
|
||||||
if err := builtins.Register(eng); err != nil {
|
if err := builtins.Register(eng); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load registry service
|
||||||
|
if err := registry.NewService(daemonCfg.InsecureRegistries).Install(eng); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// load the daemon in the background so we can immediately start
|
// load the daemon in the background so we can immediately start
|
||||||
// the http api so that connections don't fail while the daemon
|
// the http api so that connections don't fail while the daemon
|
||||||
// is booting
|
// is booting
|
||||||
|
|||||||
+3
-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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -93,6 +93,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
tlsConfig.Certificates = []tls.Certificate{cert}
|
tlsConfig.Certificates = []tls.Certificate{cert}
|
||||||
}
|
}
|
||||||
|
// Avoid fallback to SSL protocols < TLS1.0
|
||||||
|
tlsConfig.MinVersion = tls.VersionTLS10
|
||||||
}
|
}
|
||||||
|
|
||||||
if *flTls || *flTlsVerify {
|
if *flTls || *flTlsVerify {
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
Executable → Regular
+1
@@ -26,6 +26,7 @@ pages:
|
|||||||
|
|
||||||
# Introduction:
|
# Introduction:
|
||||||
- ['index.md', 'About', 'Docker']
|
- ['index.md', 'About', 'Docker']
|
||||||
|
- ['release-notes.md', 'About', 'Release Notes']
|
||||||
- ['introduction/index.md', '**HIDDEN**']
|
- ['introduction/index.md', '**HIDDEN**']
|
||||||
- ['introduction/understanding-docker.md', 'About', 'Understanding Docker']
|
- ['introduction/understanding-docker.md', 'About', 'Understanding Docker']
|
||||||
|
|
||||||
|
|||||||
+1
-37
@@ -88,40 +88,4 @@ implementation, check out the [Docker User Guide](/userguide/).
|
|||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
|
|
||||||
**Version 1.3.0**
|
A summary of the changes in each release in the current series can now be found on the separate [Release Notes page](/release-notes/)
|
||||||
|
|
||||||
This version fixes a number of bugs and issues and adds new functions and other
|
|
||||||
improvements. These include:
|
|
||||||
|
|
||||||
*New command: `docker exec`*
|
|
||||||
|
|
||||||
The new `docker exec` command lets you run a process in an existing, active
|
|
||||||
container. The command has APIs for both the daemon and the client. With
|
|
||||||
`docker exec`, you'll be able to do things like add or remove devices from running containers, debug running containers, and run commands that are not
|
|
||||||
part of the container's static specification.
|
|
||||||
|
|
||||||
*New command: `docker create`*
|
|
||||||
|
|
||||||
Traditionally, the `docker run` command has been used to both create a
|
|
||||||
container and spawn a process to run it. The new `docker create` command breaks
|
|
||||||
this apart, letting you set up a container without actually starting it. This
|
|
||||||
provides more control over management of the container lifecycle, giving you the
|
|
||||||
ability to configure things like volumes or port mappings before the container
|
|
||||||
is started. For example, in a rapid-response scaling situation, you could use
|
|
||||||
`create` to prepare and stage ten containers in anticipation of heavy loads.
|
|
||||||
|
|
||||||
*New provenance features*
|
|
||||||
|
|
||||||
Official images are now signed by Docker, Inc. to improve your confidence and
|
|
||||||
security. Look for the blue ribbons on the [Docker Hub](https://hub.docker.com/).
|
|
||||||
The Docker Engine has been updated to automatically verify that a given Official
|
|
||||||
Repo has a current, valid signature. If no valid signature is detected, Docker
|
|
||||||
Engine will use a prior image.
|
|
||||||
|
|
||||||
|
|
||||||
*Other improvements & changes*
|
|
||||||
|
|
||||||
We've added a new security options flag that lets you set SELinux and AppArmor
|
|
||||||
labels and profiles. This means you'll longer have to use `docker run
|
|
||||||
--privileged on kernels that support SE Linux or AppArmor.
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ page_keywords: docker, registry, api, hub
|
|||||||
|
|
||||||
# The Docker Hub and the Registry spec
|
# The Docker Hub and the Registry spec
|
||||||
|
|
||||||
## The 3 roles
|
## The three roles
|
||||||
|
|
||||||
|
There are three major components playing a role in the Docker ecosystem.
|
||||||
|
|
||||||
### Docker Hub
|
### Docker Hub
|
||||||
|
|
||||||
@@ -21,13 +23,15 @@ The Docker Hub has different components:
|
|||||||
- Authentication service
|
- Authentication service
|
||||||
- Tokenization
|
- Tokenization
|
||||||
|
|
||||||
The Docker Hub is authoritative for those information.
|
The Docker Hub is authoritative for that information.
|
||||||
|
|
||||||
We expect that there will be only one instance of the Docker Hub, run and
|
There is only one instance of the Docker Hub, run and
|
||||||
managed by Docker Inc.
|
managed by Docker Inc.
|
||||||
|
|
||||||
### Registry
|
### Registry
|
||||||
|
|
||||||
|
The registry has the following characteristics:
|
||||||
|
|
||||||
- It stores the images and the graph for a set of repositories
|
- It stores the images and the graph for a set of repositories
|
||||||
- It does not have user accounts data
|
- It does not have user accounts data
|
||||||
- It has no notion of user accounts or authorization
|
- It has no notion of user accounts or authorization
|
||||||
@@ -37,35 +41,35 @@ managed by Docker Inc.
|
|||||||
- It doesn't have a local database
|
- It doesn't have a local database
|
||||||
- [Source Code](https://github.com/docker/docker-registry)
|
- [Source Code](https://github.com/docker/docker-registry)
|
||||||
|
|
||||||
We expect that there will be multiple registries out there. To help to
|
We expect that there will be multiple registries out there. To help you
|
||||||
grasp the context, here are some examples of registries:
|
grasp the context, here are some examples of registries:
|
||||||
|
|
||||||
- **sponsor registry**: such a registry is provided by a third-party
|
- **sponsor registry**: such a registry is provided by a third-party
|
||||||
hosting infrastructure as a convenience for their customers and the
|
hosting infrastructure as a convenience for their customers and the
|
||||||
docker community as a whole. Its costs are supported by the third
|
Docker community as a whole. Its costs are supported by the third
|
||||||
party, but the management and operation of the registry are
|
party, but the management and operation of the registry are
|
||||||
supported by dotCloud. It features read/write access, and delegates
|
supported by Docker, Inc. It features read/write access, and delegates
|
||||||
authentication and authorization to the Docker Hub.
|
authentication and authorization to the Docker Hub.
|
||||||
- **mirror registry**: such a registry is provided by a third-party
|
- **mirror registry**: such a registry is provided by a third-party
|
||||||
hosting infrastructure but is targeted at their customers only. Some
|
hosting infrastructure but is targeted at their customers only. Some
|
||||||
mechanism (unspecified to date) ensures that public images are
|
mechanism (unspecified to date) ensures that public images are
|
||||||
pulled from a sponsor registry to the mirror registry, to make sure
|
pulled from a sponsor registry to the mirror registry, to make sure
|
||||||
that the customers of the third-party provider can “docker pull”
|
that the customers of the third-party provider can `docker pull`
|
||||||
those images locally.
|
those images locally.
|
||||||
- **vendor registry**: such a registry is provided by a software
|
- **vendor registry**: such a registry is provided by a software
|
||||||
vendor, who wants to distribute docker images. It would be operated
|
vendor who wants to distribute docker images. It would be operated
|
||||||
and managed by the vendor. Only users authorized by the vendor would
|
and managed by the vendor. Only users authorized by the vendor would
|
||||||
be able to get write access. Some images would be public (accessible
|
be able to get write access. Some images would be public (accessible
|
||||||
for anyone), others private (accessible only for authorized users).
|
for anyone), others private (accessible only for authorized users).
|
||||||
Authentication and authorization would be delegated to the Docker Hub.
|
Authentication and authorization would be delegated to the Docker Hub.
|
||||||
The goal of vendor registries is to let someone do “docker pull
|
The goal of vendor registries is to let someone do `docker pull
|
||||||
basho/riak1.3” and automatically push from the vendor registry
|
basho/riak1.3` and automatically push from the vendor registry
|
||||||
(instead of a sponsor registry); i.e. get all the convenience of a
|
(instead of a sponsor registry); i.e., vendors get all the convenience of a
|
||||||
sponsor registry, while retaining control on the asset distribution.
|
sponsor registry, while retaining control on the asset distribution.
|
||||||
- **private registry**: such a registry is located behind a firewall,
|
- **private registry**: such a registry is located behind a firewall,
|
||||||
or protected by an additional security layer (HTTP authorization,
|
or protected by an additional security layer (HTTP authorization,
|
||||||
SSL client-side certificates, IP address authorization...). The
|
SSL client-side certificates, IP address authorization...). The
|
||||||
registry is operated by a private entity, outside of dotCloud's
|
registry is operated by a private entity, outside of Docker's
|
||||||
control. It can optionally delegate additional authorization to the
|
control. It can optionally delegate additional authorization to the
|
||||||
Docker Hub, but it is not mandatory.
|
Docker Hub, but it is not mandatory.
|
||||||
|
|
||||||
@@ -77,7 +81,7 @@ grasp the context, here are some examples of registries:
|
|||||||
> - local mount point;
|
> - local mount point;
|
||||||
> - remote docker addressed through SSH.
|
> - remote docker addressed through SSH.
|
||||||
|
|
||||||
The latter would only require two new commands in docker, e.g.,
|
The latter would only require two new commands in Docker, e.g.,
|
||||||
`registryget` and `registryput`,
|
`registryget` and `registryput`,
|
||||||
wrapping access to the local filesystem (and optionally doing
|
wrapping access to the local filesystem (and optionally doing
|
||||||
consistency checks). Authentication and authorization are then delegated
|
consistency checks). Authentication and authorization are then delegated
|
||||||
|
|||||||
@@ -21,30 +21,30 @@ grasp the context, here are some examples of registries:
|
|||||||
|
|
||||||
- **sponsor registry**: such a registry is provided by a third-party
|
- **sponsor registry**: such a registry is provided by a third-party
|
||||||
hosting infrastructure as a convenience for their customers and the
|
hosting infrastructure as a convenience for their customers and the
|
||||||
docker community as a whole. Its costs are supported by the third
|
Docker community as a whole. Its costs are supported by the third
|
||||||
party, but the management and operation of the registry are
|
party, but the management and operation of the registry are
|
||||||
supported by dotCloud. It features read/write access, and delegates
|
supported by Docker. It features read/write access, and delegates
|
||||||
authentication and authorization to the Index.
|
authentication and authorization to the Index.
|
||||||
- **mirror registry**: such a registry is provided by a third-party
|
- **mirror registry**: such a registry is provided by a third-party
|
||||||
hosting infrastructure but is targeted at their customers only. Some
|
hosting infrastructure but is targeted at their customers only. Some
|
||||||
mechanism (unspecified to date) ensures that public images are
|
mechanism (unspecified to date) ensures that public images are
|
||||||
pulled from a sponsor registry to the mirror registry, to make sure
|
pulled from a sponsor registry to the mirror registry, to make sure
|
||||||
that the customers of the third-party provider can “docker pull”
|
that the customers of the third-party provider can `docker pull`
|
||||||
those images locally.
|
those images locally.
|
||||||
- **vendor registry**: such a registry is provided by a software
|
- **vendor registry**: such a registry is provided by a software
|
||||||
vendor, who wants to distribute docker images. It would be operated
|
vendor, who wants to distribute Docker images. It would be operated
|
||||||
and managed by the vendor. Only users authorized by the vendor would
|
and managed by the vendor. Only users authorized by the vendor would
|
||||||
be able to get write access. Some images would be public (accessible
|
be able to get write access. Some images would be public (accessible
|
||||||
for anyone), others private (accessible only for authorized users).
|
for anyone), others private (accessible only for authorized users).
|
||||||
Authentication and authorization would be delegated to the Index.
|
Authentication and authorization would be delegated to the Index.
|
||||||
The goal of vendor registries is to let someone do “docker pull
|
The goal of vendor registries is to let someone do `docker pull
|
||||||
basho/riak1.3” and automatically push from the vendor registry
|
basho/riak1.3` and automatically push from the vendor registry
|
||||||
(instead of a sponsor registry); i.e. get all the convenience of a
|
(instead of a sponsor registry); i.e., get all the convenience of a
|
||||||
sponsor registry, while retaining control on the asset distribution.
|
sponsor registry, while retaining control on the asset distribution.
|
||||||
- **private registry**: such a registry is located behind a firewall,
|
- **private registry**: such a registry is located behind a firewall,
|
||||||
or protected by an additional security layer (HTTP authorization,
|
or protected by an additional security layer (HTTP authorization,
|
||||||
SSL client-side certificates, IP address authorization...). The
|
SSL client-side certificates, IP address authorization...). The
|
||||||
registry is operated by a private entity, outside of dotCloud's
|
registry is operated by a private entity, outside of Docker's
|
||||||
control. It can optionally delegate additional authorization to the
|
control. It can optionally delegate additional authorization to the
|
||||||
Index, but it is not mandatory.
|
Index, but it is not mandatory.
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ grasp the context, here are some examples of registries:
|
|||||||
> Mirror registries and private registries which do not use the Index
|
> Mirror registries and private registries which do not use the Index
|
||||||
> don't even need to run the registry code. They can be implemented by any
|
> don't even need to run the registry code. They can be implemented by any
|
||||||
> kind of transport implementing HTTP GET and PUT. Read-only registries
|
> kind of transport implementing HTTP GET and PUT. Read-only registries
|
||||||
> can be powered by a simple static HTTP server.
|
> can be powered by a simple static HTTPS server.
|
||||||
|
|
||||||
> **Note**:
|
> **Note**:
|
||||||
> The latter implies that while HTTP is the protocol of choice for a registry,
|
> The latter implies that while HTTP is the protocol of choice for a registry,
|
||||||
@@ -60,13 +60,20 @@ grasp the context, here are some examples of registries:
|
|||||||
>
|
>
|
||||||
> - HTTP with GET (and PUT for read-write registries);
|
> - HTTP with GET (and PUT for read-write registries);
|
||||||
> - local mount point;
|
> - local mount point;
|
||||||
> - remote docker addressed through SSH.
|
> - remote Docker addressed through SSH.
|
||||||
|
|
||||||
The latter would only require two new commands in docker, e.g.,
|
The latter would only require two new commands in Docker, e.g.,
|
||||||
`registryget` and `registryput`, wrapping access to the local filesystem
|
`registryget` and `registryput`, wrapping access to the local filesystem
|
||||||
(and optionally doing consistency checks). Authentication and authorization
|
(and optionally doing consistency checks). Authentication and authorization
|
||||||
are then delegated to SSH (e.g., with public keys).
|
are then delegated to SSH (e.g., with public keys).
|
||||||
|
|
||||||
|
> **Note**:
|
||||||
|
> Private registry servers that expose an HTTP endpoint need to be secured with
|
||||||
|
> TLS (preferably TLSv1.2, but at least TLSv1.0). Make sure to put the CA
|
||||||
|
> certificate at /etc/docker/certs.d/my.registry.com:5000/ca.crt on the Docker
|
||||||
|
> host, so that the daemon can securely access the private registry.
|
||||||
|
> Support for SSLv3 and lower is not available due to security issues.
|
||||||
|
|
||||||
The default namespace for a private repository is `library`.
|
The default namespace for a private repository is `library`.
|
||||||
|
|
||||||
# Endpoints
|
# Endpoints
|
||||||
|
|||||||
@@ -70,6 +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 (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
|
||||||
@@ -111,7 +112,12 @@ direct access to the Docker daemon - and should be secured either using the
|
|||||||
[built in https encrypted socket](/articles/https/), or by putting a secure web
|
[built in https encrypted socket](/articles/https/), or by putting a secure web
|
||||||
proxy in front of it. You can listen on port `2375` on all network interfaces
|
proxy in front of it. You can listen on port `2375` on all network interfaces
|
||||||
with `-H tcp://0.0.0.0:2375`, or on a particular network interface using its IP
|
with `-H tcp://0.0.0.0:2375`, or on a particular network interface using its IP
|
||||||
address: `-H tcp://192.168.59.103:2375`.
|
address: `-H tcp://192.168.59.103:2375`. It is conventional to use port `2375`
|
||||||
|
for un-encrypted, and port `2376` for encrypted communication with the daemon.
|
||||||
|
|
||||||
|
> **Note** If you're using an HTTPS encrypted socket, keep in mind that only TLS1.0
|
||||||
|
> and greater are supported. Protocols SSLv3 and under are not supported anymore
|
||||||
|
> for security reasons.
|
||||||
|
|
||||||
On Systemd based systems, you can communicate with the daemon via
|
On Systemd based systems, you can communicate with the daemon via
|
||||||
[systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html), use
|
[systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html), use
|
||||||
@@ -187,14 +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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,320 @@
|
|||||||
|
page_title: Docker 1.x Series Release Notes page_description: Release Notes for
|
||||||
|
Docker 1.x. page_keywords: docker, documentation, about, technology,
|
||||||
|
understanding, release
|
||||||
|
|
||||||
|
#Release Notes
|
||||||
|
|
||||||
|
##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
|
||||||
|
(2014-10-28)
|
||||||
|
|
||||||
|
This release fixes some bugs and addresses some security issues.
|
||||||
|
|
||||||
|
*Security fixes*
|
||||||
|
|
||||||
|
Patches and changes were made to address CVE-2014-5277 and CVE-2014-3566. Specifically, changes were made to:
|
||||||
|
* Prevent fallback to SSL protocols < TLS 1.0 for client, daemon and registry
|
||||||
|
* Secure HTTPS connection to registries with certificate verification and without HTTP fallback unless `--insecure-registry` is specified.
|
||||||
|
|
||||||
|
*Runtime fixes*
|
||||||
|
|
||||||
|
* Fixed issue where volumes would not be shared
|
||||||
|
|
||||||
|
*Client fixes*
|
||||||
|
|
||||||
|
* Fixed issue with `--iptables=false` not automatically setting
|
||||||
|
`--ip-masq=false`
|
||||||
|
* Fixed docker run output to non-TTY stdout
|
||||||
|
|
||||||
|
*Builder fixes*
|
||||||
|
|
||||||
|
* Fixed escaping `$` for environment variables
|
||||||
|
* Fixed issue with lowercase `onbuild` Dockerfile instruction
|
||||||
|
|
||||||
|
|
||||||
|
##Version 1.3.0
|
||||||
|
|
||||||
|
This version fixes a number of bugs and issues and adds new functions and other
|
||||||
|
improvements. The [GitHub 1.3milestone](https://github.com/docker/docker/issues?q=milestone%3A1.3.0+) has
|
||||||
|
more detailed information. Major additions and changes include:
|
||||||
|
|
||||||
|
###New Features
|
||||||
|
|
||||||
|
*New command: `docker exec`*
|
||||||
|
|
||||||
|
The new `docker exec` command lets you run a process in an existing, active
|
||||||
|
container. The command has APIs for both the daemon and the client. With `docker
|
||||||
|
exec`, you'll be able to do things like add or remove devices from running
|
||||||
|
containers, debug running containers, and run commands that are not part of the
|
||||||
|
container's static specification. Details in the [command line reference](/reference/commandline/cli/#exec).
|
||||||
|
|
||||||
|
*New command: `docker create`*
|
||||||
|
|
||||||
|
Traditionally, the `docker run` command has been used to both create a container
|
||||||
|
and spawn a process to run it. The new `docker create` command breaks this
|
||||||
|
apart, letting you set up a container without actually starting it. This
|
||||||
|
provides more control over management of the container lifecycle, giving you the
|
||||||
|
ability to configure things like volumes or port mappings before the container
|
||||||
|
is started. For example, in a rapid-response scaling situation, you could use
|
||||||
|
`create` to prepare and stage ten containers in anticipation of heavy loads.
|
||||||
|
Details in the [command line reference](/reference/commandline/cli/#create).
|
||||||
|
|
||||||
|
*Tech preview of new provenance features*
|
||||||
|
|
||||||
|
This release offers a sneak peek at new image signing capabilities that are
|
||||||
|
currently under development. Soon, these capabilities will allow any image
|
||||||
|
author to sign their images to certify they have not been tampered with. For
|
||||||
|
this release, Official images are now signed by Docker, Inc. Not only does this
|
||||||
|
demonstrate the new functionality, we hope it will improve your confidence in
|
||||||
|
the security of Official images. Look for the blue ribbons denoting signed
|
||||||
|
images on the [Docker Hub](https://hub.docker.com/). The Docker Engine has been
|
||||||
|
updated to automatically verify that a given Official Repo has a current, valid
|
||||||
|
signature. When pulling a signed image, you'll see a message stating `the image
|
||||||
|
you are pulling has been verified`. If no valid signature is detected, Docker
|
||||||
|
Engine will fall back to pulling a regular, unsigned image.
|
||||||
|
|
||||||
|
###Other improvements & changes*
|
||||||
|
|
||||||
|
* We've added a new security options flag to the `docker run` command,
|
||||||
|
`--security-opt`, that lets you set SELinux and AppArmor labels and profiles.
|
||||||
|
This means you'll no longer have to use `docker run --privileged` on kernels
|
||||||
|
that support SE Linux or AppArmor. For more information, see the [command line
|
||||||
|
reference](/reference/commandline/cli/#run).
|
||||||
|
|
||||||
|
* A new flag, `--add-host`, has been added to `docker run` that lets you add
|
||||||
|
lines to `/etc/hosts`. This allows you to specify different name resolution for
|
||||||
|
the container than it would get via DNS. For more information, see the [command
|
||||||
|
line reference](/reference/commandline/cli/#run).
|
||||||
|
|
||||||
|
* You can now set a `DOCKER_TLS_VERIFY` environment variable to secure
|
||||||
|
connections by default (rather than having to pass the `--tlsverify` flag on
|
||||||
|
every call). For more information, see the [https guide](/articles/https).
|
||||||
|
|
||||||
|
* Three security issues have been addressed in this release: [CVE-2014-5280,
|
||||||
|
CVE-2014-5270, and
|
||||||
|
CVE-2014-5282](https://groups.google.com/forum/#!msg/docker-announce/aQoVmQlcE0A/smPuBNYf8VwJ).
|
||||||
|
|
||||||
|
##Version 1.2.0
|
||||||
|
|
||||||
|
This version fixes a number of bugs and issues and adds new functions and other
|
||||||
|
improvements. These include:
|
||||||
|
|
||||||
|
###New Features
|
||||||
|
|
||||||
|
*New restart policies*
|
||||||
|
|
||||||
|
We added a `--restart flag` to `docker run` to specify a restart policy for your
|
||||||
|
container. Currently, there are three policies available:
|
||||||
|
|
||||||
|
* `no` – Do not restart the container if it dies. (default) * `on-failure` –
|
||||||
|
Restart the container if it exits with a non-zero exit code. This can also
|
||||||
|
accept an optional maximum restart count (e.g. `on-failure:5`). * `always` –
|
||||||
|
Always restart the container no matter what exit code is returned. This
|
||||||
|
deprecates the `--restart` flag on the Docker daemon.
|
||||||
|
|
||||||
|
*New flags for `docker run`: `--cap-add` and `–-cap-drop`*
|
||||||
|
|
||||||
|
In previous releases, Docker containers could either be given complete
|
||||||
|
capabilities or they could all follow a whitelist of allowed capabilities while
|
||||||
|
dropping all others. Further, using `--privileged` would grant all capabilities
|
||||||
|
inside a container, rather than applying a whitelist. This was not recommended
|
||||||
|
for production use because it’s really unsafe; it’s as if you were directly in
|
||||||
|
the host.
|
||||||
|
|
||||||
|
This release introduces two new flags for `docker run`, `--cap-add` and
|
||||||
|
`--cap-drop`, that give you fine-grain control over the specific capabilities
|
||||||
|
you want grant to a particular container.
|
||||||
|
|
||||||
|
*New `-–device` flag for `docker run`*
|
||||||
|
|
||||||
|
Previously, you could only use devices inside your containers by bind mounting
|
||||||
|
them (with `-v`) in a `--privileged` container. With this release, we introduce
|
||||||
|
the `--device flag` to `docker run` which lets you use a device without
|
||||||
|
requiring a privileged container.
|
||||||
|
|
||||||
|
*Writable `/etc/hosts`, `/etc/hostname` and `/etc/resolv.conf`*
|
||||||
|
|
||||||
|
You can now edit `/etc/hosts`, `/etc/hostname` and `/etc/resolve.conf` in a
|
||||||
|
running container. This is useful if you need to install BIND or other services
|
||||||
|
that might override one of those files.
|
||||||
|
|
||||||
|
Note, however, that changes to these files are not saved when running `docker
|
||||||
|
build` and so will not be preserved in the resulting image. The changes will
|
||||||
|
only “stick” in a running container.
|
||||||
|
|
||||||
|
*Docker proxy in a separate process*
|
||||||
|
|
||||||
|
The Docker userland proxy that routes outbound traffic to your containers now
|
||||||
|
has its own separate process (one process per connection). This greatly reduces
|
||||||
|
the load on the daemon, which increases stability and efficiency.
|
||||||
|
|
||||||
|
###Other improvements & changes
|
||||||
|
|
||||||
|
* When using `docker rm -f`, Docker now kills the container (instead of stopping
|
||||||
|
it) before removing it . If you intend to stop the container cleanly, you can
|
||||||
|
use `docker stop`.
|
||||||
|
|
||||||
|
* Added support for IPv6 addresses in `--dns`
|
||||||
|
|
||||||
|
* Added search capability in private registries
|
||||||
|
|
||||||
|
##Version 1.1.0
|
||||||
|
|
||||||
|
###New Features
|
||||||
|
|
||||||
|
*`.dockerignore` support*
|
||||||
|
|
||||||
|
You can now add a `.dockerignore` file next to your `Dockerfile` and Docker will
|
||||||
|
ignore files and directories specified in that file when sending the build
|
||||||
|
context to the daemon. Example:
|
||||||
|
https://github.com/docker/docker/blob/master/.dockerignore
|
||||||
|
|
||||||
|
*Pause containers during commit*
|
||||||
|
|
||||||
|
Doing a commit on a running container was not recommended because you could end
|
||||||
|
up with files in an inconsistent state (for example, if they were being written
|
||||||
|
during the commit). Containers are now paused when a commit is made to them. You
|
||||||
|
can disable this feature by doing a `docker commit --pause=false <container_id>`
|
||||||
|
|
||||||
|
*Tailing logs*
|
||||||
|
|
||||||
|
You can now tail the logs of a container. For example, you can get the last ten
|
||||||
|
lines of a log by using `docker logs --tail 10 <container_id>`. You can also
|
||||||
|
follow the logs of a container without having to read the whole log file with
|
||||||
|
`docker logs --tail 0 -f <container_id>`.
|
||||||
|
|
||||||
|
*Allow a tar file as context for docker build*
|
||||||
|
|
||||||
|
You can now pass a tar archive to `docker build` as context. This can be used to
|
||||||
|
automate docker builds, for example: `cat context.tar | docker build -` or
|
||||||
|
`docker run builder_image | docker build -`
|
||||||
|
|
||||||
|
*Bind mounting your whole filesystem in a container*
|
||||||
|
|
||||||
|
`/` is now allowed as source of `--volumes`. This means you can bind-mount your
|
||||||
|
whole system in a container if you need to. For example: `docker run -v
|
||||||
|
/:/my_host ubuntu:ro ls /my_host`. However, it is now forbidden to mount to /.
|
||||||
|
|
||||||
|
|
||||||
|
###Other Improvements & Changes
|
||||||
|
|
||||||
|
* Port allocation has been improved. In the previous release, Docker could
|
||||||
|
prevent you from starting a container with previously allocated ports which
|
||||||
|
seemed to be in use when in fact they were not. This has been fixed.
|
||||||
|
|
||||||
|
* A bug in `docker save` was introduced in the last release. The `docker save`
|
||||||
|
command could produce images with invalid metadata. The command now produces
|
||||||
|
images with correct metadata.
|
||||||
|
|
||||||
|
* Running `docker inspect` in a container now returns which containers it is
|
||||||
|
linked to.
|
||||||
|
|
||||||
|
* Parsing of the `docker commit` flag has improved validation, to better prevent
|
||||||
|
you from committing an image with a name such as `-m`. Image names with dashes
|
||||||
|
in them potentially conflict with command line flags.
|
||||||
|
|
||||||
|
* The API now has Improved status codes for `start` and `stop`. Trying to start
|
||||||
|
a running container will now return a 304 error.
|
||||||
|
|
||||||
|
* Performance has been improved overall. Starting the daemon is faster than in
|
||||||
|
previous releases. The daemon’s performance has also been improved when it is
|
||||||
|
working with large numbers of images and containers.
|
||||||
|
|
||||||
|
* Fixed an issue with white-spaces and multi-lines in Dockerfiles.
|
||||||
|
|
||||||
|
##Version 1.1.0
|
||||||
|
|
||||||
|
###New Features
|
||||||
|
|
||||||
|
*`.dockerignore` support*
|
||||||
|
|
||||||
|
You can now add a `.dockerignore` file next to your `Dockerfile` and Docker will
|
||||||
|
ignore files and directories specified in that file when sending the build
|
||||||
|
context to the daemon. Example:
|
||||||
|
https://github.com/dotcloud/docker/blob/master/.dockerignore
|
||||||
|
|
||||||
|
*Pause containers during commit*
|
||||||
|
|
||||||
|
Doing a commit on a running container was not recommended because you could end
|
||||||
|
up with files in an inconsistent state (for example, if they were being written
|
||||||
|
during the commit). Containers are now paused when a commit is made to them. You
|
||||||
|
can disable this feature by doing a `docker commit --pause=false <container_id>`
|
||||||
|
|
||||||
|
*Tailing logs*
|
||||||
|
|
||||||
|
You can now tail the logs of a container. For example, you can get the last ten
|
||||||
|
lines of a log by using `docker logs --tail 10 <container_id>`. You can also
|
||||||
|
follow the logs of a container without having to read the whole log file with
|
||||||
|
`docker logs --tail 0 -f <container_id>`.
|
||||||
|
|
||||||
|
*Allow a tar file as context for docker build*
|
||||||
|
|
||||||
|
You can now pass a tar archive to `docker build` as context. This can be used to
|
||||||
|
automate docker builds, for example: `cat context.tar | docker build -` or
|
||||||
|
`docker run builder_image | docker build -`
|
||||||
|
|
||||||
|
*Bind mounting your whole filesystem in a container*
|
||||||
|
|
||||||
|
`/` is now allowed as source of `--volumes`. This means you can bind-mount your
|
||||||
|
whole system in a container if you need to. For example: `docker run -v
|
||||||
|
/:/my_host ubuntu:ro ls /my_host`. However, it is now forbidden to mount to /.
|
||||||
|
|
||||||
|
|
||||||
|
###Other Improvements & Changes
|
||||||
|
|
||||||
|
* Port allocation has been improved. In the previous release, Docker could
|
||||||
|
prevent you from starting a container with previously allocated ports which
|
||||||
|
seemed to be in use when in fact they were not. This has been fixed.
|
||||||
|
|
||||||
|
* A bug in `docker save` was introduced in the last release. The `docker save`
|
||||||
|
command could produce images with invalid metadata. The command now produces
|
||||||
|
images with correct metadata.
|
||||||
|
|
||||||
|
* Running `docker inspect` in a container now returns which containers it is
|
||||||
|
linked to.
|
||||||
|
|
||||||
|
* Parsing of the `docker commit` flag has improved validation, to better prevent
|
||||||
|
you from committing an image with a name such as `-m`. Image names with dashes
|
||||||
|
in them potentially conflict with command line flags.
|
||||||
|
|
||||||
|
* The API now has Improved status codes for `start` and `stop`. Trying to start
|
||||||
|
a running container will now return a 304 error.
|
||||||
|
|
||||||
|
* Performance has been improved overall. Starting the daemon is faster than in
|
||||||
|
previous releases. The daemon’s performance has also been improved when it is
|
||||||
|
working with large numbers of images and containers.
|
||||||
|
|
||||||
|
* Fixed an issue with white-spaces and multi-lines in Dockerfiles.
|
||||||
|
|
||||||
|
##Version 1.0.0
|
||||||
|
|
||||||
|
First production-ready release. Prior development history can be found by
|
||||||
|
searching in [GitHub](https://github.com/docker/docker).
|
||||||
+2
-1
@@ -10,6 +10,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,7 +54,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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
-2
@@ -113,7 +113,7 @@ func (s *TagStore) CmdPull(job *engine.Job) engine.Status {
|
|||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint, err := registry.NewEndpoint(hostname)
|
endpoint, err := registry.NewEndpoint(hostname, s.insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
@@ -137,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
-1
@@ -214,7 +214,7 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status {
|
|||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint, err := registry.NewEndpoint(hostname)
|
endpoint, err := registry.NewEndpoint(hostname, s.insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-11
@@ -23,10 +23,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TagStore struct {
|
type TagStore struct {
|
||||||
path string
|
path string
|
||||||
graph *Graph
|
graph *Graph
|
||||||
mirrors []string
|
mirrors []string
|
||||||
Repositories map[string]Repository
|
insecureRegistries []string
|
||||||
|
Repositories map[string]Repository
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
// FIXME: move push/pull-related fields
|
// FIXME: move push/pull-related fields
|
||||||
// to a helper type
|
// to a helper type
|
||||||
@@ -54,18 +55,20 @@ func (r Repository) Contains(u Repository) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTagStore(path string, graph *Graph, mirrors []string) (*TagStore, error) {
|
func NewTagStore(path string, graph *Graph, mirrors []string, insecureRegistries []string) (*TagStore, error) {
|
||||||
abspath, err := filepath.Abs(path)
|
abspath, err := filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
store := &TagStore{
|
store := &TagStore{
|
||||||
path: abspath,
|
path: abspath,
|
||||||
graph: graph,
|
graph: graph,
|
||||||
mirrors: mirrors,
|
mirrors: mirrors,
|
||||||
Repositories: make(map[string]Repository),
|
insecureRegistries: insecureRegistries,
|
||||||
pullingPool: make(map[string]chan struct{}),
|
Repositories: make(map[string]Repository),
|
||||||
pushingPool: make(map[string]chan struct{}),
|
pullingPool: make(map[string]chan struct{}),
|
||||||
|
pushingPool: make(map[string]chan struct{}),
|
||||||
}
|
}
|
||||||
// Load the json file if it exists, otherwise create it.
|
// Load the json file if it exists, otherwise create it.
|
||||||
if err := store.reload(); os.IsNotExist(err) {
|
if err := store.reload(); os.IsNotExist(err) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func mkTestTagStore(root string, t *testing.T) *TagStore {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
store, err := NewTagStore(path.Join(root, "tags"), graph, nil)
|
store, err := NewTagStore(path.Join(root, "tags"), graph, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -270,7 +270,7 @@ EOF
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Upload keys
|
# Upload keys
|
||||||
s3cmd sync /.gnupg/ s3://$BUCKET/ubuntu/.gnupg/
|
s3cmd sync $HOME/.gnupg/ s3://$BUCKET/ubuntu/.gnupg/
|
||||||
gpg --armor --export releasedocker > bundles/$VERSION/ubuntu/gpg
|
gpg --armor --export releasedocker > bundles/$VERSION/ubuntu/gpg
|
||||||
s3cmd --acl-public put bundles/$VERSION/ubuntu/gpg s3://$BUCKET/gpg
|
s3cmd --acl-public put bundles/$VERSION/ubuntu/gpg s3://$BUCKET/gpg
|
||||||
|
|
||||||
@@ -355,8 +355,8 @@ release_test() {
|
|||||||
|
|
||||||
setup_gpg() {
|
setup_gpg() {
|
||||||
# Make sure that we have our keys
|
# Make sure that we have our keys
|
||||||
mkdir -p /.gnupg/
|
mkdir -p $HOME/.gnupg/
|
||||||
s3cmd sync s3://$BUCKET/ubuntu/.gnupg/ /.gnupg/ || true
|
s3cmd sync s3://$BUCKET/ubuntu/.gnupg/ $HOME/.gnupg/ || true
|
||||||
gpg --list-keys releasedocker >/dev/null || {
|
gpg --list-keys releasedocker >/dev/null || {
|
||||||
gpg --gen-key --batch <<EOF
|
gpg --gen-key --batch <<EOF
|
||||||
Key-Type: RSA
|
Key-Type: RSA
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -15,6 +16,396 @@ import (
|
|||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestBuildShCmdJSONEntrypoint(t *testing.T) {
|
||||||
|
name := "testbuildshcmdjsonentrypoint"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(
|
||||||
|
name,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
ENTRYPOINT ["/bin/echo"]
|
||||||
|
CMD echo test
|
||||||
|
`,
|
||||||
|
true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, _, err := runCommandWithOutput(
|
||||||
|
exec.Command(
|
||||||
|
dockerBinary,
|
||||||
|
"run",
|
||||||
|
name))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(out) != "/bin/sh -c echo test" {
|
||||||
|
t.Fatal("CMD did not contain /bin/sh -c")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - CMD should always contain /bin/sh -c when specified without JSON")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementUser(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name, `
|
||||||
|
FROM scratch
|
||||||
|
ENV user foo
|
||||||
|
USER ${user}
|
||||||
|
`, true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.User")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if res != `"foo"` {
|
||||||
|
t.Fatal("User foo from environment not in Config.User on image")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - user environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementVolume(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name, `
|
||||||
|
FROM scratch
|
||||||
|
ENV volume /quux
|
||||||
|
VOLUME ${volume}
|
||||||
|
`, true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var volumes map[string]interface{}
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(res), &volumes); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := volumes["/quux"]; !ok {
|
||||||
|
t.Fatal("Volume /quux from environment not in Config.Volumes on image")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - volume environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementExpose(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name, `
|
||||||
|
FROM scratch
|
||||||
|
ENV port 80
|
||||||
|
EXPOSE ${port}
|
||||||
|
`, true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.ExposedPorts")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var exposedPorts map[string]interface{}
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(res), &exposedPorts); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := exposedPorts["80/tcp"]; !ok {
|
||||||
|
t.Fatal("Exposed port 80 from environment not in Config.ExposedPorts on image")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - expose environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementWorkdir(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name, `
|
||||||
|
FROM busybox
|
||||||
|
ENV MYWORKDIR /work
|
||||||
|
RUN mkdir ${MYWORKDIR}
|
||||||
|
WORKDIR ${MYWORKDIR}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - workdir environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementAddCopy(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
ctx, err := fakeContext(`
|
||||||
|
FROM scratch
|
||||||
|
ENV baz foo
|
||||||
|
ENV quux bar
|
||||||
|
ENV dot .
|
||||||
|
|
||||||
|
ADD ${baz} ${dot}
|
||||||
|
COPY ${quux} ${dot}
|
||||||
|
`,
|
||||||
|
map[string]string{
|
||||||
|
"foo": "test1",
|
||||||
|
"bar": "test2",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - add/copy environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvironmentReplacementEnv(t *testing.T) {
|
||||||
|
name := "testbuildenvironmentreplacement"
|
||||||
|
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV foo foo
|
||||||
|
ENV bar ${foo}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.Env")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
envResult := []string{}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &envResult); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
found := false
|
||||||
|
|
||||||
|
for _, env := range envResult {
|
||||||
|
parts := strings.SplitN(env, "=", 2)
|
||||||
|
if parts[0] == "bar" {
|
||||||
|
found = true
|
||||||
|
if parts[1] != "foo" {
|
||||||
|
t.Fatal("Could not find replaced var for env `bar`: got %q instead of `foo`", parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
t.Fatal("Never found the `bar` env variable")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - env environment replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildHandleEscapes(t *testing.T) {
|
||||||
|
name := "testbuildhandleescapes"
|
||||||
|
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME ${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var result map[string]map[string]struct{}
|
||||||
|
|
||||||
|
res, err := inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result["bar"]; !ok {
|
||||||
|
t.Fatal("Could not find volume bar set from env foo in volumes table")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME \${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result["${FOO}"]; !ok {
|
||||||
|
t.Fatal("Could not find volume ${FOO} set from env foo in volumes table")
|
||||||
|
}
|
||||||
|
|
||||||
|
// this test in particular provides *7* backslashes and expects 6 to come back.
|
||||||
|
// Like above, the first escape is swallowed and the rest are treated as
|
||||||
|
// literals, this one is just less obvious because of all the character noise.
|
||||||
|
|
||||||
|
_, err = buildImage(name,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENV FOO bar
|
||||||
|
VOLUME \\\\\\\${FOO}
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = inspectFieldJSON(name, "Config.Volumes")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = unmarshalJSON([]byte(res), &result); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := result[`\\\\\\${FOO}`]; !ok {
|
||||||
|
t.Fatal(`Could not find volume \\\\\\${FOO} set from env foo in volumes table`)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - handle escapes")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildOnBuildLowercase(t *testing.T) {
|
||||||
|
name := "testbuildonbuildlowercase"
|
||||||
|
name2 := "testbuildonbuildlowercase2"
|
||||||
|
|
||||||
|
defer deleteImages(name, name2)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
onbuild run echo quux
|
||||||
|
`, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, out, err := buildImageWithOut(name2, fmt.Sprintf(`
|
||||||
|
FROM %s
|
||||||
|
`, name), true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(out, "quux") {
|
||||||
|
t.Fatalf("Did not receive the expected echo text, got %s", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(out, "ONBUILD ONBUILD") {
|
||||||
|
t.Fatalf("Got an ONBUILD ONBUILD error with no error: got %s", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - handle case-insensitive onbuild statement")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvEscapes(t *testing.T) {
|
||||||
|
name := "testbuildenvescapes"
|
||||||
|
defer deleteAllContainers()
|
||||||
|
defer deleteImages(name)
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
ENV TEST foo
|
||||||
|
CMD echo \$
|
||||||
|
`,
|
||||||
|
true)
|
||||||
|
|
||||||
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-t", name))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(out) != "$" {
|
||||||
|
t.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - env should handle \\$ properly")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnvOverwrite(t *testing.T) {
|
||||||
|
name := "testbuildenvoverwrite"
|
||||||
|
defer deleteAllContainers()
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
ENV TEST foo
|
||||||
|
CMD echo ${TEST}
|
||||||
|
`,
|
||||||
|
true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-e", "TEST=bar", "-t", name))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(out) != "bar" {
|
||||||
|
t.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - env should overwrite builder ENV during run")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildOnBuildForbiddenMaintainerInSourceImage(t *testing.T) {
|
func TestBuildOnBuildForbiddenMaintainerInSourceImage(t *testing.T) {
|
||||||
name := "testbuildonbuildforbiddenmaintainerinsourceimage"
|
name := "testbuildonbuildforbiddenmaintainerinsourceimage"
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
@@ -1272,6 +1663,49 @@ func TestBuildExpose(t *testing.T) {
|
|||||||
logDone("build - expose")
|
logDone("build - expose")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildEmptyEntrypointInheritance(t *testing.T) {
|
||||||
|
name := "testbuildentrypointinheritance"
|
||||||
|
name2 := "testbuildentrypointinheritance2"
|
||||||
|
defer deleteImages(name, name2)
|
||||||
|
|
||||||
|
_, err := buildImage(name,
|
||||||
|
`FROM busybox
|
||||||
|
ENTRYPOINT ["/bin/echo"]`,
|
||||||
|
true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
res, err := inspectField(name, "Config.Entrypoint")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := "[/bin/echo]"
|
||||||
|
if res != expected {
|
||||||
|
t.Fatalf("Entrypoint %s, expected %s", res, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = buildImage(name2,
|
||||||
|
fmt.Sprintf(`FROM %s
|
||||||
|
ENTRYPOINT []`, name),
|
||||||
|
true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
res, err = inspectField(name2, "Config.Entrypoint")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = "[]"
|
||||||
|
|
||||||
|
if res != expected {
|
||||||
|
t.Fatalf("Entrypoint %s, expected %s", res, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - empty entrypoint inheritance")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildEmptyEntrypoint(t *testing.T) {
|
func TestBuildEmptyEntrypoint(t *testing.T) {
|
||||||
name := "testbuildentrypoint"
|
name := "testbuildentrypoint"
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
@@ -2328,6 +2762,7 @@ func TestBuildEnvUsage(t *testing.T) {
|
|||||||
name := "testbuildenvusage"
|
name := "testbuildenvusage"
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
dockerfile := `FROM busybox
|
dockerfile := `FROM busybox
|
||||||
|
ENV HOME /root
|
||||||
ENV PATH $HOME/bin:$PATH
|
ENV PATH $HOME/bin:$PATH
|
||||||
ENV PATH /tmp:$PATH
|
ENV PATH /tmp:$PATH
|
||||||
RUN [ "$PATH" = "/tmp:$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
|
RUN [ "$PATH" = "/tmp:$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
|
||||||
|
|||||||
@@ -82,3 +82,13 @@ func TestDaemonRestartWithVolumesRefs(t *testing.T) {
|
|||||||
|
|
||||||
logDone("daemon - volume refs are restored")
|
logDone("daemon - volume refs are restored")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDaemonStartIptablesFalse(t *testing.T) {
|
||||||
|
d := NewDaemon(t)
|
||||||
|
if err := d.Start("--iptables=false"); err != nil {
|
||||||
|
t.Fatalf("we should have been able to start the daemon with passing iptables=false: %v", err)
|
||||||
|
}
|
||||||
|
d.Stop()
|
||||||
|
|
||||||
|
logDone("daemon - started daemon with iptables=false")
|
||||||
|
}
|
||||||
|
|||||||
@@ -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")
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@@ -2374,3 +2375,68 @@ func TestRunVolumesNotRecreatedOnStart(t *testing.T) {
|
|||||||
|
|
||||||
logDone("run - volumes not recreated on start")
|
logDone("run - volumes not recreated on start")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunNoOutputFromPullInStdout(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
// just run with unknown image
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "asdfsg")
|
||||||
|
stdout := bytes.NewBuffer(nil)
|
||||||
|
cmd.Stdout = stdout
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
t.Fatal("Run with unknown image should fail")
|
||||||
|
}
|
||||||
|
if stdout.Len() != 0 {
|
||||||
|
t.Fatalf("Stdout contains output from pull: %s", stdout)
|
||||||
|
}
|
||||||
|
logDone("run - no output from pull in stdout")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunVolumesCleanPaths(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
if _, err := buildImage("run_volumes_clean_paths",
|
||||||
|
`FROM busybox
|
||||||
|
VOLUME /foo/`,
|
||||||
|
true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer deleteImages("run_volumes_clean_paths")
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
|
||||||
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := inspectFieldMap("dark_helmet", "Volumes", "/foo/")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if out != "<no value>" {
|
||||||
|
t.Fatalf("Found unexpected volume entry for '/foo/' in volumes\n%q", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err = inspectFieldMap("dark_helmet", "Volumes", "/foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, volumesStoragePath) {
|
||||||
|
t.Fatalf("Volume was not defined for /foo\n%q", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err = inspectFieldMap("dark_helmet", "Volumes", "/bar/")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if out != "<no value>" {
|
||||||
|
t.Fatalf("Found unexpected volume entry for '/bar/' in volumes\n%q", out)
|
||||||
|
}
|
||||||
|
out, err = inspectFieldMap("dark_helmet", "Volumes", "/bar")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, volumesStoragePath) {
|
||||||
|
t.Fatalf("Volume was not defined for /bar\n%q", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("run - volume paths are cleaned")
|
||||||
|
}
|
||||||
|
|||||||
@@ -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")
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ var (
|
|||||||
// the private registry to use for tests
|
// the private registry to use for tests
|
||||||
privateRegistryURL = "127.0.0.1:5000"
|
privateRegistryURL = "127.0.0.1:5000"
|
||||||
|
|
||||||
execDriverPath = "/var/lib/docker/execdriver/native"
|
dockerBasePath = "/var/lib/docker"
|
||||||
volumesConfigPath = "/var/lib/docker/volumes"
|
execDriverPath = dockerBasePath + "/execdriver/native"
|
||||||
|
volumesConfigPath = dockerBasePath + "/volumes"
|
||||||
|
volumesStoragePath = dockerBasePath + "/vfs/dir"
|
||||||
|
|
||||||
workingDirectory string
|
workingDirectory string
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -507,6 +507,16 @@ func inspectFieldJSON(name, field string) (string, error) {
|
|||||||
return strings.TrimSpace(out), nil
|
return strings.TrimSpace(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inspectFieldMap(name, path, field string) (string, error) {
|
||||||
|
format := fmt.Sprintf("{{index .%s %q}}", path, field)
|
||||||
|
inspectCmd := exec.Command(dockerBinary, "inspect", "-f", format, name)
|
||||||
|
out, exitCode, err := runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
return "", fmt.Errorf("failed to inspect %s: %s", name, out)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(out), nil
|
||||||
|
}
|
||||||
|
|
||||||
func getIDByName(name string) (string, error) {
|
func getIDByName(name string) (string, error) {
|
||||||
return inspectField(name, "Id")
|
return inspectField(name, "Id")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
)
|
)
|
||||||
|
|||||||
+73
-26
@@ -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
|
||||||
}
|
}
|
||||||
@@ -412,6 +438,8 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
|
|||||||
// identity (uncompressed), gzip, bzip2, xz.
|
// identity (uncompressed), gzip, bzip2, xz.
|
||||||
// FIXME: specify behavior when target path exists vs. doesn't exist.
|
// FIXME: specify behavior when target path exists vs. doesn't exist.
|
||||||
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = &TarOptions{}
|
options = &TarOptions{}
|
||||||
}
|
}
|
||||||
@@ -449,6 +477,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 {
|
||||||
@@ -469,7 +498,11 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent symlink breakout
|
||||||
path := filepath.Join(dest, hdr.Name)
|
path := filepath.Join(dest, hdr.Name)
|
||||||
|
if !strings.HasPrefix(path, dest) {
|
||||||
|
return breakoutError(fmt.Errorf("%q is outside of %q", path, 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
|
||||||
@@ -508,45 +541,47 @@ loop:
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TarUntar is a convenience function which calls Tar and Untar, with
|
func (archiver *Archiver) TarUntar(src, dst string) error {
|
||||||
// the output of one piped into the other. If either Tar or Untar fails,
|
|
||||||
// TarUntar aborts and returns the error.
|
|
||||||
func TarUntar(src string, 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 +589,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 +648,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,6 +24,8 @@ func mkdev(major int64, minor int64) uint32 {
|
|||||||
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
||||||
// applies it to the directory `dest`.
|
// applies it to the directory `dest`.
|
||||||
func ApplyLayer(dest string, layer ArchiveReader) error {
|
func ApplyLayer(dest string, layer ArchiveReader) error {
|
||||||
|
dest = filepath.Clean(dest)
|
||||||
|
|
||||||
// We need to be able to set any perms
|
// We need to be able to set any perms
|
||||||
oldmask := syscall.Umask(0)
|
oldmask := syscall.Umask(0)
|
||||||
defer syscall.Umask(oldmask)
|
defer syscall.Umask(oldmask)
|
||||||
@@ -93,6 +95,12 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
|
|||||||
|
|
||||||
path := filepath.Join(dest, hdr.Name)
|
path := filepath.Join(dest, hdr.Name)
|
||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
|
|
||||||
|
// Prevent symlink breakout
|
||||||
|
if !strings.HasPrefix(path, dest) {
|
||||||
|
return breakoutError(fmt.Errorf("%q is outside of %q", path, dest))
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -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,90 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func untar() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if err := syscall.Chroot(flag.Arg(0)); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
if err := syscall.Chdir("/"); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
options := new(archive.TarOptions)
|
||||||
|
dec := json.NewDecoder(strings.NewReader(flag.Arg(1)))
|
||||||
|
if err := dec.Decode(options); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
if err := archive.Untar(os.Stdin, "/", options); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
chrootArchiver = &archive.Archiver{Untar}
|
||||||
|
)
|
||||||
|
|
||||||
|
func Untar(archive io.Reader, dest string, options *archive.TarOptions) error {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := reexec.Command("docker-untar", dest, buf.String())
|
||||||
|
cmd.Stdin = archive
|
||||||
|
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,44 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/reexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func applyLayer() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if err := syscall.Chroot(flag.Arg(0)); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
if err := syscall.Chdir("/"); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
tmpDir, err := ioutil.TempDir("/", "temp-docker-extract")
|
||||||
|
if err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
os.Setenv("TMPDIR", tmpDir)
|
||||||
|
if err := archive.ApplyLayer("/", os.Stdin); err != nil {
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApplyLayer(dest string, layer archive.ArchiveReader) error {
|
||||||
|
cmd := reexec.Command("docker-applyLayer", dest)
|
||||||
|
cmd.Stdin = layer
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ApplyLayer %s %s", err, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package chrootarchive
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"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)
|
||||||
|
}
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
+32
-16
@@ -12,6 +12,12 @@ const maxLoopCounter = 100
|
|||||||
|
|
||||||
// FollowSymlink will follow an existing link and scope it to the root
|
// FollowSymlink will follow an existing link and scope it to the root
|
||||||
// path provided.
|
// path provided.
|
||||||
|
// The role of this function is to return an absolute path in the root
|
||||||
|
// or normalize to the root if the symlink leads to a path which is
|
||||||
|
// outside of the root.
|
||||||
|
// Errors encountered while attempting to follow the symlink in path
|
||||||
|
// will be reported.
|
||||||
|
// Normalizations to the root don't constitute errors.
|
||||||
func FollowSymlinkInScope(link, root string) (string, error) {
|
func FollowSymlinkInScope(link, root string) (string, error) {
|
||||||
root, err := filepath.Abs(root)
|
root, err := filepath.Abs(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -35,7 +41,6 @@ func FollowSymlinkInScope(link, root string) (string, error) {
|
|||||||
|
|
||||||
for _, p := range strings.Split(link, "/") {
|
for _, p := range strings.Split(link, "/") {
|
||||||
prev = filepath.Join(prev, p)
|
prev = filepath.Join(prev, p)
|
||||||
prev = filepath.Clean(prev)
|
|
||||||
|
|
||||||
loopCounter := 0
|
loopCounter := 0
|
||||||
for {
|
for {
|
||||||
@@ -61,25 +66,36 @@ func FollowSymlinkInScope(link, root string) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if stat.Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
||||||
dest, err := os.Readlink(prev)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.IsAbs(dest) {
|
// let's break if we're not dealing with a symlink
|
||||||
prev = filepath.Join(root, dest)
|
if stat.Mode()&os.ModeSymlink != os.ModeSymlink {
|
||||||
} 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
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process the symlink
|
||||||
|
dest, err := os.Readlink(prev)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if path.IsAbs(dest) {
|
||||||
|
prev = filepath.Join(root, dest)
|
||||||
|
} else {
|
||||||
|
prev, _ = filepath.Abs(prev)
|
||||||
|
|
||||||
|
dir := filepath.Dir(prev)
|
||||||
|
prev = filepath.Join(dir, dest)
|
||||||
|
if dir == root && !strings.HasPrefix(prev, root) {
|
||||||
|
prev = root
|
||||||
|
}
|
||||||
|
if len(prev) < len(root) || (len(prev) == len(root) && prev != root) {
|
||||||
|
prev = filepath.Join(root, filepath.Base(dest))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if prev == "/" {
|
||||||
|
prev = root
|
||||||
|
}
|
||||||
return prev, nil
|
return prev, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+139
-12
@@ -46,6 +46,7 @@ func TestFollowSymLinkUnderLinkedDir(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
|
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
|
||||||
os.Symlink("realdir", filepath.Join(dir, "linkdir"))
|
os.Symlink("realdir", filepath.Join(dir, "linkdir"))
|
||||||
@@ -97,25 +98,151 @@ func TestFollowSymLinkRelativeLink(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFollowSymLinkRelativeLinkScope(t *testing.T) {
|
func TestFollowSymLinkRelativeLinkScope(t *testing.T) {
|
||||||
link := "testdata/fs/a/f"
|
// 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
|
||||||
|
{
|
||||||
|
link := "testdata/fs/a/f"
|
||||||
|
|
||||||
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := abs(t, "testdata/test"); expected != rewrite {
|
||||||
|
t.Fatalf("Expected %s got %s", expected, rewrite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if expected := abs(t, "testdata/test"); expected != rewrite {
|
// avoid letting symlink f lead us out of the "testdata/fs" scope
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
// we don't normalize because symlink f is in scope and there is no
|
||||||
|
// information leak
|
||||||
|
{
|
||||||
|
link := "testdata/fs/a/f"
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(link, "testdata/fs")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := abs(t, "testdata/fs/test"); expected != rewrite {
|
||||||
|
t.Fatalf("Expected %s got %s", expected, rewrite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
link = "testdata/fs/b/h"
|
// 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
|
||||||
|
{
|
||||||
|
link := "testdata/fs/b/h"
|
||||||
|
|
||||||
rewrite, err = FollowSymlinkInScope(link, "testdata")
|
rewrite, err := FollowSymlinkInScope(link, "testdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := abs(t, "testdata/root"); expected != rewrite {
|
||||||
|
t.Fatalf("Expected %s got %s", expected, rewrite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if expected := abs(t, "testdata/root"); expected != rewrite {
|
// avoid letting allowing symlink e lead us to ../b
|
||||||
t.Fatalf("Expected %s got %s", expected, rewrite)
|
// normalize to the "testdata/fs/a"
|
||||||
|
{
|
||||||
|
link := "testdata/fs/a/e"
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(link, "testdata/fs/a")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := abs(t, "testdata/fs/a"); expected != rewrite {
|
||||||
|
t.Fatalf("Expected %s got %s", expected, rewrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// avoid letting symlink -> ../directory/file escape from scope
|
||||||
|
// normalize to "testdata/fs/j"
|
||||||
|
{
|
||||||
|
link := "testdata/fs/j/k"
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(link, "testdata/fs/j")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := abs(t, "testdata/fs/j"); expected != rewrite {
|
||||||
|
t.Fatalf("Expected %s got %s", expected, rewrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we don't allow escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
{
|
||||||
|
dir, err := ioutil.TempDir("", "docker-fs-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
linkFile := filepath.Join(dir, "foo")
|
||||||
|
os.Mkdir(filepath.Join(dir, ""), 0700)
|
||||||
|
os.Symlink("/", linkFile)
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(linkFile, dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rewrite != dir {
|
||||||
|
t.Fatalf("Expected %s got %s", dir, rewrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we don't allow escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
{
|
||||||
|
dir, err := ioutil.TempDir("", "docker-fs-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
linkFile := filepath.Join(dir, "foo")
|
||||||
|
os.Mkdir(filepath.Join(dir, ""), 0700)
|
||||||
|
os.Symlink("/../../", linkFile)
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(linkFile, dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rewrite != dir {
|
||||||
|
t.Fatalf("Expected %s got %s", dir, rewrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure we stay in scope without leaking information
|
||||||
|
// this also checks for escaping to /
|
||||||
|
// normalize to dir
|
||||||
|
{
|
||||||
|
dir, err := ioutil.TempDir("", "docker-fs-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
linkFile := filepath.Join(dir, "foo")
|
||||||
|
os.Mkdir(filepath.Join(dir, ""), 0700)
|
||||||
|
os.Symlink("../../", linkFile)
|
||||||
|
|
||||||
|
rewrite, err := FollowSymlinkInScope(linkFile, dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rewrite != dir {
|
||||||
|
t.Fatalf("Expected %s got %s", dir, rewrite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../i/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"`
|
||||||
|
|||||||
+98
-14
@@ -2,9 +2,9 @@ package registry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,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 (
|
||||||
@@ -34,9 +37,40 @@ func scanForApiVersion(hostname string) (string, APIVersion) {
|
|||||||
return hostname, DefaultAPIVersion
|
return hostname, DefaultAPIVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEndpoint(hostname string) (*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
|
endpoint = Endpoint{}
|
||||||
trimmedHostname string
|
trimmedHostname string
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@@ -48,23 +82,17 @@ func NewEndpoint(hostname string) (*Endpoint, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
endpoint.secure, err = isSecure(endpoint.URL.Host, insecureRegistries)
|
||||||
endpoint.URL.Scheme = "https"
|
if err != nil {
|
||||||
if _, err := endpoint.Ping(); err != nil {
|
return nil, err
|
||||||
log.Debugf("Registry %s does not work (%s), falling back to http", endpoint, err)
|
|
||||||
// TODO: Check if http fallback is enabled
|
|
||||||
endpoint.URL.Scheme = "http"
|
|
||||||
if _, err = endpoint.Ping(); err != nil {
|
|
||||||
return nil, errors.New("Invalid Registry endpoint: " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &endpoint, nil
|
return &endpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Endpoint struct {
|
type Endpoint struct {
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
Version APIVersion
|
Version APIVersion
|
||||||
|
secure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the formated URL for the root of this registry Endpoint
|
// Get the formated URL for the root of this registry Endpoint
|
||||||
@@ -88,7 +116,7 @@ func (e Endpoint) Ping() (RegistryInfo, error) {
|
|||||||
return RegistryInfo{Standalone: false}, err
|
return RegistryInfo{Standalone: false}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, _, err := doRequest(req, nil, ConnectTimeout)
|
resp, _, err := doRequest(req, nil, ConnectTimeout, e.secure)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RegistryInfo{Standalone: false}, err
|
return RegistryInfo{Standalone: false}, err
|
||||||
}
|
}
|
||||||
@@ -127,3 +155,59 @@ func (e Endpoint) Ping() (RegistryInfo, error) {
|
|||||||
log.Debugf("RegistryInfo.Standalone: %t", info.Standalone)
|
log.Debugf("RegistryInfo.Standalone: %t", info.Standalone)
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// The list of insecure registries can contain an element with CIDR notation to specify a whole subnet.
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
host, _, err := net.SplitHostPort(hostname)
|
||||||
|
if err != nil {
|
||||||
|
// 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, 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+61
-45
@@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,13 +36,21 @@ const (
|
|||||||
ConnectTimeout
|
ConnectTimeout
|
||||||
)
|
)
|
||||||
|
|
||||||
func newClient(jar http.CookieJar, roots *x509.CertPool, cert *tls.Certificate, timeout TimeoutType) *http.Client {
|
func newClient(jar http.CookieJar, roots *x509.CertPool, cert *tls.Certificate, timeout TimeoutType, secure bool) *http.Client {
|
||||||
tlsConfig := tls.Config{RootCAs: roots}
|
tlsConfig := tls.Config{
|
||||||
|
RootCAs: roots,
|
||||||
|
// Avoid fallback to SSL protocols < TLS1.0
|
||||||
|
MinVersion: tls.VersionTLS10,
|
||||||
|
}
|
||||||
|
|
||||||
if cert != nil {
|
if cert != nil {
|
||||||
tlsConfig.Certificates = append(tlsConfig.Certificates, *cert)
|
tlsConfig.Certificates = append(tlsConfig.Certificates, *cert)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !secure {
|
||||||
|
tlsConfig.InsecureSkipVerify = true
|
||||||
|
}
|
||||||
|
|
||||||
httpTransport := &http.Transport{
|
httpTransport := &http.Transport{
|
||||||
DisableKeepAlives: true,
|
DisableKeepAlives: true,
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: http.ProxyFromEnvironment,
|
||||||
@@ -78,69 +87,76 @@ func newClient(jar http.CookieJar, roots *x509.CertPool, cert *tls.Certificate,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType) (*http.Response, *http.Client, error) {
|
func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType, secure bool) (*http.Response, *http.Client, error) {
|
||||||
hasFile := func(files []os.FileInfo, name string) bool {
|
|
||||||
for _, f := range files {
|
|
||||||
if f.Name() == name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
hostDir := path.Join("/etc/docker/certs.d", req.URL.Host)
|
|
||||||
fs, err := ioutil.ReadDir(hostDir)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pool *x509.CertPool
|
pool *x509.CertPool
|
||||||
certs []*tls.Certificate
|
certs []*tls.Certificate
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, f := range fs {
|
if secure && req.URL.Scheme == "https" {
|
||||||
if strings.HasSuffix(f.Name(), ".crt") {
|
hasFile := func(files []os.FileInfo, name string) bool {
|
||||||
if pool == nil {
|
for _, f := range files {
|
||||||
pool = x509.NewCertPool()
|
if f.Name() == name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(path.Join(hostDir, f.Name()))
|
return false
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
pool.AppendCertsFromPEM(data)
|
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(f.Name(), ".cert") {
|
|
||||||
certName := f.Name()
|
hostDir := path.Join("/etc/docker/certs.d", req.URL.Host)
|
||||||
keyName := certName[:len(certName)-5] + ".key"
|
log.Debugf("hostDir: %s", hostDir)
|
||||||
if !hasFile(fs, keyName) {
|
fs, err := ioutil.ReadDir(hostDir)
|
||||||
return nil, nil, fmt.Errorf("Missing key %s for certificate %s", keyName, certName)
|
if err != nil && !os.IsNotExist(err) {
|
||||||
}
|
return nil, nil, err
|
||||||
cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName))
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
certs = append(certs, &cert)
|
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(f.Name(), ".key") {
|
|
||||||
keyName := f.Name()
|
for _, f := range fs {
|
||||||
certName := keyName[:len(keyName)-4] + ".cert"
|
if strings.HasSuffix(f.Name(), ".crt") {
|
||||||
if !hasFile(fs, certName) {
|
if pool == nil {
|
||||||
return nil, nil, fmt.Errorf("Missing certificate %s for key %s", certName, keyName)
|
pool = x509.NewCertPool()
|
||||||
|
}
|
||||||
|
log.Debugf("crt: %s", hostDir+"/"+f.Name())
|
||||||
|
data, err := ioutil.ReadFile(path.Join(hostDir, f.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
pool.AppendCertsFromPEM(data)
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(f.Name(), ".cert") {
|
||||||
|
certName := f.Name()
|
||||||
|
keyName := certName[:len(certName)-5] + ".key"
|
||||||
|
log.Debugf("cert: %s", hostDir+"/"+f.Name())
|
||||||
|
if !hasFile(fs, keyName) {
|
||||||
|
return nil, nil, fmt.Errorf("Missing key %s for certificate %s", keyName, certName)
|
||||||
|
}
|
||||||
|
cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
certs = append(certs, &cert)
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(f.Name(), ".key") {
|
||||||
|
keyName := f.Name()
|
||||||
|
certName := keyName[:len(keyName)-4] + ".cert"
|
||||||
|
log.Debugf("key: %s", hostDir+"/"+f.Name())
|
||||||
|
if !hasFile(fs, certName) {
|
||||||
|
return nil, nil, fmt.Errorf("Missing certificate %s for key %s", certName, keyName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(certs) == 0 {
|
if len(certs) == 0 {
|
||||||
client := newClient(jar, pool, nil, timeout)
|
client := newClient(jar, pool, nil, timeout, secure)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return res, client, nil
|
return res, client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, cert := range certs {
|
for i, cert := range certs {
|
||||||
client := newClient(jar, pool, cert, timeout)
|
client := newClient(jar, pool, cert, timeout, secure)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
// If this is the last cert, otherwise, continue to next cert if 403 or 5xx
|
// If this is the last cert, otherwise, continue to next cert if 403 or 5xx
|
||||||
if i == len(certs)-1 || err == nil && res.StatusCode != 403 && res.StatusCode < 500 {
|
if i == len(certs)-1 || err == nil && res.StatusCode != 403 && res.StatusCode < 500 {
|
||||||
|
|||||||
@@ -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/"))
|
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/"))
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+12
-9
@@ -13,12 +13,15 @@ import (
|
|||||||
// 'pull': Download images from any registry (TODO)
|
// 'pull': Download images from any registry (TODO)
|
||||||
// 'push': Upload images to any registry (TODO)
|
// 'push': Upload images to any registry (TODO)
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
insecureRegistries []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns a new instance of Service ready to be
|
// NewService returns a new instance of Service ready to be
|
||||||
// installed no an engine.
|
// installed no an engine.
|
||||||
func NewService() *Service {
|
func NewService(insecureRegistries []string) *Service {
|
||||||
return &Service{}
|
return &Service{
|
||||||
|
insecureRegistries: insecureRegistries,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install installs registry capabilities to eng.
|
// Install installs registry capabilities to eng.
|
||||||
@@ -32,15 +35,12 @@ func (s *Service) Install(eng *engine.Engine) error {
|
|||||||
// and returns OK if authentication was sucessful.
|
// and returns OK if authentication was sucessful.
|
||||||
// It can be used to verify the validity of a client's credentials.
|
// It can be used to verify the validity of a client's credentials.
|
||||||
func (s *Service) Auth(job *engine.Job) engine.Status {
|
func (s *Service) Auth(job *engine.Job) engine.Status {
|
||||||
var (
|
var authConfig = new(AuthConfig)
|
||||||
err error
|
|
||||||
authConfig = &AuthConfig{}
|
|
||||||
)
|
|
||||||
|
|
||||||
job.GetenvJson("authConfig", authConfig)
|
job.GetenvJson("authConfig", authConfig)
|
||||||
// TODO: this is only done here because auth and registry need to be merged into one pkg
|
|
||||||
if addr := authConfig.ServerAddress; addr != "" && addr != IndexServerAddress() {
|
if addr := authConfig.ServerAddress; addr != "" && addr != IndexServerAddress() {
|
||||||
endpoint, err := NewEndpoint(addr)
|
endpoint, err := NewEndpoint(addr, s.insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
@@ -49,11 +49,13 @@ func (s *Service) Auth(job *engine.Job) engine.Status {
|
|||||||
}
|
}
|
||||||
authConfig.ServerAddress = endpoint.String()
|
authConfig.ServerAddress = endpoint.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := Login(authConfig, HTTPRequestFactory(nil))
|
status, err := Login(authConfig, HTTPRequestFactory(nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
job.Printf("%s\n", status)
|
job.Printf("%s\n", status)
|
||||||
|
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +91,8 @@ func (s *Service) Search(job *engine.Job) engine.Status {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
endpoint, err := NewEndpoint(hostname)
|
|
||||||
|
endpoint, err := NewEndpoint(hostname, s.insecureRegistries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ func NewSession(authConfig *AuthConfig, factory *utils.HTTPRequestFactory, endpo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Session) doRequest(req *http.Request) (*http.Response, *http.Client, error) {
|
func (r *Session) doRequest(req *http.Request) (*http.Response, *http.Client, error) {
|
||||||
return doRequest(req, r.jar, r.timeout)
|
return doRequest(req, r.jar, r.timeout, r.indexEndpoint.secure)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the history of a given image from the Registry.
|
// Retrieve the history of a given image from the Registry.
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -88,7 +88,10 @@ func Merge(userConf, imageConf *Config) error {
|
|||||||
if len(userConf.Cmd) == 0 {
|
if len(userConf.Cmd) == 0 {
|
||||||
userConf.Cmd = imageConf.Cmd
|
userConf.Cmd = imageConf.Cmd
|
||||||
}
|
}
|
||||||
userConf.Entrypoint = imageConf.Entrypoint
|
|
||||||
|
if userConf.Entrypoint == nil {
|
||||||
|
userConf.Entrypoint = imageConf.Entrypoint
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if userConf.WorkingDir == "" {
|
if userConf.WorkingDir == "" {
|
||||||
userConf.WorkingDir = imageConf.WorkingDir
|
userConf.WorkingDir = imageConf.WorkingDir
|
||||||
|
|||||||
+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 {
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func (r *Repository) newVolume(path string, writable bool) (*Volume, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
|
||||||
path, err = filepath.EvalSymlinks(path)
|
path, err = filepath.EvalSymlinks(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -126,7 +127,7 @@ func (r *Repository) get(path string) *Volume {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return r.volumes[path]
|
return r.volumes[filepath.Clean(path)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) Add(volume *Volume) error {
|
func (r *Repository) Add(volume *Volume) error {
|
||||||
@@ -160,7 +161,7 @@ func (r *Repository) Delete(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
volume := r.get(path)
|
volume := r.get(filepath.Clean(path))
|
||||||
if volume == nil {
|
if volume == nil {
|
||||||
return fmt.Errorf("Volume %s does not exist", path)
|
return fmt.Errorf("Volume %s does not exist", path)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user