mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 20:54:26 +00:00
runtime: add more debug logs for non-root user operation
Previously the logging was insufficient and made debugging difficult Fixes: #5155 Signed-off-by: Feng Wang <feng.wang@databricks.com>
This commit is contained in:
parent
a58feba9bb
commit
c3015927a3
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
// only register the proto type
|
// only register the proto type
|
||||||
crioption "github.com/containerd/containerd/pkg/runtimeoptions/v1"
|
crioption "github.com/containerd/containerd/pkg/runtimeoptions/v1"
|
||||||
@ -136,7 +137,7 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con
|
|||||||
katautils.HandleFactory(ctx, vci, s.config)
|
katautils.HandleFactory(ctx, vci, s.config)
|
||||||
rootless.SetRootless(s.config.HypervisorConfig.Rootless)
|
rootless.SetRootless(s.config.HypervisorConfig.Rootless)
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
if err := configureNonRootHypervisor(s.config); err != nil {
|
if err := configureNonRootHypervisor(s.config, r.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,13 +304,17 @@ func doMount(mounts []*containerd_types.Mount, rootfs string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureNonRootHypervisor(runtimeConfig *oci.RuntimeConfig) error {
|
func configureNonRootHypervisor(runtimeConfig *oci.RuntimeConfig, sandboxId string) error {
|
||||||
userName, err := utils.CreateVmmUser()
|
userName, err := utils.CreateVmmUser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
shimLog.WithFields(logrus.Fields{
|
||||||
|
"user_name": userName,
|
||||||
|
"sandbox_id": sandboxId,
|
||||||
|
}).WithError(err).Warn("configure non root hypervisor failed, delete the user")
|
||||||
if err2 := utils.RemoveVmmUser(userName); err2 != nil {
|
if err2 := utils.RemoveVmmUser(userName); err2 != nil {
|
||||||
shimLog.WithField("userName", userName).WithError(err).Warn("failed to remove user")
|
shimLog.WithField("userName", userName).WithError(err).Warn("failed to remove user")
|
||||||
}
|
}
|
||||||
@ -331,6 +336,12 @@ func configureNonRootHypervisor(runtimeConfig *oci.RuntimeConfig) error {
|
|||||||
}
|
}
|
||||||
runtimeConfig.HypervisorConfig.Uid = uint32(uid)
|
runtimeConfig.HypervisorConfig.Uid = uint32(uid)
|
||||||
runtimeConfig.HypervisorConfig.Gid = uint32(gid)
|
runtimeConfig.HypervisorConfig.Gid = uint32(gid)
|
||||||
|
shimLog.WithFields(logrus.Fields{
|
||||||
|
"user_name": userName,
|
||||||
|
"uid": uid,
|
||||||
|
"gid": gid,
|
||||||
|
"sandbox_id": sandboxId,
|
||||||
|
}).Debug("successfully created a non root user for the hypervisor")
|
||||||
|
|
||||||
userTmpDir := path.Join("/run/user/", fmt.Sprint(uid))
|
userTmpDir := path.Join("/run/user/", fmt.Sprint(uid))
|
||||||
_, err = os.Stat(userTmpDir)
|
_, err = os.Stat(userTmpDir)
|
||||||
|
@ -1061,13 +1061,26 @@ func (q *qemu) cleanupVM() error {
|
|||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
u, err := user.LookupId(strconv.Itoa(int(q.config.Uid)))
|
u, err := user.LookupId(strconv.Itoa(int(q.config.Uid)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.Logger().WithError(err).WithField("uid", q.config.Uid).Warn("failed to find the user")
|
q.Logger().WithError(err).WithFields(
|
||||||
|
logrus.Fields{
|
||||||
|
"user": u.Username,
|
||||||
|
"uid": q.config.Uid,
|
||||||
|
}).Warn("failed to find the user")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pkgUtils.RemoveVmmUser(u.Username); err != nil {
|
if err := pkgUtils.RemoveVmmUser(u.Username); err != nil {
|
||||||
q.Logger().WithError(err).WithField("user", u.Username).Warn("failed to delete the user")
|
q.Logger().WithError(err).WithFields(
|
||||||
|
logrus.Fields{
|
||||||
|
"user": u.Username,
|
||||||
|
"uid": q.config.Uid,
|
||||||
|
}).Warn("failed to delete the user")
|
||||||
}
|
}
|
||||||
|
q.Logger().WithFields(
|
||||||
|
logrus.Fields{
|
||||||
|
"user": u.Username,
|
||||||
|
"uid": q.config.Uid,
|
||||||
|
}).Debug("successfully removed the non root user")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user