charon apparmor profile not applied on fresh install

Bug #1932197 reported by Andreas Hasenack
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
strongswan (Ubuntu)
Fix Released
High
Unassigned
Bionic
Fix Released
High
Andreas Hasenack

Bug Description

[Impact]
A fresh install of strongswan that include the strongswan-charon package will have the charon daemon running unconfined, despite there being an apparmor profile for it by default.

Furthermore, after any restart of that daemon, it will become confined, which might be even more surprising to users.

This happens because strongswan-starter is configured before strongswan-charon. Since -starter starts the charon service (the -charon package is unpacked by then), but only -charon loads the apparmor profile into the kernel, the charon daemon starts unconfined. But any restart afterwards will pick up the apparmor profile.

The fix for this was a change in the dependencies between strongswan-starter (the package that ships the systemd service file) and strongswan-charon, which ships the daemon and its apparmor profile. This change is already applied in focal and later, and was cherry-picked as-is: https://git.launchpad.net/ubuntu/+source/strongswan/commit/?h=ubuntu/focal-devel&id=063994db81135f5f165c1913fcbd36e918163ab5

[Test Plan]

In a bionic vm:
$ sudo apt install strongswan

Verify that charon is running and confined:
$ ps axwZ | grep /usr/lib/ipsec/charon | grep -v grep
/usr/lib/ipsec/charon (enforce) 1720 ? Ssl 0:00 /usr/lib/ipsec/charon

In a system with the bug, the charon service is running unconfined:
$ ps axwZ|grep /usr/lib/ipsec/charon|grep -v grep
unconfined 12374 ? Ssl 0:00 /usr/lib/ipsec/charon

[Where problems could occur]

1) The fix introduces a slight change in behavior if the user has disabled the installation of Recommended packages (i.e., apt install <pkg> --no-install-recommends). Now, whenever strongswan-charon is installed with --no-install-recommends, strongswan-starter will not be included, which means the service will not be started.

2) Because of the bug, fresh installs of the charon daemon will have it running unconfined, possibly without the user noticing. After any restart, though, it will become confined, so I don't think we will have many such cases out there in the wild. That being said, if there is a config that is incompatible with the apparmor profile, and that wasn't noticed before, now it can affect the service, since charon will, correctly, start in confined mode.

3) Restarting strongswan unattended, like how it happens during an automatic update, is not always a good idea, as it could disrupt traffic severely and leave a system unreachable. I believe sites that are sensitive to this will already have taken precautions, though.

[Other Info]
This fix represents a delta we have with Debian since it was first applied to focal. Christian and others spent a great amount of effort in trying to push this (and other bits of our delta) to debian:
- starting with https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=848890, which lead to the MRs below:
- https://salsa.debian.org/debian/strongswan/merge_requests/8
- https://salsa.debian.org/debian/strongswan/merge_requests/7
- https://salsa.debian.org/debian/strongswan/merge_requests/6
- https://salsa.debian.org/debian/strongswan/merge_requests/5

And others.

[Original Description]

Due to ordering of package installations, the apparmor profile for the `charon` daemon is not applied to the service on a fresh install on bionic.

For `apt install strongswan`, we get:
(...)
Setting up libstrongswan (5.6.2-1ubuntu2.5) ...
Setting up libstrongswan-standard-plugins (5.6.2-1ubuntu2.5) ...
Setting up libcharon-standard-plugins (5.6.2-1ubuntu2.5) ...
Setting up strongswan-libcharon (5.6.2-1ubuntu2.5) ...
Setting up strongswan-starter (5.6.2-1ubuntu2.5) ... <============
Created symlink /etc/systemd/system/multi-user.target.wants/strongswan.service → /lib/systemd/system/strongswan.service.
Setting up strongswan-charon (5.6.2-1ubuntu2.5) ... <============
Setting up strongswan (5.6.2-1ubuntu2.5) ...
(...)

$ ps axwZ|grep /usr/lib/ipsec/charon|grep -v grep
unconfined 12374 ? Ssl 0:00 /usr/lib/ipsec/charon

$ sudo aa-status | tail -n 2
1 processes are unconfined but have a profile defined.
   /usr/lib/ipsec/charon (12374)

See how strongswan-starter is setup before strongswan-charon. What happens is that -starter starts the services (including charon), but the apparmor profile is only loaded into the kernel by the strongswan-charon's postinst package, therefore too late.

In focal and later, the dependencies were changed[1]:
strongswan-starter: replaced "Recommends: strongswan-charon" with "Depends: strongswan-charon"
strongswan-charon: replaced "Depends: strongswan-starter" with "Recommends: strongswan-starter"

This has the effect that strongswan-charon will be configured already (i.e., the apparmor profile will be loaded into the kernel) by the time strongswan-starter comes along and (re)starts the services:

(...)
Setting up libstrongswan (5.8.2-1ubuntu3.1) ...
Setting up strongswan-libcharon (5.8.2-1ubuntu3.1) ...
Setting up libcharon-extauth-plugins (5.8.2-1ubuntu3.1) ...
Setting up strongswan-charon (5.8.2-1ubuntu3.1) ... <============
Setting up libstrongswan-standard-plugins (5.8.2-1ubuntu3.1) ...
Setting up strongswan-starter (5.8.2-1ubuntu3.1) ... <============
Created symlink /etc/systemd/system/multi-user.target.wants/strongswan-starter.service → /lib/systemd/system/strongswan-starter.service.
Setting up strongswan (5.8.2-1ubuntu3.1) ...
(...)

