apache / apisix-ingress-controller

APISIX Ingress Controller for Kubernetes
https://apisix.apache.org/
Apache License 2.0
1.02k stars 343 forks source link

bug: key-auth custom Header does not take effect #603

Closed arabot777 closed 3 years ago

arabot777 commented 3 years ago

Issue description

When defining the ApisixRoute, the header of the Re-specified keyAuth does not take effect.

Environment

apisix-ingress-controller version: Version: 0.6.0 Git SHA: no-git-module Go Version: go1.13.8 Building OS/Arch: linux/amd64 Running OS/Arch: linux/amd64

Kubernetes cluster version: Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-12T01:09:16Z", GoVersion:"go1.15.4", Compiler:"gc", Platform:"darwin/amd64"} Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:20:00Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

Minimal test code / Steps to reproduce the issue

  1. Define ApisixConsumers
apiVersion: apisix.apache.org/v2alpha1
kind: ApisixConsumer
metadata:
  name: keyvalue
spec:
  authParameter:
    keyAuth:
      value:
        key: foo

then view it through dashboard image

  1. Define ApisixRoute, custom keyAuth's header information.
    Reference:https://github.com/apache/apisix-ingress-controller/blob/2d12c3fdd1369e9e263342d0def6473de5c0664f/samples/deploy/crd/v1beta1/ApisixRoute.yaml#L226-L230 and https://github.com/apache/apisix-ingress-controller/blob/2d12c3fdd1369e9e263342d0def6473de5c0664f/test/e2e/features/consumer.go#L240-L263
    apiVersion: apisix.apache.org/v2alpha1
    kind: ApisixRoute
    metadata:
     name: key-auth-route
    spec:
     http:
     - name: rule1
       match:
         hosts:
         - httpbin.org
         paths:
           - /ip
         exprs:
         - subject:
             scope: Header
             name: X-Foo
           op: Equal
           value: bar
       backend:
         serviceName: httpbin
         servicePort: 80
       authentication:
         enable: true
         type: keyAuth
         keyAuth:
           header: test

then view it through dashboard。 The value of Header is still the default value apikey, not a custom value test image

What's the actual result? (including assertion message & call stack if applicable)

What's the expected result?

gxthrj commented 3 years ago

I don't have enough time today, cc @tao12345666333 @tokers If you have time.

arabot777 commented 3 years ago

My problem, keyAuth requires lowercase. I should refer to K8SAPI instead of CRD resources. https://github.com/apache/apisix-ingress-controller/blob/2d12c3fdd1369e9e263342d0def6473de5c0664f/pkg/kube/apisix/apis/config/v2alpha1/types.go#L200-L203