为需要基本认证的容器配置istio。

问题描述 投票:1回答:1

我有一个容器,它运行着一个需要基本认证的httprest服务,我已经配置了istio来为这个容器提供服务请求,这个服务在没有istio的集群上运行正常。

当用curl查询该服务时,istio-envoy返回状态401和消息 "访问该资源需要完全认证"。

我可以通过登录到容器和查询localhost得到同样的错误,但没有提供任何认证细节。因此,从所有的表象来看,似乎istio没有转发基本的认证头。

容器的日志从来没有承认登录的尝试,我只看到一个401日志消息在envoy容器。

我尝试了启用和禁用mtls.网关在端口443上监听,并转发到端口80的服务。

我如何配置 istio 来转发基本的 auth 到我的容器?

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: mfm-gateway
  namespace: mfm-istio
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 443
      name: https
      protocol: HTTPS
    hosts:
      - dev-mfm-istio.testing.co.uk
    tls:
      mode: SIMPLE
      serverCertificate: /etc/istio/testing-co-uk-certs/tls.crt
      privateKey: /etc/istio/testing-co-uk-certs/tls.key
      caCertificates: /etc/istio/testing-co-uk-certs/ca.crt
      httpsRedirect: true
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: mfm-virtualservice
  namespace: mfm-istio
spec:
  hosts:
  - "dev-mfm-istio.testing.co.uk"
  gateways:
  - mfm-istio/mfm-gateway
  http:
  - name: "Auth"
    match:
    -  uri:
         prefix: "/auth"
    route:
    - destination:
        host: authentication-service.mfm-istio.svc.cluster.local
        port:
          number: 80
  - name: "Base"
    route:
    - destination:
        host: web-application-service.mfm-istio.svc.cluster.local
        port:
          number: 80
localhost: curl -ik https://dev-mfm-istio.testing.co.uk/auth/oauth/token -d username=admin -d password=lolpassword -d grant_type=password -d scope=a -H -u admin

HTTP/2 401 
pragma: no-cache
www-authenticate: Bearer realm="authentication-service", error="unauthorized", error_description="Full authentication is required to access this resource"
cache-control: no-store
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-frame-options: DENY
content-type: application/json;charset=UTF-8
date: Fri, 17 Apr 2020 13:51:43 GMT
x-envoy-upstream-service-time: 4
server: istio-envoy

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
istio
1个回答
0
投票

AFAIK如果你的容器有一个通过spring boot实现的jwt,独立于istio,你应该在你的容器中添加 政策 中的认证方法,它定义了工作负载上可以接受哪些认证方法,如果通过了认证,哪个方法认证将设置请求的委托人。

它应该允许来自springboot的jwt在istio中进行身份验证。


关于jwt的istio策略的有用链接。


关于该错误的有用链接

{"error": "unauthorized", "error_description": "访问此资源需要完全认证"}。


要检查到底是什么原因导致了401,当使用JWT认证时,你可以按照下面的步骤来做 github问题.

© www.soinside.com 2019 - 2024. All rights reserved.