Skip to content

pgsql: add query keyword - v1 #13312

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

Closed
wants to merge 1 commit into from

Conversation

jufajardini
Copy link
Contributor

Add the pgsql.query rule keyword to match on PGSQL's simple query messages.

pgsql.query is a sticky buffer and can be used as a fast_pattern.

Task #6259

Changes (if applicable):

  • I have updated the User Guide (in doc/userguide/) to reflect the changes made

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
https://redmine.openinfosecfoundation.org/issues/6259

Describe changes:

  • add the query keyword to pgsql, matching on the pgsql.request.simple_query EVE field
  • this is a sticky buffer that can be used as a fast pattern (if I understood correctly how to do this)
  • this keyword is case sensitive

Provide values to any of the below to override the defaults.

SV_BRANCH=OISF/suricata-verify#2524

Add the `pgsql.query` rule keyword to match on PGSQL's `simple query`
request messages. This matches on the EVE:

pgsql.request.simple_query

as of now.

`pgsql.query` is a sticky buffer and can be used as a fast_pattern.

Task OISF#6259
@jufajardini jufajardini requested a review from victorjulien as a code owner May 26, 2025 00:38
Copy link

codecov bot commented May 26, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.42%. Comparing base (b4095bf) to head (b323b4a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13312      +/-   ##
==========================================
+ Coverage   83.41%   83.42%   +0.01%     
==========================================
  Files         995      996       +1     
  Lines      272813   272849      +36     
==========================================
+ Hits       227558   227620      +62     
+ Misses      45255    45229      -26     
Flag Coverage Δ
fuzzcorpus 62.07% <44.44%> (+0.03%) ⬆️
livemode 18.94% <44.44%> (+<0.01%) ⬆️
pcap 44.90% <44.44%> (-0.02%) ⬇️
suricata-verify 64.99% <94.44%> (+<0.01%) ⬆️
unittests 59.25% <44.44%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 26213

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

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

Looks good, just the question of the keyword name + a small nit

) -> bool {
let tx = cast_pointer!(tx, PgsqlTransaction);

*buffer = std::ptr::null();
Copy link
Member

Choose a reason for hiding this comment

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

nit: not sure if the compiler optimizes it, but we do a useless reset here in the (common?) success case

This keyword is a sticky buffer that allows matching on the contents of `Simple`
`query` PostgreSQL request messages parsed by the engine.

As such, it matches on the ``pgsql.request.simple_query`` field from EVE output.
Copy link
Member

Choose a reason for hiding this comment

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

should the keyword be simple_query if there is later also non-simple query type coming?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question... with the extended query, the query is sent as part of the Parse message. (cf https://www.postgresql.org/docs/13/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY)

I mentioned simple_query here thinking about the rules keyword/ log output parity.

It feels more straightforward to have this as simple_query and then maybe have the other as parse.query or extended_query and maybe have one that could unify both, in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh, the simple query postgresql's message is called "Query" in their docs (https://www.postgresql.org/docs/17/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-QUERY)

Copy link
Member

Choose a reason for hiding this comment

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

I'd try to stick with the Postgres documentation naming, as its exists and is rather complete. Rather than what we see in Wireshark. So this would just become query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit confusing to me, as the docs uses both-ish (?):

Query (F)

    Byte1('Q')

        Identifies the message as a simple query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could just use pgsql.request.query and indicate that it matches on query strings? For now, that would mean the Query from the Simple query sub-proto, but when extended query is added, that would also be the Query seen in the Parse message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're deciding to move on with using query which could be then possibly also used to inspect extended query queries

@jufajardini jufajardini mentioned this pull request May 27, 2025
1 task
@jufajardini
Copy link
Contributor Author

Followed by: #13325

@jufajardini jufajardini deleted the pgsql-6259/v1 branch May 30, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants