How-to › Ship a CLI or REPL

How to sign and notarize a CLI binary for macOS#

Sign a Go or Rust CLI with a Developer ID certificate, the hardened runtime, and a secure timestamp, notarize it, and check the signature before Apple does.

Audience
Platform team
Level
advanced
Topic
Test, package and distribute a CLI
Languages
Go and Rust
Verified

Read first: Cross-compile CLI release archives with goreleaser

Your Go CLI builds on a Linux release runner and ships as a bare binary in a tarball. A user on a Mac downloads it with a browser and runs it, but Gatekeeper blocks the first launch. The arm64 build carries only the ad hoc signature from the linker, which Gatekeeper does not accept. The amd64 build is unsigned.

What you get

You will end up with a release binary signed with a Developer ID certificate, the hardened runtime and a secure timestamp, notarized by Apple, and checked by a Go preflight before upload. This is for you if you ship a CLI to Mac users outside the App Store.

Short answer

On a Mac, sign the binary with codesign -s "Developer ID Application" -f --timestamp -o runtime, zip it with ditto, and submit the zip with xcrun notarytool submit --wait and an App Store Connect API key. From Linux, rcodesign or goreleaser with quill signs and submits instead. A bare binary cannot be stapled, so a Mac that is offline at first launch cannot find its ticket.

You will need

An Apple Developer Program membership and three things from it. A Developer ID Application certificate signs Mach-O files and command-line tools, as Apple’s notarization troubleshooting page says. An App Store Connect API key has an issuer, a key ID, and a private key that can be downloaded once. Make it a team key: the same page says individual keys cannot use notaryTool. The preflight sample needs Go 1.24 or later. The binaries come from cross-compile CLI release archives with goreleaser.

Approaches compared

ApproachWhen it fitsWhat it costs youWhen to pick something else
codesign and notarytool on a macOS runnerYou want Apple’s reference tools, and the release job can run on a MacA macOS runner in every release, with the Developer ID identity installed on itYour release pipeline is Linux only and must stay that way
goreleaser notarize with quillgoreleaser already builds the release and you ship bare binariesWorks on bare and universal binaries only, since a bundle with only its binary signed is deemed damagedYou ship an app bundle, an installer package, or a disk image
rcodesign (apple-codesign) from LinuxSigning, notarizing, and stapling from any platform, outside goreleaserA second toolchain to build, pin, and keep in step with Apple’s rulesNotarization has never passed with Apple’s tools for this binary

Apple’s tools are the reference, so a failure they report is a failure of the binary rather than of a reimplementation. The price is a Mac in the release path. rcodesign and quill sign from Linux and drop that runner, but each reimplements Apple’s format, and its authors document the gaps. rcodesign’s own guide asks you to notarize with Apple tooling first for software that has never been notarized.

Read what the Go linker leaves in a Mac binary

Cross-compile both Mac architectures, then read their signatures with the sample’s preflight, a Go program that parses the Mach-O load commands with the standard library’s debug/macho:

CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -o bin/meters-arm64 ./cmd/meters
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -o bin/meters-amd64 ./cmd/meters
go build -o bin/preflight ./cmd/preflight
bin/preflight bin/meters-arm64 bin/meters-amd64; echo "exit status $?"
bin/meters-arm64 (arm64)
  signed:           yes
  identifier:       a.out
  signer:           ad hoc, linker-signed, no certificate
  team:             none
  hardened runtime: no
  secure timestamp: no
  notary preflight: 3 problem(s)
    - not signed with a Developer ID Application certificate
    - hardened runtime not enabled
    - no secure timestamp
bin/meters-amd64 (x86_64)
  signed:           no
  notary preflight: 1 problem(s)
    - no code signature
exit status 1

The two builds differ because the linker signs only one target. Its NeedCodeSign returns true for darwin/arm64 alone. The signature it writes is ad hoc and linker-signed, with the identifier a.out whatever -o says.1 Apple silicon refuses to run unsigned code, and an ad hoc signature satisfies that rule, but the macOS 11 release notes add that binaries signed this way cannot pass through Gatekeeper.

A Rust CLI meets the same wall by another road. Its macOS targets need Xcode or the macOS SDK to link, and the same release notes say Apple’s toolchain signs an executable at link time when clang or ld links it. Everything below applies to the Mach-O file either toolchain produces.

Sign with the Developer ID identity

On a Mac, Apple’s distribution signing guide gives the command for a binary outside a bundle. --timestamp asks for a secure timestamp, -o runtime turns on the hardened runtime, and -i sets the identifier. -f signs over the signature the linker wrote, as the re-signing command in the macOS 11 release notes also does:

