Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ credentials.

:::tip
When using this approach the SBA Server decides whether the user can access the registered applications. There are more
complex solutions possible (using OAuth2) to let the clients decide if the user can access the endpoints. For that
please have a look at the samples
in [joshiste/spring-boot-admin-samples](https://github.com/joshiste/spring-boot-admin-samples).
complex solutions possible (using OAuth2) to let the clients decide if the user can access the endpoints. Implement
this with your own `HttpHeadersProvider` that acquires a token and adds it as a bearer token. See
[Server Authentication](../05-security/10-server-authentication.md) for the server side and
[Actuator Security](../05-security/20-actuator-security.md) for the client side. Runnable example projects live in
[spring-boot-admin-runtime-playground](https://github.com/codecentric/spring-boot-admin-runtime-playground).
:::

### SBA Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,72 @@ public SecurityFilterChain filterChain(HttpSecurity http,
.requestMatchers(PathPatternRequestMatcher.withDefaults()
.matcher(adminServer.path("/assets/**")))
.permitAll()
.requestMatchers(PathPatternRequestMatcher.withDefaults()
.matcher(adminServer.path("/login")))
.permitAll()
.anyRequest().authenticated()
)
.oauth2Login(oauth2 -> oauth2
.loginPage(adminServer.path("/login"))
)
// No custom loginPage: Spring Security redirects browsers to the IdP.
.oauth2Login(Customizer.withDefaults())
// Lets Spring Boot Admin Clients register with Basic credentials.
.httpBasic(Customizer.withDefaults())
.logout(logout -> logout
.logoutUrl(adminServer.path("/logout"))
.logoutSuccessUrl(adminServer.path("/"))
)
.csrf(csrf -> csrf
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())
.ignoringRequestMatchers(
PathPatternRequestMatcher.withDefaults()
.matcher(POST, adminServer.path("/instances")),
PathPatternRequestMatcher.withDefaults()
.matcher(DELETE, adminServer.path("/instances/*")),
PathPatternRequestMatcher.withDefaults()
.matcher(adminServer.path("/actuator/**"))
)
);
// CSRF and other configurations...
// CustomCsrfFilter: see "Custom CSRF Filter" above
http.addFilterAfter(new CustomCsrfFilter(), BasicAuthenticationFilter.class);
return http.build();
}
// Spring Boot's UserDetailsServiceAutoConfiguration backs off once a
// ClientRegistrationRepository exists, so spring.security.user.* is ignored.
// Define the Basic-auth user for registering clients explicitly.
@Bean
public InMemoryUserDetailsManager userDetailsService(PasswordEncoder passwordEncoder) {
UserDetails client = User.withUsername("client")
.password(passwordEncoder.encode(System.getenv("SBA_CLIENT_PASSWORD")))
.roles("CLIENT")
.build();
return new InMemoryUserDetailsManager(client);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
```

:::warning
Do not set `oauth2Login(oauth2 -> oauth2.loginPage(adminServer.path("/login")))`: `/login` is Spring Boot Admin's
local username/password form and has no link to your identity provider.
:::

Keep `httpBasic()` and the `userDetailsService` bean, otherwise Spring Boot Admin Clients cannot register with their
Basic credentials: with OAuth2 on the classpath, Spring Boot no longer creates a user from `spring.security.user.*`.
Keep the CSRF exemptions for `POST /instances`, `DELETE /instances/*` and `/actuator/**`, otherwise client
registration is rejected with `403` (or `401` when the error page itself requires authentication). See
[CSRF Protection](./30-csrf-protection.md).

:::note
Browser requests (`Accept: text/html`) are redirected to the identity provider. Requests without `Accept: text/html`,
such as plain `curl` or XHR calls, get `401` by design. When a UI session expires, the UI redirects to `login` relative
to the Admin Server's context path. Without a context path this is Spring Security's generated `/login` page, which
links to the identity provider. With `spring.boot.admin.context-path` set, it is Spring Boot Admin's own login form
instead; users then need to reload the UI to be redirected to the identity provider.
:::

---

## Role-Based Access Control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ server:
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
```

### Issue: Client registration fails with 403
### Issue: Client registration fails with 403 or 401

**Cause**: `/instances` endpoint not exempted from CSRF.
**Cause**: `/instances` endpoint not exempted from CSRF. The `CsrfFilter` rejects the request with `403`; if the forwarded `/error` page also requires authentication, the client sees `401` instead.

**Solution**: Add to `ignoringRequestMatchers`:

Expand Down
24 changes: 16 additions & 8 deletions spring-boot-admin-docs/src/site/docs/09-samples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ patterns. These samples provide working examples you can use as starting points

## Repository Location

All samples are available in
The samples listed above live in
the [Spring Boot Admin GitHub repository](https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples):

```
Expand All @@ -47,6 +47,11 @@ spring-boot-admin-samples/
└── spring-boot-admin-sample-mcp/
```

Additional example projects covering specific use cases and infrastructure (discovery setups, proxies and similar) live
in the separate
[spring-boot-admin-runtime-playground](https://github.com/codecentric/spring-boot-admin-runtime-playground)
repository.

## Running the Samples

### Prerequisites
Expand Down Expand Up @@ -264,14 +269,17 @@ Update Spring Boot Admin version in parent POM and rebuild.

## Contributing

To add a new sample:
The samples in `spring-boot-admin-samples/` demonstrate core Spring Boot Admin features. New example projects for
specific use cases and infrastructure belong in
the [spring-boot-admin-runtime-playground](https://github.com/codecentric/spring-boot-admin-runtime-playground)
repository instead.

To add a new example there:

1. Create directory under `spring-boot-admin-samples/`
2. Follow existing sample structure
3. Add `README.md` with specific instructions
4. Include `docker-compose.yml` if applicable
5. Add tests
6. Update samples documentation
1. Create a directory for your use case, following the structure of the existing examples
2. Add a `README.md` with step-by-step instructions
3. Include a `docker-compose.yml` if the example needs infrastructure
4. Add the example to the playground's `README.md`

## See Also

Expand Down
Loading