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

Move ocsp_response_cache:delete after certificate_data:set #6200

Merged
merged 1 commit into from Sep 19, 2020

Conversation

wenzong
Copy link
Contributor

@wenzong wenzong commented Sep 19, 2020

Move ocsp_response_cache:delete after certificate_data:set

What this PR does / why we need it:

There is a potential concurrency problem.

So in /configurations/servers:

  • after ocsp_response_cache:delete(uid)
  • before certificate_data:set(uid)

Since the two steps are not atomic operation, there is a small chance that some nginx worker missed the cache and read the old certificate, then fetch and cache the old ocsp_response again.

This PR change the sequence of the two operations.

However this PR is not perfect. There might be some requests still served by mismatch certificate and OCSP Response(between certificate_data:set and ocsp_response_cache:delete), but the impact is much more smaller than origin implementation.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Which issue/s this PR fixes

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 19, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @wenzong. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 19, 2020
@wenzong
Copy link
Contributor Author

wenzong commented Sep 19, 2020

/assign @ElvinEfendi

@aledbf
Copy link
Member

aledbf commented Sep 19, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 19, 2020
@aledbf aledbf added this to In Progress in 0.40.0 Sep 19, 2020
@ElvinEfendi
Copy link
Member

ElvinEfendi commented Sep 19, 2020

However this PR is not perfect. There might be some requests still served by mismatch certificate and OCSP Response(between certificate_data:set and ocsp_response_cache:delete), but the impact is much more smaller than origin implementation.

I think this is significantly better though. There will potentially be mismatch, but we will not be caching OCSP response for an outdated certificate at least. In other words if we hit the race with this PR the worst is few requests will have incorrect OCSP response, whereas with the original fix if the bug was hit incorrect OCSP response would be served until NGINX is restarted or cache is expired after 3 days.

@wenzong
Copy link
Contributor Author

wenzong commented Sep 19, 2020

However this PR is not perfect. There might be some requests still served by mismatch certificate and OCSP Response(between certificate_data:set and ocsp_response_cache:delete), but the impact is much more smaller than origin implementation.

I think this is significantly better though. There will potentially be mismatch, but we will not be caching OCSP response for an outdated certificate at least. In other words if we hit the race with this PR the worst is few requests will have incorrect OCSP response, whereas with the original fix if the bug was hit incorrect OCSP response would be served until NGINX is restarted or cache is expired after 3 days.

I also considered using some kind of lock to make the operations atomically, there is two reasons prevent me from doing so.

The first consideration is the performance could be affected by using lock. Another problem is I am not familiar with the openresty and Lua ecosystem, therefore I don't know whether there is any mature lock implementation.

So I just change the operations order to avoid severe issue ;)


Code refactored. Please review again.

@ElvinEfendi
Copy link
Member

/lgtm

FWIW lua-resty-lock is mature enough locking library for Openresty.

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Sep 19, 2020
@k8s-ci-robot k8s-ci-robot merged commit 6f226e9 into kubernetes:master Sep 19, 2020
@aledbf aledbf moved this from In Progress to done in 0.40.0 Sep 19, 2020
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
No open projects
0.40.0
  
done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants