forked from knative-extensions/eventing-kafka-broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not build OIDC config unless enabled (knative-extensions#4021)
* fix: do not build OIDC config unless enabled Signed-off-by: Calum Murray <[email protected]> * feat: receiver redeploys verticles when oidc feature changes Signed-off-by: Calum Murray <[email protected]> * feat: the control plane ensures receiver restarts When config-features changes, the control plane sets a annotation on the receiver pods so that the configmap update is reconciled by k8s Signed-off-by: Calum Murray <[email protected]> * mvn spotless:apply Signed-off-by: Calum Murray <[email protected]> * cleanup: goimports Signed-off-by: Calum Murray <[email protected]> * fix: do not re-deploy verticles Signed-off-by: Calum Murray <[email protected]> * fix: features config paths are now correct Signed-off-by: Calum Murray <[email protected]> * fix java unit tests Signed-off-by: Calum Murray <[email protected]> * mvn spotless:apply Signed-off-by: Calum Murray <[email protected]> * address review comments Signed-off-by: Calum Murray <[email protected]> --------- Signed-off-by: Calum Murray <[email protected]>
- Loading branch information
Showing
19 changed files
with
208 additions
and
79 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
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
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
107 changes: 107 additions & 0 deletions
107
...rc/main/java/dev/knative/eventing/kafka/broker/core/oidc/OIDCDiscoveryConfigListener.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,107 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.knative.eventing.kafka.broker.core.oidc; | ||
|
||
import dev.knative.eventing.kafka.broker.core.features.FeaturesConfig; | ||
import dev.knative.eventing.kafka.broker.core.file.FileWatcher; | ||
import io.vertx.core.Vertx; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.function.Consumer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class OIDCDiscoveryConfigListener implements AutoCloseable { | ||
private static final Logger logger = LoggerFactory.getLogger(OIDCDiscoveryConfigListener.class); | ||
private final String featuresConfigPath; | ||
private final Vertx vertx; | ||
private final FileWatcher configFeaturesWatcher; | ||
private final int timeoutSeconds; | ||
private List<Consumer<OIDCDiscoveryConfig>> callbacks; | ||
private OIDCDiscoveryConfig oidcDiscoveryConfig; | ||
|
||
public OIDCDiscoveryConfigListener(String featuresConfigPath, Vertx vertx, int timeoutSeconds) throws IOException { | ||
this.featuresConfigPath = featuresConfigPath; | ||
this.vertx = vertx; | ||
this.timeoutSeconds = timeoutSeconds; | ||
|
||
this.buildFeaturesAndOIDCDiscoveryConfig(); | ||
|
||
this.configFeaturesWatcher = | ||
new FileWatcher(new File(featuresConfigPath + "/" + FeaturesConfig.KEY_AUTHENTICATION_OIDC), () -> { | ||
if (this.oidcDiscoveryConfig == null) { | ||
this.buildFeaturesAndOIDCDiscoveryConfig(); | ||
if (this.oidcDiscoveryConfig != null && this.callbacks != null) { | ||
this.callbacks.stream() | ||
.filter(Objects::nonNull) | ||
.forEach(c -> c.accept(this.oidcDiscoveryConfig)); | ||
} | ||
} | ||
}); | ||
|
||
this.configFeaturesWatcher.start(); | ||
} | ||
|
||
public OIDCDiscoveryConfig getOidcDiscoveryConfig() { | ||
return oidcDiscoveryConfig; | ||
} | ||
|
||
public int registerCallback(Consumer<OIDCDiscoveryConfig> callback) { | ||
if (this.callbacks == null) { | ||
this.callbacks = new ArrayList<>(); | ||
} | ||
|
||
this.callbacks.add(callback); | ||
return this.callbacks.size() - 1; | ||
} | ||
|
||
public void deregisterCallback(int callbackId) { | ||
this.callbacks.set(callbackId, null); | ||
} | ||
|
||
private void buildOIDCDiscoveryConfig() throws ExecutionException, InterruptedException, TimeoutException { | ||
this.oidcDiscoveryConfig = OIDCDiscoveryConfig.build(this.vertx) | ||
.toCompletionStage() | ||
.toCompletableFuture() | ||
.get(this.timeoutSeconds, TimeUnit.SECONDS); | ||
} | ||
|
||
private void buildFeaturesAndOIDCDiscoveryConfig() { | ||
try { | ||
FeaturesConfig featuresConfig = new FeaturesConfig(featuresConfigPath); | ||
if (featuresConfig.isAuthenticationOIDC()) { | ||
try { | ||
this.buildOIDCDiscoveryConfig(); | ||
} catch (ExecutionException | InterruptedException | TimeoutException e) { | ||
logger.error("Unable to build OIDC Discover Config even though OIDC authentication is enabled", e); | ||
} | ||
} | ||
} catch (IOException e) { | ||
logger.warn("failed to get feature config, skipping building OIDC Discovery Config", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
this.configFeaturesWatcher.close(); | ||
} | ||
} |
Oops, something went wrong.