-
Notifications
You must be signed in to change notification settings - Fork 8
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
600: Cached Our Private Key Only After Successful Auth with RS #604
Conversation
...main/java/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSender.java
Show resolved
Hide resolved
...main/java/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSender.java
Show resolved
Hide resolved
...main/java/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSender.java
Outdated
Show resolved
Hide resolved
var senderPrivateKey = | ||
"trusted-intermediary-private-key-" + ApplicationContext.getEnvironment(); | ||
String key = this.keyCache.get(senderPrivateKey); | ||
String key = keyCache.get(OUR_PRIVATE_KEY_ID); | ||
if (key != null) { | ||
return key; |
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.
For record keeping. We still need to have a system in place that will change our private key in the cache, when it expires or when it is not valid.
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.
Exactly! Thanks for calling that out and adding that item to our engineering task list channel.
token = extractToken(rsResponse); | ||
} catch (Exception e) { | ||
throw new UnableToSendOrderException( | ||
"Error getting the API token from ReportStream", e); | ||
} | ||
|
||
// only cache our private key if we successfully authenticate to RS | ||
cachePrivateKeyIfNotCachedAlready(ourPrivateKey); |
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.
Great work here. I wonder since cachePrivateKeyIfNotCachedAlready()
deals with only our private key, what are your thoughts on renaming it cacheOurPrivateKeyIfNotCachedAlready()
?
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.
Great idea. I'll do that!
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.
Fixed.
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.
Great work. I only had some comments but everything looks good.
Kudos, SonarCloud Quality Gate passed! |
Cached Our Private Key Only After Successful Auth with RS
Before this PR, we cached our private key after retrieving it no matter what happened. This prevented us from having to continually call Azure for our secret each time we need to login to ReportStream (which is about every 5 minutes). But, if the key was bad for some reason, we would fail to login to RS in perpetuity until we restarted our application (which would clear the cache). This happened because once we retrieved the secret, we cached it without ever clearing it.
Now, we don't even cache our private key in the first place if we fail to login to RS. We also only cache the key if it wasn't already cached. This prevents us from continuously caching the key whenever we successfully authenticate with a key that was already cached.
Issue
#600.
Checklist