codesign -s "Developer ID Application" -f --timestamp -o runtime -i com.example.meters meters

From Linux, rcodesign takes the certificate as a .p12 file and the runtime flag as --code-signature-flags runtime, as its signing page shows. It asks timestamp.apple.com for a timestamp unless told otherwise.2

rcodesign sign --p12-file developer-id.p12 --p12-password-file P12_PASSWORD_FILE --code-signature-flags runtime meters

goreleaser does both from its configuration through quill, a path its documentation says has no external dependencies and works on any operating system. Its notarize.macos section takes the .p12 and the API key from the environment:

notarize:
  macos:
    - enabled: '{{ isEnvSet "MACOS_SIGN_P12" }}'
      ids:
        - meters
      sign:
        certificate: "{{.Env.MACOS_SIGN_P12}}"
        password: "{{.Env.MACOS_SIGN_PASSWORD}}"
      notarize:
        issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
        key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
        key: "{{.Env.MACOS_NOTARY_KEY}}"
        wait: true
        timeout: 20m

goreleaser’s documentation caps timeout at 20m, because Apple rejects an authentication token that lives too long. The macos_native section, which drives codesign and xcrun, is marked as a GoReleaser Pro feature.

Preflight the signature before you upload

Each rejection from Apple’s notary service costs another submission and another wait. Most of its requirements are readable in the file itself, so the sample checks them locally first:

func (r Report) Problems() []string {
	if !r.Signed {
		return []string{"no code signature"}
	}
	var p []string
	switch {
	case r.AdHoc || !r.DeveloperIDLeaf:
		p = append(p, "not signed with a Developer ID Application certificate")
	case !r.IssuedByDevIDCA:
		p = append(p, "certificate not issued by a Developer ID intermediate in the signature")
	case r.TeamID == "" || r.TeamID != r.CertTeamID:
		p = append(p, fmt.Sprintf("team %q in the CodeDirectory is not the certificate's team %q", r.TeamID, r.CertTeamID))
	}
	if !r.HardenedRuntime {
		p = append(p, "hardened runtime not enabled")
	}
	if !r.Timestamp {
		p = append(p, "no secure timestamp")
	}
	if r.GetTaskAllow {
		p = append(p, "requests the com.apple.security.get-task-allow entitlement")
	}
	return p
}

The hardened runtime is CS_RUNTIME, bit 0x10000 of the CodeDirectory flags in Apple’s kernel header cs_blobs.h. The preflight refuses a signature whose alternate CodeDirectories disagree with the first, since it cannot tell which one macOS reads. A timestamp is an unsigned attribute on the CMS signer. The Developer ID test reads the certificate that the signer’s identifier names, and looks for the two fields that Gatekeeper’s Developer ID rules name.3 The team check compares the CodeDirectory’s team with that certificate’s, because Apple’s distribution signing guide names a Developer ID identity after its team.

Presence and agreement are all it checks. It never validates the chain to Apple’s root, the CMS signature, or the timestamp token, so a pass is necessary and not sufficient.

Zip it and submit it

The notary service accepts disk images, signed flat installer packages, and zip archives, so a bare binary goes up inside a zip. Build it with ditto, as Apple’s packaging guide shows, then submit it with the API key flags that TN3147 gives:

mkdir meters-1.4.0 && ditto meters meters-1.4.0/meters && ditto -c -k --keepParent meters-1.4.0 meters-1.4.0.zip
xcrun notarytool submit meters-1.4.0.zip --issuer ISSUER_UUID --key-id API_KEY --key PATH_TO_KEY --wait

--wait returns once the service has finished, and xcrun notarytool log fetches the JSON log for the submission id. rcodesign does the same with rcodesign notary-submit --api-key-file key.json --wait, after rcodesign encode-app-store-connect-api-key has folded the three parts of the key into one JSON file. goreleaser submits during the release, and its wait setting decides whether the release waits for Apple’s answer.

Check it worked

Run the preflight’s tests. They cross-compile both architectures and read what the linker left. Then they build synthetic signatures in each state, three of them grafted over the arm64 build. Their certificates come from a throwaway CA made per run, so they prove what the checker reads, never that Apple would accept the signature:

go test -count=1 -v ./preflight | grep -E '^(=== RUN   Test[A-Za-z0-9]+$|PASS$|FAIL$)'
=== RUN   TestADeveloperIDSignatureWithRuntimeAndTimestampPasses
=== RUN   TestEachMissingPropertyIsReported
=== RUN   TestBrokenSignaturesAreRefused
=== RUN   TestGoLinkerSignsArm64AdHocOnly
=== RUN   TestASignedBinaryPassesAndEachGapFailsIt
=== RUN   TestAUniversalFileReportsEachArchitecture
=== RUN   TestFilesItCannotReadAreRefused
PASS

The last line reads PASS. On the Mac that signed the binary, Apple’s troubleshooting page gives three checks: codesign -vvv --deep --strict meters for the signature, codesign -dvv meters for a Timestamp line, and spctl -vvv --assess --type exec meters for the policy. Then download the release archive with a browser on another Mac, one that has never run the binary, and run it there.

When it goes wrong

The binary runs on a connected Mac, but Gatekeeper might block it on one without a network, as Apple’s packaging guide warns. Apple’s tools cannot staple a ticket to a standalone binary, so Gatekeeper looks the ticket up online, and rcodesign’s stapler refuses a Mach-O file for the same reason. Ship a signed installer package or disk image, notarize it, and staple that.

The notary log reports The executable does not have the hardened runtime enabled. or The signature does not include a secure timestamp. The signing step left out -o runtime or --timestamp. Run the preflight on the signed binary before submitting.

The preflight refuses a file instead of judging it. A truncated download and a file that is not Mach-O both stop it with exit status 2, never a pass:

CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -o bin/meters-arm64 ./cmd/meters
go build -o bin/preflight ./cmd/preflight
head -c 4096 bin/meters-arm64 > bin/truncated
bin/preflight bin/truncated 2>&1; echo "exit status $?"
bin/preflight go.mod 2>&1; echo "exit status $?"
preflight: bin/truncated: not a Mach-O file: EOF
exit status 2
preflight: go.mod: not a Mach-O file: invalid magic number in record at byte 0x0
exit status 2

When not to do this

Do not sign on Linux before the same binary has passed notarization once with Apple’s tools. A rejection from rcodesign or quill can be the tool or the binary, and only Apple’s path separates the two. Keep a Mac job for that first release and for any change to entitlements.

Do not ship a bare binary to users who may be offline at first launch, such as build farms behind a strict egress policy. A bare binary cannot carry its ticket, so wrap it in an installer package and staple that.

Do not read a preflight pass as notarization. It proves that the properties it reads are present, while the notary service also scans the contents for malicious code and checks the chain to Apple.

Do not use goreleaser’s quill path for an app bundle. Its documentation says a bundle in which only the binary is signed is deemed damaged, and its native path needs GoReleaser Pro and a Mac.

Last verified

Verified 2026-11-30 against Go 1.24.7 and Go 1.25.14 on Linux. Every output block is what the command preceding it printed. No Mac and no Apple account were used. codesign, notarytool, stapler, ditto, spctl, rcodesign 0.29.0, quill, and goreleaser were not run: their commands and flags are quoted from their documentation and source, read on 2026-11-30. Nothing in Rust was built: the Rust paragraph is read from the Rust platform-support page and Apple’s release notes.

Footnotes

  1. The linker passes the string a.out as the identifier in both places it signs, which is the name of another executable format. FreeBSD’s manual page for it describes “the format of executable binary files” and records that its header appeared in Version 7 AT&T UNIX. Every arm64 Mac binary that Go’s own linker signs is therefore named after a format it is not written in, until codesign -i gives it a name of its own. ↩︎ Back to text

  2. The default is http://timestamp.apple.com/ts01, set as a constant in rcodesign’s command line. Apple’s troubleshooting page says macOS accepts only one secure timestamp server, namely timestamp.apple.com, and lists its address ranges. The choice of server is therefore not a setting so much as a formality. ↩︎ Back to text

  3. The rules, as spctl --list prints them in the primer, ask for one field on the intermediate certificate and one on the leaf, under an Apple anchor. The rule that denies execution of Developer ID code without notarization applies only to a leaf whose timestamp field is on or after 20190408000000Z. A leaf with an earlier field, or none, meets the plain Developer ID rule instead, which allows execution without asking about notarization. ↩︎ Back to text

Read this page as markdown · All how-to guides

Generate the client instead of writing it#

Retries, timeouts, pagination and auth are the same problems in every client. Voxgig generates them from your OpenAPI description, in 23 languages, from one model.

Listen to Fireside, the Voxgig podcast

Since 2018, Richard Rodger has talked with developer advocates, event organizers, and the people who build developer-facing companies about the specifics of the work.