amazon-cognito - Istio request.auth.claims[cognito:groups] 不工作
问题描述
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
name: "jwt-example"
namespace: istio-system
spec:
selector:
matchLabels:
istio: ingressgateway
jwtRules:
- issuer: "https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-xxxxx"
jwksUri: "https://cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-xxxxx/.well-known/jwks.json"
和
spec:
selector:
matchLabels:
istio: ingressgateway
action: ALLOW
rules:
- from:
- source:
notRequestPrincipals: ["*"]
to:
- operation:
paths: ["/api/v1/*"]
when:
- key: request.auth.claims[cognito:groups]
values: ["testing"]
/api/v1/*
如果 JWT 令牌基于testing
AWS Cognito 组,我尝试使用上面的代码片段来允许访问。不幸的是,它现在正在显示RBAC: access denied
。请让我知道我该如何解决?
解决方案
问题
使用您当前的 AuthorizationPolicy,您可以使用正确的令牌阻止每个请求403 RBAC: access denied
。
我最近对 AuthorizationPolicy 做了一些测试,值得花点时间了解它是如何工作的。
解决方案
正如我们在评论中讨论的那样,有两种方法可以实际完成这项工作。
action:ALLOW
和_requestPrincipals
spec:
selector:
matchLabels:
istio: ingressgateway
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["*"]
或action:DENY
和NotRequestPrincipals
spec:
selector:
matchLabels:
istio: ingressgateway
action: DENY
rules:
- from:
- source:
notRequestPrincipals: ["*"]
例子
在行动书中有一个来自istio的例子。
拒绝没有 JWT 令牌的请求
让我们创建一个授权策略,在没有 JWT 令牌的情况下拒绝针对 API 网关的请求:
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: app-gw-requires-jwt
namespace: istio-system
spec:
selector:
matchLabels:
app: istio-ingressgateway
action: DENY
rules:
- from:
- source:
notRequestPrincipals: ["*"]
to:
- operation:
hosts: ["apiserver.istioinaction.io"]
此策略使用属性 notRequestPrincipals 和“*”值,这意味着源匹配所有缺少请求主体属性的请求。Request Principal 属性从请求身份验证过滤器从令牌中提取并存储在过滤器元数据中的两个声明中获取其值。这两个声明是发行人和主题,格式为 iss/sub。
推荐阅读
- join - 如何在 ClickHouse 上创建类似于使用 LIKE 和 JOIN 的 MySQL 查询的查询?
- c - 将 3 个点参数传递给另一个函数
- json - 如何以编程方式向我的 json 对象添加新字段?
- mysql - MariaDB 在 Docker 容器中的持久设置
- sonarqube - 带有混合单元测试文件和源文件的 SonarQube
- python - 未定义 OMSNX 名称“_index_deprecate”
- macos-big-sur - 搜索 Google Chrome macOS 服务
- php - 正确转换 PHP 和 SQL 数据类型
- flutter - Flutter Doctor 中的 SDK 和 android studio 问题
- vue.js - Vuelidate 2 不能与 NuxtJS 2 一起正常工作