JBoss 的安全設置
1) jmx-console
A、jmx-console登錄的用戶名和密碼設置
默認情況訪問 http://localhost:8080/jmx-console 就可以瀏覽jboss的部署管理的一些信息,不需要輸入用戶名和密碼,使用起來有點安全隱患。下面我們針對此問題對jboss進行配置,使得訪問jmx-console也必須要知道用戶名和密碼才可進去訪問。步驟如下:
1、打開%Jboss_HOME%\server\default\deploy\jmx-console.war\WEB-INF\jboss-web.xml,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注釋。修改后的該文件內容為:
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"> <jboss-web> <!-- Uncomment the security-domain to enable security. You will need to edit the htmladaptor login configuration to setup the login modules used to authentication users. --> <security-domain>java:/jaas/jmx-console</security-domain> </jboss-web>
2、修改與jboss-web.xml同級目錄下的web.xml文件,查找到<security-constraint/>節點,去掉它的注釋,修改后該部分內容為:
<!-- A security constraint that restricts access to the HTML JMX console to users with the role JBossAdmin. Edit the roles to what you want and uncomment the WEB-INF/jboss-web.xml/security-domain element to enable secured access to the HTML JMX console. --> <security-constraint> <web-resource-collection> <web-resource-name>HtmlAdaptor</web-resource-name> <description>An example security config that only allows users with the role JBossAdmin to access the HTML JMX console web application </description> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>JBossAdmin</role-name> </auth-constraint> </security-constraint>
在此處可以看出,為登錄配置了角色JBossAdmin。
3、在%Jboss_HOME%\server\default\conf\props\jmx-console-users.properties,該文件定義的格式為:用戶名=密碼,在該文件中,默認定義了一個用戶名為admin,密碼也為admin的用戶,建議設置強口令密碼。
# A sample users.properties file for use with the UsersRolesLoginModule admin=admin PS:注意修改admin密碼
在同目錄下jmx-console-roles.properties的內容如下:
# A sample roles.properties file for use with the UsersRolesLoginModule admin=JBossAdmin,HttpInvoker
該文件定義的格式為:用戶名=角色,多個角色以“,”隔開,該文件默認為admin用戶定義了JBossAdmin和HttpInvoker這兩個角色。
配置完成,需要重啟 JBoss,通過訪問: http://localhost:8080/jmx-console/ ,輸入jmx-console-roles.properties文件中定義的用戶名和密碼,訪問jmx-console的頁面。
B、刪除jmx-console
如無需jmx-console服務,可以刪除相關文件。如:jboss 6.0 之前的版本 JMX 控制台的配置文件位置為:server/$config/deploy/jmx-console.war/WEB-INF/,jboss 6.0 及以上、7.0 以前的版本,JMX 控制台的配置文件位置為:common/deploy/jmx-console.war/WEB-INF/
2) web-console
打開%Jboss_HOME%\server\default\deploy\management\console-mgr.sar\web-console.war\WEB-INF\jboss-web.xml,去掉<security-domain>節點的注釋,修改后的文件內容為:
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd"> <jboss-web> <!-- Uncomment the security-domain to enable security. You will need to edit the htmladaptor login configuration to setup the login modules used to authentication users. --> <security-domain>java:/jaas/web-console</security-domain> <!-- The war depends on the --> <depends>jboss.admin:service=PluginManager</depends> </jboss-web>
2、修改與jboss-web.xml同級目錄下的web.xml文件,查找到<security-constraint/>節點,去掉它的注釋,修改后該部分內容為:
<!-- A security constraint that restricts access to the HTML JMX console to users with the role JBossAdmin. Edit the roles to what you want and uncomment the WEB-INF/jboss-web.xml/security-domain element to enable secured access to the HTML JMX console. --> <security-constraint> <web-resource-collection> <web-resource-name>HtmlAdaptor</web-resource-name> <description>An example security config that only allows users with the role JBossAdmin to access the HTML JMX console web application </description> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>JBossAdmin</role-name> </auth-constraint> </security-constraint>
3、打開%Jboss_HOME%\server\default\deploy\management\console-mgr.sar\web-console.war\WEB-INF\classes\web-console-users.properties,設置用戶名、密碼。
# A sample users.properties file for use with the UsersRolesLoginModule admin=admin
要分配一個用戶到JBossAdmin組里,在同目錄下的web-console-roles.properties.properties文件里添加"username=JBossAdmin"
# A sample roles.properties file for use with the UsersRolesLoginModule admin=JBossAdmin
可以看到這兩個文件默認是admin/admin的用戶,為了安全起見,建議更換一個強口令密碼。
配置完成后,需要重啟 JBoss,訪問: http://localhost:8080//web-console/就需要輸入用戶口令來驗證。
如無需web-console服務,可以刪除相關文件,jboss 5 路徑:\server\default\deploy\management\console-mgr.sar\web-console.war\WEB-INF
開啟日志:
Jboss 5日志配置:
1、打開%JBOSS_HOME%\server\default\deployers\jbossweb.deployer\server.xml文件,在<HOST>標簽中增加記錄日志功能 ,將Access logger以下內容的注釋標記取消,取消后的內容如下:
<Host name="localhost" autoDeploy="false" deployOnStartup="false" deployXML="false" configClass="org.jboss.web.tomcat.security.config.JBossContextConfig" > <!-- Uncomment to enable request dumper. This Valve "logs interesting contents from the specified Request (before processing) and the corresponding Response (after processing). It is especially useful in debugging problems related to headers and cookies." --> <!-- <Valve className="org.apache.catalina.valves.RequestDumperValve" /> --> <!-- Access logger --> <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="localhost_access_log." suffix=".log" pattern="common" directory="${jboss.server.home.dir}/log" resolveHosts="false" />
2、重啟Jboss服務,網站訪問日志生成在JBOSS_HOME%\server\default\log目錄下。
Jboss7日志配置:
1、在默認的情況下,JBoss7是沒有開啟access_log的,如果要開啟這項功能,就需要修改$JBOSS_HOME\standalone\configuration\standalone.xml這個文件,備份配置文件,相關的修改內容如下所示:
<virtual-server name="default-host" enable-welcome-root="true"> <alias name="localhost"/> <alias name="example.com"/> <access-log pattern="%t %a %m %U %s %D" prefix="access_log." rotate="true"> <directory path="." relative-to="jboss.server.log.dir"/> </access-log> </virtual-server>
重啟即可看到${jbossHome}\standalone\log\目錄下生成access_log。
最后
歡迎關注個人微信公眾號:Bypass--,每周原創一篇技術干貨。
參考文章:
jboss安全配置參考
https://blog.csdn.net/qq_29277155/article/details/52810579