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

Run vscode without sandbox if user namespaces disabled #412

Merged
merged 1 commit into from
Sep 4, 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
8 changes: 7 additions & 1 deletion files/frccode
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/usr/bin/env bash
SCRIPT_PATH="$(dirname "$(realpath -s "$BASH_SOURCE[0]")")"
SANDBOX_PATH="$(realpath "$(find "$SCRIPT_PATH/../vscode" -type f -name chrome-sandbox)")"
CODE_PATH="$(realpath "$(find "$SCRIPT_PATH/../vscode" -type f -name code | grep bin)")"

"$(realpath "$(find "$SCRIPT_PATH/../vscode" -type f -name code | grep bin)")" $@
if [ "$(sysctl -n kernel.apparmor_restrict_unprivileged_userns)" -eq "0" ] || [ "$(stat -c "%U" "$SANDBOX_PATH")" == "root" ] || [ -f "/etc/apparmor.d/frccode" ]; then
"$CODE_PATH" $@
else
"$CODE_PATH" --no-sandbox $@
fi
12 changes: 12 additions & 0 deletions files/frccode.AppArmor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This profile allows everything and only exists to give the
# application a name instead of having the label "unconfined"

abi <abi/4.0>,
include <tunables/global>

profile frcvscode /home/**/wpilib/**/vscode/VSCode-linux-x64/code flags=(unconfined) {
userns,

# Site-specific additions and overrides. See local/README for details.
include if exists <local/frccode>
}
9 changes: 9 additions & 0 deletions scripts/vars.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def varsfilesh = file("files/frcvars.sh")
def codefile = file("files/frccode")
def codefileCmd = file("files/frccode.cmd")
def icoFile = file("files/wpilib-256.ico")
def appArmorFile = file("files/frccode.AppArmor")

def pathfolder = 'frccode'

Expand All @@ -22,6 +23,7 @@ ext.varsZipSetup = { AbstractArchiveTask zip->
zip.inputs.file icoFile
zip.inputs.file codefile
zip.inputs.file codefileCmd
zip.inputs.file appArmorFile

zip.from (varsfile) {
into "/$pathfolder"
Expand Down Expand Up @@ -61,4 +63,11 @@ ext.varsZipSetup = { AbstractArchiveTask zip->
zip.from (icoFile) {
into "/$pathfolder"
}

zip.from (appArmorFile) {
into "/$pathfolder/AppArmor"
rename {
"frccode"
}
}
}