Skip to content
This repository was archived by the owner on Aug 20, 2021. It is now read-only.

Commit 548be10

Browse files
authored
Merge pull request #59 from dweomer/daemon/group-flag
daemon: add socket ownership flags
2 parents fca8597 + bfdc41d commit 548be10

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

cmd/daemon/daemon_linux.go

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ the backend to support the Docker work-alike frontend of k3c.`
3939
if sf, ok := flag.(cliv1.StringFlag); ok {
4040
sf.Value = filepath.Join(config.DefaultDaemonStateDir, "k3c.sock")
4141
sf.EnvVar = "K3C_ADDRESS"
42+
sf.Destination = &config.Socket.Address
4243
app.Flags[i] = sf
4344
} else {
4445
logrus.Warnf("unexpected type for flag %q = %#v", flag.GetName(), flag)
@@ -144,6 +145,18 @@ the backend to support the Docker work-alike frontend of k3c.`
144145
Usage: "containerd-style image ref for sandboxes",
145146
Destination: &cri.Config.SandboxImage,
146147
},
148+
cliv1.IntFlag{
149+
Name: "socket-gid,group",
150+
EnvVar: "K3C_SOCKET_GID",
151+
Usage: "gRPC socket gid",
152+
Destination: &config.Socket.GID,
153+
},
154+
cliv1.IntFlag{
155+
Name: "socket-uid",
156+
EnvVar: "K3C_SOCKET_UID",
157+
Usage: "gRPC socket uid",
158+
Destination: &config.Socket.UID,
159+
},
147160
}...)
148161

149162
app.Action = func(action interface{}) cliv1.ActionFunc {
@@ -162,6 +175,8 @@ the backend to support the Docker work-alike frontend of k3c.`
162175
e = t.EnvVar
163176
case cliv1.StringFlag:
164177
e = t.EnvVar
178+
case cliv1.IntFlag:
179+
e = t.EnvVar
165180
}
166181
if e != "" {
167182
if err := os.Setenv(e, clx.GlobalString(n)); err != nil {

pkg/daemon/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/BurntSushi/toml"
1111
"github.com/containerd/containerd/platforms"
12+
"github.com/containerd/containerd/services/server/config"
1213
buildkit "github.com/moby/buildkit/cmd/buildkitd/config"
1314
"github.com/rancher/k3c/pkg/defaults"
1415
)
@@ -28,6 +29,10 @@ var (
2829
DefaultVolumesDir = filepath.Join(DefaultDaemonRootDir, "volumes")
2930
)
3031

32+
var (
33+
Socket config.GRPCConfig
34+
)
35+
3136
type K3Config struct {
3237
BootstrapSkip bool `toml:"bootstrap_skip"`
3338
BootstrapImage string `toml:"bootstrap_image"`

pkg/daemon/plugins.go

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package daemon
22

33
import (
4+
"os"
5+
"time"
6+
47
"github.com/containerd/containerd/log"
58
"github.com/containerd/containerd/platforms"
69
"github.com/containerd/containerd/plugin"
@@ -68,5 +71,30 @@ func PluginInitFunc(ic *plugin.InitContext) (interface{}, error) {
6871
service := server.NewContainerService(daemon)
6972
service.SetInitialized(true)
7073
log.G(ic.Context).WithField("bridge", cfg.BridgeName).WithField("cidr", cfg.BridgeCIDR).Info("K3C daemon")
74+
go func() {
75+
var (
76+
addr = config.Socket.Address
77+
gid = config.Socket.GID
78+
uid = config.Socket.UID
79+
)
80+
for {
81+
select {
82+
case <-time.After(100 * time.Millisecond):
83+
err := os.Chown(addr, uid, gid)
84+
if os.IsNotExist(err) {
85+
continue
86+
}
87+
log := log.G(ic.Context).WithField("address", addr).WithField("gid", gid).WithField("uid", uid)
88+
if err != nil {
89+
log.WithError(err).Warn("K3C socket")
90+
} else {
91+
log.Debug("K3C socket")
92+
}
93+
return
94+
case <-ic.Context.Done():
95+
return
96+
}
97+
}
98+
}()
7199
return service, nil
72100
}

0 commit comments

Comments
 (0)