-
Notifications
You must be signed in to change notification settings - Fork 65
Closed
Description
Problem:
I'm trying to decrypt kinesis RDS activity stream event enrypted with simple KMS
but it is failing with error 'unencryptedDataKey has not been set'
i'm not able to find, what's the problem
Code snippet:
console.log('Record: ', kinesis, rest);
const data = JSON.parse(Buffer.from(kinesis.data, 'base64').toString());
console.log('Record DATA: ', data);
const kms = new KMSClient({ region: awsRegion });
const params = {
CiphertextBlob: Buffer.from(data.key, 'base64'),
EncryptionContext: {
'aws:rds:dbc-id': [CLIENT-ID],
},
};
const command = new DecryptCommand(params);
const response = await kms.send(command);
console.log('Decrypted KEY: ', response);
const { decrypt } = buildClient(
CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT,
);
const keyring = new KmsKeyringNode({
generatorKeyId: [ALIAS-ARN],
keyIds: [response.KeyId],
});
console.log('Key ring: ', keyring);
const decryptedData = await decrypt(keyring, data.databaseActivityEvents, { encoding: 'base64' }); <<------ FAILING with error unencryptedDataKey has not been set
console.log('Decrypted DATA: ', decryptedData);
lambda policy with granted decrypt permision for kms ARN

KMS - symetric default / encrypt decrypt
KMS policy :
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
],
"Resource": "*"
}
node 18
aws-crypto 4.0.0
Metadata
Metadata
Assignees
Labels
No labels