I have implemented an istio policy so that users will need a JWT token to access my backend, and admin-backend services. However, it is not letting me through with a valid token. I am running istio-demo on minikube and have done nothing with my deployment but configure an egress for auth0. Then when I go to apply my policy, I can no longer access these services with my requests.
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
This is what is being passed in my get and post request headers(value of HEADERS):
{
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5VVkdPREl4UVRoQlFrWTJOakV4UWpnek1FSkVNalZCUVRjM1FUaEJOVFk0UVRZM016aEVNQSJ9.eyJpc3MiOiJodHRwczovL2pvcjIuZXUuYXV0aDAuY29tLyIsInN1YiI6IlRsdmg5OFl4Wkc2anFpNmRVclhlN2RIejVwZzFiaHR1QGNsaWVudHMiLCJhdWQiOiJodHRwczovL3JiYS5jb20vYWRtaW4iLCJpYXQiOjE1NTI1NTU0NjUsImV4cCI6MTU1MjY0MTg2NSwiYXpwIjoiVGx2aDk4WXhaRzZqcWk2ZFVyWGU3ZEh6NXBnMWJodHUiLCJzY29wZSI6IkFkbWluIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.grrHHrS_Ey63Tmo1KL9gUmelouYaSj0rPlv04tpJxBeVct-KRA30I1ieVgncmojRBXcdgvfpWKjeGLbb2Q7X6QwkdT0LyO3jmOBgabcTIsnnbCEg4gywc7WrN5_H_bWNiToIsouagJqiAOQ35wrVa9SVK_InR0QVEnV3yvuug042yMiMmFriG6qN2J8HPgXCE440hpSXBIIKuoBqmNZGSjZV3YvQXaLmigCNl2_PUXb52urrQqHEh06dMIT2FFfD5Cdc1RGrRT2o4krMWF2mJMOWXK1sgEOv4FfsOrdkPka24MuGViED514EoJ9a2n2QEK10zxDtv42opYT9Wjmubg"
}
function with correct header(should work) but doesn't display any responses.
@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
)
Test to make sure token fails on invalid 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
)
I figured this out a few days ago and forgot to post the answer. I needed to remove mtls from config.
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