-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(sagemaker): add sagemaker_endpoint_config_kms_encryption_enabled check (#11797) #11838
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
Open
goutham-hari
wants to merge
2
commits into
prowler-cloud:master
Choose a base branch
from
goutham-hari:sagemaker-endpoint-config-kms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions
1
...iders/aws/services/sagemaker/sagemaker_endpoint_config_kms_encryption_enabled/__init__.py
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 @@ | ||
| # empty init |
41 changes: 41 additions & 0 deletions
41
...fig_kms_encryption_enabled/sagemaker_endpoint_config_kms_encryption_enabled.metadata.json
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,41 @@ | ||
| { | ||
| "Provider": "aws", | ||
| "CheckID": "sagemaker_endpoint_config_kms_encryption_enabled", | ||
| "CheckTitle": "SageMaker endpoint configuration is encrypted with a KMS key", | ||
| "CheckType": [ | ||
| "Software and Configuration Checks/AWS Security Best Practices", | ||
| "Software and Configuration Checks/Industry and Regulatory Standards/AWS Foundational Security Best Practices", | ||
| "Effects/Data Exposure" | ||
| ], | ||
| "ServiceName": "sagemaker", | ||
| "SubServiceName": "", | ||
| "ResourceIdTemplate": "", | ||
| "Severity": "medium", | ||
| "ResourceType": "AwsSageMakerEndpointConfig", | ||
| "ResourceGroup": "ai_ml", | ||
| "Description": "**Amazon SageMaker endpoint configurations** are assessed for **at-rest encryption** using an AWS KMS key. The finding reflects whether a `KmsKeyId` is configured for the endpoint's ML volume encryption.", | ||
| "Risk": "Without **at-rest encryption** using a customer-managed KMS key, data on endpoint EBS volumes and snapshots can be exposed via storage access, copied backups, or host compromise, reducing **confidentiality** and limiting **key rotation** and **revocation** controls.", | ||
| "RelatedUrl": "", | ||
| "AdditionalURLs": [ | ||
| "https://docs.aws.amazon.com/sagemaker/latest/dg/key-management.html" | ||
| ], | ||
| "Remediation": { | ||
| "Code": { | ||
| "CLI": "aws sagemaker create-endpoint-config --endpoint-config-name <example_resource_name> --kms-key-id <example_resource_id> --production-variants file://production-variants.json", | ||
| "NativeIaC": "```yaml\n# CloudFormation: SageMaker endpoint config with KMS encryption\nResources:\n <example_resource_name>:\n Type: AWS::SageMaker::EndpointConfig\n Properties:\n KmsKeyId: <example_resource_id> # Critical: encrypts the endpoint config's EBS volume with the specified KMS key\n```", | ||
| "Other": "1. Open the AWS Console > Amazon SageMaker > Endpoint configurations\n2. Note the details of the failing endpoint configuration\n3. Click Create endpoint configuration\n4. Enter name and details identical to the previous one\n5. In Encryption key, select your KMS key\n6. Create the endpoint configuration\n7. Update any endpoints using the old config to use the new config\n8. Delete the old unencrypted endpoint configuration", | ||
| "Terraform": "```hcl\n# SageMaker endpoint config with KMS encryption\nresource \"aws_sagemaker_endpoint_configuration\" \"<example_resource_name>\" {\n name = \"<example_resource_name>\"\n kms_key_arn = \"<example_resource_arn>\" # Critical: enables EBS encryption using this KMS key\n}\n```" | ||
| }, | ||
| "Recommendation": { | ||
| "Text": "Use a **customer-managed KMS key** for endpoint ML volumes by setting `KmsKeyId`, and apply KMS to related S3 inputs/outputs. Enforce **least privilege** on key usage, enable **rotation**, and align key access with **defense in depth** to protect data at rest.", | ||
| "Url": "https://hub.prowler.com/check/sagemaker_endpoint_config_kms_encryption_enabled" | ||
| } | ||
| }, | ||
| "Categories": [ | ||
| "encryption", | ||
| "gen-ai" | ||
| ], | ||
| "DependsOn": [], | ||
| "RelatedTo": [], | ||
| "Notes": "" | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
...ndpoint_config_kms_encryption_enabled/sagemaker_endpoint_config_kms_encryption_enabled.py
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,20 @@ | ||
| from prowler.lib.check.models import Check, Check_Report_AWS | ||
| from prowler.providers.aws.services.sagemaker.sagemaker_client import sagemaker_client | ||
|
|
||
|
|
||
| class sagemaker_endpoint_config_kms_encryption_enabled(Check): | ||
| def execute(self): | ||
| findings = [] | ||
| for endpoint_config in sagemaker_client.endpoint_configs.values(): | ||
| report = Check_Report_AWS( | ||
| metadata=self.metadata(), resource=endpoint_config | ||
| ) | ||
| report.status = "PASS" | ||
| report.status_extended = f"Sagemaker Endpoint Config {endpoint_config.name} has KMS encryption enabled." | ||
| if not endpoint_config.kms_key_id: | ||
| report.status = "FAIL" | ||
| report.status_extended = f"Sagemaker Endpoint Config {endpoint_config.name} does not have KMS encryption enabled." | ||
|
|
||
| findings.append(report) | ||
|
|
||
| return findings |
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
112 changes: 112 additions & 0 deletions
112
...nt_config_kms_encryption_enabled/sagemaker_endpoint_config_kms_encryption_enabled_test.py
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,112 @@ | ||
| from unittest import mock | ||
| from uuid import uuid4 | ||
|
|
||
| from prowler.providers.aws.services.sagemaker.sagemaker_service import EndpointConfig | ||
| from tests.providers.aws.utils import ( | ||
| AWS_ACCOUNT_NUMBER, | ||
| AWS_REGION_EU_WEST_1, | ||
| set_mocked_aws_provider, | ||
| ) | ||
|
|
||
| test_endpoint_config = "test-endpoint-config" | ||
| endpoint_config_arn = f"arn:aws:sagemaker:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:endpoint-config/{test_endpoint_config}" | ||
| kms_key = str(uuid4()) | ||
|
|
||
|
|
||
| class Test_sagemaker_endpoint_config_kms_encryption_enabled: | ||
| def test_no_endpoint_configs(self): | ||
| sagemaker_client = mock.MagicMock | ||
| sagemaker_client.endpoint_configs = {} | ||
|
|
||
| aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
|
|
||
| with ( | ||
| mock.patch( | ||
| "prowler.providers.common.provider.Provider.get_global_provider", | ||
| return_value=aws_provider, | ||
| ), | ||
| mock.patch( | ||
| "prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_client", | ||
| sagemaker_client, | ||
| ), | ||
| ): | ||
| from prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled import ( | ||
| sagemaker_endpoint_config_kms_encryption_enabled, | ||
| ) | ||
|
|
||
| check = sagemaker_endpoint_config_kms_encryption_enabled() | ||
| result = check.execute() | ||
| assert len(result) == 0 | ||
|
|
||
| def test_endpoint_config_with_kms_key(self): | ||
| sagemaker_client = mock.MagicMock | ||
| sagemaker_client.endpoint_configs = {} | ||
| sagemaker_client.endpoint_configs[endpoint_config_arn] = EndpointConfig( | ||
| name=test_endpoint_config, | ||
| arn=endpoint_config_arn, | ||
| region=AWS_REGION_EU_WEST_1, | ||
| kms_key_id=kms_key, | ||
| ) | ||
|
|
||
| aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
|
|
||
| with ( | ||
| mock.patch( | ||
| "prowler.providers.common.provider.Provider.get_global_provider", | ||
| return_value=aws_provider, | ||
| ), | ||
| mock.patch( | ||
| "prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_client", | ||
| sagemaker_client, | ||
| ), | ||
| ): | ||
| from prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled import ( | ||
| sagemaker_endpoint_config_kms_encryption_enabled, | ||
| ) | ||
|
|
||
| check = sagemaker_endpoint_config_kms_encryption_enabled() | ||
| result = check.execute() | ||
| assert len(result) == 1 | ||
| assert result[0].status == "PASS" | ||
| assert ( | ||
| result[0].status_extended | ||
| == f"Sagemaker Endpoint Config {test_endpoint_config} has KMS encryption enabled." | ||
| ) | ||
| assert result[0].resource_id == test_endpoint_config | ||
| assert result[0].resource_arn == endpoint_config_arn | ||
|
|
||
| def test_endpoint_config_no_kms_key(self): | ||
| sagemaker_client = mock.MagicMock | ||
| sagemaker_client.endpoint_configs = {} | ||
| sagemaker_client.endpoint_configs[endpoint_config_arn] = EndpointConfig( | ||
| name=test_endpoint_config, | ||
| arn=endpoint_config_arn, | ||
| region=AWS_REGION_EU_WEST_1, | ||
| ) | ||
|
|
||
| aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
|
|
||
| with ( | ||
| mock.patch( | ||
| "prowler.providers.common.provider.Provider.get_global_provider", | ||
| return_value=aws_provider, | ||
| ), | ||
| mock.patch( | ||
| "prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_client", | ||
| sagemaker_client, | ||
| ), | ||
| ): | ||
| from prowler.providers.aws.services.sagemaker.sagemaker_endpoint_config_kms_encryption_enabled.sagemaker_endpoint_config_kms_encryption_enabled import ( | ||
| sagemaker_endpoint_config_kms_encryption_enabled, | ||
| ) | ||
|
|
||
| check = sagemaker_endpoint_config_kms_encryption_enabled() | ||
| result = check.execute() | ||
| assert len(result) == 1 | ||
| assert result[0].status == "FAIL" | ||
| assert ( | ||
| result[0].status_extended | ||
| == f"Sagemaker Endpoint Config {test_endpoint_config} does not have KMS encryption enabled." | ||
| ) | ||
| assert result[0].resource_id == test_endpoint_config | ||
| assert result[0].resource_arn == endpoint_config_arn |
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.