-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix(KeyStoreAdmin): Exceptions for Mutations when KMS Key is Disabled #1235
base: mutations/mutations
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -102,7 +102,7 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations { | |||||||||
grantTokens: KMS.GrantTokenList, | ||||||||||
kmsClient: KMS.IKMSClient | ||||||||||
) | ||||||||||
returns (res: Result<KMS.GenerateDataKeyWithoutPlaintextResponse, Types.Error>) | ||||||||||
returns (res: Result<KMS.GenerateDataKeyWithoutPlaintextResponse, KmsError>) | ||||||||||
requires kmsClient.ValidState() | ||||||||||
requires HasKeyId(kmsConfiguration) && KmsArn.ValidKmsArn?(GetKeyId(kmsConfiguration)) | ||||||||||
requires AttemptKmsOperation?(kmsConfiguration, encryptionContext) | ||||||||||
|
@@ -145,14 +145,14 @@ module {:options "/functionSyntax:4" } KMSKeystoreOperations { | |||||||||
|
||||||||||
:- Need( | ||||||||||
&& generateResponse.KeyId.Some?, | ||||||||||
Types.KeyStoreException( | ||||||||||
Types.KeyManagementException( | ||||||||||
message := "Invalid response from KMS GenerateDataKey:: Invalid Key Id") | ||||||||||
); | ||||||||||
Comment on lines
149
to
150
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. Nit: We should make both these messages consistent.
Suggested change
|
||||||||||
|
||||||||||
:- Need( | ||||||||||
&& generateResponse.CiphertextBlob.Some? | ||||||||||
&& KMS.IsValid_CiphertextType(generateResponse.CiphertextBlob.value), | ||||||||||
Types.KeyStoreException( | ||||||||||
Types.KeyManagementException( | ||||||||||
message := "Invalid response from AWS KMS GenerateDataKey: Invalid ciphertext") | ||||||||||
); | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,29 @@ module {:options "/functionSyntax:4" } MutationErrorRefinement { | |
+ "\nKMS Message: " + errorMessage?.UnwrapOr("") | ||
} | ||
|
||
function GenerateNewActiveException( | ||
nameonly identifier: string, | ||
nameonly kmsArn: string, | ||
nameonly error: KMSKeystoreOperations.KmsError, | ||
nameonly localOperation: string := "InitializeMutation", | ||
nameonly kmsOperation: string := "GenerateDataKeyWithoutPlaintext" | ||
): (output: Types.Error) | ||
{ | ||
var opaqueKmsError? := KmsUtils.ExtractKmsOpaque(error); | ||
var kmsErrorMessage? := KmsUtils.ExtractMessageFromKmsError(error); | ||
var errorContext := ParsedErrorContext( | ||
localOperation := localOperation, | ||
kmsOperation := kmsOperation, | ||
identifier := identifier, | ||
itemType := Structure.BRANCH_KEY_ACTIVE_TYPE, | ||
errorMessage? := kmsErrorMessage?); | ||
var message := | ||
"Key Management denied access while creating the new Active item." | ||
+ " Mutation is halted. Check access to KMS ARN: " + kmsArn + " ." | ||
+ "\n" + errorContext; | ||
Types.MutationToException(message := message) | ||
} | ||
|
||
function CreateActiveException( | ||
nameonly branchKeyItem: KeyStoreTypes.EncryptedHierarchicalKey, | ||
nameonly error: KMSKeystoreOperations.KmsError, | ||
|
@@ -166,7 +189,23 @@ module {:options "/functionSyntax:4" } MutationErrorRefinement { | |
message := "Key Management through an exception." | ||
+ " Mutation is halted. Check access to KMS." | ||
+ "\n" + errorContext); | ||
|
||
} | ||
} | ||
if (kmsWithMsg) { | ||
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. Both this and the last case in the
Example -- If the KMS Message has hasTerminalArn? as true, and the message says you don't have Encrypt permissions, wouldn't this be returned in
rather than
I am also concerned that if all the if blocks in all the cases in
are exhaustive, Line 194:
will never be triggered because in the previous if block |
||
var hasOriginalArn? := String.HasSubString(kmsErrorMessage?.value, item.KmsArn); | ||
var hasTerminalArn? := String.HasSubString(kmsErrorMessage?.value, terminalKmsArn); | ||
if (hasOriginalArn?.Some?) { | ||
return Types.MutationFromException( | ||
message := "Key Management denied access to the original KMS Key." | ||
+ " Mutation is halted. Check access to KMS ARN: " + item.KmsArn + "." | ||
+ "\n" + errorContext | ||
); | ||
} else if (hasTerminalArn?.Some?) { | ||
return Types.MutationToException( | ||
message := "Key Management denied access to the terminal KMS Key." | ||
+ " Mutation is halted. Check encrypt access to KMS ARN: " + terminalKmsArn + "." | ||
+ "\n" + errorContext | ||
); | ||
} | ||
} | ||
return Types.KeyStoreAdminException( | ||
|
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.
Just to confirm, this is a breaking change right?
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.
No. This is a nice way to do it.
KmsError
is a sub set type. So it is only some types ofTypes.Error
. This is a good mechanism to make sure that an operation only returns a specific set of errors.