I'm trying to write a transformation which in part...
# support
t
I'm trying to write a transformation which in part computes a SHA256 HMAC Signature. However, the built in libraries do not have an HMAC function, nor can I import a crypto library with
const crypto = require('crypto');
as it throws an error about using
require
. I've tried
import crypto from 'crypto'
and
import { createHmac } from 'crypto';
but still no luck. Are there any solutions for this?
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
Hi Trevin, as you are aware you cannot use imports within the libraries. So if you want to create a library it has to be vanilla JS. Alternately you can make an API request within a user transformation to get the computed HMAC SHA signature I will raise a request to the team if we can add HMAC SHA Signature as a function an expose it.
t
Do you have recommendations on storing secrets in rudderstack? For example, to make a signing function useful, it needs a secret key. But if that key is not kept secret then it's not helpful.
m
So this recommendation on storing secrets is for the SHA256 HMAC signature right? So these 2 request (addition of SHA256 HMAC Signature functionality and the ability to store the secret_key in an environment variable so that it can be fetched at run-time and used) would go in tandem ? Is my understanding correct?
t
well let's backup actually. What I'm trying to do is validate that a request to our webhooks are coming from rudderstack. Normally this is done with some HMAC Signature that a service like rudderstack would do. They would use a secret key in our account, that they then use to compute an HMAC signature of the webhook body, and then include that signature as part of the payload. Then on our side, we can use that same secret key to compute the signature to verify it's legit. I don't see any security measures like this for rudderstack in place which surprises me
m
Hi Trevin I understand the use case and have shared it with the team. The team is looking to take up the feature to build a parameter store in Q4 (Nov 2023 - Jan 2024). So technically this is 2 separate requests 1. To support SHA 256 HMAC Signature in the Transformation Library 2. To support a Parameter store when you can keep your secrets and then refer to them in your User Transformations / Libraries
g
Interesting use case @thankful-gpu-70135 While it can be made easier and more reliable to implement when the above two features are present, I do see that it is possible to implement even without these features 1. Write the SHA256 hmac code in vanilla js (found this relevant code gist online) 2. Just use a js variable string as a secret key. If the transformations code (or rudderstack account) is not shared with anyone (which is usually the case) and it is cloud transformation you're performing, only you know this secret code. Am I missing anything?
m
Hi Pradeep 1. This should technically work. Nice find 2. Ideally these secrets should not be visible to even the RudderStack team. There is value in having a Parameter store where you can store your secrets and they are fetched at Runtime.
t
Thanks both for responding. I think managing our own implementation of SHA256 HMAC is not ideal.. this should just be a central library. If that vanilla js works, can you just add that to the built in libraries? Secondly, @shy-kite-21035 is correct that these secrets shouldn't be visible. Lastly, it's far less error prone if this was a built in configuration option in the webhook desitnation vs us needing to write a transformation for it. Many plans are oddly limited to 5 transformations.
👍 1
g
Agree. Feedback is noted.