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
1 changed files with 15 additions and 1 deletions

16
api.go
View File

@ -13,6 +13,7 @@ import (
"net/http"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
)
@ -974,7 +975,20 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
return e
}
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}
return httpSrv.Serve(l)