Skip to content

Provide a property to disable the /actuator discovery page #24693

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
zromano opened this issue Jan 7, 2021 · 4 comments
Closed

Provide a property to disable the /actuator discovery page #24693

zromano opened this issue Jan 7, 2021 · 4 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@zromano
Copy link

zromano commented Jan 7, 2021

If I include spring-boot-starter-actuator there is no way for me to disable the discovery page (/actuator).

I would like to utilize other features of the actuator, such as metrics, but I do not want to be forced into exposing this endpoint.

I can disable all other endpoints with the following:

management:
  endpoints:
    enabled-by-default: false

I would think this would also disable the /actuator endpoint.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 7, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Jan 8, 2021

Disabling the endpoints by default has no effect as /actuator isn't an endpoint. Instead, it provides links to everything that is an endpoint.

There's no property to allow you to disable it at the moment, but it is possible to do so by defining your own bean. For example, if you're using the Servlet web stack and Spring MVC, you'd define a bean that's a copy-paste of the webEndpointServletHandlerMapping bean defined in WebMvcEndpointManagementContextConfiguration, but with shouldRegisterLinksMapping hard-coded to false. This is quite a few lines of code, and would look something like the following:

@Bean
@ConditionalOnMissingBean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
        ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier,
        EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties,
        WebEndpointProperties webEndpointProperties, Environment environment) {
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
    Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
    allEndpoints.addAll(webEndpoints);
    allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    String basePath = webEndpointProperties.getBasePath();
    EndpointMapping endpointMapping = new EndpointMapping(basePath);
    boolean shouldRegisterLinksMapping = StringUtils.hasText(basePath)
            || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
    return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
            corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
            shouldRegisterLinksMapping);
}

We can consider adding a property to avoid the need for copy-paste.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jan 8, 2021
@wilkinsona wilkinsona changed the title Cannot Disable the /actuator discovery page Provide a property to disable the /actuator discovery page Jan 8, 2021
@wilkinsona wilkinsona added the type: enhancement A general enhancement label Jan 8, 2021
@philwebb philwebb removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Jan 8, 2021
@philwebb philwebb added this to the 2.5.x milestone Jan 8, 2021
@philwebb philwebb added the status: pending-design-work Needs design work before any code can be developed label Jan 8, 2021
@zromano
Copy link
Author

zromano commented Jan 8, 2021

@wilkinsona Thanks for the solution. With that said, I'd love if it were as easy as setting a property 🙂

I think that if all of the endpoints are disabled then /actuator should be disabled, as it no longer provides any information.

@philwebb
Copy link
Member

philwebb commented Jan 8, 2021

We're going to add a property so that the links can be easily switched off.

@mbhave mbhave self-assigned this Feb 8, 2021
@mbhave mbhave closed this as completed in c05cb21 Feb 9, 2021
@mbhave mbhave modified the milestones: 2.5.x, 2.5.0-M2 Feb 9, 2021
@zromano
Copy link
Author

zromano commented Feb 9, 2021

Thank you 👍

@mbhave mbhave removed the status: pending-design-work Needs design work before any code can be developed label Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants