我已经实现了一个istio策略,以便用户需要一个JWT令牌来访问我的后端和admin-backend服务。但是,它并没有让我通过有效的令牌。我在minikube上运行istio-demo并且没有对我的部署做任何事情,但是为auth0配置了一个出口。然后当我开始应用我的策略时,我无法再根据我的请求访问这些服务。
RBAC的policy.yaml
apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
name: rbac
namespace: default
spec:
targets:
- name: backend
- name: admin-backend
peers:
- mtls: {}
origins:
- jwt:
issuer: "https://jor2.eu.auth0.com/"
jwksUri: "https://jor2.eu.auth0.com/.well-known/jwks.json"
principalBinding: USE_ORIGIN
这是我的get和post请求头中传递的内容(HEADERS的值):
{
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VVkdPREl4UVRoQlFrWTJOakV4UWpnek1FSkVNalZCUVRjM1FUaEJOVFk0UVRZM016aEVNQSJ9.eyJpc3MiOiJodHRwczovL2pvcjIuZXUuYXV0aDAuY29tLyIsInN1YiI6IlRsdmg5OFl4Wkc2anFpNmRVclhlN2RIejVwZzFiaHR1QGNsaWVudHMiLCJhdWQiOiJodHRwczovL3JiYS5jb20vYWRtaW4iLCJpYXQiOjE1NTI1NTU0NjUsImV4cCI6MTU1MjY0MTg2NSwiYXpwIjoiVGx2aDk4WXhaRzZqcWk2ZFVyWGU3ZEh6NXBnMWJodHUiLCJzY29wZSI6IkFkbWluIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.grrHHrS_Ey63Tmo1KL9gUmelouYaSj0rPlv04tpJxBeVct-KRA30I1ieVgncmojRBXcdgvfpWKjeGLbb2Q7X6QwkdT0LyO3jmOBgabcTIsnnbCEg4gywc7WrN5_H_bWNiToIsouagJqiAOQ35wrVa9SVK_InR0QVEnV3yvuug042yMiMmFriG6qN2J8HPgXCE440hpSXBIIKuoBqmNZGSjZV3YvQXaLmigCNl2_PUXb52urrQqHEh06dMIT2FFfD5Cdc1RGrRT2o4krMWF2mJMOWXK1sgEOv4FfsOrdkPka24MuGViED514EoJ9a2n2QEK10zxDtv42opYT9Wjmubg"
}
函数与正确的标题(应该工作),但不显示任何响应。
@app.route("/view_patients/", methods=['GET', 'POST'])
def view_patients():
global HEADERS
patients = invoke_backend(page_name="view_patients", headers=HEADERS)
return render_template(
'view_patients.html',
patients=patients
)
测试以确保令牌在无效的jwt上失败:
@app.route("/test/view_patients/", methods=['GET', 'POST'])
def test_view_patients_invalid_jwt():
jwt = "1nv4l1DJwT"
header = {
'Authorization': "Bearer " + jwt
}
patients = invoke_backend(page_name="view_patients", headers=header)
return render_template(
'view_patients.html',
patients=patients
)
几天前我想出来了,忘记发布答案了。我需要从配置中删除mtls。
apiVersion: authentication.istio.io/v1alpha1
kind: Policy
metadata:
name: auth-policy
spec:
targets:
- name: backend
- name: admin-backend
origins:
- jwt:
issuer: "https://jor2.eu.auth0.com/"
jwksUri: "https://jor2.eu.auth0.com/.well-known/jwks.json"
principalBinding: USE_ORIGIN