有没有一种方法可以从Instruments(Xcode)的命令行实例中删除授权提示?

30
我目前正在使用一个bash脚本通过Instruments启动命令行界面来启动自动化插件的运行。
在4.2版本中,这个方法已经足够好了,但是升级到Xcode 4.3之后,我现在被要求授权用户“分析其他进程”。即使正确的凭据被授予,也不会实际验证任何用户。我会得到以下错误:
Failed to authorize rights (0x20) with status: -60007.
2012-02-27 19:30:37.232 instruments[54151:1c03] Failed to connect to local pid watcher     service: (os/kern) failure

即使身份验证失败,自动化插件仍会执行,但这需要我的脚本有一个物理的保姆输入凭据,这在很多方面都违背了这些命令行运行的目的。是否可以将用户详细信息添加为参数?或者有没有其他方法可以跳过此提示,而不需要人员操作?--编辑--当您尝试从GUI第一次运行UIAutomation测试时,会出现此授权对话框。

enter image description here

我提出了一个radar rdar://10945962

-- 编辑 --

一旦GUI中回答了授权对话框,命令行上的提示就会停止出现。这种解决方法似乎不太有效,不能作为“答案”。


你曾经解决过这个问题吗?因为我目前也遇到了同样的问题... - Alexander
@Alexander 你也在使用Hudson集成吗? - Legolas
目前我正在尝试直接在服务器上通过控制台运行,但它也无法工作。 - Alexander
@Alexander 是的,我也是这个情况! - Legolas
11个回答

18

好的,我想我已经让它正常工作了。

以下是有关如何删除 xcode命令行授权提示 的更多细节:

我所做的是:

  • 将jenkins用户标记为管理员(不幸的是,目前似乎没有其他方法)
  • 进入/etc/authorization
  • 搜索键system.privilige.taskport
  • 将allow-root的值更改为true

  • <key>system.privilege.taskport</key>
    <dict>
        <key>allow-root</key>
        <false/> // change to -> <true>
        <key>class</key>
        <string>user</string>
        <key>comment</key>
        <string>Used by task_for_pid(...).
        ...
    </dict>
    

    现在我可以通过命令行脚本使用Jenkins运行我的UI自动化测试


这比我做的好多了!! :) 应该标为正确答案。 - Legolas
与calabash-ios完美协作,让我感到非常愉悦。 - Arneball
3
在OS X El Capitan中我没有找到/etc/authorization。这个情况有改变吗? - devios1
1
@devios 我在 /System/Library/Security/authorization.plist 中找到了我的。 - Key
我相信正确的拼写是 system.privilege.taskport - Lew Bloch

15

这是一个可能适合你的好命令:

security unlock-keychain -p [password] "${HOME}/Library/Keychains/login.keychain"

这是在Mac上访问钥匙串的命令行方式。我没有测试它与自动化的兼容性,但这是我将iOS构建与Jenkins集成的方式。

用密码替换[password]


在调用Instruments之前,将此行添加到我的bash脚本中可以使对话框停止出现。 - Darc
这对我在Catalina上似乎起作用了。谢谢。 - armand

10

Alexander的回答的基础上,我发现对于Mavericks而言,由于授权处理的方式(来源),你应该这样做:

sudo security authorizationdb write system.privilege.taskport allow

我通过一个VMWare虚拟机中的Jenkins作业运行zucchini功能测试,但从未能正确启动模拟器,总是卡在启动画面,可能是因为权限不正确。这帮助我解决了这个问题,希望对其他人有所帮助。


1
这个命令不会将 allow-root 设置为 true,而是完全覆盖了设置。在运行上述命令之前和之后执行 sudo security authorizationdb read system.privilege.taskport 命令进行比较。 - Jason Moore
这个(也包括其他的答案)似乎对于Yosemite系统都不起作用。 - markdb314

5
你的脚本运行时使用的用户必须被授权使用开发工具。你可以通过以下两种方式实现:
  • 将用户添加到_developer组中: sudo dscl . append /Groups/_developer GroupMembership 脚本用户名

  • 使用DevToolsSecurity命令行工具

请注意,为了使UIAutomation工具正常工作,您调用Instruments的用户也需要是能够启动窗口服务器(即运行UI)的用户,并且在UIAutomation运行时必须已经登录窗口服务器。
这些都是使用Jenkins与UIAutomation的四五个关键秘诀之一。

我尝试了这两个,但仍然被提示。 - drekka
2
DevToolsSecurity --enable 就是答案! - jacekmigacz

4

我部分地解决了这个问题。我从命令行中运行instruments,并在GUI中有授权提示(每个会话只需一次),同时在控制台中出现如下信息(每次运行instruments时):

Instruments: Instruments wants permission to analyze other processes.
Type your password to allow this.
Name ([my-username]):
Password:

Failed to authorize rights (0x20) with status: -60007.
2012-02-28 10:04:19.607 instruments[60398:1203] Failed to connect to
local pid watcher service: (os/kern) failure

我升级到xCode 4.3之前和之后对比了/etc/authorization文件。苹果替换了两个密钥:

<key>com.apple.dt.instruments.process.analysis</key>
<key>com.apple.dt.instruments.process.kill</key>

使用

<key>com.apple.instruments.process.analysis</key>

我编辑了 /etc/authorization 文件,在新的密钥下面添加了缺失的密钥,从控制台发出的问题已经解决。不幸的是,GUI提示仍然存在。

缺失的密钥:

<key>com.apple.dt.instruments.process.analysis</key>
<dict>
    <key>allow-root</key>
    <true/>
    <key>class</key>
    <string>user</string>
    <key>comment</key>
    <string>Rights for Instruments</string>
    <key>group</key>
    <string>admin</string>
    <key>shared</key>
    <true/>
    <key>timeout</key>
    <integer>36000</integer>
    </dict>
<key>com.apple.dt.instruments.process.kill</key>
<dict>
    <key>allow-root</key>
    <true/>
    <key>class</key>
    <string>user</string>
    <key>comment</key>
    <string>Rights for Instruments</string>
    <key>group</key>
    <string>admin</string>
    <key>shared</key>
    <true/>
    <key>timeout</key>
    <integer>5</integer>
</dict>

希望这能帮助你解决整个问题。

不好的是,似乎只有运行自动化测试的用户拥有管理员权限才能使其正常工作。否则它将无法工作。 - Alexander
在这种情况下,我无法将它与Hudson集成。:-/ - Legolas
我想我已经搞定了,可以看下面我的回复,不幸的是jenkins必须是管理员 :( - Alexander
编辑授权和添加上述密钥对我很有用。注意:我的测试用户具有管理员权限,我尚未尝试从Jenkins,只是通过命令行。 - ablarg

3

我在El Capitan上也遇到了这个问题。我发现这篇文章非常有帮助:https://www.dssw.co.uk/reference/authorization-rights/。根据它,我更改了以下权限以解决此问题:

system.privilege.taskport
system.privilege.taskport.debug
system.privilege.taskport.safe
com.apple.dt.instruments.process.analysis
com.apple.dt.instruments.process.kill

1
这是对我有用的解决方案:
<key>system.privilege.taskport</key>
<dict>
<key>allow-root</key>
<false/> 
<key>class</key>
<string>user</string> // change to -> allow
<key>comment</key>
<string>Used by task_for_pid(...).
...
</dict>

1
sudo security authorize -u [username]

对我起作用了。


0
在Xcode中,如果您加载组织器(Xcode->窗口->组织器)
然后在设备下选择您的机器 ->“启用开发者模式”
这应该消除了使用instruments时的提示需求。

0
我也尝试了安全解锁钥匙串并更改了/etc/authorization文件,并启用了DevToolsSecurity,但它们都没有起作用,直到我启动了Instruments GUI应用程序并运行了我的脚本,然后弹出一个对话框,我输入了我的密码,之后再次运行仪器脚本时就不需要密码了!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接