Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use appendAction for translated HeaderValueOptions #8678

Merged

Conversation

inFocus7
Copy link
Contributor

@inFocus7 inFocus7 commented Sep 12, 2023

Description

Envoy has deprecated the append field: ref. So we are now translating to the newer field append_action so users can keep the same functionality as before.

There are four append_action fields:

  • APPEND_IF_EXISTS_OR_ADD
    • Appends value if the header exists. Else, adds the header with the key and value.
  • ADD_IF_ABSENT
    • Adds the header if it doesn’t already exist. Else, no-op.
  • OVERWRITE_IF_EXISTS_OR_ADD
    • Overwrites the value if the header already exists. Else, adds the header with the key and value.
  • OVERWRITE_IF_EXISTS
    • ⁣Overwrite the header's value, if it exists. Else, no-op.

As of now, since we're just translating our existing append which is a boolean onto the append_action, we are mapping to two fields as follows:

  • append: true => append_action: APPEND_IF_EXISTS_OR_ADD
  • append: false => append_action: OVERWRITE_IF_EXISTS_OR_ADD

API/Code changes

  • append translates to Envoy's append_action

Context

Users ran into issues where the append field was essentially being ignored.
append has been deprecated in favor of append_action

Testing steps

./ci/kind/setup-kind.sh
helm install gloo _test/gloo-1.0.0-ci.tgz
kubectl apply -f - << 'EOF' 
apiVersion: v1
kind: ServiceAccount
metadata:
  name: httpbin
---
apiVersion: v1
kind: Service
metadata:
  name: httpbin
  labels:
    app: httpbin
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 80
    targetPort: 80
  selector:
    app: httpbin
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
      version: v1
  template:
    metadata:
      labels:
        app: httpbin
        version: v1
    spec:
      serviceAccountName: httpbin
      containers:
      - image: docker.io/kennethreitz/httpbin
        imagePullPolicy: IfNotPresent
        name: httpbin
        ports:
        - containerPort: 80
EOF
kubectl apply -f - << 'EOF'
apiVersion: gateway.solo.io/v1
kind: VirtualService
metadata:
  name: default
  namespace: default
spec:
  virtualHost:
    domains:
    - '*'
    options:
      headerManipulation:
        responseHeadersToAdd:
        - header:
           key: X-Frame-Options
           value: SAMEORIGIN
          append: false
    routes:
    - delegateAction:
        selector:
          labels:
            delegate: 'true'
      matchers:
      - prefix: /
EOF
kubectl apply -f - << 'EOF'
apiVersion: gateway.solo.io/v1
kind: RouteTable
metadata:
  labels:
    delegate: 'true'
  name: child
  namespace: default
spec:
  routes:
  - matchers:
    - prefix: /get
    options:
      headerManipulation:
        responseHeadersToAdd:
        - header:
            key: X-Frame-Options
            value: NEWORIGIN
    routeAction:
      single:
        upstream:
          name: default-httpbin-80
          namespace: default
EOF
kubectl port-forward -n gloo-system deploy/gateway-proxy 8080:8080 & proxynormalPortFwdPid=$!
curl http://localhost:8080/get -v

Notice only the VS header (SAMEORIGIN) is in the header.

kubectl port-forward -n gloo-system deploy/gateway-proxy 19000:19000 & proxyAdminPortFwdPid=$!

Go to: http://localhost:19000/config_dump
Notice the append_action: OVERWRITE_IF_EXISTS_OR_ADD in the Vhost.

Note: If append: true, we'll notice both headers in the curl and we may not see append_action as. the true value is the default value.
Note: Setting append: false on the Route adds the append_action: OVERWRITE_IF_EXISTS_OR_ADD in Envoy, but due to the order that header manipulation gets processed, both headers are returned.

Headers are appended to requests/responses in the following order: weighted cluster level headers, route level headers, virtual host level headers and finally global level headers.

