2013-04-09 32 views
0

我想使用详细选项执行Ant,但我不希望arguments传递到Exec任务,以便在敏感(即用户/密码)的情况下显示。Apache Ant - 隐藏/安全执行任务参数

一个例子是有一个数据库的连接:

<exec executable="/bin/sh" failonerror="true"> 
    <arg line="/opt/blah/blah/bin/frmcmp_batch.sh Module=blah Userid=username/[email protected] Module_Type=blah"/> 
</exec> 

我不想争论(特别是“用户ID =用户名/输入mypassword @嗒嗒”显示在日志中了)。

什么是隐藏/固定参数的最佳方式?

回答

0

目前我正在使用以下解决方法(描述here)来隐藏“mypassword”,但我想知道是否有更优雅的解决方案?

的build.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project default="test"> 

    <target name="test" depends=""> 
     <echo message="Testing..."/> 

     <echo message="Turning verbose off... you should NOT see the arguments..."/> 

     <script language="javascript"> 
      var logger = project.getBuildListeners().firstElement(); 
      // 2 works to turn off verbose 
      logger.setMessageOutputLevel(2); 
     </script> 

     <exec dir="." executable="cmd"> 
      <arg line="/c dummy.bat mypassword"/> 
     </exec> 

     <echo message="Turning verbose on... you should see the arguments..."/> 

     <script language="javascript"> 
      var logger = project.getBuildListeners().firstElement(); 
      // 3 works to turn verbose back on 
      logger.setMessageOutputLevel(3); 
     </script> 

     <exec dir="." executable="cmd"> 
      <arg line="/c dummy.bat mypassword"/> 
     </exec> 

    </target> 
</project> 

dummy.bat

@echo off 
echo dummy 

输出

test: 
    [echo] Testing... 
    [echo] Turning verbose off... you should NOT see the arguments... 
    [exec] dummy 
    [echo] Turning verbose on... you should see the arguments... 
    [exec] Current OS is Windows XP 
    [exec] Executing 'cmd' with arguments: 
    [exec] '/c' 
    [exec] 'dummy.bat' 
    [exec] 'mypassword' 
    [exec] 
    [exec] The ' characters around the executable and arguments are 
    [exec] not part of the command. 
    [exec] dummy 
0
,以确保密码

最好的办法是不要用一个:-)以下的答案介绍如何设置SSH密钥:

的ANT sshexec命令支持一个 “密钥文件” 属性。

更新

唉唉,脚本须藤可以是一个皇家疼痛。

以下是过去为我工作的解决方案。

  1. 配置用户不需要密码。请参阅“sudoers”文件。在我们的设置中,我们向管理员用户组中的用户授予此特殊访问权限。 (见Ant build.xml requires user input, but Eclipse has no tty
  2. 使用SSH :-)登录到本地机器是自动处理的非常有效的方式。使我们能够使用SSH密钥来控制访问,并可以限制命令的用户运行(通过authorized_keys文件的鲜为人知的特征)
  3. 使用自动化的工具,像rundeck。它为内置的sudo提供了有用的支持。可以将密码配置为在运行时(GUI)指定但未保存到任何位置的选项。有一个命令行和REST API可用于调用作业。这个解决方案可能是最不实用的,但我提到它是因为它是自动化操作任务的一个非常有用的工具。

看来你很在意出现在日志文件中的密码?我的固定是从来不写我的密码关闭,或脚本中硬编码....

+0

谢谢你的回应,但是这不是我要找的。我不想在远程主机上运行命令。我正在寻找在Ant脚本正在运行的主机上执行一个命令,这需要敏感的参数。我已经更新了这个问题来更详细地解释这个问题。 – Jesse 2013-04-10 02:34:08

+0

@Jesse更新了我的答案。 – 2013-04-10 08:58:17

+0

再次感谢您马克,但我已经在使用NOPASSWD,所以我不需要输入密码来执行sudo命令。我的问题涉及如何在示例中隐藏“Userid = username/mypassword @ blah”。我已经从示例中删除了sudo以清除此问题。 – Jesse 2013-04-10 14:51:25