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

Document for cookie expires annotation #3363

Merged
merged 1 commit into from
Jan 14, 2019
Merged

Document for cookie expires annotation #3363

merged 1 commit into from
Jan 14, 2019

Conversation

skeeey
Copy link

@skeeey skeeey commented Nov 5, 2018

What this PR does / why we need it:
Document for cookie expires annotation

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:
/assign @ElvinEfendi

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 5, 2018
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 5, 2018
@@ -50,13 +54,13 @@ Date: Fri, 10 Feb 2017 14:11:12 GMT
Content-Type: text/html
Content-Length: 612
Connection: keep-alive
Set-Cookie: INGRESSCOOKIE=a9907b79b248140b56bb13723f72b67697baac3d; Path=/; HttpOnly
Set-Cookie: INGRESSCOOKIE=a9907b79b248140b56bb13723f72b67697baac3d; Expires=Wed, 07-Nov-18 09:05:06 GMT; Max-Age=172800; Path=/; HttpOnly
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this is the correct expiry given the annotation is set to 172800? Isn’t the annotation value a Unix timestamp ?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, there is a screenshot from my test enviroment
cookie-expires

Copy link
Author

Choose a reason for hiding this comment

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

@ElvinEfendi Any more comments?

Copy link
Member

Choose a reason for hiding this comment

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

@skeeey as you can see from your screenshot it is set to 03 January 1970 which is expected given the way you implemented the feature. However in the docs you say it will be 07 Nov 2018.

Copy link
Author

Choose a reason for hiding this comment

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

@ElvinEfendi, for my screenshot, it is dev environment, I do not adjust the system time (the initial system time is 01 January 1970), so the result is 03 January 1970, but for document, I think, if user adjust his system time, it is more close to real world, Do you think we should keep the result as dev environment? if it is the expected, I can change this

Copy link
Member

Choose a reason for hiding this comment

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

01 January 1970 is Unix epoch time, same in every Unix based system.

@aledbf
Copy link
Member

aledbf commented Jan 4, 2019

@ElvinEfendi ping

@@ -11,6 +11,8 @@ Session stickiness is achieved through 3 annotations on the Ingress, as shown in
|nginx.ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|nginx.ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to INGRESSCOOKIE)|
|nginx.ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|nginx.ingress.kubernetes.io/session-cookie-expires|Number of seconds until the cookie expires that will correspond to cookie `Expires` directive|number of seconds|
Copy link
Member

Choose a reason for hiding this comment

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

This is not an accurate description. This value is rather a date as UNIX timestamp that the cookie will expire on.

Copy link
Author

Choose a reason for hiding this comment

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

change this to

|nginx.ingress.kubernetes.io/session-cookie-expires|The value is rather a date as UNIX timestamp that the cookie will expire on, it will correspond to cookie `Expires` directive|UNIX timestamp|

Do you think this is OK or not?

Copy link
Member

Choose a reason for hiding this comment

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

Looks good with a slight adjustment to the description as following:

The value is a date as UNIX timestamp that the cookie will expire on, it corresponds to cookie Expires directive

@ElvinEfendi
Copy link
Member

@skeeey I think there's a flaw in the implementation. Let's say as in your example we set session-cookie-expires to 172800. With that whenever you send a request it will always set Expires to 03 January 1970, whereas expected behaviour should be it sets the Expires to <UNIX timestamp at the time of request> + 172800 so that the cookie lasts for 2 days.

@skeeey
Copy link
Author

skeeey commented Jan 8, 2019

@skeeey I think there's a flaw in the implementation. Let's say as in your example we set session-cookie-expires to 172800. With that whenever you send a request it will always set Expires to 03 January 1970, whereas expected behaviour should be it sets the Expires to <UNIX timestamp at the time of request> + 172800 so that the cookie lasts for 2 days.

@ElvinEfendi, you are right, I examine the current implementation, I think the implementation is right, I use ngx.cookie_time to format the session-cookie-expires,

if self.cookie_expires and self.cookie_expires ~= "" then
      cookie_data.expires = ngx.cookie_time(tonumber(self.cookie_expires))
end

so the behavior should be our expected, the problem is the document is wrong, so I plan to update the example to

nginx.ingress.kubernetes.io/session-cookie-expires: "1546912535"
nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"

to distinguish the session-cookie-max-age

and this example will yield

Set-Cookie: INGRESSCOOKIE=a9907b79b248140b56bb13723f72b67697baac3d; Expires=Tue, 08-Jan-19 01:55:35 GMT; Max-Age=172800; Path=/; HttpOnly

Do you think this is OK or not?

@ElvinEfendi
Copy link
Member

  cookie_data.expires = ngx.cookie_time(tonumber(self.cookie_expires))

@skeeey the problem is here, it should look like this:

      cookie_data.expires = ngx.cookie_time(ngx.time() + tonumber(self.cookie_expires))

otherwise as I explained at #3363 (comment) everyone is going to get same Expires value in their cookie whenver (today, tomorrow, after week etc.) they get the cookie.

@skeeey
Copy link
Author

skeeey commented Jan 9, 2019

@ElvinEfendi, I am confused by timestamp :), yes, I should add it, I correct the code and document, please see the new code diff, thanks

BTW, the current example date is Date: Fri, 10 Feb 2017 14:11:12 GMT, so if the session-cookie-expires is 172800, it should be Sun, 12-Feb-17 14:11:12 GMT

@skeeey
Copy link
Author

skeeey commented Jan 10, 2019

@ElvinEfendi, the CI test failed, would you have a look? because I can run the test in my environment successfully

@@ -219,7 +219,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
local, _ := time.LoadLocation("GMT")
duration, _ := time.ParseDuration("48h")
expected := time.Date(1970, time.January, 1, 0, 0, 0, 0, local).Add(duration).Format("Mon, 02-Jan-06 15:04:05 MST")
expected := time.Now().In(local).Add(duration).Format("Mon, 02-Jan-06 15:04:05 MST")
Copy link
Member

@ElvinEfendi ElvinEfendi Jan 10, 2019

Choose a reason for hiding this comment

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

This is going to be flaky. Imagine you send the request at the very end of a second and by the time this code is being evaluated next second starts. Then the assertion below won't succeed because actual datetime will have second n, whereas expected will have n+1

I suggest you drop seconds from the format and leave only minute granularity.

@ElvinEfendi
Copy link
Member

@skeeey this is looking good now. Once you address https://github.com/kubernetes/ingress-nginx/pull/3363/files#r246778598 please squash your commits.

@aledbf
Copy link
Member

aledbf commented Jan 12, 2019

/check-cla

@aledbf
Copy link
Member

aledbf commented Jan 12, 2019

@ElvinEfendi ping (last PR to be included in 0.22)

@@ -11,6 +11,8 @@ Session stickiness is achieved through 3 annotations on the Ingress, as shown in
|nginx.ingress.kubernetes.io/affinity|Sets the affinity type|string (in NGINX only ``cookie`` is possible|
|nginx.ingress.kubernetes.io/session-cookie-name|Name of the cookie that will be used|string (default to INGRESSCOOKIE)|
|nginx.ingress.kubernetes.io/session-cookie-hash|Type of hash that will be used in cookie value|sha1/md5/index|
|nginx.ingress.kubernetes.io/session-cookie-expires|The value is a date as UNIX timestamp that the cookie will expire on, it corresponds to cookie Expires directive|number of seconds|
Copy link
Member

Choose a reason for hiding this comment

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

This is not accurate now that we made this annotation to accept number of seconds as well (it gets appended to current time to generate date for Expires attribute)

@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 14, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ElvinEfendi, skeeey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 14, 2019
@k8s-ci-robot k8s-ci-robot merged commit 1db9c91 into kubernetes:master Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants