Skip to content

Conversation

@realark
Copy link
Contributor

@realark realark commented Nov 10, 2017

This fixes the bug which was capturing raw mongo queries with sensitive information.

The root cause was the byteman instrumentation was attempting to use a patched version of the TracingCommandListener. However, it was unable to do the bytecode patching because that class is not on the runtime classpath (because it is a dependency).

The fix is to create a new class, DDTracingCommandListener, inside of MongoHelper with the desired behavior. This is mostly the code from opentracing's TracingCommandListener. I will leave comments in sections where this PR will cause change.

In addition to the new unit tests, manual testing was done with the dropwizard-mongo sample app.

@realark realark added the type: bug Bug report and fix label Nov 10, 2017
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like some extra eyes on this section in particular. I ported over the behavior the instrumentation was attempting to apply, but I'm not 100% sure if the span tags are correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks ok to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we need to set the service name somewhere:
span.setTag(DDTags.SERVICE_NAME, "mongo");

@tylerbenson tylerbenson changed the title Ark/mongo quickfix Fix Mongo Query Sanitizing Nov 10, 2017
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to use mongo.query as the operation name.

Copy link
Contributor

Choose a reason for hiding this comment

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

The method call to errorLogs can be replaced with:
span.log(Collections.singletonMap("error.object", throwable));

Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of scares me a little... unbounded cache that relies on the behavior below for removal. What do you think @realark?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm okay with it because the monog CommandListener api guarantees the started event will generate a failed/success event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In other words, the mongo java driver itself would have to be buggy for the map to leak. We're not relying on good user code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this method is no longer used and can be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we've to

Copy link
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

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

Once that unused method is deleted, I'm ok with this being merged.

Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

I think we should address Tyler's comments, especially unbounded cache issue

@realark realark merged commit ce40cbf into master Nov 13, 2017
@realark realark deleted the ark/mongo_quickfix branch November 13, 2017 15:36
@tylerbenson
Copy link
Contributor

@palazzem I think the cache is ok for now since it was already being done that way with the existing mongo instrumentation. Certainly something we can look at in the future though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants