-
Notifications
You must be signed in to change notification settings - Fork 45
Use FIPs endpoints in Govcloud regions #575
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
Merged
nhulston
merged 11 commits into
main
from
nicholas.hulston/use-fips-endpoints-in-gov-regions
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a41cbb3
use fips endpoints in govcloud regions
nhulston ca7e5c5
lint
nhulston bbf8042
log when using fips endpoints
nhulston 0c4fdc4
lint
nhulston 6d5ff78
lint
nhulston f054e22
lint again
nhulston af87910
change to debug
nhulston 7fdd7e8
add unit test
nhulston 6396cef
lint
nhulston 7411cf2
fix `test_no_fips_for_standard_regions`
nhulston 2b02f02
lint
nhulston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
|
||
import datadog_lambda.api as api | ||
|
||
|
||
class TestDatadogLambdaAPI(unittest.TestCase): | ||
def setUp(self): | ||
api.api_key = None | ||
self.env_patcher = patch.dict( | ||
os.environ, | ||
{ | ||
"DD_API_KEY_SECRET_ARN": "", | ||
"DD_API_KEY_SSM_NAME": "", | ||
"DD_KMS_API_KEY": "", | ||
"DD_API_KEY": "", | ||
"DATADOG_API_KEY": "", | ||
"AWS_REGION": "", | ||
}, | ||
clear=True, | ||
) | ||
self.env_patcher.start() | ||
|
||
@patch("boto3.client") | ||
def test_secrets_manager_fips_endpoint(self, mock_boto3_client): | ||
mock_client = MagicMock() | ||
mock_client.get_secret_value.return_value = {"SecretString": "test-api-key"} | ||
mock_boto3_client.return_value = mock_client | ||
|
||
os.environ["AWS_REGION"] = "us-gov-east-1" | ||
os.environ["DD_API_KEY_SECRET_ARN"] = "test-secrets-arn" | ||
|
||
api_key = api.get_api_key() | ||
|
||
mock_boto3_client.assert_called_with( | ||
"secretsmanager", | ||
endpoint_url="https://secretsmanager-fips.us-gov-east-1.amazonaws.com", | ||
) | ||
self.assertEqual(api_key, "test-api-key") | ||
|
||
@patch("boto3.client") | ||
def test_ssm_fips_endpoint(self, mock_boto3_client): | ||
mock_client = MagicMock() | ||
mock_client.get_parameter.return_value = { | ||
"Parameter": {"Value": "test-api-key"} | ||
} | ||
mock_boto3_client.return_value = mock_client | ||
|
||
os.environ["AWS_REGION"] = "us-gov-west-1" | ||
os.environ["DD_API_KEY_SSM_NAME"] = "test-ssm-param" | ||
|
||
api_key = api.get_api_key() | ||
|
||
mock_boto3_client.assert_called_with( | ||
"ssm", endpoint_url="https://ssm-fips.us-gov-west-1.amazonaws.com" | ||
) | ||
self.assertEqual(api_key, "test-api-key") | ||
|
||
@patch("boto3.client") | ||
@patch("datadog_lambda.api.decrypt_kms_api_key") | ||
def test_kms_fips_endpoint(self, mock_decrypt_kms, mock_boto3_client): | ||
mock_client = MagicMock() | ||
mock_boto3_client.return_value = mock_client | ||
mock_decrypt_kms.return_value = "test-api-key" | ||
|
||
os.environ["AWS_REGION"] = "us-gov-west-1" | ||
os.environ["DD_KMS_API_KEY"] = "encrypted-api-key" | ||
|
||
api_key = api.get_api_key() | ||
|
||
mock_boto3_client.assert_called_with( | ||
"kms", endpoint_url="https://kms-fips.us-gov-west-1.amazonaws.com" | ||
) | ||
self.assertEqual(api_key, "test-api-key") | ||
|
||
@patch("boto3.client") | ||
def test_no_fips_for_standard_regions(self, mock_boto3_client): | ||
mock_client = MagicMock() | ||
mock_client.get_secret_value.return_value = {"SecretString": "test-api-key"} | ||
mock_boto3_client.return_value = mock_client | ||
|
||
os.environ.clear() | ||
os.environ["AWS_REGION"] = "us-west-2" | ||
os.environ["DD_API_KEY_SECRET_ARN"] = "test-arn" | ||
|
||
api.get_api_key() | ||
|
||
mock_boto3_client.assert_called_with("secretsmanager", endpoint_url=None) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.