istio JWT authentication for single service behind ingress gateway

Blink

I have 2 services running on AKS (v1.16.13) and deployed the following istio (v1.7.3) configuration. First one is a UI where I invoke the OIDC flow and get JWT token, second one is a backend service which should require a valid JWT token.

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: myapp-gateway
  namespace: "istio-system"
spec:
  selector:
    istio: ingressgateway
  servers:
  - hosts:
    - myapp.com
    port:
      name: http-myapp
      number: 80
      protocol: HTTP
    tls:
      httpsRedirect: true
  - hosts:
    - myapp.com
    port:
      name: https-myapp
      number: 443
      protocol: HTTPS
    tls:
      credentialName: myapp-credential
      mode: SIMPLE
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: myapp
  namespace: myapp
spec:
  gateways:
  - istio-system/myapp-gateway
  hosts:
  - myapp.com
  http:
  - match:
    - uri:
        prefix: /ui
    route:
    - destination:
        host: myapp-ui.myapp.svc.cluster.local
        port:
          number: 4200
  - match:
    - uri:
        prefix: /backend/
    rewrite:
      uri: /
    route:
    - destination:
        host: myapp-service-backend.myapp.svc.cluster.local
        port:
          number: 8080
---
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
  name: myapp-jwt-backend
  namespace: myapp
spec:
  jwtRules:
  - issuer: https://oktapreview.com
  selector:
    matchLabels:
      app: myapp-service-backend

With that config I would expect to get 401 if I invoke myapp.com/backend but that's not the case. Request authentication doesn't kick in.

After some further research (https://discuss.istio.io/t/cannot-use-jwt-policy-with-an-externalname-virtualservice-target/2794/3), I found out that I can't apply RequestAuthentication on a VirtualService but only on a Gateway which is quite odd to me but ok. I've changed the RequestAuthentication to the following but still nothing has changed after invoking backend:

apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
  name: myapp-jwt-backend
  namespace: istio-system
spec:
  jwtRules:
  - issuer: https://oktapreview.com
  selector:
    matchLabels:
      istio: myapp-gateway

Do you have any idea how can I setup istio for my use case? Assuming the RequestAuthentication would work on a gateway, do I need 2 gateway? 1 for UI and the second for backend? Seems like an overkill.

Blink

Thanks to the sachin's comment and going again through the documentation made me realized that I need AuthorizationPolicy on top of RequestAuthentication:

apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:    
  name: myapp-require-jwt-backend
spec:
  action: ALLOW
  rules:
  - from:
    - source:
        requestPrincipals:
        - https://xxx/*
  selector:
    matchLabels:
      app: myapp-service-backend

The request authentication is only making sure that when a JWT token is provided, it has to be a valid one. If there is no token, it will just pass through the request.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Trouble setting up secure connection for ingress behind ingress - bad gateway

分類Dev

Istio Ingress Gateway using SDS failing due to credential Name

分類Dev

istioのingress-gatewayでSSLを終了する方法は?

分類Dev

Istio Ingress Regex Negation

分類Dev

Is it possible to have SAML 2.0 Authentication and JWT Authentication in a single Application?

分類Dev

Istio: End user Authentication

分類Dev

Istio on Azure Governors Service?

分類Dev

Istio on Azure Container Service (AKS)

分類Dev

JWT Angular Authentication on Refresh

分類Dev

ユーザー向けサービスのIstioリクエストルーティングがingress-gatewayで機能しない

分類Dev

Kubernetes Ingressの502 Bad Gateway

分類Dev

Express Gateway jwt return Unauthorized

分類Dev

AWS API Gateway with external authentication

分類Dev

JWT Authentication in Angular - Multiple authentication levels

分類Dev

HTTPClient and JWT Authentication in C#

分類Dev

JWT Authentication fails in Hyperledger Composer

分類Dev

React-Redux authentication with JWT

分類Dev

Grafana, Prometheus, Kiali authentication with AzureAD and istio internal load balancer

分類Dev

API Gateway authentication with Cognito Federated Identities

分類Dev

Spring Integration outbound-gateway with basic authentication

分類Dev

Authentication credentials were not provided with djangorestframework-jwt

分類Dev

How to add JWT token authentication to protect routes

分類Dev

Is Basic Authentication a Session based authentication and why Jwt is more recommended?

分類Dev

Is there a way to proxy calls to an ExternalName service thanks to an Istio VirtualService?

分類Dev

istio exclut le service de ext-auth

分類Dev

Azure Kubernetes - Jaeger UI is not showing the Service deployed as a part of ISTIO?

分類Dev

How to host multiple applications in one Istio service mesh?

分類Dev

Install Jenkins as a Service or Run it behind Apatche

分類Dev

github service hook and basic authentication

Related 関連記事

  1. 1

    Trouble setting up secure connection for ingress behind ingress - bad gateway

  2. 2

    Istio Ingress Gateway using SDS failing due to credential Name

  3. 3

    istioのingress-gatewayでSSLを終了する方法は?

  4. 4

    Istio Ingress Regex Negation

  5. 5

    Is it possible to have SAML 2.0 Authentication and JWT Authentication in a single Application?

  6. 6

    Istio: End user Authentication

  7. 7

    Istio on Azure Governors Service?

  8. 8

    Istio on Azure Container Service (AKS)

  9. 9

    JWT Angular Authentication on Refresh

  10. 10

    ユーザー向けサービスのIstioリクエストルーティングがingress-gatewayで機能しない

  11. 11

    Kubernetes Ingressの502 Bad Gateway

  12. 12

    Express Gateway jwt return Unauthorized

  13. 13

    AWS API Gateway with external authentication

  14. 14

    JWT Authentication in Angular - Multiple authentication levels

  15. 15

    HTTPClient and JWT Authentication in C#

  16. 16

    JWT Authentication fails in Hyperledger Composer

  17. 17

    React-Redux authentication with JWT

  18. 18

    Grafana, Prometheus, Kiali authentication with AzureAD and istio internal load balancer

  19. 19

    API Gateway authentication with Cognito Federated Identities

  20. 20

    Spring Integration outbound-gateway with basic authentication

  21. 21

    Authentication credentials were not provided with djangorestframework-jwt

  22. 22

    How to add JWT token authentication to protect routes

  23. 23

    Is Basic Authentication a Session based authentication and why Jwt is more recommended?

  24. 24

    Is there a way to proxy calls to an ExternalName service thanks to an Istio VirtualService?

  25. 25

    istio exclut le service de ext-auth

  26. 26

    Azure Kubernetes - Jaeger UI is not showing the Service deployed as a part of ISTIO?

  27. 27

    How to host multiple applications in one Istio service mesh?

  28. 28

    Install Jenkins as a Service or Run it behind Apatche

  29. 29

    github service hook and basic authentication

ホットタグ

アーカイブ