fix(health): token_broker health check only when tokens are enabled #71

Merged
james.maes merged 1 commits from fix/health-token-broker-only-when-tokens-on into release/0.1 2026-11-09 18:36:25 +00:00
2 changed files with 34 additions and 1 deletions

No files matched your search

@@ -65,7 +65,13 @@ public final class AuthentikHealthChecks
public static void register(QInstance instance, AuthentikQBitConfig config)
{
HealthChecksMetaData registry = HealthChecksMetaData.ofOrWithNew(instance);
for(String name : List.of("api", "api_token", "mapper", "token_broker"))
/////////////////////////////////////////////////////////////////////////////////////////////////
// the token broker is only used when tokens are on; with tokens off a registered check //
// could only ever report UNKNOWN "not configured", and core cannot remove a registered check. //
/////////////////////////////////////////////////////////////////////////////////////////////////
List<String> names = Boolean.TRUE.equals(config.getTokensEnabled())
? List.of("api", "api_token", "mapper", "token_broker") : List.of("api", "api_token", "mapper");
for(String name : names)
{
registry.withCheck(new HealthCheckMetaData().withName("authentik." + name).withLabel("Authentik " + name)
.withComponent("authentik").withCategory(HealthCategory.IDENTITY).withKind(HealthCheckKind.DEPENDENCY)
@@ -117,6 +117,33 @@ class AuthentikHealthChecksTest
/*******************************************************************************
** With tokens off the token broker is not used, so no token_broker check is
** registered (it could only ever show UNKNOWN "not configured"); the rest stay.
*******************************************************************************/
@Test
void registrationWithTokensOffOmitsTokenBroker() throws QException
{
QInstance tokensOff = AuthentikTestSupport.produce(AuthentikTestSupport.unitConfig().withApiToken(SECRET).withTokensEnabled(false));
var checks = HealthChecksMetaData.ofOrWithNew(tokensOff).resolveAll(tokensOff);
assertThat(checks).extracting(c -> c.getName()).containsExactly("authentik.api", "authentik.api_token", "authentik.mapper");
}
/*******************************************************************************
** With tokens explicitly on the token broker check is registered as before.
*******************************************************************************/
@Test
void registrationWithTokensOnKeepsTokenBroker() throws QException
{
QInstance tokensOn = AuthentikTestSupport.produce(AuthentikTestSupport.unitConfig().withApiToken(SECRET).withTokensEnabled(true));
var checks = HealthChecksMetaData.ofOrWithNew(tokensOn).resolveAll(tokensOn);
assertThat(checks).extracting(c -> c.getName()).containsExactly("authentik.api", "authentik.api_token", "authentik.mapper", "authentik.token_broker");
}
/*******************************************************************************
** Version responses are allowlisted before entering details.
*******************************************************************************/