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

Upstream-commit: 999a8d72492c7937aa9f826406ae40158017f766
Component: engine
This commit is contained in:
Daniel Mizyrycki
2013-08-12 15:15:52 -07:00
parent 64cd837579
commit fdc7c648cb

View File

@ -15,6 +15,7 @@ import (
"net/http"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
)
@ -1086,7 +1087,25 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
return e
}
if proto == "unix" {
os.Chmod(addr, 0700)
if err := os.Chmod(addr, 0660); err != nil {
return err
}
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)
if err := os.Chown(addr, 0, gid); err != nil {
return err
}
}
}
httpSrv := http.Server{Addr: addr, Handler: r}
return httpSrv.Serve(l)