Skip to content

Commit

Permalink
Add ability to customize container uid&gid
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Dec 13, 2020
1 parent ed5b820 commit b1e9e0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions containerPasswd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root:x:0:0::/w:/bin/bash
go-judge:x:1536:1536::/w:/bin/bash
7 changes: 7 additions & 0 deletions env/env_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
containerName = "executor_server"
defaultWorkDir = "/w"
containerCredStart = 10000
containerCred = 1000
)

// NewBuilder build a environment builder
Expand Down Expand Up @@ -62,10 +63,14 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) {
hostName := containerName
domainName := containerName
workDir := defaultWorkDir
cUID := containerCred
cGID := containerCred
if mc != nil {
hostName = mc.HostName
domainName = mc.DomainName
workDir = mc.WorkDir
cUID = mc.UID
cGID = mc.GID
}
c.Info("Creating container builder: hostName=", hostName, ", domainName=", domainName, ", workDir=", workDir)

Expand All @@ -79,6 +84,8 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) {
HostName: hostName,
DomainName: domainName,
WorkDir: workDir,
ContainerUID: cUID,
ContainerGID: cGID,
}
cgb := cgroup.NewBuilder(c.CgroupPrefix).WithCPUAcct().WithMemory().WithPids()
if c.Cpuset != "" {
Expand Down
2 changes: 2 additions & 0 deletions env/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Mounts struct {
WorkDir string `yaml:"workDir"`
HostName string `yaml:"hostName"`
DomainName string `yaml:"domainName"`
UID int `yaml:"uid"`
GID int `yaml:"gid"`
Proc bool `yaml:"proc"`
}

Expand Down
8 changes: 8 additions & 0 deletions mount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ mount:
- type: tmpfs
target: /tmp
data: size=16m,nr_inodes=4k
# bind a /etc/passed to show customized user name
# - type: bind
# source: /home/criyle/go-judge/containerPasswd.txt
# target: /etc/passwd
# java & ghc wants /proc/self/exe
proc: true
# container work directory
Expand All @@ -55,3 +59,7 @@ workDir: /w
hostName: executor_server
# container domain name
domainName: executor_server
# container user uid
uid: 1536
# container user gid
gid: 1536

0 comments on commit b1e9e0d

Please sign in to comment.