Skip to content

[CDRIVER-4454] Azure auto-KMS testing #1104

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

Merged

Conversation

vector-of-bool
Copy link
Contributor

Refer: CDRIVER-4454

This changeset adds a simple IMDS-mimicking HTTP server based on Bottle. Further test cases and behaviors can be added to this server in the future. This also includes addition tweaks to the HTTP API and a timer API. (This changeset builds upon #1103)

Individual commits can be viewed in order.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Nice, LGTM with an update to the timeout handling and documentation for the error constants.

I suggest moving mock server to drivers-evergreen-tools to make it accessible to other drivers when adding specification tests.

template engines - all in a single file and with no dependencies other than the
Python Standard Library.

Homepage and documentation: http://bottlepy.org/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat, I did not know about bottle.

When moving this to drivers-evergreen-tools, consider using Flask. The mock OSCP server depends on Flask.

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 chose Bottle here because it is a single-file library that does not required additional dependencies. Flask etc will require a form of external dependency management. I'm fine doing external dev/CI Python dependencies, but I would like for there to be a more reliable development/CI workflow then is currently present.

if TYPE_CHECKING:
from typing import Protocol

class _RequstParams(Protocol):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
class _RequstParams(Protocol):
class _RequestParams(Protocol):

try:
return fn()
except AssertionError as e:
traceback.format_exc()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
traceback.format_exc()
traceback.print_exc()

@@ -49,7 +49,8 @@ typedef enum {
MONGOC_ERROR_SERVER, /* Error API Version 2 only */
MONGOC_ERROR_TRANSACTION,
MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION, /* An error coming from libmongocrypt */
MONGOC_ERROR_POOL
MONGOC_ERROR_POOL,
MONGOC_ERROR_AZURE,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the errors.rst with the new domain and value.

// +1 to prevent passing zero as a timeout
mcd_get_milliseconds (mcd_timer_remaining (timer)) + 1,
&host_list,
error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch. If _mongoc_http_send requires a non-zero timeout, I suggest checking the timeout before each blocking call:

#define CHECK_TIMEOUT(msg)                                        \
   if (mcd_get_milliseconds (mcd_timer_remaining (timer)) == 0) { \
      bson_set_error (error,                                      \
                      MONGOC_ERROR_STREAM,                        \
                      MONGOC_ERROR_STREAM_SOCKET,                 \
                      "Timeout before %s: %s",                    \
                      msg,                                        \
                      req->host);                                 \
      goto fail;                                                  \
   }

   CHECK_TIMEOUT ("connect")

mongoc_stream_tls_handshake_block interprets 0 as "no timeout".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this, there's a several goofs in timing that may be a problem, e.g. an unguarded multiply of timeout_ms * 1000 that can overflow. Requiring the timeout to not be zero is strange behavior.

I also realize now that asserting on overflow in the duration code is probably bad (for example, one might want mcd_seconds(INT64_MAX) to become a maximum duration, rather than terminate the program, and using assertions implies that the caller is supposed to know what the time encoding is).

return mcd_azure_access_token_from_imds (out,
NULL, // Use the default host
0, // Default port as well
NULL, // No extra headres
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
NULL, // No extra headres
NULL, // No extra headers

@vector-of-bool
Copy link
Contributor Author

@kevinAlbs I did some changes to the time arithmetic to be saturating rather than asserting (See this commit). It shouldn't have any effect on the behavior of the in most cases, but I feel better about it. Could you take a quick look at that change?

return mcd_seconds (m * 60);
}

/// Convert an abstract duration to a number of milliseconds
/**
* @brief Obtain the cound of full milliseconds encoded in the given duration
Copy link
Collaborator

Choose a reason for hiding this comment

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

"count"

@vector-of-bool vector-of-bool merged commit 671a151 into mongodb:master Sep 14, 2022
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.

2 participants