-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(ca_certificates): invalidate ca store caches when a ca cert is updated and prevent ca_certificates that are still being referenced by other entities from being deleted #11789
Conversation
7f4192b
to
ba5ec21
Compare
b4d8a8e
to
99d35c7
Compare
99d35c7
to
7b28832
Compare
updated and prevent ca_certificates that are still being referenced by other entities from being deleted. Fix [FTI-2060](https://konghq.atlassian.net/browse/FTI-2060)
40c454b
to
22c27b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM. Just a question: the reference relationship of
|
Maybe doing an initial traversal at the init phase instead.
As mentioned in the ticket, this is another optional solution that will complicate the code a lot. Considering the CA certificates won't be updated frequently, not sure if it’s worthwhile. BTW, the reason why we can't get the entities that reference ca_certificates efficiently is postgres doesn't support foreign key arrays. There was a proposed patch 6 years ago but it never got included because some major surgery is still required. |
This can be implemented with a |
In the Idea: instead of performing all the filtering in Lua (expensive) or trying to enforce this constraint solely in the DB with schema/trigger changes (leaks plugin-specific business logic into the storage layer), what if we added some specialized Something kinda like... -- note: you might even be able to teach `kong/db/dao/init.lua` to
-- auto-generate this code if the type definition for the `ca_certificates`
-- field is annotated to reflect the foreign relationship.
function services:select_by_ca_certificate(cert_id)
-- idk if this is correct at all
local rows, err = self.strategy:query("SELECT * FROM services WHERE %s = ANY(ca_certificates)",
cert_id)
-- ...
return services
end
-- alternatively, one could craft a method that uses `SELECT COUNT(*) FROM ...`,
-- which would be more efficient given that we don't actually care about
-- retrieving the matching entities This would negate the need to iterate and filter through all entities in Lua land, but it also avoids putting too much business logic into the DB. |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11789-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11789-to-master-to-upstream
git checkout -b cherry-pick-11789-to-master-to-upstream
ancref=$(git merge-base a6d647566991e339ea5126113df4bef21fe0115d 6cb08ab74d3da794493649eaeaf525cf4503edcc)
git cherry-pick -x $ancref..6cb08ab74d3da794493649eaeaf525cf4503edcc |
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between master and cherry-pick-11789-to-master-to-upstream"} |
Summary
Currently, when a CA certificate is updated, the related CA certificate store caches won't be invalidated. And a CA certificate can be deleted even if it's still referenced by other entities. This PR fixes these issues.
link to #10120
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdFull changelog
:select_by_ca_certificate()
method tokong.db.services
andkong.db.plugins
to select entities referencing a ca certificate.ca_certificates:delete()
. Before deleting a ca certificate, check all the entities and plugins that may reference it and prevent deletion if any one is referencing it.Issue reference
Fix FTI-2060