【问题标题】:How to get the gpg-agent to ask for the password when used in maven-gpg-plugin在 maven-gpg-plugin 中使用时如何让 gpg-agent 询问密码
【发布时间】:2018-03-25 14:49:28
【问题描述】:

我有几个项目想要使用 gpg 密钥对生成的工件进行签名。过去我使用 gpg 1.x(即旧版本),在此设置中,我在~/.m2/settings-security.xml 中加密了密码(但可用)。

我不喜欢这样(但当时我写道,这是我设法运行的设置)。

我最近开始研究是否可以在不存储密码的情况下使其全部运行。所以现在在~/.m2/settings.xml 我有这样的东西(这个配置文件是活动的):

<profile>
  <id>signingkey</id>
  <properties>
    <gpg.executable>gpg2</gpg.executable>
    <gpg.keyname>ABCDEF01</gpg.keyname>
  </properties>
</profile>

在 pom.xml 中,我有带有这个基本配置的 maven-gpg-plugin

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-gpg-plugin</artifactId>
      <version>1.6</version>
      <executions>
        <execution>
          <id>sign-artifacts</id>
          <phase>verify</phase>
          <goals>
            <goal>sign</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

现在,当我在我的 Ubuntu 16.04 系统上执行此操作时,gpg-agent(gpg2 的一部分)和 gnome-keyring-daemon 在第一次使用后会记住密码。

所以在这个系统上,我通常处于已经运行 gpg-agent 的情况,因此,当我在项目中执行 mvn clean verify 时,无需询问任何问题即可签署工件,因为密码在 gpg- 中可用代理。

到目前为止一切顺利。

为了确保我拥有完美干净的软件构建(并且对于某些项目也确保正确安装所有工具),我经常从单独的 docker 环境构建/部署软件。

在这样一个“非常干净”的 docker 环境中,启动时没有 gpg-agent,我发现简单地运行 mvn clean verify 会产生一个未签名的构建,因为我得到了

You need a passphrase to unlock the secret key for
user: "Niels Basjes (Software Signing Key) <signed@basjes.nl>"
...
gpg: cancelled by user

据我所知,因为我应该输入密码但没有提供提示。

此时我只找到了一种解决方法,那就是在构建软件之前执行gpg2 --sign pom.xml 之类的操作,因为这会启动 gpg-agent 并显示一个对话框来输入密码。

我想要更改我的设置,以便我可以简单地执行mvn verify,第一次登录尝试将为我弹出密码对话框并将密码缓存在 gpg-agent 中。

基本上我的问题是如何做到这一点;或更好:设置它的正确方法是什么?

【问题讨论】:

    标签: maven gnupg maven-gpg-plugin


    【解决方案1】:

    您可以使用以下配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                    <goal>sign</goal>
                </goals>
                <configuration>
                    <executable>gpg2</executable>
                    <gpgArguments>
                        <arg>--pinentry-mode</arg>
                        <arg>loopback</arg>
                    </gpgArguments>
                    <passphrase>${gpg.passphrase}</passphrase>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    将您的 gpg 密码放在带有配置文件的 settings.xml 文件中,并使用配置文件进行构建。属性名称是固定的,不能更改。 您也可以使用属性 gpg.executable 以这种方式设置可执行文件

    <properties>
        <gpg.passphrase>MySpecialPassword</gpg.passphrase>
    </properties>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 2021-12-18
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多