見出し画像

Catalina 用にコマンドラインツール配布 zip を公証する

備忘録。

macOS Catalina 以降 notarize された zip/pkg/dmg じゃないとアーカイブ展開後のソフトウェアを GUI 許可なしでは使えない。

困ったのは、自作なり他の作者のツールを CI Server で使いたいなーとなったとき。
ダイアログクリックはできないから事前に配布 zip を notalize するのがいいのかなーと考える。
そうすれば展開後のツール実行時にダイアログが出ない。

altool --notarize-app

WWDC 2019 のセッション動画を見直すと altool で公証できることに気づく。

altool は Xcode Command Line Tools に古くからあるもので、ipa を App Store Connect にアップロードするときに使われる。

altool --help でオプションを見ると --notarize-app があるのでこちらを使って App Store Connect に配布用 zip をアップロードして Apple に公証してもらう。
(事前に公証用の App Identifier を作成しておく)

$ xcrun altool --notarize-app \
    --primary-bundle-id "__先程作成した app_identifier__" \
    --username "__developer_email__" \
    --password "__developer password__" \
    --file /path/to/your/tool.zip

しばらくすると Your Mac software was successfully notarized. というタイトルのメールが来る。

Your Mac software has been notarized. You can now export this software and distribute it directly to users.

Bundle Identifier: 先程の App Identifier
Request Identifier: xxx-xxxxx-...

for details on exporting a notarized app, visit Xcode Help or the notarization guide.

Best Regards,
Apple Developer Relations

メール以外にも altool で公証されたかどうかはチェックできる。
照合のためメールの Request Identifier が必要になるのだけど。

$ xcrun altool --notarization-history \
    -u "__developer_email__" -p "__developer_password__"

Notarization History - page 0

Date                      RequestUUID                          Status  Status Code Status Message
------------------------- ------------------------------------ ------- ----------- ----------------
2019-10-30 00:01:57 +0000 xxxxxxxxxxxxxxxxxxxxxxx              success 0           Package Approved

その後この zip を展開してツール実行してみるとダイアログも出ず実行できました。

よもやま1: zip だと公証済みかはチェックできない?

pkg/dmg だと spctl でチェックできる。

$ spctl --assess --verbose --type install <path-to-pkg>
<path-to-pkg>: accepted
source=Notarized Developer ID
$ spctl --assess --verbose --type open —-context "context:primary-signature" <path-to-dmg>
<path-to-dmg>: accepted
source=Notarized Developer ID

zip だと上記コマンドは通らなかった。

よもやま2: spctl で公証ダイアログを常に出さないようにする

macOS の Security & Privacy のダウンロードしたアプリケーションの実行許可にあったすべてのアプリケーションを実行オプションを spctl で復活させるのは可能。

$ man spctl
...
SYNOPSIS
    ...
    spctl --status
...
DESCRIPTION
    ...
     --master-disable
             Disable the assessment subsystem altogether.  Operations that would be denied by system policy will be allowed to proceed; assessment APIs always report success.  Requires root access.​

もし CI 実行してる macOS のサーバで実行するとうまくいくのだろうか? 
CircleCI macOS Catalina + Xcode 11.2 Beta2 で検証してみたらうまくいきました

$ sudo spctl --master-disable
$ curl -L -O https://myhost.com/path/to/tool.zip
$ unzip -q tool.zip
$ ./mytool 'do operation' # It works!

読んでいただきありがとうございますー よろしければシェアもおねがいします🙏