如何覆盖部署到 Tomcat 的 Web 应用程序中的安全约束

Spe*_*dge 5 java tomcat jenkins

我有点困惑,但是一个合理的解决方案可能会帮助很多人(甚至数千人?)。

我想将最新版本的 Jenkins(撰写本文时为 1.599)部署到 Tomcat 容器 (7.0.39),然后强制所有流量使用 SSL。

我将 $CATALINA_BASE/conf/server.xml 中的连接器设置为所需的值。然后我将以下内容添加到 $CATALINA_BASE/conf/web.xml ...

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Jenkins</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

然而遗憾的是,这不起作用,因为它在 Jenkins 战争中被 web.xml 覆盖了。

<security-constraint>
  <web-resource-collection>
    <web-resource-name>other</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <!-- no security constraint --> 
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

据我了解,没有办法让我从 Tomcat web.xml 强制设置。我不会在每次新版本出现时手动编辑我的 WAR,这不是一个选项。

因此,问题是,更改服务器或客户端 web.xml 以便默认设置仍然存在的最佳方法是什么,但我们可以选择强制传输机密保证。

欢迎任何想法!:)

Alo*_*ito 1

不确定这是否有帮助,但我遇到了相反的问题。公司政策是不允许 PUT、DELETE 或 OPTIONS,因此他们在 tomcat conf/web.xml 中有这样的部分:

<security-constraint>
  <web-resource-collection>
     <web-resource-name>
       restricted methods
     </web-resource-name>
     <url-pattern> /* </url-pattern>
     <http-method> PUT </http-method>
     <http-method> DELETE </http-method>
     <http-method> OPTIONS </http-method>
     <http-method> TRACE </http-method>
  </web-resource-collection>
  <auth-constraint />
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

我发现我可以在子目录的应用程序 web.xml 中覆盖它

<security-constraint>
   <web-resource-collection>
    <web-resource-name>REST Endpoints</web-resource-name>
    <url-pattern>/rest/*</url-pattern>
  </web-resource-collection>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

但不适用于上下文根(以下不允许 OPTIONS 工作):

<security-constraint>
   <web-resource-collection>
    <web-resource-name>REST Endpoints</web-resource-name>
    <url-pattern>/*</url-pattern>
   </web-resource-collection>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

这对您来说意味着您可以要求子目录使用 SSL 而不会出现任何问题。不确定这是否足以满足您的詹金斯要求。