@@ -28,6 +28,7 @@ import (
2828)
2929
3030const ZigVersion = "0.14.1"
31+ const RcodesignVersion = "0.29.0"
3132
3233type ApoxyCli struct {}
3334
@@ -292,12 +293,71 @@ Commits:
292293 return result , nil
293294}
294295
296+ // SignDarwinBinary signs and notarizes a macOS binary using rcodesign.
297+ // This runs entirely on Linux using rcodesign (Rust reimplementation of Apple codesign).
298+ func (m * ApoxyCli ) SignDarwinBinary (
299+ ctx context.Context ,
300+ binary * dagger.File ,
301+ appleP12 * dagger.Secret ,
302+ appleP12Password * dagger.Secret ,
303+ appleNotaryKey * dagger.Secret ,
304+ ) * dagger.File {
305+ rcodesignURL := fmt .Sprintf (
306+ "https://github.com/indygreg/apple-platform-rs/releases/download/apple-codesign%%2F%s/apple-codesign-%s-x86_64-unknown-linux-musl.tar.gz" ,
307+ RcodesignVersion , RcodesignVersion ,
308+ )
309+
310+ return dag .Container ().
311+ From ("ubuntu:22.04" ).
312+ WithEnvVariable ("DEBIAN_FRONTEND" , "noninteractive" ).
313+ WithExec ([]string {"apt-get" , "update" }).
314+ WithExec ([]string {"apt-get" , "install" , "-y" , "wget" , "zip" }).
315+ // Install rcodesign.
316+ WithExec ([]string {"sh" , "-c" , fmt .Sprintf (
317+ "wget -qO- '%s' | tar xzf - -C /usr/local/bin --strip-components=1 --wildcards '*/rcodesign'" ,
318+ rcodesignURL ,
319+ )}).
320+ // Mount secrets.
321+ WithMountedSecret ("/secrets/developer-id.p12" , appleP12 ).
322+ WithMountedSecret ("/secrets/p12-password" , appleP12Password ).
323+ WithMountedSecret ("/secrets/notary-key.json" , appleNotaryKey ).
324+ // Copy unsigned binary.
325+ WithFile ("/work/apoxy" , binary ).
326+ // Sign with hardened runtime.
327+ WithExec ([]string {
328+ "rcodesign" , "sign" ,
329+ "--p12-file" , "/secrets/developer-id.p12" ,
330+ "--p12-password-file" , "/secrets/p12-password" ,
331+ "--code-signature-flags" , "runtime" ,
332+ "/work/apoxy" ,
333+ }).
334+ // Verify signature.
335+ WithExec ([]string {"rcodesign" , "verify" , "/work/apoxy" }).
336+ // Notarize: wrap in ZIP (required by Apple), submit, and wait.
337+ WithExec ([]string {"sh" , "-c" , "cd /work && zip apoxy.zip apoxy" }).
338+ WithExec ([]string {
339+ "rcodesign" , "notary-submit" ,
340+ "--api-key-path" , "/secrets/notary-key.json" ,
341+ "--max-wait-seconds" , "900" ,
342+ "--wait" ,
343+ "/work/apoxy.zip" ,
344+ }).
345+ // Return the signed binary (not the ZIP).
346+ File ("/work/apoxy" )
347+ }
348+
295349// PublishGithubRelease publishes a CLI binary to GitHub releases.
296350func (m * ApoxyCli ) PublishGithubRelease (
297351 ctx context.Context ,
298352 src * dagger.Directory ,
299353 githubToken * dagger.Secret ,
300354 tag , sha string ,
355+ // +optional
356+ appleP12 * dagger.Secret ,
357+ // +optional
358+ appleP12Password * dagger.Secret ,
359+ // +optional
360+ appleNotaryKey * dagger.Secret ,
301361) * dagger.Container {
302362 cliCtrLinuxAmd64 := m .BuildCLI (ctx , src , "linux/amd64" , tag , sha )
303363 cliCtrLinuxArm64 := m .BuildCLI (ctx , src , "linux/arm64" , tag , sha )
@@ -329,6 +389,13 @@ func (m *ApoxyCli) PublishGithubRelease(
329389 }
330390 }
331391
392+ darwinAmd64Binary := cliCtrMacosAmd64 .File ("/apoxy" )
393+ darwinArm64Binary := cliCtrMacosArm64 .File ("/apoxy" )
394+ if appleP12 != nil && appleP12Password != nil && appleNotaryKey != nil {
395+ darwinAmd64Binary = m .SignDarwinBinary (ctx , darwinAmd64Binary , appleP12 , appleP12Password , appleNotaryKey )
396+ darwinArm64Binary = m .SignDarwinBinary (ctx , darwinArm64Binary , appleP12 , appleP12Password , appleNotaryKey )
397+ }
398+
332399 return dag .Container ().
333400 From ("ubuntu:22.04" ).
334401 WithEnvVariable ("DEBIAN_FRONTEND" , "noninteractive" ).
@@ -341,8 +408,8 @@ func (m *ApoxyCli) PublishGithubRelease(
341408 WithSecretVariable ("GITHUB_TOKEN" , githubToken ).
342409 WithFile ("/apoxy-linux-amd64" , cliCtrLinuxAmd64 .File ("/apoxy" )).
343410 WithFile ("/apoxy-linux-arm64" , cliCtrLinuxArm64 .File ("/apoxy" )).
344- WithFile ("/apoxy-darwin-amd64" , cliCtrMacosAmd64 . File ( "/apoxy" ) ).
345- WithFile ("/apoxy-darwin-arm64" , cliCtrMacosArm64 . File ( "/apoxy" ) ).
411+ WithFile ("/apoxy-darwin-amd64" , darwinAmd64Binary ).
412+ WithFile ("/apoxy-darwin-arm64" , darwinArm64Binary ).
346413 // Create tarballs for each platform
347414 WithExec ([]string {"sh" , "-c" , "cd /tmp && cp /apoxy-linux-amd64 apoxy && tar czf /apoxy_Linux_x86_64.tar.gz apoxy && rm apoxy" }).
348415 WithExec ([]string {"sh" , "-c" , "cd /tmp && cp /apoxy-linux-arm64 apoxy && tar czf /apoxy_Linux_arm64.tar.gz apoxy && rm apoxy" }).
0 commit comments