1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

API, issue 1471: Allow users belonging to the docker group to use the docker client

This commit is contained in:
Daniel Mizyrycki 2013-08-12 11:07:58 -07:00 committed by Michael Crosby
parent 1643943402
commit c015d26e96

16
api.go
View file

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strconv" "strconv"
"strings" "strings"
) )
@ -974,7 +975,20 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
return e return e
} }
if proto == "unix" { if proto == "unix" {
os.Chmod(addr, 0700) os.Chmod(addr, 0660)
groups, err := ioutil.ReadFile("/etc/group")
if err != nil {
return err
}
re := regexp.MustCompile("(^|\n)docker:.*?:([0-9]+)")
if gidMatch := re.FindStringSubmatch(string(groups)); gidMatch != nil {
gid, err := strconv.Atoi(gidMatch[2])
if err != nil {
return err
}
utils.Debugf("docker group found. gid: %d", gid)
os.Chown(addr, 0, gid)
}
} }
httpSrv := http.Server{Addr: addr, Handler: r} httpSrv := http.Server{Addr: addr, Handler: r}
return httpSrv.Serve(l) return httpSrv.Serve(l)