feat(token hook): allow a custom header for the Azure token hook - #64
Merged
Conversation
DROID_AZURE_TOKEN_HEADER and DROID_AZURE_TOKEN_HEADER_VALUE define a custom header to send to the Azure token hook, taking precedence over the default X-API-Key header sourced from DROID_AZURE_TOKEN_X_API_KEY. Setting only one of the two raises an error to avoid a confusing 401 from the hook. The header logic is moved to a shared get_token_hook_headers() function used by both the Sentinel and Microsoft XDR platforms, and covered by unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Azure token hook was hardcoded to send its credential in an
X-API-Keyheader, which does not work with gateways expecting a different header name. This adds support for an arbitrary header name and value while keeping the existing behaviour untouched.Changes
get_token_hook_headers()insrc/droid/platforms/common.pyas the single source of truth for the token hook headers.DROID_AZURE_TOKEN_HEADERandDROID_AZURE_TOKEN_HEADER_VALUEto define a custom header.ValueErrorwhen only one of the two variables is set, instead of silently sending no header.sentinel.pyandms_xdr.py, removing the duplicated header logic.Behaviour
DROID_AZURE_TOKEN_X_API_KEYX-API-Key: <value>DROID_AZURE_TOKEN_HEADER+DROID_AZURE_TOKEN_HEADER_VALUE<name>: <value>DROID_AZURE_TOKEN_X_API_KEYValueError, no request sentExisting setups relying on
DROID_AZURE_TOKEN_X_API_KEYare unaffected.Tests
tests/test_platforms_common.pycovers the header resolution logic and the error cases.tests/test_token_hook.pycovers the end to end behaviour for both Sentinel and MS XDR, asserting the headers actually passed torequests.getand that no request is made when the configuration is incomplete.