Skip to content

Add code signing of release binaries via cargo-code-sign#18280

Draft
zanieb wants to merge 3 commits intomainfrom
zb/cargo-code-sign
Draft

Add code signing of release binaries via cargo-code-sign#18280
zanieb wants to merge 3 commits intomainfrom
zb/cargo-code-sign

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Mar 3, 2026

Adds code signing of our release binaries on Windows and macOS, using temporary self-signed certificates for testing.

Instead of signing via uv build as explored in #18262, we use a cargo extension to sign on build. This allows us to sign both the artifacts inside and outside of wheels without changing maturin. This builds on patterns introduced in #18276.

I built cargo-code-sign as a standalone tool, heavily referencing existing code signing techniques in the ecosystem, see https://github.com/zanieb/code-sign-tools

Includes #18295
This does not configure secrets for the actual release environment yet.

@zanieb zanieb force-pushed the zb/cargo-auditable branch from d64d72a to 5cacad5 Compare March 3, 2026 22:27
@zanieb zanieb force-pushed the zb/cargo-code-sign branch 8 times, most recently from 1104b91 to 5810e1c Compare March 4, 2026 01:58
@zanieb zanieb force-pushed the zb/cargo-auditable branch 2 times, most recently from 9db7448 to 6e33a04 Compare March 4, 2026 02:55
@zanieb zanieb force-pushed the zb/cargo-code-sign branch from 5810e1c to 921eac1 Compare March 4, 2026 02:58
@zanieb zanieb force-pushed the zb/cargo-auditable branch 5 times, most recently from 49125e3 to 355fe05 Compare March 4, 2026 16:15
@zanieb zanieb force-pushed the zb/cargo-code-sign branch 5 times, most recently from e91fbc7 to 6ea7974 Compare March 4, 2026 17:54
@zanieb zanieb force-pushed the zb/cargo-code-sign branch from 6ea7974 to b7dd415 Compare March 4, 2026 18:14
Comment on lines +111 to +116
openssl req -x509 -newkey rsa:2048 -sha256 -days 7 -nodes \
-keyout "$CERT_DIR/key.pem" \
-out "$CERT_DIR/cert.pem" \
-subj "/CN=$CERT_NAME" \
-addext "extendedKeyUsage=codeSigning" \
-addext "keyUsage=digitalSignature"
Copy link
Member

Choose a reason for hiding this comment

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

I think there are additional Apple-specific X.509 extensions we need to include here, in order for the self-signed cert to look "right" to Apple's codesigning machinery.

Ref: https://docs.rs/apple-codesign/0.29.0/src/apple_codesign/certificate.rs.html#1276-1286

(Maybe it makes sense to use rcodesign to bootstrap the testing cert here?)

zanieb added a commit that referenced this pull request Mar 6, 2026
Inspired by #18252 

This required an upstream change
rust-secure-code/cargo-auditable#245 which is
now released.

This increases binary sizes slightly, ~4KB.

The cargo wrapper implementation will be extended in #18280 to code sign
binaries.
Base automatically changed from zb/cargo-auditable to main March 6, 2026 17:38
zanieb added a commit that referenced this pull request Mar 6, 2026
Instead of generating test secrets in the workflow itself as was done in
#18280 for testing.

This includes a script to generate self-signed certificates and adds
them to the `release-test` environment. We'll populate the real secrets
in the `release` environment. We may want a dedicated environment for
code-signing secrets? We also may want to sign with the real secrets on
`main` or similar.
Instead of generating test secrets in the workflow itself as was done in
#18280 for testing.

This includes a script to generate self-signed certificates and adds
them to the `release-test` environment. We'll populate the real secrets
in the `release` environment. We may want a dedicated environment for
code-signing secrets? We also may want to sign with the real secrets on
`main` or similar.
Comment on lines +5 to +7
## Secrets: CODESIGN_CERTIFICATE_PASSWORD, CODESIGN_IDENTITY_MACOS,
## CODESIGN_CERTIFICATE_MACOS, CODESIGN_CERTIFICATE_WINDOWS
## Variables: CODESIGN_ALLOW_UNTRUSTED_MACOS
Copy link
Member Author

Choose a reason for hiding this comment

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

Enumerate these in a bullet point list, we don't need to differentiate between secrets / variables in this doc

@zanieb zanieb temporarily deployed to uv-test-publish March 6, 2026 17:48 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants