首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Kubernetes Openshift客户端认证

Kubernetes Openshift客户端认证
EN

Stack Overflow用户
提问于 2018-12-16 15:27:45
回答 1查看 738关注 0票数 2

我正在使用openshift 3.9,并尝试在我的命名空间中列出fabirc8 Kubernetes-client ( https://github.com/fabric8io/kubernetes-client )中的所有Pods。我使用的是Java8和openshift客户端的版本

代码语言:javascript
运行
复制
 <dependency>
        <groupId>io.fabric8</groupId>
        <artifactId>openshift-client</artifactId>
        <version>4.1.0</version>
    </dependency>

在吊舱内部,我可以使用bash获得一张荚的列表。

代码语言:javascript
运行
复制
# using TLS connection with crt file defined
curl --cacert $CERT \
  -H "Authorization: Bearer $TOKEN" \
   https://$ENDPOINT/api/v1/namespaces/$NAMESPACE/pods

这意味着我的服务帐户有权在名称空间中列出豆荚。

使用java,我无法授权jet。

代码语言:javascript
运行
复制
 try (OpenShiftClient client = new DefaultOpenShiftClient()) {
        System.out.println("Client opened is: " + client.getConfiguration().getOauthToken());
        client.pods().list().getItems().stream().forEach(
                p -> System.out.println("pod: " + p));
    }

即使我使用builderConfig显式地指定了客户机,错误也如下所示:

线程"OkHttp Dispatcher“中对授权请求的意外响应(401未经授权)中的异常。丢失标题:位置!在io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor.authorize(OpenShiftOAuthInterceptor.java:128) at io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor.intercept(OpenShiftOAuthInterceptor.java:63) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java。util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

问题似乎是这个类:https://github.com/fabric8io/kubernetes-client/blob/master/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java

在第132行中,没有设置令牌的位置,因此无法找到令牌。我一个人解决不了这个问题。也许我必须设置标题授权:独自携带。

EN

回答 1

Stack Overflow用户

发布于 2022-09-19 16:29:30

代码语言:javascript
运行
复制
try creating client this way 
    private OpenShiftClient buildClient(String namespace) {
        logger.info("OpenShiftClient buildClient:" + openshiftConfig);
        return new DefaultOpenShiftClient(new ConfigBuilder().withMasterUrl(clusterUrl))
                .withNamespace(namespace)
                .withTrustCerts(true)
                .withDisableHostnameVerification(true)
                .withUsername(openshiftConfig.getUsername()).withPassword( Password).withTrustCerts(true).build());
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53803629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档