-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARTEMIS-5219] load all certificates
In the JAAS login module for Kubernetes, the current implementation is loading only a single CA from the bundle that is given by OpenShift, which in turn leads to an issue where the broker don't find a proper PKIX path. This is fixing the issue by loading every certificates from the bundle. The commit also brings in a new command line that can be used to test if pod is well configured to perform token reviews or not.
- Loading branch information
Showing
4 changed files
with
152 additions
and
3 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
94 changes: 94 additions & 0 deletions
94
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/TokenReview.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.activemq.artemis.cli.commands; | ||
|
||
import org.apache.activemq.artemis.spi.core.security.jaas.kubernetes.client.KubernetesClient; | ||
import org.apache.activemq.artemis.spi.core.security.jaas.kubernetes.client.KubernetesClientImpl; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "token-review", description = "Perform a kubernetes token review") | ||
public class TokenReview extends InputAbstract { | ||
|
||
@CommandLine.Option(names = "--kube-host", description = "hostname for kubernetes api server") | ||
protected String kubeHost; | ||
|
||
@CommandLine.Option(names = "--kube-port", description = "port for kubernetes api server") | ||
protected String kubeport; | ||
|
||
@CommandLine.Option(names = "--token-path", description = "path to the token to access the kubernetes api server with access to token reviews") | ||
protected String tokenpath; | ||
|
||
@CommandLine.Option(names = "--ca-path", description = "path to the kubernetes api server trusted CAs") | ||
protected String capath; | ||
|
||
@CommandLine.Option(names = "--token", description = "token to review") | ||
protected String token; | ||
|
||
@Override | ||
public Object execute(ActionContext context) throws Exception { | ||
super.execute(context); | ||
|
||
context.out.println(); | ||
if (kubeHost == null) { | ||
kubeHost = input("--kube-host", "What is the cluster host?", "api.crc.testing"); | ||
} | ||
if (kubeport == null) { | ||
kubeport = input("--kube-port", "What is the cluster port?", "6443"); | ||
} | ||
if (tokenpath == null) { | ||
tokenpath = input("--token-path", "What is the token path?", "/var/run/secrets/kubernetes.io/serviceaccount/token"); | ||
} | ||
if (capath == null) { | ||
capath = input("--ca-path", "What is the ca path?", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"); | ||
} | ||
if (token == null) { | ||
token = input("--token", "What is the token?", "sha256~Cg_LIHObUgJHvF_Ziv9k9eHZQ3_UUNihRD9vA96hQKU"); | ||
} | ||
String prevKSH = System.getProperty("KUBERNETES_SERVICE_HOST", kubeHost); | ||
String prevKSP = System.getProperty("KUBERNETES_SERVICE_PORT", kubeport); | ||
String prevTP = System.getProperty("KUBERNETES_TOKEN_PATH", tokenpath); | ||
String prevCP = System.getProperty("KUBERNETES_CA_PATH", capath); | ||
System.setProperty("KUBERNETES_SERVICE_HOST", kubeHost); | ||
System.setProperty("KUBERNETES_SERVICE_PORT", kubeport); | ||
System.setProperty("KUBERNETES_TOKEN_PATH", tokenpath); | ||
System.setProperty("KUBERNETES_CA_PATH", capath); | ||
try { | ||
KubernetesClient client = new KubernetesClientImpl(); | ||
org.apache.activemq.artemis.spi.core.security.jaas.kubernetes.model.TokenReview tr = client.getTokenReview(token); | ||
context.out.println("*******************************************************************************************************************************"); | ||
context.out.println("* Performing a token review on:"); | ||
context.out.println("* host:: " + kubeHost); | ||
context.out.println("* port:: " + kubeport); | ||
context.out.println("* tokenpath:: " + tokenpath); | ||
context.out.println("* capath:: " + capath); | ||
context.out.println("*"); | ||
context.out.println("* Result:"); | ||
context.out.println("* token:: " + token); | ||
context.out.println("* username:: " + tr.getUsername()); | ||
context.out.println("*******************************************************************************************************************************"); | ||
context.out.println(); | ||
} finally { | ||
System.setProperty("KUBERNETES_SERVICE_HOST", prevKSH); | ||
System.setProperty("KUBERNETES_SERVICE_PORT", prevKSP); | ||
System.setProperty("KUBERNETES_TOKEN_PATH", prevTP); | ||
System.setProperty("KUBERNETES_CA_PATH", prevCP); | ||
} | ||
|
||
return null; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/Kubernetes.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,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.activemq.artemis.cli.commands.tools; | ||
|
||
import org.apache.activemq.artemis.cli.commands.HelpAction; | ||
import org.apache.activemq.artemis.cli.commands.TokenReview; | ||
import org.apache.activemq.artemis.cli.commands.tools.journal.CompactJournal; | ||
import org.apache.activemq.artemis.cli.commands.tools.journal.DecodeJournal; | ||
import org.apache.activemq.artemis.cli.commands.tools.journal.EncodeJournal; | ||
import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter; | ||
import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
|
||
@Command(name = "kube", description = "use 'help kube' for sub commands list", subcommands = {TokenReview.class}) | ||
public class Kubernetes implements Runnable { | ||
|
||
CommandLine commandLine; | ||
|
||
public Kubernetes(CommandLine commandLine) { | ||
this.commandLine = commandLine; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
HelpAction.help(commandLine, "data"); | ||
} | ||
|
||
} |
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