Skip to content

Autoconfigured OAuth2 Resource Server is missing client metrics #30891

Closed
@mafr

Description

@mafr

While using spring-boot-starter-oauth2-resource-server I noticed that there are no HTTP client metrics for any of the calls that are made to the authorization server for downloading public keys.

My configuration:

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: http://localhost:8090/realms/myrealm

It looks like the OAuth2ResourceServerJwtConfiguration doesn't set an instrumented RestTemplate, which means the NimbusJwtDecoder and its JwkSetUriJwtDecoderBuilder uses its default uninstrumented instance.

When constructing the JwtDecoder myself using the RestTemplateBuilder provided by Spring Boot, I see client metrics:

    @Bean
    public JwtDecoder jwtDecoder(RestTemplateBuilder builder) {
        RestTemplate rest = builder
                .setConnectTimeout(Duration.ofSeconds(10))
                .setReadTimeout(Duration.ofSeconds(5))
                .build();

        return NimbusJwtDecoder
                .withJwkSetUri(jwkSetUri)
                .restOperations(rest)
                .build();
    }

Example:

http_client_requests_seconds_count{clientName="localhost",method="GET",outcome="SUCCESS",status="200",uri="/realms/myrealm/protocol/openid-connect/certs",} 1.0
http_client_requests_seconds_sum{clientName="localhost",method="GET",outcome="SUCCESS",status="200",uri="/realms/myrealm/protocol/openid-connect/certs",} 0.029850946
http_client_requests_seconds_max{clientName="localhost",method="GET",outcome="SUCCESS",status="200",uri="/realms/myrealm/protocol/openid-connect/certs",} 0.029850946

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions