cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: print out statements in logs with redaction markers only around sensitive bits (make SQL keywords etc non-redactable)

Open pxlogan opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe. Currently in the SQL Audit logs AWS secret keys are fully displayed when they are logged. Even though these can be redacted when extracted it is bad behaviour to have these logged ever.

Describe the solution you'd like No secret keys/similar displayed in logs ever,

Describe alternatives you've considered None

Additional context

Epic CC-4113

pxlogan avatar May 18 '21 16:05 pxlogan

@pxlogan just a heads up, in 21.1 users can configure their logs such that sensitive information (like secrets) are redacted upfront before it is written to a log file (using redact and redactable see https://www.cockroachlabs.com/docs/v21.1/log-sinks.html). The inability do that upfront was a limitation of our old logging system in 20.2 and prior versions. With 21.1, users can prevent secrets from ever showing up on logs

cc @knz as this relates to our recent conversations about redacting operational vs application sensitive information

thtruo avatar May 19 '21 19:05 thtruo

Yes correct, Paul if they don't like their secrets they can set redact: true in the sink that collects their query execution.

However we do have a problem with this: the AWS keys are part of the SQL syntax of the statement. The entire statement is considered sensitive information. With pre-redaction enabled, the entire statement gets erased from the log. This negates the ability of the user to track their query execution.

The proper approach here is to introduce partial redactability for SQL statements included in logs -- so that the sensitive part of the SQL statement is marked sensitive, but the rest remains marked safe. This is a SQL observability action item.

knz avatar May 20 '21 08:05 knz

I changed the title of the issue accordingly.

cc @jordanlewis for triage.

knz avatar May 20 '21 08:05 knz

The technical work required is to create a new SQL AST pretty-printer that emits a RedactableString instead of a regular go string, and uses redaction markers around literals and object names.

knz avatar May 20 '21 08:05 knz

Questions from @maryliag and @THardy98

Thomas pushed everything to his branch

here is a few questions (some of them are written on the code itself):

  1. How to identify virtual schemas/tables to not enforce redaction there?
  2. To perform the actual redaction on redact.go, (currently he just added a code to format statements with correct redaction markers), would that be something like: if redactable , cast r.msg into RedactableString using redact.Sprint and call Redact on the RedactableString ?
  3. Is there a special treatment on complex queries? They’re not working properly, his guess is that is most likely due to the handling of the ObjectNamePrefix case in formatNodeMaybeRedact
  4. What’s the best place to add the function formatNodeMaybeRedact ?
  5. He created the function CloseAndGetRedactableString, do we really need something like this? Since it gets cast to a normal string anyways in logEventsWithSystemEventLogOption
  6. Do we intend to keep the old redaction functionality (i.e. redact entire statements)? If yes, he would need to implement a conditional in logEventsWithSystemEventLogOption that checks where to parse the statement AST using AsStringWithFQNames or AsRedactableStringWithFQNames for example, right?

knz avatar Jun 11 '21 14:06 knz

@THardy98 please create a draft PR with your branch. We'll discuss your questions in reviewable.

knz avatar Jun 11 '21 14:06 knz