使用 Ivy 和私人公司存储库时,我的凭据应该放在哪里?

发布于 2024-12-05 19:01:08 字数 234 浏览 1 评论 0 原文

我正在使用 Ant + Ivy,我的公司最近为我们自己的私人图书馆设置了 Nexus 服务器。 Ivy 可以通过使用 ibilio 解析器和 m2兼容=true 从 Nexus 服务器获取依赖项,但我必须将我的凭据放入 ivysettings.xml 文件中。

不同的开发人员应该如何存储他们的凭据?

ivysettings.xml 文件是否不应在 vcs 中提交?

我真的不想以纯文本形式存储我的密码。

I'm using Ant + Ivy, and my company has recently set up a Nexus server for our own private libraries. Ivy can get dependencies from the Nexus server by using a ibilio resolver and m2compatible=true, but I have to put my credentials in a ivysettings.xml file.

How are different developers supposed to store their credentials?

Is the ivysettings.xml file not supposed to be commited in vcs?

I really don't want to store my password in plain text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静谧幽蓝 2024-12-12 19:01:08

使用具有控制 Nexus 凭据的属性的设置文件:

<ivysettings>
    <property name="repo.host" value="default.mycompany.com" override="false"/>
    <property name="repo.realm" value="Sonatype Nexus Repository Manager" override="false"/>
    <property name="repo.user" value="deployment"  override="false"/>
    <property name="repo.pass" value="deployment123"  override="false"/>          

    <credentials host="${repo.host}" realm="${repo.realm}" username="${repo.user}" passwd="${repo.pass}"/>

    ..
    ..
</ivysettings>

运行构建时,您可以指定真实的用户名和密码:

ant -Drepo.user=mark -Drepo.pass=s3Cret

更新/增强

将密码作为属性存储在文件系统上需要加密。

Jasypt 有一个可以生成加密字符串的命令行程序:

$ encrypt.sh verbose=0 password=123 input=s3Cret
hXiMYkpsPY7j3aIh/2/vfQ==

这可以保存在构建的属性文件中

username=bill
password=ENC(hXiMYkpsPY7j3aIh/2/vfQ==)

:以下 ANT 目标将解密任何加密的 ANT 属性:

<target name="decrypt">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
    import org.jasypt.properties.EncryptableProperties
    import org.jasypt.encryption.pbe.StandardPBEStringEncryptor

    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor()
    encryptor.setPassword(properties["master.pass"])

    Properties props = new EncryptableProperties((Properties)properties, encryptor);

    props.propertyNames().each {
        properties[it] = props.getProperty(it)
    }
    </groovy>
</target>

当然,要实现此目的,需要在构建过程中指定用于加密属性的密码。

ant -Dmaster.pass=123

这意味着该解决方案仅适用于隐藏静态数据。

Use a settings file with properties controlling the Nexus credentials:

<ivysettings>
    <property name="repo.host" value="default.mycompany.com" override="false"/>
    <property name="repo.realm" value="Sonatype Nexus Repository Manager" override="false"/>
    <property name="repo.user" value="deployment"  override="false"/>
    <property name="repo.pass" value="deployment123"  override="false"/>          

    <credentials host="${repo.host}" realm="${repo.realm}" username="${repo.user}" passwd="${repo.pass}"/>

    ..
    ..
</ivysettings>

When you run the build you can then specify the true username and password:

ant -Drepo.user=mark -Drepo.pass=s3Cret

Update/Enhancement

Storing passwords as properties on the file system requires encryption.

Jasypt has a command-line program that can generate encrypted strings:

$ encrypt.sh verbose=0 password=123 input=s3Cret
hXiMYkpsPY7j3aIh/2/vfQ==

This can be saved in the build's property file:

username=bill
password=ENC(hXiMYkpsPY7j3aIh/2/vfQ==)

The following ANT target will decrypt any encrypted ANT properties:

<target name="decrypt">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
    import org.jasypt.properties.EncryptableProperties
    import org.jasypt.encryption.pbe.StandardPBEStringEncryptor

    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor()
    encryptor.setPassword(properties["master.pass"])

    Properties props = new EncryptableProperties((Properties)properties, encryptor);

    props.propertyNames().each {
        properties[it] = props.getProperty(it)
    }
    </groovy>
</target>

Of course to make this work, the password used for encrypting the properties needs to be specified as part of the build.

ant -Dmaster.pass=123

This means the solution is only good for hiding data at rest.

网名女生简单气质 2024-12-12 19:01:08

出于我的目的,命令行凭据不是一个选项,因为我正在通过 Jenkins 运行,并且它们会清楚地粘贴在构建输出上,因此这是我的解决方案,它通过相当安全的方式实现了平衡。

  • 在您的主目录中创建一个包含敏感信息的属性文件(我们将其称为“maven.repo.properties”)

    repo.username=admin
    repo.password=密码
    
  • 在构建文件顶部附近,导入属性文件

    <属性文件=“${user.home}/maven.repo.properties”/>
    
  • 在 build.xml 下的发布目标中,设置 ivy 设置文件位置(确实会签入代码控件)但嵌入您的凭证属性

    <目标名称=“发布”>
        
            ;
        
        
    
    
  • 像您一样创建 ivysettings.xml之前,但删除用户名和密码属性

然后,您可以利用操作系统的权限来确保maven.repo.properties 文件对除您(或您的自动构建实现)之外的所有人都正确隐藏。

For my purposes the command-line credentials weren't an option because I'm running through Jenkins and they'd be clearly pasted on the build output, so here was my solution which strikes a balance by being reasonably secure.

  • Create a properties file in your home directory that contains the sensitive information (we'll call it "maven.repo.properties")

    repo.username=admin
    repo.password=password
    
  • Near the top of your build file, import the property file

    <property file="${user.home}/maven.repo.properties"/>
    
  • In your publish target under build.xml, set your ivy settings file location (which does get checked in to code control) but embed your credential properties

    <target name="publish">
        <ivy:settings file="ivysettings.xml">
            <credentials host="repohostname" realm="Artifactory Realm" username="${repo.username}" passwd="${repo.password}"/>
        </ivy:settings>
        <!-- ivy:makepom and ivy:publish targets go here -->
    </target>
    
  • Create your ivysettings.xml just as you did before, but strip out the username and passwd attributes

You can then leverage your operating system's permissions to make sure that the maven.repo.properties file is properly hidden from everybody except you (or your automatic build implementation).

柠栀 2024-12-12 19:01:08

Mark O'Connor 的答案中的 ivysettings.xml 示例实际上应该如下所示:

<ivysettings>
  <property name="repo.host" value="default.mycompany.com" override="false"/>
  <property name="repo.realm" value="Sonatype Nexus Repository Manager" override="false"/>
  <property name="repo.user" value="deployment"  override="false"/>
  <property name="repo.pass" value="deployment123"  override="false"/>          

  <credentials host="${repo.host}" realm="${repo.realm}" username="${repo.user}" passwd="${repo.pass}"/>

  ..
</ivysettings>

意思是,属性名称不应该被 ${...} 包围(我花了很长时间才发现为什么失败了 - 但现在我知道如何调试 ivy 访问 - 使用 commons-httpclient-3.0,将所有内容设置为详细等)

The ivysettings.xml sample in Mark O'Connor's answer should actually be as follows:

<ivysettings>
  <property name="repo.host" value="default.mycompany.com" override="false"/>
  <property name="repo.realm" value="Sonatype Nexus Repository Manager" override="false"/>
  <property name="repo.user" value="deployment"  override="false"/>
  <property name="repo.pass" value="deployment123"  override="false"/>          

  <credentials host="${repo.host}" realm="${repo.realm}" username="${repo.user}" passwd="${repo.pass}"/>

  ..
</ivysettings>

Means, the property names should not be surrounded by ${...} (it took me quite a while to find out why this failed - but now I know how to debug ivy access - use commons-httpclient-3.0, set everything to verbose etc.)

我要还你自由 2024-12-12 19:01:08

除了 Mark O'Connor 的答案之外,您还可以通过将这些属性放入 antrc 启动文件或进入 环境使用的变量由蚂蚁。请注意,这两个地方都不是很安全。

Additional to Mark O'Connor's answer you can hide the password from your daily work and from the prying eyes of your workmates by putting these properties either into the antrc startup file or into the environment variables used by ant. Please note that they are not very secure in either place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文