Skip to content

Commit

Permalink
fix(db): pass "read" on read-only database operations
Browse files Browse the repository at this point in the history
### Summary

@jeremyjpj0916 mentions in discussion thread:
https://github.com/Kong/kong/discussions/13513

That Kong may work unexpectedly or require write node for general operation.

I did quick search and found couple of  missing places where we don't give
"read" as a parameter for readonly operations. This may not fix all the
issues that we have for how resilient Kong nodes are for write node being
offline, but at least it is obvious to fix these at first.

Signed-off-by: Aapo Talvensaari <[email protected]>
(cherry picked from commit c29db18)
  • Loading branch information
bungle authored and github-actions[bot] committed Aug 20, 2024
1 parent f18e8ee commit 5eca2b4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-db-read-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "Fixed an issue where 'read' was not always passed to Postgres read-only database operations."
type: bugfix
scope: Core
2 changes: 1 addition & 1 deletion kong/db/strategies/postgres/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Plugins:select_by_ca_certificate(ca_id, limit, plugin_names)
name_condition,
limit_condition)

return connector:query(qs)
return connector:query(qs, "read")
end

return Plugins
2 changes: 1 addition & 1 deletion kong/db/strategies/postgres/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Services:select_by_ca_certificate(ca_id, limit)
kong.db.connector:escape_literal(ca_id),
limit_condition)

return kong.db.connector:query(qs)
return kong.db.connector:query(qs, "read")
end

return Services
2 changes: 1 addition & 1 deletion kong/db/strategies/postgres/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ local function page(self, size, token, options, tag)

sql = fmt(sql, unpack(args))

local res, err = self.connector:query(sql)
local res, err = self.connector:query(sql, "read")

if not res then
return nil, self.errors:database_error(err)
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/response-ratelimiting/policies/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ return {
connector:escape_literal(service_id),
connector:escape_literal(route_id))

local res, err = connector:query(q)
local res, err = connector:query(q, "read")
if not res then
return nil, err
end
Expand Down

0 comments on commit 5eca2b4

Please sign in to comment.