-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(health): fix health check url authentication (#9117)
- Loading branch information
1 parent
ddb4e1b
commit c2bc41d
Showing
10 changed files
with
101 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...mpl/src/main/java/com/datahub/authentication/authenticator/HealthStatusAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.datahub.authentication.authenticator; | ||
|
||
import com.datahub.authentication.Actor; | ||
import com.datahub.authentication.ActorType; | ||
import com.datahub.authentication.Authentication; | ||
import com.datahub.authentication.AuthenticationException; | ||
import com.datahub.authentication.AuthenticationRequest; | ||
import com.datahub.authentication.AuthenticatorContext; | ||
import com.datahub.plugins.auth.authentication.Authenticator; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static com.datahub.authentication.AuthenticationConstants.SYSTEM_CLIENT_ID_CONFIG; | ||
|
||
|
||
/** | ||
* This Authenticator is used for allowing access for unauthenticated health check endpoints | ||
* | ||
* It exists to support load balancers, liveness/readiness checks | ||
* | ||
*/ | ||
@Slf4j | ||
public class HealthStatusAuthenticator implements Authenticator { | ||
private static final Set<String> HEALTH_ENDPOINTS = Set.of( | ||
"/openapi/check/", | ||
"/openapi/up/" | ||
); | ||
private String systemClientId; | ||
|
||
@Override | ||
public void init(@Nonnull final Map<String, Object> config, @Nullable final AuthenticatorContext context) { | ||
Objects.requireNonNull(config, "Config parameter cannot be null"); | ||
this.systemClientId = Objects.requireNonNull((String) config.get(SYSTEM_CLIENT_ID_CONFIG), | ||
String.format("Missing required config %s", SYSTEM_CLIENT_ID_CONFIG)); | ||
} | ||
|
||
@Override | ||
public Authentication authenticate(@Nonnull AuthenticationRequest context) throws AuthenticationException { | ||
Objects.requireNonNull(context); | ||
if (HEALTH_ENDPOINTS.stream().anyMatch(prefix -> String.join("", context.getServletInfo(), context.getPathInfo()).startsWith(prefix))) { | ||
return new Authentication( | ||
new Actor(ActorType.USER, systemClientId), | ||
"", | ||
Collections.emptyMap() | ||
); | ||
} | ||
throw new AuthenticationException("Authorization not allowed. Non-health check endpoint."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters