37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
jailer.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-05-03 17:29 . Jail helm
package jailer
import (
"fmt"
"os"
"os/exec"
"os/user"
"path"
"strconv"
"syscall"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
const BaseJailPath = "/opt/jail"
// CreateJail sets up the named directory for use with chroot
func CreateJail(name string) error {
logrus.Debugf("Creating jail for %v", name)
_, err := os.Stat(path.Join(BaseJailPath, name))
if err == nil {
return nil
}
cmd := exec.Command("/usr/bin/jailer.sh", name)
out, err := cmd.CombinedOutput()
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("error running the jail command: %v", string(out)))
}
logrus.Debugf("Output from create jail command %v", string(out))
return nil
}
// GetUserCred looks up the user and provides it in syscall.Credential
func GetUserCred() (*syscall.Credential, error) {
u, err := user.Current()
if err != nil {
uID := os.Getuid()
u, err = user.LookupId(strconv.Itoa(uID))
if err != nil {
return nil, err
}
}
i, err := strconv.ParseUint(u.Uid, 10, 32)
if err != nil {
return nil, err
}
uid := uint32(i)
i, err = strconv.ParseUint(u.Gid, 10, 32)
if err != nil {
return nil, err
}
gid := uint32(i)
return &syscall.Credential{Uid: uid, Gid: gid}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc6

搜索帮助