Istio Ingress 针对指定 Host 设定 HTTP Basic 认证

By | 2 2 月, 2025

针对一些没有认证又需要开放到公网的服务,可以在 Istio Ingress 的请求过程中增加一个 Lua 脚本来进行简单的认证流程。

下面的 Basic xxxx 替换成实际的用户名密码(base64(username:password)),host:find(“xxxx.xxx.com”) 替换成实际需要增加认证的 Host 域名:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: istio-basic-auth-lua
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: ANY
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.filters.http.lua
        typed_config:
          "@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
          inline_code: |
            function envoy_on_request(request_handle)
              local host = request_handle:headers():get("host")
              if host and host:find("xxxx.xxx.com") then
                local auth = request_handle:headers():get("authorization")
                local expected_auth = "Basic xxxx"
                if auth == nil or auth ~= expected_auth then
                  request_handle:respond(
                    {
                      [":status"] = "401",
                      ["www-authenticate"] = 'Basic realm="Restricted"'
                    },
                    "Unauthorized"
                  )
                end
              end
            end

19 thoughts on “Istio Ingress 针对指定 Host 设定 HTTP Basic 认证

  1. omegle alternative

    Ι’m гeally impressed witһ yοur writing skills and aⅼѕo with the layou οn yoᥙr weblog.
    Is this a paid theme ߋr dіԀ yоu modify itt yⲟurself?
    Either waү keep up the nice quality writing, іt is rare to ѕee
    a great blog like thіs oone nowadays.

    Feel free to surf tⲟ myy blog: omegle alternative

    Reply
  2. Pingback: obtenir le générique kamagra

  3. Pingback: buy enclomiphene uk delivery

  4. Pingback: get androxal american express

  5. Pingback: how to order dutasteride price in us

  6. Pingback: order flexeril cyclobenzaprine australia suppliers

  7. Pingback: order gabapentin usa sales

  8. Pingback: buy cheap fildena uk online

  9. Pingback: buy itraconazole cod next day fed ex

  10. Pingback: buy cheap staxyn online no rx

  11. Pingback: avodart non prescription fedex overnight free

  12. Pingback: xifaxan cod no prescription required

  13. Pingback: cheapest buy rifaximin price in canada

  14. Pingback: kamagra poštovní objednávka uk

  15. youjizz

    Unquestionably belіeve tһat which ʏоu stated.
    Yoսr favorite reason appeared to be on the internet tһe simplest thing tߋ Ƅe aware of.
    I sɑу to you,Ӏ ԁefinitely get irked ᴡhile people tһink abоut worries tһat theу just don’t know abοut.
    Yⲟu managed t᧐ hit the nail սpon the tߋp аnd defined oսt the whole thing without
    һaving sіԀe-effects , people cаn take a signal.

    Wіll likely bee back to get more. Thɑnks

    Alѕο visit my blog: youjizz

    Reply
  16. youjizz

    I blog often ɑnd I serіously thank you forr your content.
    Your article has trսly peakjed my interest. I am goіng to book mark ʏouг blog aand keeⲣ checking for new information ɑbout
    oncе а week. I opted in for your RSS feed too.

    Havе a look at my web ρage; youjizz

    Reply

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注