From c015d26e96e1f6ebee2a577468c747bf3d2aeeb9 Mon Sep 17 00:00:00 2001 From: Daniel Mizyrycki Date: Mon, 12 Aug 2013 11:07:58 -0700 Subject: [PATCH] API, issue 1471: Allow users belonging to the docker group to use the docker client --- api.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 221cabed56..6b692ed984 100644 --- a/api.go +++ b/api.go @@ -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)