Skip to content
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
5 changes: 5 additions & 0 deletions Coder-Desktop/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ targets:
# Skip in CI
exit 0
fi
if [ "${CODE_SIGNING_ALLOWED}" = "NO" ]; then
# Signing-free builds (e.g. `make test`) can't produce a helper
# the app will accept over XPC, so don't install one.
exit 0
fi
/usr/bin/osascript <<'APPLESCRIPT'
do shell script "/bin/bash -c " & quoted form of ((system attribute "SRCROOT") & "/../scripts/upsert-dev-helper.sh") with administrator privileges
APPLESCRIPT
Expand Down
26 changes: 26 additions & 0 deletions scripts/upsert-dev-helper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# This script operates like postinstall + preinstall, but for local development
# builds, where the helper is necessary. Instead of looking for
# /Applications/Coder Desktop.app, it looks for
Expand All @@ -12,6 +13,31 @@ LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper"
LAUNCH_DAEMON_PLIST_NAME="$LAUNCH_DAEMON_NAME.plist"
LAUNCH_DAEMON_BINARY_PATH="/Applications/Coder/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper"

# Must match `Validator.xpcPeerRequirement` in Coder-Desktop/VPNLib/Validate.swift.
XPC_PEER_REQUIREMENT='anchor apple generic and certificate leaf[subject.OU] = "4399GN35BJ"'

if [ ! -f "$LAUNCH_DAEMON_BINARY_PATH" ]; then
echo "error: helper binary not found at '$LAUNCH_DAEMON_BINARY_PATH'." >&2
echo "Build the 'Coder Desktop' app target first so it installs to /Applications/Coder." >&2
exit 1
fi

# Refuse to install a helper the app will reject over XPC. The app validates
# XPC peers against this requirement; bootstrapping a helper that fails it
# only surfaces later as cryptic 'errSecCSReqFailed' (-67050) connection
# errors. A stale or ad-hoc-signed helper can end up in the installed bundle
# when Xcode skips the "Embed Dependencies" (CodeSignOnCopy) phase, or when a
# build with code signing disabled (e.g. `make test`) writes into it.
if ! codesign --verify --strict -R="$XPC_PEER_REQUIREMENT" "$LAUNCH_DAEMON_BINARY_PATH"; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip signature enforcement for unsigned test builds

On a local make test run with CI unset, the Makefile explicitly passes CODE_SIGNING_REQUIRED=NO and CODE_SIGNING_ALLOWED=NO, while the Coder Desktop test scheme builds the app target and its post-build script invokes this helper installer. The resulting helper is unsigned or ad-hoc signed and cannot satisfy the Apple anchor/team-certificate requirement, so this new exit 1 aborts xcodebuild before the tests run. This breaks the documented signing-free test workflow, particularly for external contributors without Coder's certificate; skip the installer/verification when signing is disabled or during test builds.

Useful? React with 👍 / 👎.

echo "error: '$LAUNCH_DAEMON_BINARY_PATH' does not satisfy the app's XPC peer code signing requirement:" >&2
echo " $XPC_PEER_REQUIREMENT" >&2
codesign --display --verbose=2 "$LAUNCH_DAEMON_BINARY_PATH" >&2 || true
echo "The installed helper is likely stale or ad-hoc signed. To fix, delete it and rebuild:" >&2
echo " rm '$LAUNCH_DAEMON_BINARY_PATH'" >&2
echo "then rebuild the 'Coder Desktop' target so the embed phase re-copies and re-signs the helper." >&2
exit 1
fi

# Stop an existing launch daemon, if it exists
sudo launchctl bootout "system/$LAUNCH_DAEMON_NAME" 2>/dev/null || true

Expand Down
Loading