Bug 872653
| Summary: | Provide an audit event containing the LXC "init" process ID. | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Daniel Berrangé <berrange> | ||||||
| Component: | libvirt | Assignee: | Daniel Berrangé <berrange> | ||||||
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Virtualization Bugs <virt-bugs> | ||||||
| Severity: | unspecified | Docs Contact: | |||||||
| Priority: | unspecified | ||||||||
| Version: | 7.0 | CC: | ajia, bili, cwei, dwalsh, dyuan, eparis, mzhan, sgrubb | ||||||
| Target Milestone: | rc | ||||||||
| Target Release: | --- | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Whiteboard: | |||||||||
| Fixed In Version: | libvirt-1.0.1-1.el7 | Doc Type: | Bug Fix | ||||||
| Doc Text: | Story Points: | --- | |||||||
| Clone Of: | |||||||||
| : | 918671 (view as bug list) | Environment: | |||||||
| Last Closed: | 2014-06-13 12:37:21 UTC | Type: | Bug | ||||||
| Regression: | --- | Mount Type: | --- | ||||||
| Documentation: | --- | CRM: | |||||||
| Verified Versions: | Category: | --- | |||||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||||
| Embargoed: | |||||||||
| Bug Depends On: | 882324, 901535 | ||||||||
| Bug Blocks: | |||||||||
| Attachments: |
|
||||||||
|
Description
Daniel Berrangé
2012-11-02 16:33:20 UTC
Created attachment 640177 [details]
This patch adds auditing with the initpid call to the libvirt-lxc
audit message looks like:
time->Wed Nov 7 11:22:41 2012
type=VIRT_CONTROL msg=audit(1352305361.019:4442): pid=27370 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 msg='lxc=apache1 op=start reason=booted uuid=13541cfd-4bf4-80fd-ff24-0779f856d558 init-pid=27371 exe="/usr/libexec/libvirt_lxc" hostname=? addr=? terminal=? res=success'
Problem is the stop message never happens. Seems like libvirtd is just killing the libvirt-lxc process and it is not cleaning up problerly?
It seems like your attachment is only the .spec file changes, not the actual patch. The libvirt LXC driver in fact already issues audit logs on every start/stop of a container. These are issued from libvirtd, rather than libvirt_lxc precisely so that they're guaranteed to be issued even if libvirt_lxc crashes. So we don't need to add further stop/start audit events in libvirt_lxc. Rather we need to have libvirt_lxc sends the init pid back to libvirtd, so that it can include it in the event it already emits. Created attachment 641091 [details]
oops wrong patch
Here is the updated patch.
I think pushing this into libvirt, would be difficult.
Merged upstream http://libvirt.org/git/?p=libvirt.git;a=commit;h=a61583366412cf0254332fc8e3b678d9a3494d7c Log an audit message with the LXC init pid Currently the LXC driver logs audit messages when a container is started or stopped. These audit messages, however, contain the PID of the libvirt_lxc supervisor process. To enable sysadmins to correlate with audit messages generated by processes /inside/ the container, we need to include the container init process PID. We can't do this in the main 'start' audit message, since the init PID is not available at that point. Instead we output a completely new audit record, that lists both PIDs. type=VIRT_CONTROL msg=audit(1353433750.071:363): pid=20180 uid=0 auid=501 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='virt=lxc op=init vm="busy" uuid=dda7b947-0846-1759-2873-0f375df7d7eb vm-pid=20371 init-pid=20372 exe="/home/berrange/src/virt/libvirt/daemon/.libs/lt-libvirtd" hostname=? addr=? terminal=pts/6 res=success' This bug can not be verified for the Bug 882324 has not been fixed. # cat toy.xml <domain type='lxc'> <name>toy</name> <uuid>bb428983-cb9f-4702-0f8d-7d4e143d9aad</uuid> <memory unit='KiB'>500000</memory> <currentMemory unit='KiB'>500000</currentMemory> <vcpu>4</vcpu> <os> <type arch='x86_64'>exe</type> <init>/bin/sh</init> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <console type='pty'> <target type='lxc' port='0'/> </console> </devices> </domain> # virsh -c lxc:/// define toy.xml Domain toy defined from toy.xml # virsh -c lxc:/// start toy error: Failed to start domain toy error: internal error Unable to find 'memory' cgroups controller mount Because of the Bug 882324 is not fixed. And audit.log: # cat /var/log/audit/audit.log ..... type=VIRT_CONTROL msg=audit(1356318313.853:457): pid=4195 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc op=start reason=booted vm="toy" uuid=bb428983-cb9f-4702-0f8d-7d4e143d9aad vm-pid=0 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=failed' ..... Only get 'vm-pid=0' and no 'init-pid=xxxx' because of the lxc guet can not start. This bug still can not be verified for the new bug: Bug 901535 - can not start lxc guest with kernel-3.7.0-0.31.el7 adding depends on bug for it. (In reply to comment #4) > > type=VIRT_CONTROL msg=audit(1353433750.071:363): pid=20180 uid=0 auid=501 > ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 > msg='virt=lxc op=init vm="busy" uuid=dda7b947-0846-1759-2873-0f375df7d7eb > vm-pid=20371 init-pid=20372 > exe="/home/berrange/src/virt/libvirt/daemon/.libs/lt-libvirtd" hostname=? > addr=? terminal=pts/6 res=success' Hi Daniel, I got different audit message with you when I successfully started a LXC guest, please see the following audit log: <slice> type=VIRT_MACHINE_ID msg=audit(1359689340.213:4604): pid=1521 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc vm="toy" uuid=f61a1b4d-d6ef-a731-f302-b970f2a9aab2 vm-ctx=? img-ctx=? model=selinux exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' type=VIRT_RESOURCE msg=audit(1359689340.437:4605): pid=1521 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc resrc=mem reason=start vm="toy" uuid=f61a1b4d-d6ef-a731-f302-b970f2a9aab2 old-mem=0 new-mem=500000 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' type=VIRT_RESOURCE msg=audit(1359689340.437:4606): pid=1521 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc resrc=vcpu reason=start vm="toy" uuid=f61a1b4d-d6ef-a731-f302-b970f2a9aab2 old-vcpu=0 new-vcpu=4 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' type=VIRT_CONTROL msg=audit(1359689340.437:4607): pid=1521 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc op=start reason=booted vm="toy" uuid=f61a1b4d-d6ef-a731-f302-b970f2a9aab2 vm-pid=357 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' type=AVC msg=audit(1359689340.444:4608): avc: denied { read } for pid=358 comm="sh" name=".bash_history" dev="dm-1" ino=397278 scontext=system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file type=SYSCALL msg=audit(1359689340.444:4608): arch=c000003e syscall=2 success=no exit=-13 a0=21645d0 a1=0 a2=1b6 a3=14 items=0 ppid=0 pid=358 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 ses=4294967295 tty=pts3 comm="sh" exe="/usr/bin/bash" subj=system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 key=(null) type=AVC msg=audit(1359689340.444:4609): avc: denied { read } for pid=358 comm="sh" name=".bash_history" dev="dm-1" ino=397278 scontext=system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file type=SYSCALL msg=audit(1359689340.444:4609): arch=c000003e syscall=2 success=no exit=-13 a0=21645d0 a1=0 a2=1b6 a3=14 items=0 ppid=0 pid=358 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 ses=4294967295 tty=pts3 comm="sh" exe="/usr/bin/bash" subj=system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 key=(null) </slice> There are several questions in here, the first, I haven't seen 'init' operation (op=init) except for "op=start"; the second, also can't find "init-pid=xxx" in audit message; finally, it exists a AVC denied(read) at above audit log. # rpm -q libvirt kernel audit libvirt-1.0.0-1.el7.x86_64 kernel-3.7.0-0.33.el7.x86_64 audit-2.2.1-2.el7.x86_64 Did the guest actually start up successfully ? The AVC message makes me thing it exited on startup due to SELinux denials. If so, this would explain the lack of the init audit message. (In reply to comment #8) > Did the guest actually start up successfully ? The AVC message makes me > thing it exited on startup due to SELinux denials. If so, this would explain > the lack of the init audit message. Yes, the previous bug 901535 has been fixed on kernel-3.7.0-0.33.el7.x86_64, I can successfully start a LXC guest now. # virsh -c lxc:// list Id Name State ---------------------------------------------------- 357 toy running # virsh -c lxc:// dumpxml toy <domain type='lxc' id='357'> <name>toy</name> <uuid>f61a1b4d-d6ef-a731-f302-b970f2a9aab2</uuid> <memory unit='KiB'>500000</memory> <currentMemory unit='KiB'>500000</currentMemory> <vcpu placement='static'>4</vcpu> <os> <type arch='x86_64'>exe</type> <init>/bin/sh</init> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <console type='pty' tty='/dev/pts/2'> <source path='/dev/pts/2'/> <target type='lxc' port='0'/> <alias name='console0'/> </console> </devices> <seclabel type='none' model='selinux'/> </domain> Hi Daniel, As the Bug 901535 is verified,I am verifying this bug, and get expected result as Comment #1: <snip> type=VIRT_CONTROL msg=audit(1359966784.379:6704): pid=27795 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc op=init vm="toy" uuid=bb428983-cb9f-4702-0f8d-7d4e143d9aad vm-pid=28019 init-pid=28029 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' <snip> Can this bug be set to VERIFIED? Thanks, EricLee It was decided that the init PID is insufficient on its own. Thus we must also include the container PID namespace inode number. Thus the audit message should look like this (note the extra 'pid-ns' field, which reflects the inode of /proc/CONTAINER-INIT-PID/ns/pid). type=VIRT_CONTROL msg=audit(1362582468.378:50): pid=19284 uid=0 auid=0 ses=312 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='virt=lxc op=init vm="demo" uuid=0770f019-2d4e-09e9-8e4a-719e12b3a18e vm-pid=19620 init-pid=19622 pid-ns=3242 exe="/home/berrange/src/virt/libvirt/daemon/.libs/lt-libvirtd" hostname=? addr=? terminal=pts/6 res=success' This is posted here https://www.redhat.com/archives/libvir-list/2013-March/msg00211.html commit ab1ef3bc6ced28d6796eb67151ef5a5328344827
Author: Daniel P. Berrange <berrange>
Date: Wed Mar 6 14:56:49 2013 +0000
Include pid namespace inode in LXC audit messages
To allow the efficient correlation of container audit messages
with host hosts, include the pid namespace inode in audit
messages.
This bug has been verified on libvirt-1.1.0-1.el7.x86_64 with kernel-3.10.0-0.rc7.64.el7.x86_64, so move it to VERIFIED status. # tail -1 /var/log/audit/audit.log type=VIRT_CONTROL msg=audit(1373428179.484:14): pid=982 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 msg='virt=lxc op=init vm="toy" uuid=9a1ef54e-1e66-4512-a0a1-47ea9023c7f7 vm-pid=1841 init-pid=1843 pid-ns=4026532272 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success' This request was resolved in Red Hat Enterprise Linux 7.0. Contact your manager or support representative in case you have further questions about the request. |