Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ $ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline

```bash
$ detect-secrets scan --list-all-plugins
AmazonBedrockApiKeyDetector
ArtifactoryDetector
AWSKeyDetector
AzureStorageKeyDetector
Expand Down
18 changes: 18 additions & 0 deletions detect_secrets/plugins/amazon_bedrock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
This plugin searches for Amazon Bedrock API keys
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector

class AmazonBedrockApiKeyDetector(RegexBasedDetector):
"""Scans for Amazon Bedrock API keys."""
secret_type = 'Amazon Bedrock API key'

denylist = [
# refs https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html
# Long-lived keys begin with ABSK
re.compile(r'(?<![A-Za-z0-9+/=])ABSK[A-Za-z0-9+/]{109,269}={0,2}(?![A-Za-z0-9+/=])'),
# Short-lived keys begin with bedrock-api-key-
re.compile(r'bedrock-api-key-YmVkcm9jay5hbWF6b25hd3MuY29t')
]
21 changes: 21 additions & 0 deletions tests/plugins/amazon_bedrock_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from detect_secrets.plugins.amazon_bedrock import AmazonBedrockApiKeyDetector


class TestAmazonBedrockDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('ABSKQmVkcm9ja0FQSUtleS1EXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXM=', True),
('ABSKQmVkcm9ja0FQSUtleS1', False),
('bedrock-api-key-YmVkcm9jay5hbWF6b25hd3MuY29tEXAMPLE', True),
('bedrock-api-key', False),
],
)
def test_analyze(self, payload, should_flag):
logic = AmazonBedrockApiKeyDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)

assert len(output) == int(should_flag)