中间件安全加固之Jboss

JBoss 的安全设置

1) jmx-console

A、jmx-console登录的用户名和密码设置

默认情况访问 http://localhost:8080/jmx-console 就可以浏览jboss的部署管理的一些信息,不需要输入用户名和密码,使用起来有点安全隐患。下面我们针对此问题对jboss进行配置,使得访问jmx-console也必须要知道用户名和密码才可进去访问。步骤如下:

1、打开%Jboss_HOME%serverdefaultdeployjmx-console.warWEB-INFjboss-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%serverdefaultconfpropsjmx-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%serverdefaultdeploymanagementconsole-mgr.sarweb-console.warWEB-INFjboss-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%serverdefaultdeploymanagementconsole-mgr.sarweb-console.warWEB-INFclassesweb-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  路径:serverdefaultdeploymanagementconsole-mgr.sarweb-console.warWEB-INF

 开启日志:

Jboss 5日志配置:

1、打开%JBOSS_HOME%serverdefaultdeployersjbossweb.deployerserver.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%serverdefaultlog目录下。

Jboss7日志配置:

1、在默认的情况下,JBoss7是没有开启access_log的,如果要开启这项功能,就需要修改$JBOSS_HOMEstandaloneconfigurationstandalone.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}standalonelog目录下生成access_log。

最后

欢迎关注个人微信公众号:Bypass--,每周原创一篇技术干货。 

参考文章:

jboss安全配置参考

https://blog.csdn.net/qq_29277155/article/details/52810579

原文地址:https://www.cnblogs.com/xiaozi/p/9198797.html