mac security 命令在守护进程运行时需要写权限?

jph*_*jph 5 macos tomcat keychain launchd

我的任务是将 Tomcat/Jenkins 安装从已弃用(现已在 Yosemite 中删除)的 SystemStarter 框架移动到 launchd。它作为“构建”用户启动并运行良好,除了一件事。我们构建过程的一部分涉及调用“安全”命令来操作钥匙串。这失败如下:

security: cert import failed: write permissions error
security: problem decoding
Run Code Online (Sandbox Code Playgroud)

如果我通过 ssh 进入构建机器并从命令提示符启动 Tomcat,通过 bin/startup.sh,则调用security不会抱怨。它只在我通过 launchd 启动 Tomcat 时抱怨。我的 plist 看起来像这样:

<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.apache.tomcat</string>
    <key>UserName</key>
    <string>builduser</string>
    <key>WorkingDirectory</key>
    <string>/Users/builduser</string>
    <key>Program</key>
    <string>/Users/builduser/bin/tomcat.sh</string>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <true/>
    </dict>
    <key>EnvironmentVariables</key>
    <dict>
        <key>CATALINA_HOME</key>
        <string>/Users/builduser/Tomcat</string>
        <key>CATALINA_OPTS</key>
        <string>-Djava.awt.headless=true</string>
        <key>JAVA_OPTS</key>
        <string>-Xmx1024m -XX:MaxPermSize=512m</string>
    </dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

plist 位于 /Library/LaunchDaemons 中,而 tomcat.sh 只是一个启动 tomcat 然后等待进程终止的包装器。

小智 4

我自己也遇到过类似的问题 - 我正在.mobileprovision使用解码文件

cmd -D -i <path_to_file>

一切都在本地和通过 SSH 运行,但从 Python 应用程序执行时抛出异常security: cert import failed: write permissions error

我发现这个解决方法似乎是相同的问题,他们最终创建了临时文件keychain并在security命令中使用它:

cmd -D -k <specific_keychain> -i <path_to_file>

我不能 100% 确定这是否是这个问题的正确解决方案,但它确实运作良好。