-
Notifications
You must be signed in to change notification settings - Fork 2
Example storage of secret and timed renewal #24
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?
Conversation
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.
I am still pretty confused about what the use case for this is? What are you trying to actually achieve here?
All in all I think this is a pretty bad idea, the code doesn't belong in a script, the keys shouldn't be stored in a JSON store or in a script.
try { | ||
LOG.info('Starting secure string encryption example...'); | ||
|
||
const secretKey = 'MySecureEncryptionKey123456789012'; // 32 characters for AES-256 |
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!
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.
Yes I know the key can't go here but I figured we could discuss where to put it and if there is somewhere safe to do this.
I've updated the description with the reasoning why I put any time into this. I also wasn't originally sure if this was going to be possible safely so instead of taking up a bunch of everyones time I code up a few examples quickly using Junie and put them out here for us to discuss. I orignally wanted to use the Mango keystore for this but I'm not sure how to store random strings in it. |
Upon further investigation I could probably do something like this using a
|
Ha ha, I just found this class when looking at our script tools in Mango: I was looking at a way to create a Global lock, which can easily be done by adding another Binding in the Java Code that contains code to handling the locking so that in the scripts one could do this:
But this is plenty of rope to hang yourself with, and I'm pretty against putting a way to lock code into the script environment. |
However I would be for adding a global map storage that we can use to persist data between scripts. Then if someone was tricky enough they could create and store a lock there... This seems like a better idea. I don't think we currently support that, if we did it would look something like this to allow us to add bindings at runtime:
Usage:
|
After discussion we have come up with some alternative ways to accomplish this:
The token doesn't need be stored in an encrypted state, just protected from other user's viewing. This use-case is probably a little extreme for a Script in Mango. |
Overview
The use case for this is to allow a Mango user to write a script that can refresh an API Key on a set interval so they can continue to use an API from an Event Handler that needs to use an API with a Key Rotation requirement. We cannot know when the event handler will be activated so we must rely on some other mechanism to refresh the keys before they expire.
The traditional way of doing this would be to make the request and if it fails to authenticate just renew the token. The reason we are trying a new approach is due to this happening many times at the same time from Event Handler. So I think a global locking mechanism to reload the token could be used, but at the risk of backing up all the event handlers that are waiting on a key.
Goals
These examples attempt to accomplish 2 things:
Concerns
The main concerns I want reviewed are:
Concept
The idea is that the script will generate a secret into the JSON Data Store and allow you to schedule a timer task to reload it using a callback so you can control how the secret is created. When you want to stop the task you update the JSON Data entry to have
shouldRegenerate
=false