Skip to content
Merged
Changes from 1 commit
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
34 changes: 32 additions & 2 deletions src/ghas.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ def get_secret_alerts(
github_hostname: str,
org: str,
secret_factory: secret_mgmt.SecretFactory,
secret_types: tuple[str, ...] = (
'ec_private_key',
'generic_private_key',
'http_basic_authentication_header',
'http_bearer_authentication_header',
'mongodb_connection_string',
'mysql_connection_url',
'openssh_private_key',
'pgp_private_key',
'postgres_connection_string',
'rsa_private_key',
), # https://docs.github.com/en/code-security/reference/secret-security/supported-secret-scanning-patterns#supported-generic-patterns
) -> collections.abc.Generator[SecretAlert]:
"""
Fetch open secret scanning alerts using authenticated GitHub client.
Expand All @@ -171,12 +183,31 @@ def get_secret_alerts(
)

count = 0
seen_urls = set()

# default alerts
for alert_raw in github_api_request_paginated(
url=url,
secret_factory=secret_factory,
):
count += 1
yield dacite.from_dict(SecretAlert, alert_raw)
alert = dacite.from_dict(SecretAlert, alert_raw)
yield alert
seen_urls.add(alert.url)

# generic alerts
url = f'{url}&secret_type={",".join(secret_types)}'

for alert_raw in github_api_request_paginated(
url=url,
secret_factory=secret_factory,
):
alert = dacite.from_dict(SecretAlert, alert_raw)
if alert.url not in seen_urls:
# deduplicating, as we are effectively quering the same data source twice
Comment thread
zkdev marked this conversation as resolved.
seen_urls.add(alert.url)
yield alert
count += 1

logger.info(f'found {count} secret alerts for {github_hostname}/{org}')

Expand Down Expand Up @@ -441,7 +472,6 @@ def scan(
all_metadata_keys = set()

now = datetime.datetime.now(tz=datetime.timezone.utc)

all_existing_metadata = [
odg.model.ArtefactMetadata.from_dict(raw)
for raw in delivery_service_client.query_metadata(
Expand Down