gemmellr commented on code in PR #5407: URL: https://github.com/apache/activemq-artemis/pull/5407#discussion_r1888718616
########## artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/TokenReview.java: ########## @@ -0,0 +1,69 @@ +/* + * 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 { + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + context.out.println(); + String kubeHost = input("--kube-host", "What is the cluster host?", "api.crc.testing"); + String kubeport = input("--kube-port", "What is the cluster port?", "6443"); + String tokenpath = input("--token-path", "What is the token path?", "/var/run/secrets/kubernetes.io/serviceaccount/token"); + String capath = input("--ca-path", "What is the ca path?", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"); + 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); + String token = input("--token", "What is the token?", "sha256~Cg_LIHObUgJHvF_Ziv9k9eHZQ3_UUNihRD9vA96hQKU"); Review Comment: Not sure I'd put in a default token ########## artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/TokenReview.java: ########## @@ -0,0 +1,69 @@ +/* + * 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 { + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + context.out.println(); + String kubeHost = input("--kube-host", "What is the cluster host?", "api.crc.testing"); + String kubeport = input("--kube-port", "What is the cluster port?", "6443"); + String tokenpath = input("--token-path", "What is the token path?", "/var/run/secrets/kubernetes.io/serviceaccount/token"); + String capath = input("--ca-path", "What is the ca path?", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"); + 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); + String token = input("--token", "What is the token?", "sha256~Cg_LIHObUgJHvF_Ziv9k9eHZQ3_UUNihRD9vA96hQKU"); + 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); + } Review Comment: I'd be inclined to do something so that specific option values could neatly be passed in rather than resorting to the 'get + set + run + reset'. E.g pass in an 'environment' map of options, kind of like the way JNDI InitialContext stuff works. If the value is specified that way, use it, otherwise pull the value the way it currently would have been. ########## artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/TokenReview.java: ########## @@ -0,0 +1,69 @@ +/* + * 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 { + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + context.out.println(); + String kubeHost = input("--kube-host", "What is the cluster host?", "api.crc.testing"); + String kubeport = input("--kube-port", "What is the cluster port?", "6443"); + String tokenpath = input("--token-path", "What is the token path?", "/var/run/secrets/kubernetes.io/serviceaccount/token"); + String capath = input("--ca-path", "What is the ca path?", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"); Review Comment: I'm not entirely convinced this should be a CLI command, but if it is... Using the Option handling would seem nicer than always requiring input. Could fall back to input for e.g the token if not specified (think some other options do that). Deferring to the the actual KubernetesClientImpl constants for defaults and key names etc (below) rather than having distinct literal ones here might also be preferable. ########## artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/kubernetes/client/KubernetesClientImpl.java: ########## @@ -160,9 +163,13 @@ private SSLContext buildSSLContext() throws Exception { try (InputStream fis = new FileInputStream(certFile)) { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(fis); + Collection c = certFactory.generateCertificates(fis); + Iterator i = c.iterator(); trustStore.load(null, null); - trustStore.setCertificateEntry(certFile.getName(), certificate); + while (i.hasNext()) { + Certificate cert = (Certificate)i.next(); Review Comment: Wouldn't need the cast if you add the missing collection type detail above. ########## artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/kubernetes/client/KubernetesClientImpl.java: ########## @@ -160,9 +163,13 @@ private SSLContext buildSSLContext() throws Exception { try (InputStream fis = new FileInputStream(certFile)) { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(fis); + Collection c = certFactory.generateCertificates(fis); Review Comment: Missing a generic type -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact