When running the Discovery Client it'll not register to the Discovery Server caused by a 401 error.

c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure with status code 401; retrying on another server if available

it works when I disable Spring Security in the discovery server but it doesn't when security is enabled. The username and password are given in the DefaultZone url.

When I CURL the Discovery server with username and password in the URL it works, it seems like something goes wrong in the Discovery Client.

This returns 200 success: curl http://user:password@localhost:8761

Spring cloud version: 2022.0.3 Spring boot version: 3.1.5

Discovery server -> Security Config (Disable CSRF)

@Configuration
@EnableWebSecurity
public class SecurityConfig{
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        return http
                .csrf(AbstractHttpConfigurer::disable)
                .securityMatcher("/eureka/**")
                .build();
    }
}

Discovery server -> application.yml

spring:
  application:
    name: DiscoveryServer
  security:
    user:
      name: user
      password: password
server:
  port: 8762
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://user:password@localhost:${server.port}/eureka/

Discovery client -> application.yml

spring:
  application:
    name: GDPRAgent
server:
  port: 8099
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://user:password@localhost:8762/eureka/

Comment From: OlgaMaciaszek

Hello @Issamhanzaz, please take a look at this working sample (and especially the Spring Security config in EurekaApplication) and see if it helps you solve the issue. If not, please provide a minimal, complete, verifiable example that reproduces the issue.

Comment From: spring-cloud-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-cloud-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

Comment From: ugale-deepak3010

Still facing same issue.

http://localhost:8761/

above url is working when I put password manually.

but while registering using another site getting this error: Request execution failure with status code 401;

here is service code. eureka.client.service-url.default-zone=http://eureka:root@localhost:8761/eureka

Comment From: OlgaMaciaszek

@ugale-deepak3010 Is there a password you need? If it's secured, you will need to properly configure security in your server; you can see a sample for the server here: https://github.com/spring-cloud-samples/eureka/tree/Eureka-With-Security-4.x.