Skip to content

Actuator's EndpointRequest doesn't consider server.servlet.path #12934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
candrews opened this issue Apr 20, 2018 · 14 comments
Closed

Actuator's EndpointRequest doesn't consider server.servlet.path #12934

candrews opened this issue Apr 20, 2018 · 14 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@candrews
Copy link
Contributor

candrews commented Apr 20, 2018

In application.properties, set server.servlet.path=/spring

Now notice that EndpointRequest.* doesn't match anything. For example, a request for /spring/actuator/health doesn't match (a request for /actuator/health does match, though - even though it will return a 404).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 20, 2018
@mbhave
Copy link
Contributor

mbhave commented Apr 20, 2018

@candrews I don't think it does. The RequestMatcher matches on request.getServletPath, which in this case (even when the request is /spring/actuator/health) is /actuator/health. If you would like us to investigate this issue further, please provide a minimalistic sample that we can use to reproduce the issue.

@mbhave mbhave added the status: waiting-for-feedback We need additional information before we can continue label Apr 20, 2018
@candrews
Copy link
Contributor Author

Create a new project using https://start.spring.io/ including Web, Security, and Actuator
In application.properties: server.servlet.path=/spring
Create this class:

package com.example.demo;

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            	// this line works
//            	.requestMatchers(new AntPathRequestMatcher("/spring/actuator/health")).permitAll()
            	
//            	 this line does not work, but should: https://github.com/spring-projects/spring-boot/issues/12934
            	.requestMatchers(EndpointRequest.to("health")).permitAll()
                .anyRequest().denyAll()
                
                .and()
            .formLogin()
                .loginPage("/spring/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }
    
}

Run it, now go to http://localhost:8080/spring/actuator/health

I'd expect to get a JSON result back with the health check status of "UP" I actually get a 302 redirect.
In WebSecurityConfig, if you comment out the first noted line, and uncomment the second noted line, then run this test again, you'll get the expected result.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 20, 2018
@mbhave
Copy link
Contributor

mbhave commented Apr 20, 2018

ah, I didn't realize that the property you were configuring was server.servlet.path and not server.servlet.context-path. The issue title says context-path and if that's what you want to do, you'd need to set server.servlet.context-path. EndpointRequest will work in that case. But we need to fix the case where EndpointRequest doesn't match if server.servlet.path is set.

@mbhave mbhave added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Apr 20, 2018
@mbhave mbhave added this to the 2.0.x milestone Apr 20, 2018
@mbhave mbhave changed the title Actuator's EndpointRequest doesn't consider context path Actuator's EndpointRequest doesn't consider server.servlet.path Apr 20, 2018
@candrews
Copy link
Contributor Author

I'm sorry about the error in the title :(
I'm glad we're on the same page now, though! Thank you.

@mbhave mbhave self-assigned this Apr 24, 2018
@n0mer
Copy link

n0mer commented May 3, 2018

@mbhave server.servlet.context-path is also ignored in 2.0.1.RELEASE for webflux

I have the following in application.yml

management:
  server:
    port: ${MANAGEMENT_PORT:8889}
    servlet:
      context-path: "/management"

But info endpoint is mapped to /actuator/info, not to /management/actuator/info

2018-05-03 12:38:40.235  INFO 1 --- [           main] .b.a.e.w.r.WebFluxEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public org.reactivestreams.Publisher<org.springframework.http.ResponseEntity<java.lang.Object>> org.springframework.boot.actuate.endpoint.web.reactive.AbstractWebFluxEndpointHandlerMapping$ReadOperationHandler.handle(org.springframework.web.server.ServerWebExchange)

@snicoll
Copy link
Member

snicoll commented May 3, 2018

@n0mer that fact that it has servlet in the name should be a strong indicator that it will not work on environments that do not require the servlet API. If you have more questions, please ask on StackOverflow or come chat with us on Gitter.

@n0mer
Copy link

n0mer commented May 4, 2018

@snicoll with all respect - do you think that SO or Gitter are proper places to report bugs?

This feature (configuration of custom context-path for webflux), as per https://stackoverflow.com/questions/49196368/context-path-with-webflux, is not yet supported.

image

@wilkinsona
Copy link
Member

@n0mer What you're talking about is not a bug. It's by design that a servlet-specific property has no effect on a WebFlux application. It's also unrelated to this issue which is specifically about the EndpointRequest class that's used to configure Spring Security.

@gmcouto
Copy link

gmcouto commented May 5, 2018

I am facing this issue with 2.0.1-RELEASE, but only with jolokia endpoint. All other endpoints are working as expected.

@gmcouto
Copy link

gmcouto commented May 7, 2018

I'm still facing this jolokia endpoint issue... With the current 2.0.2.BUILD-SNAPSHOT build.

//actuator specific version
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version:'2.0.2.BUILD-SNAPSHOT'
compile group: 'org.springframework.boot', name: 'spring-boot-actuator', version:'2.0.2.BUILD-SNAPSHOT'

Shouldn't it be fixed?

@mbhave
Copy link
Contributor

mbhave commented May 7, 2018

@gmcouto the issue with the JolokiaEndpoint is different. It doesn't appear to be included in the RequestMatcher created by EndpointRequest#including (or excluded from the RequestMatcher if (EndpointRequest#excluded)) . I've created a separate issue for that here.

If you've found that the bug with the Jolokia endpoint is related to the servlet-path being set (which was the original issue here), please provide a sample that reproduces that and we can reopen this issue.

@gmcouto
Copy link

gmcouto commented May 8, 2018

If you have server.servlet.path property set on your application, all actuator endpoints will be moved to it accordingly, except the jolokia endpoints.

How the jolokia endpoint is:
http://host:port/context-path/actuator/jolokia

How the jolokia endpoint should be:
http://host:port/context-path/servlet-path/actuator/jolokia

Examples of other endpoints:
http://host:port/context-path/servlet-path/actuator/health
http://host:port/context-path/servlet-path/actuator/auditevents
http://host:port/context-path/servlet-path/actuator/beans

Sample
defect-actuator-jolokia.zip

I have added the same information to the other defect. Not sure how you prefer to track this.

@mbhave
Copy link
Contributor

mbhave commented May 8, 2018

@gmcouto Thanks for the sample but this issue was about the matchers created by EndpointRequest. Your application does not have Spring Security on the classpath so it has nothing to do with the original issue.

The jolokia issue you've noticed is a separate bug and I've opened an issue for it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

7 participants