mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 05:04:26 +00:00
runtime: store the user name in hypervisor config
The user name will be used to delete the user instead of relying on uid lookup because uid can be reused. Fixes: #5155 Signed-off-by: Feng Wang <feng.wang@databricks.com>
This commit is contained in:
parent
5cafe21770
commit
f914319874
@ -335,6 +335,7 @@ func configureNonRootHypervisor(runtimeConfig *oci.RuntimeConfig, sandboxId stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
runtimeConfig.HypervisorConfig.Uid = uint32(uid)
|
runtimeConfig.HypervisorConfig.Uid = uint32(uid)
|
||||||
|
runtimeConfig.HypervisorConfig.User = userName
|
||||||
runtimeConfig.HypervisorConfig.Gid = uint32(gid)
|
runtimeConfig.HypervisorConfig.Gid = uint32(gid)
|
||||||
shimLog.WithFields(logrus.Fields{
|
shimLog.WithFields(logrus.Fields{
|
||||||
"user_name": userName,
|
"user_name": userName,
|
||||||
|
@ -380,6 +380,9 @@ type HypervisorConfig struct {
|
|||||||
// BlockiDeviceAIO specifies the I/O API to be used.
|
// BlockiDeviceAIO specifies the I/O API to be used.
|
||||||
BlockDeviceAIO string
|
BlockDeviceAIO string
|
||||||
|
|
||||||
|
// The user maps to the uid.
|
||||||
|
User string
|
||||||
|
|
||||||
// KernelParams are additional guest kernel parameters.
|
// KernelParams are additional guest kernel parameters.
|
||||||
KernelParams []Param
|
KernelParams []Param
|
||||||
|
|
||||||
|
@ -680,7 +680,7 @@ func (q *qemu) checkBpfEnabled() {
|
|||||||
q.Logger().WithError(err).Warningf("failed to get bpf_jit_enable status")
|
q.Logger().WithError(err).Warningf("failed to get bpf_jit_enable status")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
enabled, err := strconv.Atoi(string(out))
|
enabled, err := strconv.Atoi(strings.TrimSpace(string(out)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.Logger().WithError(err).Warningf("failed to convert bpf_jit_enable status to integer")
|
q.Logger().WithError(err).Warningf("failed to convert bpf_jit_enable status to integer")
|
||||||
return
|
return
|
||||||
@ -1063,26 +1063,25 @@ func (q *qemu) cleanupVM() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
u, err := user.LookupId(strconv.Itoa(int(q.config.Uid)))
|
if _, err := user.Lookup(q.config.User); err != nil {
|
||||||
if err != nil {
|
|
||||||
q.Logger().WithError(err).WithFields(
|
q.Logger().WithError(err).WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"user": u.Username,
|
"user": q.config.User,
|
||||||
"uid": q.config.Uid,
|
"uid": q.config.Uid,
|
||||||
}).Warn("failed to find the user")
|
}).Warn("failed to find the user, it might have been removed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pkgUtils.RemoveVmmUser(u.Username); err != nil {
|
if err := pkgUtils.RemoveVmmUser(q.config.User); err != nil {
|
||||||
q.Logger().WithError(err).WithFields(
|
q.Logger().WithError(err).WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"user": u.Username,
|
"user": q.config.User,
|
||||||
"uid": q.config.Uid,
|
"uid": q.config.Uid,
|
||||||
}).Warn("failed to delete the user")
|
}).Warn("failed to delete the user")
|
||||||
}
|
}
|
||||||
q.Logger().WithFields(
|
q.Logger().WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"user": u.Username,
|
"user": q.config.User,
|
||||||
"uid": q.config.Uid,
|
"uid": q.config.Uid,
|
||||||
}).Debug("successfully removed the non root user")
|
}).Debug("successfully removed the non root user")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user