Chapter 4. Security and Authentication of HawtIO HawtIO enables authentication out of the box depending on the runtimes/containers it runs with. To use HawtIO with your application, either setting up authentication for the runtime or disabling HawtIO authentication is necessary. 4.1. Configuration properties The following table lists the Security-related configuration properties for the HawtIO core system. Name Default Description hawtio.authenticationContainerDiscoveryClasses io.hawt.web.tomcat.TomcatAuthenticationContainerDiscovery List of used AuthenticationContainerDiscovery implementations separated by a comma. By default, there is just TomcatAuthenticationContainerDiscovery, which is used to authenticate users on Tomcat from tomcat-users.xml file. Feel free to remove it if you want to authenticate users on Tomcat from the configured JAAS login module or feel free to add more classes of your own. hawtio.authenticationContainerTomcatDigestAlgorithm NONE When using the Tomcat tomcat-users.xml file, passwords can be hashed instead of plain text. Use this to specify the digest algorithm; valid values are NONE, MD5, SHA, SHA-256, SHA-384, and SHA-512. hawtio.authenticationEnabled true Whether or not security is enabled. hawtio.keycloakClientConfig classpath:keycloak.json Keycloak configuration file used for the front end. It is mandatory if Keycloak integration is enabled. hawtio.keycloakEnabled false Whether to enable or disable Keycloak integration. hawtio.noCredentials401 false Whether to return HTTP status 401 when authentication is enabled, but no credentials have been provided. Returning 401 will cause the browser popup window to prompt for credentials. By default this option is false, returning HTTP status 403 instead. hawtio.realm hawtio The security realm used to log in. hawtio.rolePrincipalClasses Fully qualified principal class name(s). A comma can separate multiple classes. hawtio.roles Admin, manager, viewer The user roles are required to log in to the console. A comma can separate multiple roles to allow. Set to * or an empty value to disable role checking when HawtIO authenticates a user. hawtio.tomcatUserFileLocation conf/tomcat-users.xml Specify an alternative location for the tomcat-users.xml file, e.g. /production/userlocation/. 4.2. Quarkus HawtIO is secured with the authentication mechanisms that Quarkus and also Keycloak provide. If you want to disable HawtIO authentication for Quarkus, add the following configuration to application.properties : quarkus.hawtio.authenticationEnabled = false 4.2.1. Quarkus authentication mechanisms HawtIO is just a web application in terms of Quarkus, so the various mechanisms Quarkus provides are used to authenticate HawtIO in the same way it authenticates a Web application. Here we show how you can use the properties-based authentication with HawtIO for demonstrating purposes. Important The properties-based authentication is not recommended for use in production. This mechanism is for development and testing purposes only. To use the properties-based authentication with HawtIO, add the following dependency to pom.xml : <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-elytron-security-properties-file</artifactId> </dependency> You can then define users in application.properties to enable the authentication. For example, defining a user hawtio with password s3cr3t! and role admin would look like the following: quarkus.security.users.embedded.enabled = true quarkus.security.users.embedded.plain-text = true quarkus.security.users.embedded.users.hawtio = s3cr3t! quarkus.security.users.embedded.roles.hawtio = admin Example: See Quarkus example for a working example of the properties-based authentication. 4.2.2. Quarkus with Keycloak See Keycloak Integration - Quarkus . 4.3. Spring Boot In addition to the standard JAAS authentication, HawtIO on Spring Boot can be secured through Spring Security or Keycloak . If you want to disable HawtIO authentication for Spring Boot, add the following configuration to application.properties : hawtio.authenticationEnabled = false 4.3.1. Spring Security To use Spring Security with HawtIO: Add org.springframework.boot:spring-boot-starter-security to the dependencies in pom.xml : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> Spring Security configuration in src/main/resources/application.properties should look like the following: spring.security.user.name = hawtio spring.security.user.password = s3cr3t! spring.security.user.roles = admin,viewer A security config class has to be defined to set up how to secure the application with Spring Security: @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().authenticated() .and() .formLogin() .and() .httpBasic() .and() .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); return http.build(); } } Example: See springboot-security example for a working example. 4.3.1.1. Connecting to a remote application with Spring Security If you try to connect to a remote Spring Boot application with Spring Security enabled, make sure the Spring Security configuration allows access from the HawtIO console. Most likely, the default CSRF protection prohibits remote access to the Jolokia endpoint and thus causes authentication failures at the HawtIO console. Warning Be aware that it will expose your application to the risk of CSRF attacks. The easiest solution is to disable CSRF protection for the Jolokia endpoint at the remote application as follows. import org.springframework.boot.actuate.autoconfigure.jolokia.JolokiaEndpoint; import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { ... // Disable CSRF protection for the Jolokia endpoint http.csrf().ignoringRequestMatchers(EndpointRequest.to(JolokiaEndpoint.class)); return http.build(); } } To secure the Jolokia endpoint even without Spring Security's CSRF protection, you need to provide a jolokia-access.xml file under src/main/resources/ like the following (snippet) so that only trusted nodes can access it: <restrict> ... <cors> <allow-origin>http*://localhost:*</allow-origin> <allow-origin>http*://127.0.0.1:*</allow-origin> <allow-origin>http*://*.example.com</allow-origin> <allow-origin>http*://*.example.com:*</allow-origin> <strict-checking /> </cors> </restrict> 4.3.2. Spring Boot with Keycloak See Keycloak Integration - Spring Boot .

Commands:
quarkus.hawtio.authenticationEnabled = false
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-elytron-security-properties-file</artifactId> </dependency>
quarkus.security.users.embedded.enabled = true quarkus.security.users.embedded.plain-text = true quarkus.security.users.embedded.users.hawtio = s3cr3t! quarkus.security.users.embedded.roles.hawtio = admin
hawtio.authenticationEnabled = false
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
spring.security.user.name = hawtio spring.security.user.password = s3cr3t! spring.security.user.roles = admin,viewer
@EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().authenticated() .and() .formLogin() .and() .httpBasic() .and() .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); return http.build(); } }
import org.springframework.boot.actuate.autoconfigure.jolokia.JolokiaEndpoint; import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // Disable CSRF protection for the Jolokia endpoint http.csrf().ignoringRequestMatchers(EndpointRequest.to(JolokiaEndpoint.class)); return http.build(); } }
<restrict> <cors> <allow-origin>http*://localhost:*</allow-origin> <allow-origin>http*://127.0.0.1:*</allow-origin> <allow-origin>http*://*.example.com</allow-origin> <allow-origin>http*://*.example.com:*</allow-origin> <strict-checking /> </cors> </restrict>