问题描述
我的RequestAuthentication是这个
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
Metadata:
name: testing-dev-authenticator
namespace: istio-system
spec:
selector:
matchLabels:
istio: ingressgateway
jwtRules:
- issuer: "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com"
jwksUri: "https://securetoken.google.com/<project-name>"
我的授权政策是这样的
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
Metadata:
name: test-dev-authorizer-all-svc
namespace: dev
spec:
action: ALLOW
rules:
- from:
- source:
notRequestPrincipals: ["*"]
to:
- operation:
notPaths: ["/message/ping"]
我的要求是我不想让 jwt auth 检查 healthz(我的情况是 /message/ping),但我总是 上面的响应是“RBAC:访问被拒绝”
解决方法
我希望部署在“dev”命名空间中的所有 pod 都经过身份验证,除了健康检查,它的路径是 path : ["/user/ping","/message/ping"] 但我无法同时提供两者时间
我已经重现了您的问题,并且我认为它正在按照您的意愿运行。
有我的 RequestAuthentication 和 AuthorizationPolicy yaml。
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: testing-dev-authenticator
namespace: istio-system
spec:
selector:
matchLabels:
istio: ingressgateway
jwtRules:
- issuer: "testing@secure.istio.io"
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.8/security/tools/jwt/samples/jwks.json"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: require-jwt
namespace: istio-system
spec:
selector:
matchLabels:
istio: ingressgateway
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["*"]
to:
- operation:
paths: ["/productpage"]
- to:
- operation:
paths: ["/api/v1/products"]
您可以使用以下命令从 JWT 中排除路径(例如 "/api/v1/products" ),当 "/productpage" 需要 JWT 并且将拒绝所有没有令牌的请求时。
如果您想排除多个路径,那么这应该可行:
paths: ["/api/v1/products","/login"]
所以在你的情况下
paths: ["/user/ping","/message/ping"]
我已经在 bookinfo 应用程序上测试了上述配置。
有我用过的令牌
TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.8/security/tools/jwt/samples/demo.jwt -s)
测试:
api/v1/products
Without token
200
With token
200
------------------------------------------------------------------
/productpage
Without token
403
With token
200
您还提到您想在特定的命名空间中执行此操作,那么您可以尝试使用这些 RequestAuthentication 和 AuthorizationPolicy yaml。
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: testing-dev-authenticator
namespace: dev
spec:
jwtRules:
- issuer: "testing@secure.istio.io"
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.8/security/tools/jwt/samples/jwks.json"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: test-dev-only-authorized-api
namespace: dev
spec:
action: DENY
rules:
- from:
- source:
notRequestPrincipals: ["*"]
to:
- operation:
paths: ["/productpage"]
同样基于 bookinfo 应用程序。
测试:
api/v1/products
Without token
200
With token
200
------------------------------------------------------------------
/productpage
Without token
403
With token
200
其他资源: