-
Notifications
You must be signed in to change notification settings - Fork 1.5k
KMS Retry support #1999
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
base: main
Are you sure you want to change the base?
KMS Retry support #1999
Changes from all commits
df2a759
5bff2ae
68115e8
226b0f7
bf0140f
3f6a2ce
4a5c864
38a268f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -o errexit # Exit the script with error if any of the commands fail | ||
|
|
||
| # Supported/used environment variables: | ||
| # MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info) | ||
|
|
||
| ############################################ | ||
| # Main Program # | ||
| ############################################ | ||
| RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE:-$0}")" | ||
| . "${RELATIVE_DIR_PATH}/setup-env.bash" | ||
| echo "Running KMS Retry tests" | ||
|
|
||
| cp ${JAVA_HOME}/lib/security/cacerts mongo-truststore | ||
| ${JAVA_HOME}/bin/keytool -importcert -trustcacerts -file ${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem -keystore mongo-truststore -storepass changeit -storetype JKS -noprompt | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
readonly KMS_TLS_CERT_PATH="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"I implemented the proposed change in stIncMale@189a6d6, tested here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [informational comment] The file |
||
|
|
||
| export GRADLE_EXTRA_VARS="-Pssl.enabled=true -Pssl.trustStoreType=jks -Pssl.trustStore=`pwd`/mongo-truststore -Pssl.trustStorePassword=changeit" | ||
|
|
||
| ./gradlew -version | ||
|
|
||
| # Disable errexit so both suites run and their exit codes can be captured below. | ||
| set +o errexit | ||
|
|
||
| ./gradlew --stacktrace --info ${GRADLE_EXTRA_VARS} -Dorg.mongodb.test.uri=${MONGODB_URI} \ | ||
| -Dorg.mongodb.test.kms.retry.ca.path="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem" \ | ||
| driver-sync:cleanTest driver-sync:test --tests ClientSideEncryptionKmsRetryProseTest | ||
| first=$? | ||
| echo "sync exit code: $first" | ||
|
|
||
| ./gradlew --stacktrace --info ${GRADLE_EXTRA_VARS} -Dorg.mongodb.test.uri=${MONGODB_URI} \ | ||
| -Dorg.mongodb.test.kms.retry.ca.path="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem" \ | ||
| driver-reactive-streams:cleanTest driver-reactive-streams:test --tests ClientSideEncryptionKmsRetryProseTest | ||
| second=$? | ||
| echo "reactive exit code: $second" | ||
|
|
||
| if [ $first -ne 0 ]; then | ||
| exit $first | ||
| elif [ $second -ne 0 ]; then | ||
| exit $second | ||
| else | ||
| exit 0 | ||
| fi | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file are all CSOT-related, and @dariakp confirmed that we should not do any more CSOT-related work (except for removing CSOT, or making sure the code still compiles and works). Thus, I think we should remove all the CSOT-related changes from the PR, including CSOT-related tests in |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,10 +24,12 @@ | |||||||||||||||||||||||||||||
| import com.mongodb.MongoClientSettings; | ||||||||||||||||||||||||||||||
| import com.mongodb.MongoConfigurationException; | ||||||||||||||||||||||||||||||
| import com.mongodb.client.model.vault.RewrapManyDataKeyOptions; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.TimeoutContext; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.authentication.AwsCredentialHelper; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.authentication.AzureCredentialHelper; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.authentication.GcpCredentialHelper; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.crypt.capi.MongoCryptOptions; | ||||||||||||||||||||||||||||||
| import com.mongodb.internal.time.Timeout; | ||||||||||||||||||||||||||||||
| import com.mongodb.lang.Nullable; | ||||||||||||||||||||||||||||||
| import org.bson.BsonDocument; | ||||||||||||||||||||||||||||||
| import org.bson.BsonDocumentWrapper; | ||||||||||||||||||||||||||||||
|
|
@@ -52,6 +54,32 @@ | |||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| public final class MongoCryptHelper { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static final String KMS_TIMEOUT_ERROR_MESSAGE = "KMS key decryption exceeded the timeout limit."; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Throws a {@code MongoOperationTimeoutException} if the operation timeout has expired or the | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's |
||||||||||||||||||||||||||||||
| * KMS retry backoff would exceed the remaining operation time. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @param operationTimeout the operation timeout, or null if none | ||||||||||||||||||||||||||||||
| * @param backoffMicros the backoff to sleep before the next KMS attempt, in microseconds | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| public static void checkKmsRetryBackoff(@Nullable final Timeout operationTimeout, final long backoffMicros) { | ||||||||||||||||||||||||||||||
| if (operationTimeout == null) { | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| operationTimeout.run(TimeUnit.MICROSECONDS, | ||||||||||||||||||||||||||||||
| // infinite timeout: no CSOT budget to enforce; libmongocrypt's retry count is the only limit | ||||||||||||||||||||||||||||||
| () -> { }, | ||||||||||||||||||||||||||||||
| remainingMicros -> { | ||||||||||||||||||||||||||||||
| if (remainingMicros < backoffMicros) { | ||||||||||||||||||||||||||||||
| throw TimeoutContext.createMongoTimeoutException(KMS_TIMEOUT_ERROR_MESSAGE); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| () -> { | ||||||||||||||||||||||||||||||
| throw TimeoutContext.createMongoTimeoutException(KMS_TIMEOUT_ERROR_MESSAGE); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+80
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static MongoCryptOptions createMongoCryptOptions(final ClientEncryptionSettings settings) { | ||||||||||||||||||||||||||||||
| return createMongoCryptOptions(settings.getKmsProviders(), false, emptyList(), emptyMap(), null, null, | ||||||||||||||||||||||||||||||
| settings.getKeyExpiration(TimeUnit.MILLISECONDS)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[informational comment]
This function runs
${DRIVERS_TOOLS}/.evergreen/csfle/setup.sh, which starts the KMS failpoint server required by the prose test. One can see that${DRIVERS_TOOLS}/.evergreen/csfle/setup.shindeed starts it at https://github.com/mongodb-labs/drivers-evergreen-tools/blob/18aed4f176dab1ed505c9a2a53466ddf3f4796ec/.evergreen/csfle/start-servers.sh#L70-L74: