Skip to content

eventpb,sql: lay some foundation for redactable statement strings#66431

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20210614-sql-redactable-statement
Jun 16, 2021
Merged

eventpb,sql: lay some foundation for redactable statement strings#66431
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20210614-sql-redactable-statement

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Jun 14, 2021

Informs #65401.
Needed as prerequisite for #66359.

Prior to this change, the centralized structured logging logic and the
query logging mechanism were both assuming that the entirety of the
statement string was unsafe for reporting.

We want in a later change to introduce some nuance into this. However,
the structured event logging encoding did not know anything else than
strings that were either completely-safe or completely-unsafe.

This patch introduces the possibility for a structured event to
contain a string of go type redact.RedactableString, where the
caller has already taken responsibility for placing redaction markers.

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz force-pushed the 20210614-sql-redactable-statement branch 2 times, most recently from 9a9f717 to 499bff9 Compare June 14, 2021 18:17
@knz knz requested a review from dhartunian June 14, 2021 18:29
@knz knz force-pushed the 20210614-sql-redactable-statement branch from 499bff9 to e94ff7b Compare June 14, 2021 18:35
Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dhartunian, @knz, @rauchenstein, and @THardy98)


pkg/sql/event_log.go, line 486 at r1 (raw file):

		// In the system.eventlog table, we do not use redaction markers.
		// (compatibility with previous versions of CockroachDB.)
		infoBytes = infoBytes.StripMarkers()

I'm not following this part. Why do you need to append the marker if you will remove right after?

Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dhartunian, @maryliag, @rauchenstein, and @THardy98)


pkg/sql/event_log.go, line 486 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

I'm not following this part. Why do you need to append the marker if you will remove right after?

The problem is that the json.Marshal code that was there prior to this PR does not work with fields that have type redact.RedactableString - it takes the redaction markers as part of the JSON serialization.

The consumers of system.eventlog require all the strings to never contain redaction markers.

Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dhartunian, @maryliag, @rauchenstein, and @THardy98)


pkg/sql/event_log.go, line 486 at r1 (raw file):

Previously, knz (kena) wrote…

The problem is that the json.Marshal code that was there prior to this PR does not work with fields that have type redact.RedactableString - it takes the redaction markers as part of the JSON serialization.

The consumers of system.eventlog require all the strings to never contain redaction markers.

It's also incorrect/unsafe to use StripMarkers (or equivalent logic) on the output of json.Marshal, because that would break events that contain a unicode character as part of a SQL literal, and the unicode character happens to be the same as a redaction marker (e.g. INSERT INTO ... VALUES('›') )

Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Thank you for this!
:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @dhartunian, @knz, @rauchenstein, and @THardy98)


pkg/sql/event_log.go, line 486 at r1 (raw file):

Previously, knz (kena) wrote…

It's also incorrect/unsafe to use StripMarkers (or equivalent logic) on the output of json.Marshal, because that would break events that contain a unicode character as part of a SQL literal, and the unicode character happens to be the same as a redaction marker (e.g. INSERT INTO ... VALUES('›') )

Got it!

Copy link
Copy Markdown
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

:lgtm: thx for adding me on this. it was a helpful example to understand.

Reviewed 6 of 10 files at r1.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @knz, @rauchenstein, and @THardy98)

Prior to this change, the centralized structured logging logic and the
query logging mechanism were both assuming that the entirety of the
statement string was unsafe for reporting.

We want in a later change to introduce some nuance into this. However,
the structured event logging encoding did not know anything else than
strings that were either completely-safe or completely-unsafe.

This patch introduces the possibility for a structured event to
contain a string of go type `redact.RedactableString`, where the
caller has already taken responsibility for placing redaction markers.

Release note: None
@knz knz force-pushed the 20210614-sql-redactable-statement branch from e94ff7b to 8531ddd Compare June 16, 2021 10:43
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jun 16, 2021

TFYRs!

bors r=maryliag,dhartunian

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 16, 2021

Build succeeded:

@craig craig bot merged commit b7b29a9 into cockroachdb:master Jun 16, 2021
@knz knz deleted the 20210614-sql-redactable-statement branch June 16, 2021 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants