我已经实施了一个istio策略,以便用户需要JWT令牌才能访问我的后端和管理后端服务。但是,这并不能阻止我使用有效的令牌。我在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
)
答案 0 :(得分:1)
几天前我发现了这个问题,却忘记了发布答案。我需要从配置中删除MTL。
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