CDRIVER-4689 add mongoc_oidc_callback_t #1945
Open
+1,625
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements the abstraction of an OIDC Callback as required for CDRIVER-4689.
This PR does not yet implement usage of the OIDC Callback by
mongoc_client_t
ormongo_client_pool_t
as is documented by the proposed API doc examples (mongoc_client_set_oidc_callback
andmongoc_client_pool_set_oidc_callback
do not exist).This PR implements an abstraction for the OIDC Callback feature:
The spec requires the abstraction is capable of extending parameters and return values in a backward compatible manner:
Therefore, the parameters (
mongoc_oidc_callback_params_t
) and the return values (mongoc_oidc_credential_t
) are opaque types. All "parameters" and "return values" must be accessed using functions to ensure the addition of new parameters and return types will not break API or ABI compatibility. Therefore, the callback function as implemented by a user must be declared as follows:The callback function type is specified as
mongoc_oidc_callback_fn_t
.The Authentication spec requires:
To distinguish between success, cancellation due to a timeout, and cancellation due to an error, the callback function is expected to return with one of three conditions, expressed as pseudocode (this would be implemented within the handshake algorithm):
Although the current implementation proposes ignoring
cancel_with_timeout
whencancel_with_error
is set (prioritize error over timeout), this can be changed into a Client API usage error if preferable. It would admittedly be unusual for both to ever be set at the same time.Note
cancel_with_timeout
andcancel_with_error
are implemented as out parameters rather than as return values to avoid requiring users to create and return amongoc_oidc_credential_t
object during cancellation. This should help distinguish success vs. cancellation.The proposed API deliberately avoids allowing the user to specify any details regarding the error or timeout. Note the absence of a
bson_error_t
parameter or even support for aconst char*
error message string:This is to avoid locking the API into supporting
bson_error_t
codes, error messages, and/or any other details that are irrelevant to satisfying the minimal requirements of the OIDC Callback API. Instead, support for any additional details is completely deferred to theuser_data
in/out parameter, whose behavior may be defined entirely by the user as they require, as shown in the API example code:Therefore, the mongoc library will not need to handle propagation of user-provided error details. It can focus simply on implementing the MONGODB-OIDC authentication's mechanism algorithmic requirements only.
Note
The
cancel_with_*
functions always returnNULL
to support thereturn
syntax above. This is primarily for convenience and to help avoid confusion with return value null vs. not-null requirements. However, users may choose to manually returnNULL
instead.The
timeout
andexpires_in
parameter types areint64_t
. This is to be consistent withbson_get_monotonic_time()
,expiration_ms_to_timer()
,mongoc_async_cmd_t::timeout_ms
,timeout_msec
parameters, etc. and to avoid signedness inconsistency due touint64_t
anduint32_t
, avoid narrowing conversions due toint32_t
.The
timeout
parameter is meant to be directly compared againstbson_get_monotonic_time()
by the user to determine when to report a timeout, as shown in API example code.The
expires_in
parameter is meant to be used after the callback function has (successfully) returned to compute the timestamp when the associated access token will expire (in the cache) and the OIDC callback function must be re-invoked. This will likely be computed asbson_get_monotonic_time() + to_microseconds (*expires_in)
(internally represented as anmcd_time_point
). Details are TBD and will depend on the implementation of Credential Caching and the overall MONGODB-OIDC authentication algorithm.