2015-02-24 62 views
2

我有點沉迷於此,但合理的解決方案可能有助於不少人(甚至數千人)。我如何覆蓋部署到Tomcat的webapp中的安全約束條件

我想將最新版本的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> 

但不幸的是,這不會因爲它是由詹金斯戰爭中的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> 

據我所知,沒有辦法讓我從Tomcat的web.xml強制設置。每當新版本發佈時我都不會手動編輯我的WAR,但這不是一個選項。

因此,問題是,更改服務器或客戶端web.xml以使默認設置仍然存在的最佳方式是什麼,但是我們可以選擇強制執行CONFIDENTIAL的傳輸保證。

歡迎任何想法! :)

回答

1

不知道它是否有幫助,但我有相反的問題。公司的政策是不允許PUT,DELETE或選項,所以他們在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> 

,我發現我可以在應用程序的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> 

但不適合上下文根(以下不允許OPTIONS工作):

<security-constraint> 
    <web-resource-collection> 
    <web-resource-name>REST Endpoints</web-resource-name> 
    <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
</security-constraint> 

你的言下之意是,你可以要求SSL的子目錄機智沒有任何問題。不知道這是否足以滿足詹金斯的要求。

0

我只注意到從http://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html以下語言:

當相同的URL模式和http-方法發生在多個安全 約束,在圖案和方法的限制被定義由 組合個別限制,這可能導致 無意中拒絕訪問。

這表明您指定的約束條件將被組合,這意味着您正在嘗試應該工作。你確定SSL在服務器上配置正確嗎?編輯應用程序中的web.xml實際上是否解決了這個問題?這從同一篇文章節似乎表明,如果沒有正確配置SSL,它可能回落到http:

爲了保證數據傳輸通過安全連接,確保 即SSL支持的配置適合您服務器。 SSL支持已爲配置用於GlassFish服務器的 。