Envoy: [ASK] Envoy Cors Configuration Sample

Created on 7 Dec 2017  路  2Comments  路  Source: envoyproxy/envoy

@mattklein123 Is there any example how to set cors enabled in route config? I can't find valid example out there.

Thank you

aredocs help wanted

Most helpful comment

Just found this issue by accident.
Maybe I find the time to add an example in the near future. For now maybe this helps? I am using grpc-web here, too.
The CORS settings are set for all routes and on the /serviceB route it is specifically disabled.

listeners:
- address: tcp://0.0.0.0:443
  filters:
  - type: read
    name: http_connection_manager
    config:
      access_log:
      - path: /dev/stdout
      codec_type: auto
      stat_prefix: ingress_http
      route_config:
        virtual_hosts:
        - name: gateway
          domains:
          - "*"
          cors:
            allow_origin: ["*"]
            allow_headers: "content-type, x-grpc-web"
            allow_methods: "POST"
          routes:
          - timeout_ms: 0
            prefix: /serviceA
            cluster: serviceA
          - timeout_ms: 0
            prefix: /serviceB
            cluster: experiment
            cors:
              enabled: false
      filters:
      - type: both
        name: cors
        config: {}
     - type: both
        name: grpc_web
        config: {}
      - type: decoder
        name: router
        config: {}
admin:
  access_log_path: /dev/stdout
  address: tcp://0.0.0.0:8001
cluster_manager:
  clusters:
  - name: featureA
    features: http2
    connect_timeout_ms: 250
    type: strict_dns
    lb_type: round_robin
    hosts:
    - url: tcp://featureA
  - name: featureB
    features: http2
    connect_timeout_ms: 250
    type: strict_dns
    lb_type: round_robin
    hosts:
    - url: tcp://featureB

All 2 comments

Just found this issue by accident.
Maybe I find the time to add an example in the near future. For now maybe this helps? I am using grpc-web here, too.
The CORS settings are set for all routes and on the /serviceB route it is specifically disabled.

listeners:
- address: tcp://0.0.0.0:443
  filters:
  - type: read
    name: http_connection_manager
    config:
      access_log:
      - path: /dev/stdout
      codec_type: auto
      stat_prefix: ingress_http
      route_config:
        virtual_hosts:
        - name: gateway
          domains:
          - "*"
          cors:
            allow_origin: ["*"]
            allow_headers: "content-type, x-grpc-web"
            allow_methods: "POST"
          routes:
          - timeout_ms: 0
            prefix: /serviceA
            cluster: serviceA
          - timeout_ms: 0
            prefix: /serviceB
            cluster: experiment
            cors:
              enabled: false
      filters:
      - type: both
        name: cors
        config: {}
     - type: both
        name: grpc_web
        config: {}
      - type: decoder
        name: router
        config: {}
admin:
  access_log_path: /dev/stdout
  address: tcp://0.0.0.0:8001
cluster_manager:
  clusters:
  - name: featureA
    features: http2
    connect_timeout_ms: 250
    type: strict_dns
    lb_type: round_robin
    hosts:
    - url: tcp://featureA
  - name: featureB
    features: http2
    connect_timeout_ms: 250
    type: strict_dns
    lb_type: round_robin
    hosts:
    - url: tcp://featureB

Is it possible to disable cors for specific method ? As you achieved for specific route/serviceB is disabled

Was this page helpful?
0 / 5 - 0 ratings