-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(custom resources): Can not get public key for a KMS key #19065
Comments
The same issue with CDK 2.20.0. |
I wonder if this is because the response is a |
Unfortunately, I'm not sure CDK can do much here - we don't really control wha the response from the services is. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Maybe it's a matter of reformatting (I'm sorry if the word is not the proper one) the command output to a sort of human readable? After all, the |
The fact that you get that error message might also suggest that the response was an "Access Denied", which is not a JSON object. Can you try temporarly giving the Custom Resource admin permissions, and see if that changes anything? (I guess also allow all principals from the account |
@skinny85 thanks for the answer. I've tried what you asked for, but still receiving |
Hmm, I'm kind of lost then. Maybe I would try to do a call using the JavaScript AWS SDK, and see what response it gives me there perhaps...? |
The SDK returns this object. Of particular interest is PublicKey, which is a Uint8Array (i.e. it's not a base64-encoded string). |
Interesting! That's probably the source of the |
Edit: This comment is in response to a now-deleted comment pointing out this line as a potential cause for the error: const childKey = Buffer.isBuffer(child[key]) ? child[key].toString('utf8') : child[key]; I don't think this is what's causing the "not valid JSON" error, but I'd like to point out that decoding an arbitrary buffer with |
Had the same issue as everyone here. The line @johannes-sscrc linked does seem to be related to the error. Indeed, Publickey seems to be in a binary format: DER, and the proper way to encode it appears to be base64 and not utf8. Thus, a quick fix for me was to replace the above line with: const childKey = Buffer.isBuffer(child[key]) ? child[key].toString('base64') : child[key]; Then the PublicKey is returned in base64, and there's no error anymore. Generally, it would be good to have a hook/param here to allow the caller to specify how to encode the buffer for specific keys, in order to unblock such issues in the general case. |
@sashee did you end up finding a work-around for getting the public key of a KMS key using a custom resource? I'm getting the same invalid JSON error. |
@synthetic-luis , yeah, a custom resource can fetch the public key and output it for other resources. Unfortunately, I can't provide code example as it was done for a client, but the implementation was straightforward. |
@sashee thanks for the response. Can you please elaborate on how you then overcame the invalid JSON issue (in general terms) as it relates to the code you posted above? For example, did you have to change your code above (e.g. add a new parameter to the |
@synthetic-luis , I just checked the code and I remember wrongly. So I needed a keypair for IVS playback key and I thought to use KMS for that. It did not work (partly because of the issue here) so I implemented a lambda function that generates the key. Not the ideal solution, but it works reliably so far. |
@sashee this helps a lot. Thank you! |
Would love to have a fix or workaround for this. |
@DanielLaberge if it helps, what worked for me was creating a post deploy script that uses the KMS SDK to do what I needed to do |
What is the problem?
I tried to extract the public key for an asymmetric KMS key but I get a
Response is not valid JSON
error.Reproduction Steps
What did you expect to happen?
I expected that the stack deploys and I can extract the public key.
What actually happened?
Response is not valid JSON
In the CloudWatch Logs, I see that the PublicKey is retrieved, but it seems in a unusable format:
CDK CLI Version
2.12.0
Framework Version
No response
Node.js Version
v16.14.0
OS
Ubuntu
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: