CORS error in Kong deployed with Helm chart and Terraform in AWS EKS

56 views Asked by At

I deployed Kong using Terraform and Helm chart.

The main.tf is as follows:

 resource "helm_release" "kong" {
  name       = "kong"
  repository = "https://charts.konghq.com"
  chart      = "kong"
  namespace  = "kong"
  version    = "2.33.3"
  atomic     = "false"
  lint       = "true"
  create_namespace = true
  timeout    =  120 


values = [
    <<-EOF
    manager:
      enabled: true
      type: NodePort
      http:
        enabled: true
      tls:
        enabled: false
      ingress:
        enabled: true
        hostname: devapi.example.com
        path: /*
        pathType: ImplementationSpecific
        annotations:
          "kubernetes.io/ingress.class": "alb"
          "alb.ingress.kubernetes.io/scheme": "internal"
          "alb.ingress.kubernetes.io/group.name": "kong-alb-internal"
          "alb.ingress.kubernetes.io/group.order": "501"
          "alb.ingress.kubernetes.io/listen-ports": "[{\"HTTPS\":443}, {\"HTTP\":80}]"
          "alb.ingress.kubernetes.io/ssl-redirect": "443"
          "alb.ingress.kubernetes.io/certificate-arn": "arn:*******"
    admin:
      enabled: true
      type: NodePort
      http:
        enabled: true
      tls:
        enabled: false
      ingress:
        enabled: true
        tls: true
        hostname: adminapi.example.com
        path: /
        pathType: ImplementationSpecific
        annotations:
          "kubernetes.io/ingress.class": "alb"
          "alb.ingress.kubernetes.io/scheme": "internal"
          "alb.ingress.kubernetes.io/group.name": "kong-alb-internal"
          "alb.ingress.kubernetes.io/group.order": "502"
          "alb.ingress.kubernetes.io/listen-ports": "[{\"HTTPS\":443}, {\"HTTP\":80}]"
          "alb.ingress.kubernetes.io/ssl-redirect": "443"
          "alb.ingress.kubernetes.io/certificate-arn": "arn:*********"
    plugins:
      configMaps:
      - pluginName: "cors"
        name: "kong-cors-plugin"
    EOF  
  ]
}
resource "kubernetes_config_map" "kong_cors_plugin" {
  metadata {
    name      = "kong-cors-plugin"
    namespace = "kong"
  }

  data = {
    "_config" = <<-EOT
    { 
      "origins": ["*"],
      "methods": ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
      "headers": ["Accept", "Authorization", "Content-Type"],
      "exposed_headers": ["X-Custom-Header"],
      "credentials": true,
      "max_age": 3600
    }
    EOT
  }
}

It's okay.

When I open https://devapi.example.com/services, I encounter the following CORS error:

Access to XMLHttpRequest at 'https://adminapi.example.com/services?sort_desc=1&size=30' from origin 'https://devapi.example.com' has been blocked by CORS policy: No 'Access- Control-Allow-Origin' header is present on the requested resource.

I also added the CORS plugin, but it did not work.

0

There are 0 answers