Closed mianelson closed 5 years ago
I observed the same behavior. Does it work for you in previous versions?
We observe the same behavior. It works for us in 0.40 Version .
Anyone knows when can we expect fix for that?
@mianelson @cornelius-keller Thanks for reporting it.
Just to confirm, what you are saying is that given the following response from the authorization server:
HTTP/1.1 302
set-cookie=a; Domain=whatever.com; Path=/'
set-cookie=b; Domain=whatever.com; Path=/'
Only cookie b
gets set?
If correct, that's a bug probably attributed to this logic: https://github.com/envoyproxy/envoy/blob/e135ec80b768ba9c7a415eb66746f04dec431ed7/source/extensions/filters/http/ext_authz/ext_authz.cc#L138
IRC, it's was a bug fixing due to a segfault that we found in the previous implementation.
FYI @FrancoCorleone
I have different http code but the rest is correct. I have two cookies and only one is set. I checked by proxing direcetly to auth service bypassing ambassador and both are set so it has to be further than auth service itself
Yeah, that's the correct behaviour for setting multiple cookies. I will need to get my hands into Envoy just to confirm it, but it seems that the logic described above is what causing the issue.
Ok let me know when it's fixed. Thanks!
@gsagula yes, can confirm as well that that is the behavior we're experiencing. It's been a while since I've worked in C++, but that line you tracked down in ext_authz.cc is where my search ended as well.
Any update on this issue? When it going to be fixed? We can not update to 50 version because of this issue.
Same here. Any updates? @gsagula ?
@gsagula: RFC 6265 is pretty unequivocal that multiple Set-Cookie
headers must be supported, so I'm sad to say that I have to call this one definitely a bug that needs fixing.
@kflynn I’m aware of the RFC and that it is a bug. However, it’s not up to me to prioritize the fix.
@gsagula, any suggested workaround till then as there is no date for a fix planned?
@FrancoCorleone As I mentioned in https://github.com/datawire/ambassador/issues/1211#issuecomment-463745263, the problem is in Envoy proxy. I don't think that there is a workaround other than just trying to set one cookie instead of multiples if possible. Regarding prioritazation, it is more of quetion for @kflynn.
Fixed in 0.51.
@richarddli Are you sure it is fixed? I am using quay.io/datawire/ambassador:0.51.1 and I still observe that issue.
@FrancoCorleone Thanks for reporting, I'm looking into that.
@gsagula thanks for quick response. Let me know when you find out anything. For any interested parties. Until it works for you, you can easily work around that issue by making inner redirects setting additional cookies. In my case, I have only two cookies so just one additional redirect.
@FrancoCorleone We found the problem. I will make sure that we get a new image tomorrow. Thanks!
Thanks, @gsagula.
@gsagula I can confirm the issue still exists even in the latest version of ambassador (0.52.0). I created a repository to demonstrate the issue here: https://github.com/woraphol-j/ambassador-cookie-stripped-demo Let me know if you have any question.
@woraphol-j it worked for me in 0.51.2. @gsagula is something broken again in newer version?
@FrancoCorleone @woraphol-j It works for me with quay.io/datawire/ambassador:0.52.0
:
curl -v -H "requested-cookie: foo, bar, baz" -H "requested-status:307" http://localhost:61880/get
> GET /get HTTP/1.1
> Host: localhost:61880
> User-Agent: curl/7.54.0
> Accept: */*
> requested-cookie: foo, bar, baz
> requested-status:307
>
< HTTP/1.1 307 Temporary Redirect
< content-length: 1289
< content-type: text/plain
< set-cookie: foo=foo
< set-cookie: bar=bar
< set-cookie: baz=baz
< date: Sun, 24 Mar 2019 17:10:41 GMT
docker-compose:
version: '2'
services:
# curl -v -H "requested-cookie: foo, bar, baz" -H "requested-status:307" http://localhost:61880/get
ambassador:
image: quay.io/datawire/ambassador:0.52.0
ports:
- 61880:80
volumes:
- ./config:/ambassador/ambassador-config
environment:
- AMBASSADOR_NO_KUBEWATCH=no_kubewatch
networks:
- ambassador
auth-service:
image: quay.io/datawire/kat-backend:11
environment:
- DEBUG=1
- BACKEND=true
networks:
ambassador:
aliases:
- ambassador
expose:
- "8080"
ports:
- "61898:8080"
echo-service:
image: quay.io/datawire/kat-backend:11
environment:
- DEBUG=1
- BACKEND=true
networks:
ambassador:
aliases:
- ambassador
expose:
- "8080"
networks:
ambassador: {}
config:
---
apiVersion: ambassador/v1
kind: Module
name: ambassador
config:
use_remote_address: true
---
apiVersion: ambassador/v1
kind: AuthService
name: authentication
auth_service: "auth-service:8080"
path_prefix: "/extauth"
proto: http
allowed_request_headers:
- requested-status
- requested-cookie
allowed_authorization_headers:
- set-cookie
---
apiVersion: ambassador/v1
kind: Mapping
name: echo-service
prefix: /
service: "echo-service:8080"
@gsagula Thanks your quick reply. Really appreciated it. However, I tried the exact same configuration as yours and it turned out it DOES NOT work (at least as I expected) as it shows in the result (as I commented):
curl -v -H "requested-cookie: foo, bar, baz" -H "requested-status:200" http://localhost:61880/get
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 61880 (#0)
> GET /get HTTP/1.1
> Host: localhost:61880
> User-Agent: curl/7.54.0
> Accept: */*
> requested-cookie: foo, bar, baz
> requested-status:200
>
< HTTP/1.1 200 OK
< set-cookie: foo=foo
< set-cookie: bar=bar
< set-cookie: baz=baz
< date: Mon, 25 Mar 2019 05:44:03 GMT
< content-length: 1122
< content-type: text/plain; charset=utf-8
< x-envoy-upstream-service-time: 1
< server: envoy
<
{
"backend": "true",
"request": {
"headers": {
"accept": [
"*/*"
],
"content-length": [
"0"
],
"requested-cookie": [
"foo, bar, baz"
],
"requested-status": [
"200"
],
"set-cookie": [
"baz=baz" // *** only the last set-cookie returned from auth-service reaches the echo server
],
"user-agent": [
"curl/7.54.0"
],
"x-envoy-expected-rq-timeout-ms": [
"3000"
],
"x-envoy-internal": [
"true"
],
"x-envoy-original-path": [
"/get"
],
"x-forwarded-for": [
"192.168.192.1"
],
"x-forwarded-proto": [
"http"
],
"x-request-id": [
"47c74108-e76b-41c4-a829-efc003b945a8"
]
},
"host": "localhost:61880",
"method": "GET",
"tls": {
"enabled": false
},
"url": {
"fragment": "",
"host": "",
"opaque": "",
"path": "/get",
"query": {},
"rawQuery": "",
"scheme": ""
}
},
"response": {
"headers": {
"set-cookie": [ // the final result is correct because the echo server receives the request with requested-cookie: foo, bar, baz
"foo=foo",
"bar=bar",
"baz=baz"
]
}
}
* Connection #0 to host localhost left intact
}%
Note that when I call the auth-service directly, it returns a response with 3 set-cookies correctly
curl -v -H "requested-cookie: foo, bar, baz" -H "requested-status:200" http://localhost:61898/get
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 61898 (#0)
> GET /get HTTP/1.1
> Host: localhost:61898
> User-Agent: curl/7.54.0
> Accept: */*
> requested-cookie: foo, bar, baz
> requested-status:200
>
< HTTP/1.1 200 OK
< Set-Cookie: foo=foo
< Set-Cookie: bar=bar
< Set-Cookie: baz=baz
< Date: Mon, 25 Mar 2019 06:00:35 GMT
< Content-Length: 658
< Content-Type: text/plain; charset=utf-8
I’m not sure what you mean by not working, I can see the 3 set-cookie headers in the response.
< set-cookie: foo=foo
< set-cookie: bar=bar
< set-cookie: baz=baz
-- Gabriel Linden Sagula
Hi @gsagula there is only one set-cookie
in the request to the echo server
"set-cookie": [
"baz=baz"
],
I think the flow is (Please correct me if I am wrong)
requested-cookie: foo, bar, baz
header.requested-cookie: foo, bar, baz
header.requested-cookie: foo, bar, baz
header, Ambassador still returns the correct result in the end with 3 set-cookie response headers.
Describe the bug When AuthService returns a non-200 response to Ambassador, only one
set-cookie
header can be sent back to the client, all otherset-cookie
headers are stripped. All cookies have the same domain, max_age, etc.To Reproduce Steps to reproduce the behavior:
set-cookie
header on auth responsesset-cookie
header on responseset-cookie
headers are present on response from AuthService as the response passes back through Ambassador; there should be >1set-cookie
header on the response from the AuthService and only 1set-cookie
header on the response that Ambassador filters and sends back to the clientExpected behavior We expect all
set-cookie
headers to be returned by Ambassador when the AuthService returns a response. Rolling the service back to Ambassador v0.40.2 results in the expected behavior.Versions (please complete the following information):
Additional context Here is logging we captured of the issue. Notice that
x-request-destination
is preserved butsession
is removed in the final response.Here's the AuthService annotation that we are using:
We also verified this behavior against normal non-AuthService request/response flows, and did not see Ambassador filtering any response headers.