Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: firewalld system containers #150

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

peterbaouoft
Copy link

The original thought came from https://bugzilla.redhat.com/show_bug.cgi?id=1403331

The container is still work in progress. The docker file can be
compiled successfully. When running the command, the service will not error out.
However, the command will time out eventually (not executing properly). I have a
few thoughts for debugging, will take a while to figure it out.

Have it here first for some early feedback :). (will modify the commit
message once lifting the WIP )

The container is still work in progress. The docker file can be
compiled successfully. However, when starting the service via
systemctl, the command will time out eventually. I have a
few thoughts for debugging, will take a while to figure it out.

Have it here first for some feedback :). (will modify the commit
message once lifting the WIP )
Copy link
Collaborator

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work, it seems to work quite well here. I have some comments inline

mkdir -p /exports/hostfs/etc/dbus-1/system.d && \
cp /etc/sysconfig/firewalld /exports/hostfs/etc/sysconfig && \
# Copy all the polkit related files into current polkit
cp /usr/share/polkit-1/actions/org.fedoraproject.FirewallD1.* /exports/hostfs/usr/share/polkit-1/actions && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there another location we can use instead of "/usr/share"? Otherwise this would not work on Atomic Host

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :D.
yea ...., I think it would be hard to do so on Atomic Host to make a change to read only /usr .. IMO, the way how package layering works in Atomic Host is that we make a new bootable deployment which contains the completely new /usr with the package installed ( package layering avoided modifying current /usr directly ). So in this case, the polkit related files will still be in /usr/share, except that it is inside a deployment folder..

After package layering firewalld on atomic host, the location of policy is: 
/sysroot/ostree/deploy/fedora-atomic/deploy/c3d2bde48ccd610057a7d7bb8dbb883bc23a86b61fbef74c934e14253ba7f475.0/usr/share/polkit-1/actions/org.fedoraproject.FirewallD1.policy

So, I think what we could possibly do on atomic host is that..
1: we first check if we are on an atomic host or an ostree managed OS?
2: If we are, we find out where the current bootable deployment is (somehow), then we directly copy these files into that bootable deployment /usr directory. would that work? WDYT @giuseppe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to configure polkit to look into another directory? We can probably change it to use /var/ or /etc instead of /usr/share. That will work on Atomic Host without the need of copying files to /usr and breaking the assumption it is read only.

mkdir -p /exports/hostfs/usr/lib/firewalld && \
cp -r /usr/lib/firewalld/* /exports/hostfs/usr/lib/firewalld && \
cp /usr/sbin/ebtables /exports/hostfs/usr/sbin/ && \
cp /usr/sbin/ipset /exports/hostfs/sbin/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not copy binaries (ebtables and ipset) outside of the container

Copy link
Author

@peterbaouoft peterbaouoft Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea... I agree it is ugly.. but currently I can't find a neat way to let firewalld find the binaries. During the execution of firewalld, it will call those binaries(ipset and ebatables) for checking.
https://github.com/firewalld/firewalld/blob/master/src/firewall/config/__init__.py.in#L105
https://github.com/firewalld/firewalld/blob/master/src/firewall/core/fw.py#L76

# commands used by backends
COMMANDS = {
    "ipv4":         "/usr/sbin/iptables",
    "ipv4-restore": "/usr/sbin/iptables-restore",
    "ipv6":         "/usr/sbin/ip6tables",
    "ipv6-restore": "/usr/sbin/ip6tables-restore",
    "eb":           "/usr/sbin/ebtables",
    "eb-restore":   "/usr/sbin/ebtables-restore",
    "ipset":        "/usr/sbin/ipset",
    "modinfo":      "/sbin/modinfo",
    "modprobe":     "/sbin/modprobe",
    "rmmod":        "/sbin/rmmod",
}
above is translated commands to loactions when opening firewalld code repo with pycharm

If I do not have those binaries copied to the host, there will be a WARNING message displayed in the log :(. Is there a good way to let firewalld use those commands while not copying the binaries of the commands to the host? :)

edit: it is also possible that I am having a misunderstanding of the concept. So, please correct me if I am wrong. :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is it using the binaries from the host? Isn't enough they are in the container? /usr is coming from the container

Copy link
Author

@peterbaouoft peterbaouoft Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking + reading more documents, there are still a few doubts about the implementation. Any hints would be appreciated =).

/usr is coming from container

1: Then I am a bit confused about how systemd handles paths. I understand that the executable in /usr/bin/xxx will all first be resolved as /var/lib/containers/atomic/firewalld.0/rootfs/usr/bin/xx right? But what if /usr/bin/firewalld/ calls other binaries (e.g ipset), during its execution? Does systemd/runc still able to make the path canonical ( relative to the container's rootfs )?

However, do note this is just a general question about relative path concept, this is not in reply to the answer above.

2: The above confusion also leads to my next question. I found that without copying /usr/share/polkit-1/actions/xxx files into the host, the program will fail due to Access denied. But systemd will resolve the path for us right? Why it seems necessary to copy these policy files into host in order to resolve the access denied error ?

A lot of the decisions( like copying polkit and /usr/lib files) are made just because of try and error, that is why I am a bit tempting to understand the concept behind it. It will be great if there is a document to read through :p.

3: While looking at the files generated for firewalld. I see two important files related to dbus service. One is /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service and another one is
/etc/dbus-1/system.d/FirewallD.conf. ( those were used for dbus I believe)

Then, I think the normal way how firewalld works on the file system (based on inspection and analysis and some guessing) is that it launches dbus --> dbus checks the polkit rules ( uses conf file) and other policies --> dbus launches systemd service through the service file.

If that is the case, I am a bit unsure about how to link our service.template file to this dbus service. As, we had an extra layer of runc in between. I tested a bit with

[Service]
Type=dbus
BusName=org.fedoraproject.FirewallD1
ExecStart=$EXEC_START
ExecStop=$EXEC_STOP
Restart=on-failure
WorkingDirectory=$DESTDIR
RuntimeDirectory=${NAME}

will make the service being "active" status. (with type=notify, the service always hang ). But I am a bit unsure about if I did it correctly, and what will the drawbacks might be in the future. WDYT?

4: I am unsure about the relationship between dbus conf and service files, and their relationship when policy kit is involved. Is there any document that is recommended to read in order to shorten this knowledge gap?

Also, the service file /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service seems to be empty when installing onto a fresh container, probably due to the broken systemd on a container. Any solutions for that, and do we ever want to copy related service files (e.g polkit.service) onto the host?

Sorry for these many questions, the knowledge gap is huge for me at the beginning. I was not able to find any meaningful documents to help me make further progress =(. we can have a bluejean chat too if written reply takes too much time. More importantly, thanks for your time =)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once the container runs, the process there has a visibility only on /var/lib/containers/atomic/firewalld.0/rootfs, that becomes '/'. Unless you call executables directly from the systemd service file (which you don't AFAICS), systemd doesn't have any knowledge of how the container looks like and what is inside.

We still need to copy the polkit files to the host and that is correct, since we are using polkit from the host and I think this part works already fine in your current version. I've played around with it and tried few different things, firewalld was working well.

"Type=dbus" means systemd consider the service started up once it acquires its name from the dbus connection. You are bind mounting the dbus socket to the container, so firewalld can do that in the same way as it would if running on the host.

The only part I'd like you to investigate is that we can use /etc/dbus-1/ instead of /usr/share for copying the dbus files, as copying files to /usr/share goes against the Atomic Host assumption of /usr being read only, even if we can circumvent it going into the /sysroot path.

And really no worries about the knowledge gap. You are doing a great job, take your time to understand the (too many) pieces involved. This is more important than being in a hurry to complete the patch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr/local is a special case, and it is writeable on Atomic Host, so it should work fine

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, I will try this out, been trying to fight against weird network error lately, sorry if it might take a while, and thanks for your suggestion =D.

Copy link
Author

@peterbaouoft peterbaouoft Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response, did not get a chance to work on this until now. In the meantime, may I ask a few extra questions for clarification? Thanks in advance =)

1: how is /usr "read only" enforced on Atomic Host? (ostree managed systems). The root still can modify files in /usr right? In that case, won't it still "betrays" the concept of read only?

My guess: is it that at boot time, the image we actually read is not from current /, rather it is from /sysroot/ostree/deploy/fedora-atomic/deploy/xxx?

2: If copying files into /usr is not allowed except /usr/local/share, do we need to take care about files copied into /usr/lib as well?

My guess : /usr/lib is from /lib, but it is still writing to read only /usr, so we need to take care of it?

3: There are plenty of extra files listed when I did rpm -qpl xxx (package), some of them includes man pages info, or other related/sub binaries. For example, firewalld usually comes with firewall-cmd, do we need to worry about these files too?

My guess: those won't be necessary because what we want is only the firewalld's functionality( i.e: to create firewalls), and other files may not be needed to save space / dependency handling

These are doubts of mine, and I make some guesses to them, feel free to correct me if I happen to get it wrong :p. Thanks for your time =D.

Edit: 4: Another question, related to Q1 and Q2, will /etc changes also be effective after reboot on Atomic Host?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. /usr is enforced to be read only by a readonly mountpoint. Only /usr/localis writeable: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s09.html

  2. /usr/lib is not writeable, what do we still need to copy there?

  3. we could copy firewall-cmd to the host (under /usr/local) but for now, let's not copy it and require users to use atomic run for launching the command within the container itself.

Copy link
Author

@peterbaouoft peterbaouoft Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr is enforced to be read only by a readonly mountpoint. Only /usr/local is writeable: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s09.html

ah I see, yea, it makes sense now, so I assume that any changes made to the existing /usr/local
will be permanent right? (i.e visible after reboot)

/usr/lib is not writeable, what do we still need to copy there?

before, I want to copy those xml files into /usr/lib but later figured that /etc xml seem to work as well,
(files are got from rpm -qlp firewalld package). But I figured, those xml files can be copied to the /etc/firewalld as well, so I think we should be ok =).

/usr/lib/firewalld/helpers/Q.931.xml
/usr/lib/firewalld/helpers/RAS.xml
/usr/lib/firewalld/helpers/amanda.xml
/usr/lib/firewalld/helpers/ftp.xml
/usr/lib/firewalld/helpers/h323.xml
/usr/lib/firewalld/helpers/irc.xml
/usr/lib/firewalld/helpers/netbios-ns.xml
/usr/lib/firewalld/helpers/pptp.xml
/usr/lib/firewalld/helpers/sane.xml
/usr/lib/firewalld/helpers/sip.xml
/usr/lib/firewalld/helpers/snmp.xml
/usr/lib/firewalld/helpers/tftp.xml
/usr/lib/firewalld/icmptypes/address-unreachable.xml
/usr/lib/firewalld/icmptypes/bad-header.xml
/usr/lib/firewalld/icmptypes/beyond-scope.xml
/usr/lib/firewalld/icmptypes/communication-prohibited.xml
/usr/lib/firewalld/icmptypes/destination-unreachable.xml
/usr/lib/firewalld/icmptypes/echo-reply.xml
/usr/lib/firewalld/icmptypes/echo-request.xml
/usr/lib/firewalld/icmptypes/failed-policy.xml
/usr/lib/firewalld/icmptypes/fragmentation-needed.xml
/usr/lib/firewalld/icmptypes/host-precedence-violation.xml
/usr/lib/firewalld/icmptypes/host-prohibited.xml
/usr/lib/firewalld/icmptypes/host-redirect.xml
/usr/lib/firewalld/icmptypes/host-unknown.xml
/usr/lib/firewalld/icmptypes/host-unreachable.xml
/usr/lib/firewalld/icmptypes/ip-header-bad.xml
/usr/lib/firewalld/icmptypes/neighbour-advertisement.xml
/usr/lib/firewalld/icmptypes/neighbour-solicitation.xml
/usr/lib/firewalld/icmptypes/network-prohibited.xml
/usr/lib/firewalld/icmptypes/network-redirect.xml
/usr/lib/firewalld/icmptypes/network-unknown.xml
/usr/lib/firewalld/icmptypes/network-unreachable.xml
/usr/lib/firewalld/icmptypes/no-route.xml
/usr/lib/firewalld/icmptypes/packet-too-big.xml
/usr/lib/firewalld/icmptypes/parameter-problem.xml
/usr/lib/firewalld/icmptypes/port-unreachable.xml
/usr/lib/firewalld/icmptypes/precedence-cutoff.xml
/usr/lib/firewalld/icmptypes/protocol-unreachable.xml
/usr/lib/firewalld/icmptypes/redirect.xml
/usr/lib/firewalld/icmptypes/reject-route.xml
/usr/lib/firewalld/icmptypes/required-option-missing.xml
/usr/lib/firewalld/icmptypes/router-advertisement.xml
/usr/lib/firewalld/icmptypes/router-solicitation.xml
/usr/lib/firewalld/icmptypes/source-quench.xml
/usr/lib/firewalld/icmptypes/source-route-failed.xml
/usr/lib/firewalld/icmptypes/time-exceeded.xml
/usr/lib/firewalld/icmptypes/timestamp-reply.xml
/usr/lib/firewalld/icmptypes/timestamp-request.xml
/usr/lib/firewalld/icmptypes/tos-host-redirect.xml
/usr/lib/firewalld/icmptypes/tos-host-unreachable.xml
/usr/lib/firewalld/icmptypes/tos-network-redirect.xml
/usr/lib/firewalld/icmptypes/tos-network-unreachable.xml
/usr/lib/firewalld/icmptypes/ttl-zero-during-reassembly.xml
/usr/lib/firewalld/icmptypes/ttl-zero-during-transit.xml
/usr/lib/firewalld/icmptypes/unknown-header-type.xml
/usr/lib/firewalld/icmptypes/unknown-option.xml
/usr/lib/firewalld/ipsets/README
/usr/lib/firewalld/services/RH-Satellite-6.xml
/usr/lib/firewalld/services/amanda-client.xml
/usr/lib/firewalld/services/amanda-k5-client.xml
/usr/lib/firewalld/services/bacula-client.xml
/usr/lib/firewalld/services/bacula.xml
/usr/lib/firewalld/services/bitcoin-rpc.xml
/usr/lib/firewalld/services/bitcoin-testnet-rpc.xml
/usr/lib/firewalld/services/bitcoin-testnet.xml
/usr/lib/firewalld/services/bitcoin.xml
/usr/lib/firewalld/services/ceph-mon.xml
/usr/lib/firewalld/services/ceph.xml
/usr/lib/firewalld/services/cfengine.xml
/usr/lib/firewalld/services/condor-collector.xml
/usr/lib/firewalld/services/ctdb.xml
/usr/lib/firewalld/services/dhcp.xml
/usr/lib/firewalld/services/dhcpv6-client.xml
/usr/lib/firewalld/services/dhcpv6.xml
/usr/lib/firewalld/services/dns.xml
/usr/lib/firewalld/services/docker-registry.xml
/usr/lib/firewalld/services/dropbox-lansync.xml
/usr/lib/firewalld/services/elasticsearch.xml
/usr/lib/firewalld/services/freeipa-ldap.xml
/usr/lib/firewalld/services/freeipa-ldaps.xml
/usr/lib/firewalld/services/freeipa-replication.xml
/usr/lib/firewalld/services/freeipa-trust.xml
/usr/lib/firewalld/services/ftp.xml
/usr/lib/firewalld/services/ganglia-client.xml
/usr/lib/firewalld/services/ganglia-master.xml
/usr/lib/firewalld/services/high-availability.xml
/usr/lib/firewalld/services/http.xml
/usr/lib/firewalld/services/https.xml
/usr/lib/firewalld/services/imap.xml
/usr/lib/firewalld/services/imaps.xml
/usr/lib/firewalld/services/ipp-client.xml
/usr/lib/firewalld/services/ipp.xml
/usr/lib/firewalld/services/ipsec.xml
/usr/lib/firewalld/services/iscsi-target.xml
/usr/lib/firewalld/services/kadmin.xml
/usr/lib/firewalld/services/kerberos.xml
/usr/lib/firewalld/services/kibana.xml
/usr/lib/firewalld/services/klogin.xml
/usr/lib/firewalld/services/kpasswd.xml
/usr/lib/firewalld/services/kshell.xml
/usr/lib/firewalld/services/ldap.xml
/usr/lib/firewalld/services/ldaps.xml
/usr/lib/firewalld/services/libvirt-tls.xml
/usr/lib/firewalld/services/libvirt.xml
/usr/lib/firewalld/services/managesieve.xml
/usr/lib/firewalld/services/mdns.xml
/usr/lib/firewalld/services/mosh.xml
/usr/lib/firewalld/services/mountd.xml
/usr/lib/firewalld/services/ms-wbt.xml
/usr/lib/firewalld/services/mssql.xml
/usr/lib/firewalld/services/mysql.xml
/usr/lib/firewalld/services/nfs.xml
/usr/lib/firewalld/services/nrpe.xml
/usr/lib/firewalld/services/ntp.xml
/usr/lib/firewalld/services/openvpn.xml
/usr/lib/firewalld/services/ovirt-imageio.xml
/usr/lib/firewalld/services/ovirt-storageconsole.xml
/usr/lib/firewalld/services/ovirt-vmconsole.xml
/usr/lib/firewalld/services/pmcd.xml
/usr/lib/firewalld/services/pmproxy.xml
/usr/lib/firewalld/services/pmwebapi.xml
/usr/lib/firewalld/services/pmwebapis.xml
/usr/lib/firewalld/services/pop3.xml
/usr/lib/firewalld/services/pop3s.xml
/usr/lib/firewalld/services/postgresql.xml
/usr/lib/firewalld/services/privoxy.xml
/usr/lib/firewalld/services/proxy-dhcp.xml
/usr/lib/firewalld/services/ptp.xml
/usr/lib/firewalld/services/pulseaudio.xml
/usr/lib/firewalld/services/puppetmaster.xml
/usr/lib/firewalld/services/quassel.xml
/usr/lib/firewalld/services/radius.xml
/usr/lib/firewalld/services/rpc-bind.xml
/usr/lib/firewalld/services/rsh.xml
/usr/lib/firewalld/services/rsyncd.xml
/usr/lib/firewalld/services/samba-client.xml
/usr/lib/firewalld/services/samba.xml
/usr/lib/firewalld/services/sane.xml
/usr/lib/firewalld/services/sip.xml
/usr/lib/firewalld/services/sips.xml
/usr/lib/firewalld/services/smtp-submission.xml
/usr/lib/firewalld/services/smtp.xml
/usr/lib/firewalld/services/smtps.xml
/usr/lib/firewalld/services/snmp.xml
/usr/lib/firewalld/services/snmptrap.xml
/usr/lib/firewalld/services/spideroak-lansync.xml
/usr/lib/firewalld/services/squid.xml
/usr/lib/firewalld/services/ssh.xml
/usr/lib/firewalld/services/synergy.xml
/usr/lib/firewalld/services/syslog-tls.xml
/usr/lib/firewalld/services/syslog.xml
/usr/lib/firewalld/services/telnet.xml
/usr/lib/firewalld/services/tftp-client.xml
/usr/lib/firewalld/services/tftp.xml
/usr/lib/firewalld/services/tinc.xml
/usr/lib/firewalld/services/tor-socks.xml
/usr/lib/firewalld/services/transmission-client.xml
/usr/lib/firewalld/services/vdsm.xml
/usr/lib/firewalld/services/vnc-server.xml
/usr/lib/firewalld/services/wbem-https.xml
/usr/lib/firewalld/services/xmpp-bosh.xml
/usr/lib/firewalld/services/xmpp-client.xml
/usr/lib/firewalld/services/xmpp-local.xml
/usr/lib/firewalld/services/xmpp-server.xml
/usr/lib/firewalld/xmlschema/check.sh
/usr/lib/firewalld/xmlschema/icmptype.xsd
/usr/lib/firewalld/xmlschema/ipset.xsd
/usr/lib/firewalld/xmlschema/service.xsd
/usr/lib/firewalld/xmlschema/zone.xsd
/usr/lib/firewalld/zones/FedoraServer.xml
/usr/lib/firewalld/zones/FedoraWorkstation.xml
/usr/lib/firewalld/zones/block.xml
/usr/lib/firewalld/zones/dmz.xml
/usr/lib/firewalld/zones/drop.xml
/usr/lib/firewalld/zones/external.xml
/usr/lib/firewalld/zones/home.xml
/usr/lib/firewalld/zones/internal.xml
/usr/lib/firewalld/zones/public.xml
/usr/lib/firewalld/zones/trusted.xml
/usr/lib/firewalld/zones/work.xml
/usr/lib/systemd/system/firewalld.service

we could copy firewall-cmd to the host (under /usr/local) but for now, let's not copy it and require users to use atomic run for launching the command within the container itself.

sure, makes sense =)

EDIT: It seems like /usr/lib/firewalld files can be used directly from the container, I understood it wrong, will omit the sections earlier.

maintainer="Rui xin Bao <[email protected]>" \
atomic.type="system"

RUN dnf install --setopt=tsflags=nodocs -y firewalld && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that kmod need to be installed as well:

2017-11-27 07:49:21 WARNING: modinfo command is missing, not able to detect conntrack helpers. 

Installing the kmod package, solved this problem for me

"platform": {
"os": "linux",
"arch": "amd64"
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop the "platform" section as it is not used anymore in OCI

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure :)

},
{
"type": "bind",
"source": "/etc/sysconfig/firewalld",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this error in my log:

Failed to open temporary file: [Errno 30] Read-only file system: '/etc/sysconfig/network-scripts/ifcfg-ens3.xz8ngeo7'

I think we should bind mount the entire /etc/sysconfig

]
},
{
"type": "bind",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to bind mount /dev/log as we are already bind mounting /dev

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yup, I copied this from net-snmp config.json.template file :p, will drop it then :).

]
},
{
"destination": "/dev/pts",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably drop this as well

]
},
{
"destination": "/dev/shm",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one

"rbind",
"rw",
"mode=755"
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does firewalld need to access anything under /home or /root?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does firewalld need to access anything under /home or /root?

I am not aware of it, it is also copied parts from net-snmp's config.json.template. so, will remove it to check if it is necessary

@ashcrow
Copy link
Collaborator

ashcrow commented Nov 27, 2017

@peterbaouoft doing good, keep it up 😄

@peterbaouoft
Copy link
Author

Addressed most of the comments above. Now the service seem to run with active running on Atomic Host shown below: ( will add README.md sooner and likely tmr )

[root@localhost firewalld]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-12-04 04:30:33 UTC; 9min ago
  Process: 3852 ExecStop=/bin/runc --systemd-cgroup kill firewalld (code=exited, status=0/SUCCESS)
 Main PID: 3865 (runc)
    Tasks: 7 (limit: 4915)
   Memory: 5.1M
      CPU: 13ms
   CGroup: /system.slice/firewalld.service
           └─3865 /bin/runc --systemd-cgroup run firewalld

Dec 04 04:30:33 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 04 04:30:33 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

[root@localhost firewalld]# rpm-ostree status
State: idle
Deployments:
  fedora-atomic:fedora/26/x86_64/atomic-host
                   Version: 26.150 (2017-10-14 23:19:12)
                BaseCommit: d518b37c348eb814093249f035ae852e7723840521b4bcb4a271a80b5988c44a
                    Commit: 14af07323295072070ab4964bd5df50ea1745a068b0ed80c3c52326b215d9296
              GPGSignature: Valid signature by E641850B77DF435378D1D7E2812A6B4B64DAB85D
           LayeredPackages: git vim

● fedora-atomic:fedora/26/x86_64/atomic-host
                   Version: 26.150 (2017-10-14 23:19:12)
          BootedBaseCommit: d518b37c348eb814093249f035ae852e7723840521b4bcb4a271a80b5988c44a
                    Commit: 0511d91a45a2733667caae26c4263183d52a30e828eb4c18a648c12c3dda7be7
                LiveCommit: 14af07323295072070ab4964bd5df50ea1745a068b0ed80c3c52326b215d9296
              GPGSignature: Valid signature by E641850B77DF435378D1D7E2812A6B4B64DAB85D
           LayeredPackages: git

  fedora-atomic:fedora/26/x86_64/atomic-host
                   Version: 26.150 (2017-10-14 23:19:12)
                BaseCommit: d518b37c348eb814093249f035ae852e7723840521b4bcb4a271a80b5988c44a
                    Commit: 0511d91a45a2733667caae26c4263183d52a30e828eb4c18a648c12c3dda7be7
              GPGSignature: Valid signature by E641850B77DF435378D1D7E2812A6B4B64DAB85D
           LayeredPackages: git

However, one problem remain is that, when I run systemctl stop firewalld, it shows me a failed status:

[root@localhost firewalld]# systemctl stop firewalld
[root@localhost firewalld]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-12-04 04:42:07 UTC; 3s ago
  Process: 4119 ExecStop=/bin/runc --systemd-cgroup kill firewalld (code=exited, status=0/SUCCESS)
  Process: 3865 ExecStart=/bin/runc --systemd-cgroup run firewalld (code=exited, status=143)
 Main PID: 3865 (code=exited, status=143)
      CPU: 30ms

Dec 04 04:30:33 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 04 04:30:33 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Dec 04 04:42:07 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Dec 04 04:42:07 localhost.localdomain systemd[1]: firewalld.service: Main process exited, code=exited, status=143/n/a
Dec 04 04:42:07 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
Dec 04 04:42:07 localhost.localdomain systemd[1]: firewalld.service: Unit entered failed state.
Dec 04 04:42:07 localhost.localdomain systemd[1]: firewalld.service: Failed with result 'exit-code'.

I run a check to look for journal look, there is one suscipious line:

<warn>  [1512362701.1380] firewall: [0x55f9b3941f00,change:"eth0"]: complete: request failed (An SELinux policy prevents this sender from sending this message to this recipient, 0 matched rules; type="method_call", sender=":1.2" (uid=0 pid=709 comm="/usr/sbin/NetworkManager --no-daemon " label="system_u:system_r:NetworkManager_t:s0") interface="org.fedoraproject.FirewallD1.zone" member="changeZone" error name="(unset)" requested_reply="0" destination=":1.82" (uid=0 pid=4220 comm="/usr/bin/python3 -Es /usr/sbin/firewalld --nofork " label="system_u:system_r:container_runtime_t:s0"))

and this is the link for entire log, any ideas why is that happening ? https://paste.fedoraproject.org/paste/49rl5Pgd4bxCV~y5n9bIjw.

I am personally not familiar with firewalld. So, also wonders, other than the stopping failure, is the current behavior for firewalld behaving correctly?

Thanks for your time =).

@giuseppe
Copy link
Collaborator

giuseppe commented Dec 4, 2017

could you try with KillMode=none in the systemd unit file? Does that solve the issue you are seeing?

Another thing I was wondering about, does firewalld load kernel modules? If yes, I think we should bind mount /usr/lib/modules from the host, to avoid mismatches between the host and the modules used by the container.

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 4, 2017

Thanks for the review/commenting =).

could you try with KillMode=none in the systemd unit file?

hmm.. I tried the container again on my f27 host, now it seems not recognizing /usr/local/share
's actions...... any resolutions to that? Unfortunately, on my f26 host ( without denied error)
, killmode = none seems also not solving the problem of failing from systemctl stop firewalld,
I still suspect that it might be due to the selinux problem reported earlier.

Below is the info from my f27 host. Thoughts? ( only add one kill mode = none , and nothing else)

[root@localhost firewalld.0]# runc --systemd-cgroup run firewalld
2017-12-04 16:29:30 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.98" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file

[root@localhost firewalld.0]# ll -a /usr/local/share/polkit-1/actions/
total 12
drwxr-xr-x. 2 root root  164 Dec  4 16:28 .
drwxr-xr-x. 3 root root   21 Dec  4 15:58 ..
-rw-r--r--. 1 root root 3916 Jan  1  1970 org.fedoraproject.FirewallD1.desktop.policy.choice
-rw-r--r--. 1 root root 4024 Jan  1  1970 org.fedoraproject.FirewallD1.policy
-rw-r--r--. 1 root root 4024 Jan  1  1970 org.fedoraproject.FirewallD1.server.policy.choice

[root@localhost firewalld.0]# rpm-ostree status
State: idle
Deployments:
* fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                BaseCommit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4
           LayeredPackages: git

  fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                    Commit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4

Another thing I was wondering about, does firewalld load kernel modules? If yes, I think we should bind mount /usr/lib/modules from the host,

ah, good point, I think we do need it =), https://github.com/firewalld/firewalld/blob/master/src/firewall/functions.py#L336. we just bind as ro mount right? ( and rprivate in the options), because we do not want to modify it?

EDIT The failure for dbus access error seems to be a flake... please disregard it for now =)

@giuseppe
Copy link
Collaborator

giuseppe commented Dec 4, 2017

a read-only rslave bind mount is fine, in case it is ever overriden on the host, we will get the changes.

I've not seen the SELinux failure and the KillMode= helped me to solve the failure on exit.

Could you try to temporarily disable selinux and see if it works? We can address the selinux issue later, for example you could try to set the SELinux label in the config.json.template file to something like "system_u:system_r:firewalld_t:s0"

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 4, 2017

a read-only rslave bind mount is fine, in case it is ever overriden on the host, we will get the changes

sure, I will try to find usages of rslave, and apply it to the config files =D.

I've not seen the SELinux failure and the KillMode= helped me to solve the failure on exit

... Now the KillMode=none solves the problem for me. i guess it was probably due to the internal errors I had some where earlier, sorry for my misunderstanding =(. But now the container seems to work =D, will try and test it a bit more, and going to complete the README.md.

Thanks for the info and your time =D.

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 4, 2017

@peterbaouoft let me know when you are ready for others to test. I'll be happy to give it a go!

@peterbaouoft
Copy link
Author

@ashcrow, sure, I still have some doubts currently about some parts of the system containers, may want to confirm with gisueppe about those. After those doubts are cleared, I think this system container should be ready for test =).

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 4, 2017

@peterbaouoft sounds good. And to reiterate, good work so far! Hope you're learning quite a bit 😁

@peterbaouoft
Copy link
Author

Pushed a fixup ⬆️, and also a documentation for installation instructions. Now the system container seems no longer have the failed state when running systemctl stop firewalld

There are also a few doubts that I came across while making this container. Hopefully those won't bother you too much =).

Q1: It might be a doubt that is related to previously asked questions, but I still think I am a bit unsure about the concept.. The doubt is that what might be the purpose that we copy /etc/firewalld into the host? I noticed during the execution of firewalld, files in /usr/lib/firewalld are used within the container.
I wonder if /etc/firewalld can be used by the firewalld binary in the container. (without copying it to the host).

My Guess: we might want user to configure the /etc/firewalld themselves, that might be one of the reasons why we copy it to the host

Q2: For my other testing machines that are not atomic host, some of them seems not including policy kit by default, leading to some "service not found" warnings during execution. If that is the case, do we want to worry about the case where polkit is not installed?

Q3: Minor: I noticed that there are some empty folders left over when running atomic containers delete firewalld. I see we have projectatomic/atomic#1131 that address this problem, so do we still have empty folders left over when the patch is applied? ( sorry, can't run a easy check, it seemed hard to build and apply upstream atomic into Atomic Host).

The output is as following: as you can see /etc/firewalld and its empty subdirectories are not deleted

[root@localhost ~]# atomic containers list -a
[root@localhost ~]# cd /etc/firewalld
bash: cd: /etc/firewalld: No such file or directory
[root@localhost ~]# atomic install --system --system-package=no --name=firewalld firewalld
Extracting to /var/lib/containers/atomic/firewalld.0
File /./etc already exists.
File /./usr already exists.
File /./var already exists.
File /etc/dbus-1 already exists.
File /etc/sysconfig already exists.
File /etc/dbus-1/system.d already exists.
File /etc/sysconfig/firewalld already exists.
File /usr/local already exists.
File /usr/local/share already exists.
File /usr/local/share/polkit-1 already exists.
File /usr/local/share/polkit-1/actions already exists.
File /var/log already exists.
Created file /etc/dbus-1/system.d/FirewallD.conf
Created file /etc/firewalld
Created file /etc/firewalld/firewalld-server.conf
Created file /etc/firewalld/firewalld-standard.conf
Created file /etc/firewalld/firewalld-workstation.conf
Created file /etc/firewalld/firewalld.conf
Created file /etc/firewalld/helpers
Created file /etc/firewalld/icmptypes
Created file /etc/firewalld/ipsets
Created file /etc/firewalld/lockdown-whitelist.xml
Created file /etc/firewalld/services
Created file /etc/firewalld/zones
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy.choice
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.policy
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy.choice
Created file /var/log/firewalld
systemctl daemon-reload
systemctl enable firewalld
[root@localhost ~]# atomic containers delete firewalld
Do you wish to delete the following images?

   ID           NAME                 IMAGE_NAME                STORAGE   
   firewalld    firewalld            firewalld                 ostree    

Confirm (y/N) y
systemctl disable --now firewalld
systemctl daemon-reload
[root@localhost ~]# ll /etc/firewalld/
total 0
drwxr-xr-x. 2 root root 6 Dec  4 21:01 helpers
drwxr-xr-x. 2 root root 6 Dec  4 21:01 icmptypes
drwxr-xr-x. 2 root root 6 Dec  4 21:01 ipsets
drwxr-xr-x. 2 root root 6 Dec  4 21:01 services
drwxr-xr-x. 2 root root 6 Dec  4 21:01 zones

@giuseppe
Copy link
Collaborator

giuseppe commented Dec 5, 2017

  1. yes, the reason why we copy the files to /etc and bind mount them into the container is that in this way users can configure it in the usual way. Otherwise it would not be possible to modify /etc in the container.

  2. good point. Should we make the dependency on policykit optional?

  3. Patch #1131 should fix that. If you want to try it, you can run atomic directly from the local directory. Clone the repository and use ./atomic instead of /usr/bin/atomic.

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 5, 2017

Patch #1131 should fix that. If you want to try it, you can run atomic directly from the local directory. Clone the repository and use ./atomic instead of /usr/bin/atomic.

$ sudo python ./atomic

@peterbaouoft
Copy link
Author

good point. Should we make the dependency on policykit optional?

I am not sure how hard it would be to do optional dependency checking =), but willing to do so if needed. But currently this container is targeting for Atomic Host right? If so, we don't necessarily need to install the polkit as we already have polkit as base package in Atomic Host. ( we can just assume polkit is there :p)

So my opinion is, we don't need to have this optional dependency( we can assume polkit is there on host) unless people outside atomic host wants it? WDYT @giuseppe

Patch #1131 should fix that. If you want to try it, you can run atomic directly from the local directory. Clone the repository and use ./atomic instead of /usr/bin/atomic.

cool, lemme try that :p

$ sudo python atomic

thx, @ashcrow :-)

@giuseppe
Copy link
Collaborator

giuseppe commented Dec 5, 2017

I was suggesting about having the systemd dependency as optional, so that it is used only when polkit is available (i.e. Wants= in the systemd service file)

@peterbaouoft
Copy link
Author

I was suggesting about having the systemd dependency as optional, so that it is used only when polkit is available (i.e. Wants= in the systemd service file)

ah oops, I misunderstood earlier. Sorry for my poor english. In this case, do we want Require= or Wants=, I think both should be ok since Wants is A weaker version of Requires=
so it will be Wants=polkit.service or Requires=polkit.service right? I would try with Wants=polkit.service first since that is what you suggested :p.

@peterbaouoft
Copy link
Author

It is odd..... now when I install the container to a new (freshly) installed Atomic Host, it can't seem to find /usr/local/share's policy file via dbus any more =(. ( DBusAcessError for org.fedoraproject.FirewallD1)

But then, if ... I uninstall the container, and reinstall back, it runs without a problem..(#facepalm). Then every reinstall after that seems ok.... Interesting... Need investigating/testing more to see if the behavior can always be reproduced. (Sorry for the delay so far...)

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 5, 2017

@peterbaouoft no need to be sorry 😄

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 5, 2017

...After some painful debugging..., I have found two ways currently that a system container for firewalld could fail to start. But I am unaware if those causes will be the same. Both errors appear to happen consistently ( at least had three tries, hopefully it is not just only me =( ).

For case 1, the reproducing step is too long, so did not have a log of it...

1: Fresh install firewalld on a freshly provisioned Atomic Host (i.e rpm-ostree install git, then follow instructions for installing it). The first systemctl start firewalld will fail. Then by atomic uninstall firewalld and atomic install --system --system-package=no --name=firewalld firewalld, the service will likely have an active status. ( shown below for an example)

2: This one is reproducible without having a freshly installed Atomic Host. It only requires you having a "working" firewalld system container.

The steps to reproduce are as follows: on a f27 atomic host, steps to do after seeing a failed firewalld service

[root@localhost ~]# atomic uninstall firewalld
systemctl disable --now firewalld
systemctl daemon-reload
[root@localhost ~]# atomic install --system --system-package=no --name=firewalld firewalld
Extracting to /var/lib/containers/atomic/firewalld.0
Created file /etc/dbus-1/system.d/FirewallD.conf
Created file /etc/firewalld
Created file /etc/firewalld/firewalld-server.conf
Created file /etc/firewalld/firewalld-standard.conf
Created file /etc/firewalld/firewalld-workstation.conf
Created file /etc/firewalld/firewalld.conf
Created file /etc/firewalld/helpers
Created file /etc/firewalld/icmptypes
Created file /etc/firewalld/ipsets
Created file /etc/firewalld/lockdown-whitelist.xml
Created file /etc/firewalld/services
Created file /etc/firewalld/zones
Created file /etc/sysconfig/firewalld
Created file /usr/local/share/polkit-1
Created file /usr/local/share/polkit-1/actions
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy.choice
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.policy
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy.choice
Created file /var/log/firewalld
systemctl daemon-reload
systemctl enable firewalld
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-12-05 21:37:56 UTC; 3s ago
 Main PID: 1536 (runc)
    Tasks: 8 (limit: 4915)
   Memory: 468.0K
      CPU: 2ms
   CGroup: /system.slice/firewalld.service
           └─1536 /bin/runc --systemd-cgroup run firewalld

Dec 05 21:37:55 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 05 21:37:56 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

After that, the failure can be reproduced through the following commands:

[root@localhost ~]# systemctl stop dbus
Warning: Stopping dbus.service, but it can still be activated by:
  dbus.socket
[root@localhost ~]# systemctl stop polkit
[root@localhost ~]# systemctl start dbus
[root@localhost ~]# systemctl start polkit
[root@localhost ~]# systemctl start firewalld
Job for firewalld.service failed because the control process exited with error code.
See "systemctl  status firewalld.service" and "journalctl  -xe" for details.
[root@localhost ~]# date       
Tue Dec  5 21:40:41 UTC 2017

=====================Output in /var/log/firewalld which tracks error messages============
2017-12-05 21:40:29 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.10" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file
2017-12-05 21:40:30 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.15" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file
2017-12-05 21:40:31 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.20" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file
2017-12-05 21:40:32 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.25" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file

Any clues what could be the causes for the problem? I am not sure at all how to solve this atm.. Thanks in advance =). @giuseppe can you take a look when you have time? :-).
P.S: I can provide slightly more details if needed, do not want to make the content look too long here

EDIT: the dockerfile I tested is mostly similar to the current one, except that the base image is From fedora (I could not download the image from registry.fedoraproject.org today)

@giuseppe
Copy link
Collaborator

giuseppe commented Dec 6, 2017

the selinux issue we were seeing is fixed by:

projectatomic/atomic#1143

Could you please verify if it works for you?

Also, dbus must be reloaded before it considers the new configuration. I am fine if you just document this step. After the atomic install, the user needs to run "killall -SIGHUP dbus-daemon".

Doesn't the same issue happen with the firewalld rpm? I don't see any special handling in the post scripts for it.

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 6, 2017

Could you please verify if it works for you?

looks like it is working \o/, now the second case(dbus) no longer fails out after the patch is applied. (On my testing machine)

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-12-06 20:46:46 UTC; 25s ago
 Main PID: 2234 (runc)
    Tasks: 7 (limit: 4915)
   Memory: 1.3M
      CPU: 7ms
   CGroup: /system.slice/firewalld.service
           └─2234 /bin/runc --systemd-cgroup run firewalld

Dec 06 20:46:46 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 06 20:46:46 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]# systemctl stop dbus
Warning: Stopping dbus.service, but it can still be activated by:
  dbus.socket
[root@localhost ~]# systemctl start dbus
[root@localhost ~]# systemctl start polkit
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-12-06 20:47:34 UTC; 3s ago
  Process: 2309 ExecStop=/bin/runc --systemd-cgroup kill firewalld (code=exited, status=0/SUCCESS)
 Main PID: 2331 (runc)
    Tasks: 7 (limit: 4915)
   Memory: 1.3M
      CPU: 7ms
   CGroup: /system.slice/firewalld.service
           └─2331 /bin/runc --systemd-cgroup run firewalld

Dec 06 20:47:33 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 06 20:47:34 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

Also, dbus must be reloaded before it considers the new configuration. I am fine if you just document this step. After the atomic install, the user needs to run "killall -SIGHUP dbus-daemon".

ah a bit weird, the above worked without me trying the killall command, I will also document it later just in case =).

Doesn't the same issue happen with the firewalld rpm? I don't see any special handling in the post scripts for it.

for rpm, I am not seeing this behavior. But since the patch kinda solves the problem for me, let's not worry about it then?

EDIT: now it appears the fresh install problem also got fixed :D. here is the log if you are interested.
Note: it is really long as I need to apply upstream changes with the selinux fix:
https://paste.fedoraproject.org/paste/X2m3Meu2AI-DJhHB9JwF-A

@peterbaouoft
Copy link
Author

@giuseppe , Seems like with the new patch applied, both failing cases before all passes as well =)

[root@localhost atomic]# rpm-ostree status
State: idle
Deployments:
* fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                BaseCommit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4
           LayeredPackages: PyYAML gcc gcc-go git golang-github-cpuguy83-go-md2man libffi-devel ostree-devel pylint python-dbus python-devel python-gobject-base python-slip-dbus python2-coverage python2-dateutil python2-pylint python3-pylint redhat-rpm-config rpm-python
                  Unlocked: development

  fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                    Commit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4
[root@localhost atomic]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-12-08 18:54:39 UTC; 2min 44s ago
  Process: 1951 ExecStop=/bin/runc --systemd-cgroup kill firewalld (code=exited, status=0/SUCCESS)
 Main PID: 1970 (runc)
    Tasks: 8 (limit: 4915)
   Memory: 5.4M
      CPU: 19ms
   CGroup: /system.slice/firewalld.service
           └─1970 /bin/runc --systemd-cgroup run firewalld

Dec 08 18:54:38 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 08 18:54:39 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost atomic]# systemctl stop dbus
Warning: Stopping dbus.service, but it can still be activated by:
  dbus.socket
[root@localhost atomic]# systemctl start firewalld
[root@localhost atomic]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-12-08 18:57:32 UTC; 4s ago
  Process: 2153 ExecStop=/bin/runc --systemd-cgroup kill firewalld (code=exited, status=0/SUCCESS)
 Main PID: 2172 (runc)
    Tasks: 7 (limit: 4915)
   Memory: 5.3M
      CPU: 19ms
   CGroup: /system.slice/firewalld.service
           └─2172 /bin/runc --systemd-cgroup run firewalld

Dec 08 18:57:31 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 08 18:57:32 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

This is the host applying atomic upstream changes, the firewalld container might be ready for other folks to test =). The service is passing. Tho, tbh, I am not too certain what will the expected firewalld functionality be, so if there is any functionality issues, please let me know :p.

Also Note: currently only firewalld binary is shipped, (i.e no firewall-cmd or other related commands is there with it yet).

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 8, 2017

@peterbaouoft I'll give it a shot and report back!

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 8, 2017

Very close. I ended up hitting a missing directory and an SELinux issue. Here is how I found them ...

Install

[root@fedora-27-ah-beta ~]# systemctl status firewalld                                 
Unit firewalld.service could not be found.                                                                                                                                    
[root@fedora-27-ah-beta ~]# atomic install --system --system-package=no -n firewalld --storage ostree docker:firewalld:latest                                                 
Extracting to /var/lib/containers/atomic/firewalld.0                                                                                                                          
Created file /etc/dbus-1/system.d/FirewallD.conf                                                                                                                              
Created file /etc/firewalld/firewalld-server.conf                                                                                                                             
Created file /etc/firewalld/firewalld-standard.conf                                                                                                                           
Created file /etc/firewalld/firewalld-workstation.conf                                                                                                                        
Created file /etc/firewalld/firewalld.conf                                             
Created file /etc/firewalld/lockdown-whitelist.xml                                                                                                                            
Created file /etc/sysconfig/firewalld                                                                                                                                         
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy.choice                                                                             
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.policy                                                                                            
Created file /usr/local/share/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy.choice                                                                              
Created file /var/log/firewalld                                                                                                                                               
systemctl daemon-reload                                                                                                                                                       
systemctl enable firewalld                                                             
[root@fedora-27-ah-beta ~]# systemctl status firewalld                                                                                                                        
● firewalld.service - firewalld - dynamic firewall daemon                                                                                                                     
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)                                                                                    
   Active: inactive (dead)                                                                                                                                                    
[root@fedora-27-ah-beta ~]# systemctl start firewalld                                                                                                                         
Job for firewalld.service failed because the control process exited with error code.                                                                                          
See "systemctl  status firewalld.service" and "journalctl  -xe" for details. 

Look at issue

Investigate

[root@fedora-27-ah-beta ~]# cd /var/lib/containers/atomic/firewalld.0/
[root@fedora-27-ah-beta firewalld.0]# /bin/runc --systemd-cgroup run 'firewalld'
container_linux.go:265: starting container process caused "process_linux.go:348: container init caused \"rootfs_linux.go:57: mounting \\\"/run/firewalld\\\" to rootfs \\\"/var/lib/containers/atomic/firewalld.0/rootfs\\\" at \\\"/run/firewalld\\\" caused \\\"stat /run/firewalld: no such file or directory\\\"\""

Create dir and try again

[root@fedora-27-ah-beta firewalld.0]# sudo mkdir /run/firewalld
[root@fedora-27-ah-beta firewalld.0]# /bin/runc --systemd-cgroup run 'firewalld'
2017-12-08 19:36:47 ERROR: Exception DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.207" is not allowed to own the service "org.fedoraproject.FirewallD1" due to security policies in the configuration file

Run ausearch -l

type=AVC msg=audit(1512761962.841:424): avc:  denied  { read } for  pid=1 comm="systemd" name="firewalld" dev="dm-0" ino=28120247 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:container_share_t:s0 tclass=file permissive=0

Later I remembered this comment about using a specific version of atomic. I used it but got the same error.

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 8, 2017

Very close. I ended up hitting a missing directory and an SELinux issue

Ouch, and thanks for the feedback =), the missing directory is expected as that should be autogenerated by systemd with
RuntimeDirectory=${NAME} line in service.template file.

Tho, for selinux is a bit weird... it seems working on my side T_T. I might need more info to debug here, hopefully you won't mind =). Did you try killall -SIGHUP dbus-daemon after applying the patch ? Also, do note the patch does not fix the issue in place, you need to reinstall the container because selinux label applied to files seems not get reset with the patch.

The patch for restoring selinux label should be effective at installation time(copying files) to the host.

So the steps what I usually do on a fresh installed Atomic Host for firewalld container is:

1: Layer all the packages needed for atomic upstream so I can do make install 
2: git clone atomic and git clone atomic-system-containers
3: checkout specific version of atomic, and firewalld 
4: do an docker build, atomic pull, atomic install path
5: reload dbus configuration
6: Start the service

Wondering do you also follow a similar path? @ashcrow.
P.S: The set up is a bit messy here, sorry for the confusion.

@ashcrow
Copy link
Collaborator

ashcrow commented Dec 8, 2017

Following exactly the steps in the paste (installing packages, unlocking, overwriting atomic rather than running from source, killing dbus) did end up working. I'm not sure if it's due to an update in packages or if the source runs didn't work as expected. 👍

This probably is blocked on projectatomic/atomic#1143 at this point.

@peterbaouoft
Copy link
Author

peterbaouoft commented Dec 15, 2017

Update: Now another problem arises for the container ( so many cases to consider about #facepalm):

The log is as follows: ( this is after applying the selinux fix patch)

[root@localhost firewalld]# rpm-ostree status
State: idle
Deployments:
* fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                BaseCommit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4
           LayeredPackages: PyYAML gcc gcc-go git golang-github-cpuguy83-go-md2man libffi-devel pylint python-dbus python-devel python-gobject-base python-slip-dbus python2-coverage python2-dateutil python2-pylint python3-pylint redhat-rpm-config rpm-python
                  Unlocked: development

  fedora-atomic:fedora/27/x86_64/atomic-host
                   Version: 27.16 (2017-11-28 23:08:35)
                    Commit: 86727cdbc928b7f7dd0e32f62d3b973a8395d61e0ff751cfea7cc0bc5222142f
              GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4

[root@localhost firewalld]# killall -SIGHUP dbus-daemon
[root@localhost firewalld]# systemctl start firewalld
[root@localhost firewalld]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/etc/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-12-15 15:31:11 UTC; 5s ago
 Main PID: 2254 (runc)
    Tasks: 8 (limit: 4915)
   Memory: 144.0K
      CPU: 1ms
   CGroup: /system.slice/firewalld.service
           └─2254 /bin/runc --systemd-cgroup run firewalld

Dec 15 15:31:09 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 15 15:31:11 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost firewalld]# atomic run firewalld firewall-cmd --state
ERROR:dbus.proxies:Introspect error on :1.41:/org/fedoraproject/FirewallD1: dbus.exceptions.DBusException: org.freedesktop.PolicyKit1.Error.Failed: Action org.fedoraproject.FirewallD1.info is not registered
Error: Action org.fedoraproject.FirewallD1.config is not registered

=====================================================================
A suspicious warning in journal log is as follows:
localhost.localdomain NetworkManager[716]: <warn>  [1513351872.5476] firewall: [0x55fdb04f3180,change:"eth0"]: complete: request failed (Action org.fedoraproject.FirewallD1.config is not registered

I suspect one of the causes may be that applications do not tend to recognize the policy files copied /usr/local/share. The default location is /usr/share, but we able unable to copy files into /usr on atomic host. Currently investigating if a fix can exist for this problem

@giuseppe
Copy link
Collaborator

if you don't find an answer, could you try asking on the polkit-devel mailing list?

@giuseppe
Copy link
Collaborator

For a better understanding, I've tried to make the changes required into polkit. I've tried locally with the version of polkit from my branch and it solves the problem you are seeing. I changed the system container to copy the files under /etc/polkit-1/actions:

https://github.com/giuseppe/polkit/tree/polkit-alternative-actions-directory

Let's see where the discussion goes, and I could cleanup the patch if needed. I am not sure it is an acceptable version yet since it changes the API.

@giuseppe
Copy link
Collaborator

giuseppe commented Jan 2, 2018

@peterbaouoft could you file a bugzilla for polkit to allow an alternative directory for reading these files?

@giuseppe
Copy link
Collaborator

@peterbaouoft could you please followup with the polkit people so to enable this use case for system containers on Atomic?

@peterbaouoft
Copy link
Author

peterbaouoft commented Feb 15, 2018

@giuseppe yea, I would like to. But colin is the maintainer for polkit right? I guess we can bring this up at standup or so? WDYT

FTR: the issue refers to https://lists.freedesktop.org/archives/polkit-devel/2017-December/000566.html

@ashcrow
Copy link
Collaborator

ashcrow commented Feb 15, 2018

/cc @cgwalters What's your take on the above?

@peterbaouoft
Copy link
Author

gentle pin :-)

@cgwalters
Copy link
Member

cgwalters commented Feb 22, 2018

For the record I'm not "the" maintainer of polkit; I've done some work on it in the past...I probably still have git push access but I'd need to check. it's unfortunately I'd say one of the projects in the base OS with the biggest ratio of "criticality:maintaner time".

I imagine a patch to add /etc would be fairly easy, but it's going to be quite a while before it propagates outwards.

I still feel like long term the syscontainers RPM path (or alternatively, a special rpm-ostree overlay model for syscontainer files) is going to be the biggest win as then syscontainers can be more equivalent to RPM in practical power.

@giuseppe
Copy link
Collaborator

I had prepared a patch for polkit to use /etc:

giuseppe/polkit@d69e133

This solves the issue we were seeing.

While I agree with you that the .rpm installation should be our goal, I think it won't hurt to have an alternative way for enabling it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants