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

Capture postgres extended protocol queries in audit log #6303

Merged
merged 1 commit into from Apr 14, 2021

Conversation

r0mant
Copy link
Collaborator

@r0mant r0mant commented Apr 3, 2021

This pull request enhances database access Postgres protocol integration to support logging of Postgres "extended query protocol" messages in the audit log.

Extended query protocol is a fancy name for parameterized prepared statements. Normal SQL queries are executed with a single wire message (Query) while prepared statements are executed in 3 steps:

  • First, client sends Parse message to prepare the (optionally) parameterized query.
  • Next, client sends Bind message to "prime" the prepared query for execution and bind it to parameters into a what Postgres calls "destination portal".
  • Finally, client sends Execute message to execute the specified "portal" i.e. query bound to parameters.

More information about Postgres extended query protocol: https://www.postgresql.org/docs/10/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY.

Many GUI clients use this extended protocol flow to run SQL statements and without this these statements are not captured in our audit log at all. With this update, the queries and their parameters are captured, for example:

Screen Shot 2021-04-02 at 5 45 03 PM

Fixes #6051. Also needs backport as this is going to 6.2.

@r0mant r0mant added backport-required database-access Database access related issues and PRs labels Apr 3, 2021
@r0mant r0mant requested review from awly and russjones April 3, 2021 00:58
@r0mant r0mant requested a review from klizhentas as a code owner April 3, 2021 00:58
@r0mant r0mant self-assigned this Apr 3, 2021
@r0mant r0mant requested a review from fspmarshall April 6, 2021 01:09
@r0mant
Copy link
Collaborator Author

r0mant commented Apr 7, 2021

@awly @fspmarshall Would appreciate a review on this one guys, thanks.

api/constants/constants.go Show resolved Hide resolved
lib/events/filesessions/filestream.go Show resolved Hide resolved
lib/srv/db/audit_test.go Outdated Show resolved Hide resolved
lib/srv/db/audit_test.go Outdated Show resolved Hide resolved
lib/srv/db/common/audit.go Outdated Show resolved Hide resolved
lib/srv/db/common/statements.go Outdated Show resolved Hide resolved
lib/srv/db/common/statements.go Outdated Show resolved Hide resolved
lib/srv/db/postgres/engine.go Outdated Show resolved Hide resolved
lib/srv/db/postgres/engine.go Show resolved Hide resolved
lib/srv/db/postgres/test.go Outdated Show resolved Hide resolved
@r0mant r0mant force-pushed the roman/prep-stmt branch 2 times, most recently from 5b1233f to c35a718 Compare April 9, 2021 17:01
lib/srv/db/postgres/engine.go Show resolved Hide resolved
lib/srv/db/common/statements.go Outdated Show resolved Hide resolved
lib/srv/db/common/statements.go Outdated Show resolved Hide resolved
Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

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

Bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-required database-access Database access related issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres prepared statements aren't captured in audit log
4 participants