Skip to content

Conversation

@alcaeus
Copy link
Member

@alcaeus alcaeus commented Jun 24, 2021

DRIVERS-1816

This does not cover replies to all commands, since we're only able to make assertions against successful commands. With some authentication commands, getting them to work is a sizeable effort. For that reason, it's up to engineers to ensure they're not just redacting replies to the commands where we test this, but rather all commands. This includes replies that are potentially sensitive, e.g. replies for saslStart and saslContinue.

Note that due to a limitation of the unified test format, we can't make assertions against the contents of CommandFailedEvents. While the spec doesn't explicitly mention this event, it is assumed that drivers redact replies when they are exposed in CommandFailedEvents. That said, most if not all replies will not contain sensitive information, so I believe it's ok to leave this untested for the time being.

@alcaeus alcaeus self-assigned this Jun 24, 2021
@alcaeus alcaeus requested a review from a team as a code owner June 24, 2021 17:13
@alcaeus alcaeus requested review from kmahar and removed request for a team June 24, 2021 17:13
Copy link
Contributor

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Thanks for adding these tests! To be clear, do these changes assert the following?

  1. Most security-sensitive fields are redacted from security-sensitive commands (you've added assertions for payload, mechanism, etc.)
  2. Server replies to hellos and legacy hellos are similarly redacted.

And, it's up to individual drivers to assert all other replies are redacted (including failures)?

@alcaeus alcaeus requested a review from a team as a code owner June 25, 2021 06:15
@alcaeus alcaeus requested review from jmikola and removed request for a team June 25, 2021 06:15
@@ -0,0 +1,462 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

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

While working on the recent changes, I realised that the original PR that added support for the observeSensitiveCommands client entity option didn't create the 1.5 schema version and also didn't add the tests to the unified test format's Makefile.

Copy link
Member

Choose a reason for hiding this comment

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

I definitely missed that while reviewing #1015.

@prashantmital: Any idea what happened there? You updated the test file itself to use 1.5 but the PR never included a schema-1.5.json. Did you actually make one and just forget to git add it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I didn't create schema-1.5.json at all. Completely slipped my mind that this was something I needed to do.

SCHEMA=../schema-1.5.json

.PHONY: all invalid valid-fail valid-pass versioned-api load-balancers gridfs transactions crud collection-management HAS_AJV
.PHONY: all invalid valid-fail valid-pass versioned-api load-balancers gridfs transactions crud collection-management command-monitoring HAS_AJV
Copy link
Member Author

Choose a reason for hiding this comment

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

I've love to find a different option for this at some point in time. Ideally, we'd go through all directories, grab every .yml file, attempt to read a schema version for it (skipping the file if we don't find one) and validating the file against the explicit schema version indicated in the file. @jmikola do you think this is feasible? If so I'd file a ticket so we can eventually return to this.

This solution would fix two issues:

  1. it would no longer require us to manually add new folders with unified test files here, and
  2. it validates files against the schema version they claim to be, which can catch errors when somebody adds functionality from newer schema versions without bumping the schemaVersion in the file.

Copy link
Member

Choose a reason for hiding this comment

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

DRIVERS-1767 already exists to track this. If there's some variation to the behavior (e.g. skipping files that don't have a schemaVersion field) feel free to note that as a suggested approach in the ticket.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll check it out, thanks for pointing me in the right direction

@alcaeus alcaeus requested review from benjirewis and removed request for behackett June 25, 2021 06:30
# This assertion will currently always hold true since we're
# not expecting successful authentication, in which case this
# field is missing anyways.
speculativeAuthenticate: { $$exists: false }
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if I remove the logic for redacting replies, this test (and the corresponding one for legacy hello) still passes in the Go driver. The reply still exists (because I'm no longer redacting), isWritablePrimary is true, and speculativeAuthenticate does not exist because authentication failed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is unfortunately true. I can either remove the reply assertions in this test or leave them in to show intent.

I've tried to create a user beforehand so we can actually test the auth process (and thus get a speculativeAuthenticate in the reply) but wasn't able to get it to pass consistently without spending more time. With the tight timeline on this I opted to take a more pragmatic approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this to expect the redaction of the reply in this scenario as well. I've worked around the limitation in the C driver, so there's no reason for the spec tests to assume the reply shouldn't be redacted.

alcaeus added 5 commits June 29, 2021 09:43
This allows redacting replies to a hello command with speculative authentication, even when the reply does not contain any sensitive fields.
This changes the test expectation for a hello command with sensitive information. Previously, the test did not require redaction of the reply, as it does not contain sensitive information (due to speculative authentication failing). However, this makes the test useless, as it can no longer test that the redaction logic applies to hello at all. Until we're able to test successful authentication, it's sensible to require redacting the reply to ensure drivers are spec compliant.
- name: runCommand
object: *database
arguments:
commandName: ismaster
Copy link
Member

Choose a reason for hiding this comment

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

Noted that you're using the all-lowercase variant of isMaster here in order to test both forms accepted by the server (and dictated by the spec).

@durran
Copy link
Member

durran commented Jul 1, 2021

Tests pass on Node: mongodb/node-mongodb-native#2872

Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

Just a schema version bump to 1.5 in entity-client-observeSensitiveCommands-type.yml

@alcaeus alcaeus requested review from durran and jmikola and removed request for dariakp and kmahar July 2, 2021 07:46
@jmikola jmikola removed their request for review July 2, 2021 13:44
@alcaeus alcaeus merged commit 289f405 into mongodb:master Jul 5, 2021
@alcaeus alcaeus deleted the drivers-1816 branch July 5, 2021 12:58
p-mongo pushed a commit to p-mongo/specifications that referenced this pull request Jul 13, 2021
* upstream/master:
  DRIVERS-1836 Skip tests with $out stage on serverless (mongodb#1036)
  DRIVERS-1816 Test redaction of replies to security sensitive commands (mongodb#1026)
  DRIVERS-1828: Remove insertedCount and improve use of $$unsetOrMatches (mongodb#1034)
  DRIVERS-1819 Disable writes and other unsupported operations in snapshot reads (mongodb#1033)
kevinAlbs pushed a commit to kevinAlbs/specifications that referenced this pull request Nov 9, 2021
…mongodb#1026)

* DRIVERS-1816 Test redaction of replies to security sensitive commands

* Use strings for minServerVersions

* Add 1.5 schema and validate unified APM tests

* Allow redaction of non-sensitive replies to hello

This allows redacting replies to a hello command with speculative authentication, even when the reply does not contain any sensitive fields.

* Require redacting replies to sensitive commands

This changes the test expectation for a hello command with sensitive information. Previously, the test did not require redaction of the reply, as it does not contain sensitive information (due to speculative authentication failing). However, this makes the test useless, as it can no longer test that the redaction logic applies to hello at all. Until we're able to test successful authentication, it's sensible to require redacting the reply to ensure drivers are spec compliant.

* Use correct schema version in test
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.

7 participants