$ ps axwZ | grep /usr/lib/ipsec/charon | grep -v grep
/usr/lib/ipsec/charon (enforce) 1720 ? Ssl 0:00 /usr/lib/ipsec/charon

1. https://launchpad.net/ubuntu/+source/strongswan/5.8.1-1ubuntu1

Related branches

Changed in strongswan (Ubuntu):
status: New → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in strongswan (Ubuntu Bionic):
status: New → Confirmed
Changed in strongswan (Ubuntu Bionic):
assignee: nobody → Andreas Hasenack (ahasenack)
importance: Undecided → High
Changed in strongswan (Ubuntu):
importance: Undecided → High
Changed in strongswan (Ubuntu Bionic):
status: Confirmed → In Progress
description: updated
description: updated
description: updated
description: updated
description: updated
description: updated
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Package uploaded, waiting for SRU team to review

"[ubuntu/bionic-proposed] strongswan 5.6.2-1ubuntu2.6 (Waiting for approval)"

Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello Andreas, or anyone else affected,

Accepted strongswan into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/strongswan/5.6.2-1ubuntu2.6 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in strongswan (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-bionic
Revision history for this message
Andreas Hasenack (ahasenack) wrote :
Download full text (3.5 KiB)

bionic verification

reproducing the bug

strongswan was just installed:

ubuntu@bionic-strongswan-apparmor-1932197:~$ apt-cache policy strongswan-charon
strongswan-charon:
  Installed: 5.6.2-1ubuntu2.5
  Candidate: 5.6.2-1ubuntu2.5
  Version table:
 *** 5.6.2-1ubuntu2.5 500
        500 http://br.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     5.6.2-1ubuntu2.3 500
        500 http://br.archive.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     5.6.2-1ubuntu2 500
        500 http://br.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

charon is running unconfined:
ubuntu@bionic-strongswan-apparmor-1932197:~$ ps axwZ | grep /usr/lib/ipsec/charon | grep -v grep
unconfined 1898 ? Ssl 0:00 /usr/lib/ipsec/charon

I now purge it all:
ubuntu@bionic-strongswan-apparmor-1932197:~$ sudo apt purge strongswan --autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libcharon-standard-plugins* libstrongswan* libstrongswan-standard-plugins* strongswan* strongswan-charon* strongswan-libcharon* strongswan-starter*
0 upgraded, 0 newly installed, 7 to remove and 36 not upgraded.
(...)

Confirm it's not running:
ubuntu@bionic-strongswan-apparmor-1932197:~$ ps axwZ | grep /usr/lib/ipsec/charon | grep -v grep
ubuntu@bionic-strongswan-apparmor-1932197:~$

The apparmor profiles are still loaded in the kernel, so I remove them too:
ubuntu@bionic-strongswan-apparmor-1932197:~$ sudo aa-status | grep ipsec
   /usr/lib/ipsec/charon
   /usr/lib/ipsec/stroke

ubuntu@bionic-strongswan-apparmor-1932197:~$ echo "profile /usr/lib/ipsec/charon {}" | sudo apparmor_parser -R
ubuntu@bionic-strongswan-apparmor-1932197:~$ echo "profile /usr/lib/ipsec/stroke {}" | sudo apparmor_parser -R
ubuntu@bionic-strongswan-apparmor-1932197:~$ sudo aa-status | grep ipsec
ubuntu@bionic-strongswan-apparmor-1932197:~$

And now I install the packages from bionic-proposed:
ubuntu@bionic-strongswan-apparmor-1932197:~$ sudo apt install strongswan
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libcharon-standard-plugins libstrongswan libstrongswan-standard-plugins strongswan-charon strongswan-libcharon strongswan-starter
Suggested packages:
  libstrongswan-extra-plugins libcharon-extra-plugins
The following NEW packages will be installed:
  libcharon-standard-plugins libstrongswan libstrongswan-standard-plugins strongswan strongswan-charon strongswan-libcharon strongswan-starter
0 upgraded, 7 newly installed, 0 to remove and 54 not upgraded.
Need to get 868 kB of archives.
After this operation, 3871 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Confirming I have the one from proposed installed:
ubuntu@bionic-strongswan-apparmor-1932197:~$ apt-cache policy strongswan-charon
strongswan-charon:
  Installed: 5.6.2-1ubuntu2.6
  Candidate: 5.6.2-1ubuntu2.6
  Version table:
 *** 5.6.2-1ubuntu2.6 500
        500 http://br.archive.ubuntu.com/ubuntu bionic-proposed/main amd64 Packages
        1...

Read more...

tags: added: verification-done-bionic
removed: verification-needed-bionic
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package strongswan - 5.6.2-1ubuntu2.6

---------------
strongswan (5.6.2-1ubuntu2.6) bionic; urgency=medium

  * d/control: change dependency relationship between strongswan-charon and
    strongswan-starter so that the charon service is started with the apparmor
    profile applied (LP: #1932197)

 -- Andreas Hasenack <email address hidden> Fri, 18 Jun 2021 19:58:12 +0000

Changed in strongswan (Ubuntu Bionic):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for strongswan has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.