Secure your Go builds with AppArmor
If you have a Linux system with AppArmor, you can use it to secure your Go builds.
First install Go in /usr/local/go as in the the instructions.
Then add this file to /etc/apparmor.d, replace ${HOME} with your home directory.
#include <tunables/global>
profile go /usr/local/go/bin/go {
#include <abstractions/base>
#include <abstractions/consoles>
/tmp/ r,
/tmp/** rwkix,
@{PROC}/** r,
/sys/** r,
/dev/** r,
/etc/** r,
/usr/** r,
/bin/** ix,
/usr/bin/** ix,
/usr/libexec/** ix,
/usr/lib/** ix,
/usr/local/go/** rix,
owner @{HOME}/.config/go/** rw,
owner @{HOME}/.cache/go-build/** rwkix,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/tmp/GoLand/** rwkix,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/coverage/** rwk,
owner @{HOME}/.local/share/JetBrains/IntelliJIdea*/go-plugin/** rix,
owner @{HOME}/.config/dlv/** r,
owner @{HOME}/.gitconfig r,
owner @{HOME}/.gitignore r,
owner @{HOME}/go/** rwkl,
owner @{HOME}/go/bin/* rwklix,
owner @{HOME}/src/** rwk,
/etc/resolv.conf r,
@{PROC}/sys/net/** r,
/run/systemd/resolve/** r,
network,
signal (receive) set=(int,term,kill),
ptrace,
}
profile go-fmt /usr/local/go/bin/gofmt {
#include <abstractions/base>
#include <abstractions/consoles>
/tmp/** rwkix,
/usr/local/go/** rix,
owner @{HOME}/.config/go/** rw,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/tmp/GoLand/** rwk,
owner @{HOME}/go/** rwk,
owner @{HOME}/src/** rwk,
signal (receive) set=(int,term,kill),
}
profile go-bin ${HOME}/{go/bin/*,.cache/go-build/**,.cache/JetBrains/IntelliJIdea*/tmp/GoLand/*} {
#include <abstractions/base>
#include <abstractions/consoles>
/etc/** r,
/bin/** ix,
/usr/bin/** ix,
/tmp/ r,
/tmp/** rwk,
/usr/local/go/** rix,
owner @{HOME}/.config/go/** r,
owner @{HOME}/.cache/go-build/** rix,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/tmp/GoLand/** rix,
owner @{HOME}/go/** r,
owner @{HOME}/go/bin/* rix,
owner @{HOME}/src/** r,
/etc/resolv.conf r,
@{PROC}/sys/net/** r,
/run/systemd/resolve/** r,
network,
signal (receive) set=(int,term,kill),
ptrace (tracedby, readby) peer=go,
}
Then run sudo service apparmor reload to activate it (it will be loaded automatically on boot). This is tested un Ubuntu desktop 24.04.
It will also enable use of the Go plugin to IntelliJ IDEA.
Secure your Rust builds with AppArmor
If you have a Linux system with AppArmor, you can use it to secure your Rust builds.
First install Rust with rustup in ~/.cargo/bin.
Then add this file to /etc/apparmor.d, replace ${HOME} with your home directory.
#include <tunables/global>
profile cargo-bin ${HOME}/{.cargo/bin/*,.local/share/JetBrains/IntelliJIdea*/intellij-rust/bin/linux/x64/*} {
#include <abstractions/base>
#include <abstractions/consoles>
@{PROC}** r,
/sys/** r,
/usr/bin/** ix,
/usr/include/** r,
/usr/libexec/** rix,
/usr/share/** r,
/tmp/ r,
/tmp/** rwkix,
owner @{HOME}/.gitconfig r,
owner @{HOME}/.gitignore r,
owner @{HOME}/.rustup/** r,
owner @{HOME}/.rustup/toolchains/** rix,
owner @{HOME}/.cargo/ r,
owner @{HOME}/.cargo/** rwkl,
owner @{HOME}/.cargo/bin/** rwklix,
owner @{HOME}/.local/share/JetBrains/IntelliJIdea*/intellij-rust/** r,
owner @{HOME}/.local/share/JetBrains/IntelliJIdea*/intellij-rust/bin/linux/x64/* rix,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/intellij-rust/** rwk,
owner @{HOME}/src/** rwklix,
/etc/resolv.conf r,
@{PROC}/sys/net/** r,
network,
/run/systemd/resolve/** r,
signal (receive) set=(int,term,kill),
}
profile rustup ${HOME}/.cargo/bin/rustup {
#include <abstractions/base>
#include <abstractions/consoles>
/etc/** r,
@{PROC}** r,
/sys/** r,
/usr/bin/** ix,
/usr/include/** r,
/usr/libexec/** rix,
/usr/share/** r,
/tmp/ r,
/tmp/** rwkix,
owner @{HOME}/.gitconfig r,
owner @{HOME}/.gitignore r,
owner @{HOME}/.rustup/** rwkl,
owner @{HOME}/.rustup/toolchains/** rwklix,
owner @{HOME}/.cargo/ r,
owner @{HOME}/.cargo/** rwkl,
owner @{HOME}/.cargo/bin/** rwklix,
owner @{HOME}/.local/share/JetBrains/IntelliJIdea*/intellij-rust/** r,
owner @{HOME}/.local/share/JetBrains/IntelliJIdea*/intellij-rust/bin/linux/x64/* rix,
owner @{HOME}/.cache/JetBrains/IntelliJIdea*/intellij-rust/** rwk,
owner @{HOME}/src/** rwklix,
/etc/resolv.conf r,
@{PROC}/sys/net/** r,
network,
/run/systemd/resolve/** r,
signal (receive) set=(int,term,kill),
}
Then run sudo service apparmor reload to activate it (it will be loaded automatically on boot). This is tested un Ubuntu desktop 24.04.
It will also enable use of the Rust plugin to IntelliJ IDEA.
Secure your Gradle builds with AppArmor
If you have a Linux system with AppArmor, you can use it to secure your Gradle builds.
Here is how I installed it on Ubuntu Linux:
-
Make sure you have a Java Development Kit installed.
-
Set the
JAVA_HOMEenvironment variable to point to your JDK by creating a file/etc/profile.d/java.shwith this content:#!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 -
Make a manual installation of Gradle in
/opt/gradle. -
Make it available in PATH:
$ cd /usr/bin $ sudo ln -s ../../opt/gradle/gradle-8.14.3/bin/gradle .
Speed-up and secure your Maven builds with Maven Daemon
You can speed-up Maven builds considerably by using Maven Daemon.
Here is how I installed it on Ubuntu Linux:
-
Make sure you have a Java Development Kit installed.
-
Set the
JAVA_HOMEenvironment variable to point to your JDK by creating a file/etc/profile.d/java.shwith this content:#!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 -
Unpack it into
/opt -
Make it available in PATH:
$ cd /usr/bin $ sudo ln -s ../../opt/maven-mvnd-1.0.2-linux-amd64/bin/mvnd . $ sudo ln -s mvnd mvn
You can configure IntelliJ IDEA to use it by setting Maven home path to /opt/maven-mvnd-1.0.2-linux-amd64.
You need to do this for all existing Maven projects you have. Also make sure that the
registry setting maven.use.scripts is true.