Skip to content

Instantly share code, notes, and snippets.

@dlangille
Last active March 1, 2022 12:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlangille/f8cbf363aef45ced0c0f to your computer and use it in GitHub Desktop.
Save dlangille/f8cbf363aef45ced0c0f to your computer and use it in GitHub Desktop.
Find all pkg audit issues in FreeBSD jails and hosts.
#!/bin/sh
JLS="/usr/sbin/jls"
PKG="/usr/sbin/pkg"
# list of the jail ids for all jails
JAILS=`${JLS} jid`
RESULT=""
CHECKING=$1
if [ "${CHECKING}" != 'host' ]
then
for jail in ${JAILS}
do
JAILSTATUS=`${PKG} -j ${jail} audit -q`
if [ "${JAILSTATUS}" != "" ]
then
HOSTNAME=`${JLS} -j ${jail} host.hostname`
RESULT="${RESULT}${HOSTNAME}: ${JAILSTATUS} "
fi
done
else
RESULT=`${PKG} audit -q`
if [ "${RESULT}" != "" ]
then
RESULT="`hostname`: ${RESULT}"
fi
fi
if [ "${RESULT}" == "" ]
then
echo 'No problems found'
exit 0
else
echo ${RESULT}
exit 2
fi
@dlangille
Copy link
Author

Sample output:

$ sudo ~/bin/jails-pkg-audit.sh
Problems found in these jails
serpico python27-2.7.6_1

The above searches all jails.

The following does just the host:

$ ~/bin/jails-pkg-audit.sh host
No problems found

@dlangille
Copy link
Author

I am writing this because portaudit does not like pkg: http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/186562

@FlorianHeigl
Copy link

I'm also still unsure if pkg audit really covers everything portaudit did.
On my systems, it looked just fine, but now after updating base it reports no issues at all.
Maybe because the packages are from tinderbox, I have no idea.

I'll try with yours and see if "audit" sees more than "pkg audit" (yay for uniformity)

@FlorianHeigl
Copy link

Nevermind, this does just the same, was too tired in the morning :)

If you look at the bitbucket link I gave, you can do it like this:
I'll put a link, useless markup trying to make me go suicidal.

http://hastebin.com/utijotomif.vhdl

@dlangille
Copy link
Author

dlangille commented Mar 17, 2019

I think the goals of these scripts can be replaced with:

  • /usr/local/etc/periodic/security/405.pkg-base-audit
  • /usr/local/etc/periodic/security/410.pkg-audit

And these /etc/periodic.conf settings:

pkg_jails='*'
security_status_baseaudit_enable="YES" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment