Add canary service to GKE (#2594)

This commit is contained in:
Lai Jiang
2024-10-22 17:12:00 +00:00
committed by GitHub
parent 4d96e5a6b1
commit a9ba770bfa
20 changed files with 368 additions and 49 deletions
@@ -151,12 +151,14 @@ public final class EppProtocolModule {
static EppServiceHandler provideEppServiceHandler(
@Named("idToken") Supplier<String> idTokenSupplier,
@Named("hello") byte[] helloBytes,
@Named("canary") boolean canary,
FrontendMetrics metrics,
ProxyConfig config,
@HttpsRelayProtocol boolean localRelay) {
return new EppServiceHandler(
localRelay ? "localhost" : config.epp.relayHost,
config.epp.relayPath,
canary,
idTokenSupplier,
helloBytes,
metrics);
@@ -41,6 +41,7 @@ public class ProxyConfig {
public String projectId;
public String oauthClientId;
public boolean canary;
public List<String> gcpScopes;
public int serverCertificateCacheSeconds;
public Gcs gcs;
@@ -278,6 +278,13 @@ public class ProxyModule {
() -> OidcTokenUtils.createOidcToken(credentialsBundle, clientId), 1, TimeUnit.HOURS);
}
@Singleton
@Provides
@Named("canary")
static boolean provideIsCanary(ProxyConfig config) {
return config.canary;
}
@Singleton
@Provides
static CloudKMS provideCloudKms(GoogleCredentialsBundle credentialsBundle, ProxyConfig config) {
@@ -96,11 +96,13 @@ public final class WhoisProtocolModule {
static WhoisServiceHandler provideWhoisServiceHandler(
ProxyConfig config,
@Named("idToken") Supplier<String> idTokenSupplier,
@Named("canary") boolean canary,
FrontendMetrics metrics,
@HttpsRelayProtocol boolean localRelay) {
return new WhoisServiceHandler(
localRelay ? "localhost" : config.whois.relayHost,
config.whois.relayPath,
canary,
idTokenSupplier,
metrics);
}
@@ -8,6 +8,9 @@
# GCP project ID
projectId: your-gcp-project-id
# Whether to connect to the canary (instead of regular) service.
canary: false
# OAuth client ID set as the audience of the OIDC token. This value must be the
# same as the auth.oauthClientId value in Nomulus config file, which usually is
# the IAP client ID, to allow the request to access IAP protected endpoints.
@@ -60,10 +60,11 @@ public class EppServiceHandler extends HttpsRelayServiceHandler {
public EppServiceHandler(
String relayHost,
String relayPath,
boolean canary,
Supplier<String> idTokenSupplier,
byte[] helloBytes,
FrontendMetrics metrics) {
super(relayHost, relayPath, idTokenSupplier, metrics);
super(relayHost, relayPath, canary, idTokenSupplier, metrics);
this.helloBytes = helloBytes.clone();
}
@@ -62,6 +62,7 @@ import javax.net.ssl.SSLHandshakeException;
public abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpResponse> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String CANARY_HEADER = "canary";
protected static final ImmutableSet<Class<? extends Exception>> NON_FATAL_INBOUND_EXCEPTIONS =
ImmutableSet.of(ReadTimeoutException.class, SSLHandshakeException.class);
@@ -72,6 +73,7 @@ public abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHt
private final Map<String, Cookie> cookieStore = new LinkedHashMap<>();
private final String relayHost;
private final String relayPath;
private final boolean canary;
private final Supplier<String> idTokenSupplier;
protected final FrontendMetrics metrics;
@@ -79,10 +81,12 @@ public abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHt
HttpsRelayServiceHandler(
String relayHost,
String relayPath,
boolean canary,
Supplier<String> idTokenSupplier,
FrontendMetrics metrics) {
this.relayHost = relayHost;
this.relayPath = relayPath;
this.canary = canary;
this.idTokenSupplier = idTokenSupplier;
this.metrics = metrics;
}
@@ -104,6 +108,9 @@ public abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHt
.set(HttpHeaderNames.HOST, relayHost)
.set(HttpHeaderNames.AUTHORIZATION, "Bearer " + idTokenSupplier.get())
.setInt(HttpHeaderNames.CONTENT_LENGTH, byteBuf.readableBytes());
if (canary) {
request.headers().set(CANARY_HEADER, "true");
}
request.content().writeBytes(byteBuf);
return request;
}
@@ -33,9 +33,10 @@ public final class WhoisServiceHandler extends HttpsRelayServiceHandler {
public WhoisServiceHandler(
String relayHost,
String relayPath,
boolean canary,
Supplier<String> idTokenSupplier,
FrontendMetrics metrics) {
super(relayHost, relayPath, idTokenSupplier, metrics);
super(relayHost, relayPath, canary, idTokenSupplier, metrics);
}
@Override