Grant the build user access to /dev/kvm if requested. The device is
passed with its host GID, which won't match any container group, so
create/point a group at that GID and add builder to it. gosu picks up
supplementary groups.
Signed-off-by: Jose Quaresma <
jose.q...@oss.qualcomm.com>
---
container-entrypoint | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/container-entrypoint b/container-entrypoint
index 0725a8c..71f0892 100755
--- a/container-entrypoint
+++ b/container-entrypoint
@@ -104,6 +104,22 @@ restore_managed_dirs_owner()
chown_managed_dirs 0 0
}
+# Grant the build user access to /dev/kvm if requested. The device is
+# passed with its host GID, which won't match any container group, so
+# create/point a group at that GID and add builder to it. gosu picks up
+# supplementary groups, so no host-side permission change is needed.
+add_kvm_group_id()
+{
+ if [ -n "$KAS_ENABLE_KVM" ] && [ -c /dev/kvm ]; then
+ KVM_GID=$(stat -c '%g' /dev/kvm)
+ if ! kvm_grp=$(getent group "$KVM_GID" | cut -d: -f1) || [ -z "$kvm_grp" ]; then
+ kvm_grp=hostkvm
+ groupadd --non-unique --gid "$KVM_GID" "$kvm_grp"
+ fi
+ usermod --append --groups "$kvm_grp" builder
+ fi
+}
+
if mount | grep -q "on / type aufs"; then
cat <<EOF >&2
WARNING: Generation of wic images will fail!
@@ -139,6 +155,7 @@ else
groupmod -o --gid "$GROUP_ID" builder
usermod -o --uid "$USER_ID" --gid "$GROUP_ID" builder >/dev/null
+ add_kvm_group_id
chown -R "$USER_ID":"$GROUP_ID" /builder
# copy host SSH config into home of builder
if [ -d /var/kas/userdata/.ssh ]; then
--
2.55.0