0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KVMのユーザセッションでもホストのbr0を使いたい

Last updated at Posted at 2025-06-13

■今回の主役はAppArmor。セキュリティの目的で止めること自体は良いけど、
 ちゃんと理由をエラーやログに出すなりして残そうね、意味ないから。

「apparmor-utils」がなければインストールして進みましょう

$ apt-file search bin/aa-disable
apparmor-utils: /usr/sbin/aa-disable

$ sudo apt install -y apparmor-utils

■今回の環境では、一部stableで動かないような新しいHWがあって、
 kernelバージョンを上げる必要に迫られtestingを使っている。

他も試したけど、bookwormでも同じ手順でいけた。

$ head -n 2 /etc/*release
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"

■ちなみにbookworm12.2.0以前の環境ではKVMのユーザセッションでホストbr0が使えている

$ head -n 2 /etc/*release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"

$ grep cdrom /etc/apt/sources.list
#deb cdrom:[Debian GNU/Linux 12.2.0 _Bookworm_ - Official amd64 NETINST with firmware 20231007-10:28]/ bookworm main non-free-firmware contrib non-free
# (e.g. netinst, live or single CD). The matching "deb cdrom"

$ virsh dumpxml kvm-debian12 | lsec -sep '^    <' br0 | grep -v "mac address"
    <interface type='bridge'>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>

■「virsh edit」で構文は間違いなく正しいのに動かないので、
 「権限」か「セキュリティ」だけど、クリーンインストールだしまともなエラーを出さないので、多分後者と予想

■症状は、いつもどおりKVM入れても、
 「ホストのブリッジネットワークを仮想マシンにアサインする」と、
 システムセッションではできるのに、ユーザセッションではできない。

つまりユーザ権限のときに起きる。一般に権限ならそれなりのエラーメッセージを出力するので、と探していたら、「AppAromor」

そんな気はしてた。やっぱりお前か

$ sudo aa-status | grep bridge
libvirtd//qemu_bridge_helper

■ピンポイントの「qemu_bridge_helper」という粒度で指定することは出来ないので、

$ sudo aa-disable libvirtd//qemu_bridge_helper
libvirtd//qemu_bridge_helper does not exist, please double-check the path.

■libvirtdごと無効にする

$ sudo aa-disable libvirtd
Disabling /usr/sbin/libvirtd.

$ sudo aa-status | grep bridge

$ sudo systemctl restart libvirtd

■やっとまともなエラーメッセージに出会えた、権限ね。

$ virsh start rhel8.6 
error: ドメイン 'rhel8.6' の起動に失敗しました
error: /usr/lib/qemu/qemu-bridge-helper --use-vnet --br=br0 --fd=34: failed to communicate with bridge helper: stderr=failed to create tun device: Operation not permitted
: Transport endpoint is not connected

$ env LANG=C ls -l /usr/lib/qemu/qemu-bridge-helper
-rwxr-xr-x 1 root root 664280 May  3 18:06 /usr/lib/qemu/qemu-bridge-helper

$ sudo chmod u+s /usr/lib/qemu/qemu-bridge-helper

$ env LANG=C ls -l /usr/lib/qemu/qemu-bridge-helper 
-rwsr-xr-x 1 root root 715864 May 13 03:01 /usr/lib/qemu/qemu-bridge-helper

■無事に起動するようになった。
 「lsec」はhttps://github.com/labunix/lsec

$ virsh start rhel8.6 

$ virsh dumpxml rhel8.6 | lsec -sep '^    <' br0 | grep -v "mac address"
    <interface type='bridge'>
      <source bridge='br0'/>
      <target dev='tap1'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>

■分かったあとなら、次からはlibvirtdで探す方が良さそう

$ sudo aa-status | grep libvirtd
   libvirtd
   libvirtd//qemu_bridge_helper
   /usr/sbin/libvirtd (1131) libvirtd
   /usr/sbin/libvirtd (5405) libvirtd

■ホストのネットワークを使うことを許可する

$ sudo mkdir /etc/qemu
$ sudo cat /etc/qemu/bridge.conf
allow virbr0
allow br0

$ sudo chown -R :libvirt /etc/qemu/
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?