Kubernetes Istio:RequestAuthentication jwksUri不解析内部服务名称 通知
其根本原因与相同,但在进一步诊断后,我将其改写为Simple(试图获得帮助) 问题 我试图在Istio网格中配置RequestAuthentication(和AuthorizationPolicy)。我的JWK令牌由内部OAUTH服务器(基于CloudFoundry)提供,该服务器可以很好地用于其他服务。 当我配置uri以获取签名密钥、链接到内部pod时,问题就出现了。此时,Istio没有解析内部pod的名称。我感到困惑,因为微服务能够连接到我所有的内部POD(mongodb、mysql、rabbitmq),包括uaa。为什么RequestAuthentication不能做同样的事情 UAA服务配置(注意:我还创建了一个用于外部访问的虚拟服务,现在运行良好) RequestAuthentication:注意参数jwksUri,查找Kubernetes Istio:RequestAuthentication jwksUri不解析内部服务名称 通知,kubernetes,istio,kubernetes-pod,kubernetes-dns,istio-gateway,Kubernetes,Istio,Kubernetes Pod,Kubernetes Dns,Istio Gateway,其根本原因与相同,但在进一步诊断后,我将其改写为Simple(试图获得帮助) 问题 我试图在Istio网格中配置RequestAuthentication(和AuthorizationPolicy)。我的JWK令牌由内部OAUTH服务器(基于CloudFoundry)提供,该服务器可以很好地用于其他服务。 当我配置uri以获取签名密钥、链接到内部pod时,问题就出现了。此时,Istio没有解析内部pod的名称。我感到困惑,因为微服务能够连接到我所有的内部POD(mongodb、mysql、rab
uaa
hostname
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
name: "ra-product-composite"
spec:
selector:
matchLabels:
app: "product-composite"
jwtRules:
- issuer: "http://uaa:8090/uaa/oauth/token"
jwksUri: "http://uaa:8090/uaa/token_keys"
forwardOriginalToken: true
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: "ap-product-composite"
spec:
selector:
matchLabels:
app: "product-composite"
action: ALLOW
rules:
- to:
- operation:
methods: ["GET","POST","DELETE","HEAD","PUT"]
paths: ["*"]
错误日志(在istiod pod中)
变通办法
目前,我已将OAUTH服务器声明为外部服务器,并重定向了请求,但这是完全低效的
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: se-auth
spec:
hosts:
- "host.docker.internal"
ports:
- number: 8090
name: http
protocol: HTTP
resolution: DNS
location: MESH_EXTERNAL
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-auth
spec:
hosts:
- "kubernetes.example.com"
gateways:
- gw-ingress
http:
- match:
- uri:
prefix: /oauth
rewrite:
uri: "/uaa/oauth"
route:
- destination:
port:
number: 8090
host: "host.docker.internal"
- match:
- uri:
prefix: /uaa
rewrite:
uri: "/uaa"
route:
- destination:
port:
number: 8090
host: "host.docker.internal"
---
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
name: "ra-product-composite"
spec:
selector:
matchLabels:
app: "product-composite"
jwtRules:
- issuer: "http://uaa:8090/uaa/oauth/token"
jwksUri: "http://host.docker.internal:8090/uaa/token_keys"
forwardOriginalToken: true
解决方法2:
我已经在主机名中使用FQDN(完全限定名)解决了这个问题。但这并不能解决我的问题,因为将配置文件链接到名称空间(我使用多个名称空间,只需要一个配置文件)
在任何情况下,我当前的行是:
jwksUri: "http://uaa.mynamespace.svc.cluster.local:8090/uaa/token_keys"
我完全确定这是一个愚蠢的配置参数,但我找不到它!提前感谢jwksUri:“http://uaa:8090/uaa/token_keys“
将无法从istiod工作,因为http://uaa
将被解释为http://uaa.istio-system.svc.cluster.local
。这就是为什么你的变通方法解决了这个问题
我不明白为什么您的变通方法2不是一个充分的解决方案。假设您的uaa服务在命名空间
auth
中运行。如果您使用uaa.auth.svc.cluster.local
配置jwksUri
,每个kubernetes吊舱都可以调用它,而不管它的名称空间是什么。谢谢!我将重新考虑每个名称空间使用OAUTH。而且,我不明白为什么,如果RequestAuthentication部署在我的名称空间中,它将使用istio名称空间来解析dns。这就是dns在k8s中的工作方式uaa
、uaa.auth
、uaa.auth.svc
和uaa.auth.svc.cluster.local
是调用uaa服务的等效dns记录。但是uaa
将仅在调用方位于auth
命名空间中时解析。如果您呼叫http://uaa
k8s使用调用方名称空间将其解释为uaa..svc.cluster.local
。因此,对于istiod
将使用istio名称空间。这就是为什么我们应该始终使用完整的fqdn,即.svc.cluster.local
在这里阅读更多关于它的内容,再次感谢Christoph。诀窍在于“使用调用者名称空间”。我假设它将使用创建RequestAuthentication资源的名称空间。
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: se-auth
spec:
hosts:
- "host.docker.internal"
ports:
- number: 8090
name: http
protocol: HTTP
resolution: DNS
location: MESH_EXTERNAL
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-auth
spec:
hosts:
- "kubernetes.example.com"
gateways:
- gw-ingress
http:
- match:
- uri:
prefix: /oauth
rewrite:
uri: "/uaa/oauth"
route:
- destination:
port:
number: 8090
host: "host.docker.internal"
- match:
- uri:
prefix: /uaa
rewrite:
uri: "/uaa"
route:
- destination:
port:
number: 8090
host: "host.docker.internal"
---
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
name: "ra-product-composite"
spec:
selector:
matchLabels:
app: "product-composite"
jwtRules:
- issuer: "http://uaa:8090/uaa/oauth/token"
jwksUri: "http://host.docker.internal:8090/uaa/token_keys"
forwardOriginalToken: true
jwksUri: "http://uaa.mynamespace.svc.cluster.local:8090/uaa/token_keys"