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

Add AppArmor profile to fix Brioche builds on Ubuntu 24.04 #2

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ on:
- main

jobs:
setup-brioche:
runs-on: ubuntu-latest
test-setup-brioche:
strategy:
matrix:
runs-on:
- ubuntu-22.04
- ubuntu-24.04
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Brioche
uses: ./ # Uses an action in the root directory
with:
version: 'v0.1.3' # Optional, defaults to v0.1.3
version: 'v0.1.3' # Optional, defaults to v0.1.3

- name: Verify Brioche installation
run: |
brioche --version
brioche install -r hello_world
hello-world

WATERMARK="$(date -uIs)"
sed -i "s/\${WATERMARK}/${WATERMARK}/g" example-project/project.bri
brioche build -p example-project -o output
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: 'Directory where Brioche should be installed'
required: false
default: '$HOME/.local/bin'
install-apparmor:
description: "Install AppArmor profile for Brioche. Defaults to 'auto'"
required: false
default: 'auto'
runs:
using: 'composite'
steps:
Expand All @@ -23,3 +27,4 @@ runs:
env:
install_dir: ${{ inputs.install-dir }}
version: ${{ inputs.version }}
install_apparmor: ${{ inputs.install-apparmor }}
9 changes: 9 additions & 0 deletions apparmor.d/brioche-gh-actions.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
abi <abi/4.0>,
include <tunables/global>

# Enable unprivileged user namespaces for Brioche. See this Ubuntu blog post
# for more context:
# https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces
${BRIOCHE_INSTALL_PATH} flags=(default_allow) {
userns,
}
6 changes: 6 additions & 0 deletions example-project/brioche.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"hello_world": "c3fc0c4d755cd81cda36168337912de7dbb27cb8eb1d9d11c60fff613526fb44",
"std": "c61485184862a8ed1ec3fc12f3a6f5ea91c32b6f450cbe81cbc596c0c7e2a06d"
}
}
13 changes: 13 additions & 0 deletions example-project/project.bri
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as std from "std";
import helloWorld from "hello_world";

// Replaced with a timestamp to ensure the build can't be cached
const WATERMARK_VALUE = "${WATERMARK}";

export default function () {
return std.runBash`
hello-world | tee "$BRIOCHE_OUTPUT"
`
.env({ WATERMARK_VALUE })
.dependencies(helloWorld());
}
51 changes: 44 additions & 7 deletions install-brioche.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ set -euo pipefail
# https://github.com/brioche-dev/brioche.dev/blob/main/public/install.sh

# Validate environment variables
if [ -z "${HOME:-}" ]; then
echo '::error::$HOME must be set'
if [ -z "${GITHUB_PATH:-}" -o -z "${GITHUB_ACTION_PATH:-}" ]; then
echo '::error::$GITHUB_PATH or $GITHUB_ACTION_PATH not set! This script should be run in GitHub Actions'
exit 1
fi
if [ -z "${install_dir:-}" -o -z "${version:-}" ]; then
echo '::error::$install_dir and $version must be set'
if [ -z "${HOME:-}" ]; then
echo '::error::$HOME must be set'
exit 1
fi
if [ -z "${GITHUB_PATH:-}" ]; then
echo '::error::$GITHUB_PATH not set! This script should be run in GitHub Actions'
if [ -z "${install_dir:-}" -o -z "${version:-}" -o -z "${install_apparmor:-}" ]; then
echo '::error::$install_dir, $version, and $install_apparmor must be set'
exit 1
fi

Expand Down Expand Up @@ -46,7 +46,7 @@ case "$install_dir" in
;;
esac

# Get the URL based on the OS and architecture
# Get the OS and architecture-specific config, such as download URL and AppArmor config
case "$OSTYPE" in
linux*)
case "$(uname -m)" in
Expand All @@ -59,6 +59,32 @@ case "$OSTYPE" in
exit 1
;;
esac

case "$install_apparmor" in
auto)
# Detect if we should install an AppArmor profile. AppArmor 4.0
# introduced new features to restrict unprivileged user
# namespaces, which Ubuntu 23.10 enforces by default. The
# Brioche AppArmor policy is meant to lift this restriction
# for sandboxed builds, which we only need to do on AppArmor 4+.
# So, we only install the policy if AppArmor is enabled and
# we find the config file for AppArmor abi 4.0.
if type aa-enabled >/dev/null && aa-enabled -q && [ -e /etc/apparmor.d/abi/4.0 ]; then
should_install_apparmor=1
else
should_install_apparmor=
fi
;;
true)
should_install_apparmor=1
;;
false)
should_install_apparmor=
;;
*)
echo "::error::Invalid value for \$install_apparmor: $install_apparmor"
;;
esac
;;
*)
echo "::error::Sorry, Brioche isn't currently supported on your operating system"
Expand Down Expand Up @@ -98,3 +124,14 @@ for new_path in "${new_paths[@]}"; do
done

echo '::endgroup'


if [ -n "$should_install_apparmor" ]; then
echo "::group::Installing AppArmor config"

export BRIOCHE_INSTALL_PATH="$install_dir/brioche"
cat "$GITHUB_ACTION_PATH/apparmor.d/brioche-gh-actions.tpl" | envsubst | sudo tee /etc/apparmor.d/brioche-gh-actions
sudo apparmor_parser -r /etc/apparmor.d/brioche-gh-actions

echo "::endgroup"
fi
Loading