forked from knative-extensions/eventing-kafka-broker
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-v1.15] do not build OIDC config unless enabled (#1352)
* fix: do not build OIDC config unless enabled (knative-extensions#4021) (knative-extensions#4055) * fix: do not build OIDC config unless enabled * feat: receiver redeploys verticles when oidc feature changes * 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 * mvn spotless:apply * cleanup: goimports * fix: do not re-deploy verticles * fix: features config paths are now correct * fix java unit tests * mvn spotless:apply * address review comments --------- Signed-off-by: Calum Murray <cmurray@redhat.com> * usage of CopyOnWriteArrayList/AtomicRef Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> * using concurrent hash map and atomic integer for ids Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> --------- Signed-off-by: Calum Murray <cmurray@redhat.com> Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> Co-authored-by: Calum Murray <cmurray@redhat.com>
- Loading branch information
Showing
19 changed files
with
209 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
108 changes: 108 additions & 0 deletions
108
...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,108 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors (knative-dev@googlegroups.com) | ||
* | ||
* 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.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
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 final ConcurrentHashMap<Integer, Consumer<OIDCDiscoveryConfig>> callbacks; | ||
private final AtomicReference<OIDCDiscoveryConfig> oidcDiscoveryConfig; | ||
private final AtomicInteger callbackIdGenerator; | ||
|
||
public OIDCDiscoveryConfigListener(String featuresConfigPath, Vertx vertx, int timeoutSeconds) throws IOException { | ||
this.featuresConfigPath = featuresConfigPath; | ||
this.vertx = vertx; | ||
this.timeoutSeconds = timeoutSeconds; | ||
this.oidcDiscoveryConfig = new AtomicReference<>(); | ||
this.callbacks = new ConcurrentHashMap<>(); | ||
this.callbackIdGenerator = new AtomicInteger(0); | ||
|
||
this.buildFeaturesAndOIDCDiscoveryConfig(); | ||
|
||
this.configFeaturesWatcher = | ||
new FileWatcher(new File(featuresConfigPath + "/" + FeaturesConfig.KEY_AUTHENTICATION_OIDC), () -> { | ||
if (this.oidcDiscoveryConfig.get() == null) { | ||
this.buildFeaturesAndOIDCDiscoveryConfig(); | ||
OIDCDiscoveryConfig config = this.oidcDiscoveryConfig.get(); | ||
if (config != null) { | ||
this.callbacks.values().forEach(callback -> callback.accept(config)); | ||
} | ||
} | ||
}); | ||
|
||
this.configFeaturesWatcher.start(); | ||
} | ||
|
||
public OIDCDiscoveryConfig getOidcDiscoveryConfig() { | ||
return oidcDiscoveryConfig.get(); | ||
} | ||
|
||
public int registerCallback(Consumer<OIDCDiscoveryConfig> callback) { | ||
int id = callbackIdGenerator.incrementAndGet(); | ||
this.callbacks.put(id, callback); | ||
return id; | ||
} | ||
|
||
public void deregisterCallback(int callbackId) { | ||
this.callbacks.remove(callbackId); | ||
} | ||
|
||
private void buildOIDCDiscoveryConfig() throws ExecutionException, InterruptedException, TimeoutException { | ||
OIDCDiscoveryConfig config = OIDCDiscoveryConfig.build(this.vertx) | ||
.toCompletionStage() | ||
.toCompletableFuture() | ||
.get(this.timeoutSeconds, TimeUnit.SECONDS); | ||
this.oidcDiscoveryConfig.set(config); | ||
} | ||
|
||
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.