Notes for reviewers

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@inFocus7 inFocus7 added the work in progress signals bulldozer to keep pr open (don't auto-merge) label Sep 12, 2023
@github-actions github-actions bot added the keep pr updated signals bulldozer to keep pr up to date with base branch label Sep 12, 2023
@github-actions
Copy link

github-actions bot commented Sep 12, 2023

Visit the preview URL for this PR (updated for commit c8eef51):

https://gloo-edge--pr8678-fix-use-append-actio-pswgy3jy.web.app

(expires Mon, 25 Sep 2023 14:23:22 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 77c2b86e287749579b7ff9cadb81e099042ef677

Copy link
Contributor

@sam-heilbron sam-heilbron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Some small thoughts for consolidation that I think we can do. As part of this, should we update our docs about this feature to clarify what the current behavior is?

projects/gloo/pkg/plugins/headers/plugin.go Outdated Show resolved Hide resolved
pkg/utils/api_conversion/type.go Outdated Show resolved Hide resolved
@inFocus7 inFocus7 changed the title fix: Use appendAction for translated HeaderValueOptions Use appendAction for translated HeaderValueOptions Sep 14, 2023
@inFocus7 inFocus7 requested a review from a team as a code owner September 14, 2023 17:45
@solo-changelog-bot
Copy link

Issues linked to changelog:
#8525

@inFocus7 inFocus7 removed the work in progress signals bulldozer to keep pr open (don't auto-merge) label Sep 15, 2023
Co-authored-by: Art <artberger@users.noreply.github.com>
inFocus7 and others added 2 commits September 15, 2023 17:24
…nd_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>
…nd_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>
@soloio-bulldozer soloio-bulldozer bot merged commit ede7844 into main Sep 18, 2023
13 checks passed
@soloio-bulldozer soloio-bulldozer bot deleted the fix/use-append-action-for-header-value-options-v3 branch September 18, 2023 14:16
inFocus7 added a commit that referenced this pull request Sep 20, 2023
* update header value options to convert append to envoy v3's append action

* update tests to expect appendAction

* remove focused test

* Update append description

* add changelog

* add extra informatnion on header append/removal docs

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>
inFocus7 added a commit that referenced this pull request Sep 20, 2023
* update header value options to convert append to envoy v3's append action

* update tests to expect appendAction

* remove focused test

* Update append description

* add changelog

* add extra informatnion on header append/removal docs

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>
soloio-bulldozer bot added a commit that referenced this pull request Sep 21, 2023
…on (#8704)

* Use appendAction for translated HeaderValueOptions (#8678)

* update header value options to convert append to envoy v3's append action

* update tests to expect appendAction

* remove focused test

* Update append description

* add changelog

* add extra informatnion on header append/removal docs

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>

* update changelog

* Expose most_specific_header_mutations_wins (#8692)

* add most_specific_header_mutations_wins route config option

* translate and add MostSpecificHeaderMutationsWins to translator_test

* add changelog

* add skipCI-kube-tests:true directive

* add header manipulation order e2e tests and expose routeTable in testContext's testClients

* codegen

* Add section in docs to include mostSpecificHeaderMutationsWins

* remove skipCI-kube-tests:true directive

* review comment updates

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* review comment updates pt 2

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>

* codegen

* do not skip kube tests

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>
soloio-bulldozer bot added a commit that referenced this pull request Sep 21, 2023
…on (#8705)

* Use appendAction for translated HeaderValueOptions (#8678)

* update header value options to convert append to envoy v3's append action

* update tests to expect appendAction

* remove focused test

* Update append description

* add changelog

* add extra informatnion on header append/removal docs

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

* Update docs/content/guides/traffic_management/request_processing/append_remove_headers/_index.md

Co-authored-by: Art <artberger@users.noreply.github.com>

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>

* update changelog

* Expose most_specific_header_mutations_wins (#8692)

* add most_specific_header_mutations_wins route config option

* translate and add MostSpecificHeaderMutationsWins to translator_test

* add changelog

* add skipCI-kube-tests:true directive

* add header manipulation order e2e tests and expose routeTable in testContext's testClients

* codegen

* Add section in docs to include mostSpecificHeaderMutationsWins

* remove skipCI-kube-tests:true directive

* review comment updates

* Apply suggestions from code review

Co-authored-by: Art <artberger@users.noreply.github.com>

* review comment updates pt 2

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>

* codegen

* remove ContainHeaderKeys from header tests

* do not skip kube tests

* add matcher suite test

* add route table client to gateway

---------

Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Art <artberger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep pr updated signals bulldozer to keep pr up to date with base branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants