tl;dr:
Maven 中不存在的验证机制以及 POM DSL 中缺少的语言构造是严重的安全威胁。直到MNG-6026 https://issues.apache.org/jira/browse/MNG-6026已解决,请使用类似的东西摇篮见证人 https://github.com/WhisperSystems/gradle-witness.
介绍
到目前为止提供的答案似乎都没有解决问题。签署工件只是第一步进入正确的方向。但是用于签署工件的密钥被认为是可信/有效的条件非常不透明,有时甚至很弱。例如:如何pgpverify-maven-插件 https://stackoverflow.com/a/25319548/194894 or Nexus 专业版 https://stackoverflow.com/a/3309802/194894实际验证签名对于工件是否有效?仅从密钥服务器检索密钥并验证工件是不够的。
Sonatype 在他们的文章中简要提到了这一点博客文章 http://blog.sonatype.com/2012/03/the-first-line-of-defense-checksums-and-pgp-signatures-in-repositories/#.VpfdjK8rK00:
PGP 签名:另一个层面
在消费方面,您可以使用 Nexus Professional 中的采购
检查签名是否存在,以及在发布方面
使用 PGP 签名签署您的版本并进行 PGP 签名
在公钥服务器上可用将帮助人们仔细检查
工件和校验和是一致的。注:我觉得还有更多
创建鼓励使用 PGP 密钥的工具需要做的工作
更重要的是,给予存储库管理员一些控制权
哪些密钥值得信任。
(强调我的)
使用信任信息扩展项目对象模型 (POM)
我们需要的是能够对从您的项目或工件到声明的依赖项的信任关系进行建模。因此,如果所有相关方都声明这种关系,我们就能够创建一条从根(例如项目)到其依赖项直至最后一个传递依赖项的“信任链”。这项目对象模型 (POM) https://maven.apache.org/pom.html需要通过 元素来扩展依赖项。
现在的情况
现在我们有类似的东西
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
</dependency>
硬依赖
对于硬依赖项, 可以包含工件的 sha256sum 及其 POM 文件:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<verification>
<checksum hash='sha-256'>
<pom>[sha256 of junit pom file]</pom>
<artifact>[sha256sum of artifact (junit.jar)]</artifact>
</checksum>
</verification>
</dependency>
软依赖
如果使用软依赖或范围依赖,那么我们可以指定用于对工件进行签名的密钥对的公钥(或多个)
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>[4.0,4.5)</version>
<verification>
<openpgp>[secure fingerprint of OpenPGP key]</openpgp>
<!-- possible further 'openpgp' elements in case the artifacts in the
specified version range where signed by multiple keys -->
</verification>
</dependency>
And now?
谢谢peter https://stackoverflow.com/questions/3307146/verification-of-dependency-authenticy-in-maven-pom-based-automated-build-systems/34795359?noredirect=1#comment62178671_34795359触发了我,我提出了 Apache Maven 的功能请求:MNG-6026 https://issues.apache.org/jira/browse/MNG-6026。让我们看看接下来会发生什么。
其他方法
摇篮见证人 https://github.com/WhisperSystems/gradle-witness对 gradle 做了类似的事情。但它有一些缺点:
- 它构建在 gradle 之上(并构建在 POM 中)
- 它只允许硬依赖,因为它使用哈希。
对于Maven 强制执行器插件 https://maven.apache.org/enforcer/maven-enforcer-plugin/.
pgpverify-maven-插件 http://www.simplify4u.org/pgpverify-maven-plugin/index.html显然也遵循这种方法。虽然缺少文档,但有一个测试所谓的keysMap财产 https://github.com/s4u/pgpverify-maven-plugin/blob/7dc1cb0f2c74352e7995c7cf1261dba040b7eb30/src/test/resources/keysMap1.properties,这也在配置文件中显示为keysMapLocation https://github.com/s4u/pgpverify-maven-plugin/blob/7dc1cb0f2c74352e7995c7cf1261dba040b7eb30/src/it/sigOkKeysMap/pom.xml#L46.