mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-06-11 05:46:05 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ed3b5b8ba | |||
| 3e7b429189 | |||
| 983275a013 | |||
| f2965bbc26 | |||
| 90225380cf | |||
| 600abbae93 | |||
| 75f95559d6 | |||
| e085e14247 | |||
| 368d3a2661 | |||
| 3c8fde25ee | |||
| ec0bb53839 | |||
| bfb3fcea4c | |||
| 61cd4aea3f | |||
| 01b49f0743 | |||
| 4a5a49b5bb | |||
| a21cb64a94 |
@@ -134,7 +134,17 @@ jobs:
|
||||
# docker-compose.yml references prowlercloud/prowler-api:latest from the registry,
|
||||
# which lags behind PR changes; build locally so E2E exercises the API image
|
||||
# produced by this PR.
|
||||
run: docker build -t prowlercloud/prowler-api:latest ./api
|
||||
#
|
||||
# The image installs the SDK from git@master (api/uv.lock), so a PR changing BOTH the SDK
|
||||
# and the API would run against the OLD SDK and crash on startup. Overlay the checkout's
|
||||
# SDK source so both run together. New SDK dependencies still need an api/uv.lock bump.
|
||||
run: |
|
||||
docker build -t prowlercloud/prowler-api:pr-base ./api
|
||||
docker build -t prowlercloud/prowler-api:latest -f - prowler <<'DOCKERFILE'
|
||||
FROM prowlercloud/prowler-api:pr-base
|
||||
RUN rm -rf /home/prowler/.venv/lib/python3.12/site-packages/prowler
|
||||
COPY --chown=prowler:prowler . /home/prowler/.venv/lib/python3.12/site-packages/prowler
|
||||
DOCKERFILE
|
||||
|
||||
- name: Start API services
|
||||
run: |
|
||||
|
||||
@@ -122,7 +122,7 @@ Every AWS provider scan will enqueue an Attack Paths ingestion job automatically
|
||||
| Vercel | 26 | 6 | 0 | 8 | Official | UI, API, CLI |
|
||||
| Okta | 1 | 1 | 0 | 1 | Official | CLI |
|
||||
| Scaleway [Contact us](https://prowler.com/contact) | 1 | 1 | 0 | 1 | Unofficial | CLI |
|
||||
| StackIT [Contact us](https://prowler.com/contact) | 4 | 1 | 0 | 1 | Unofficial | CLI |
|
||||
| StackIT [Contact us](https://prowler.com/contact) | 7 | 2 | 0 | 3 | Unofficial | CLI |
|
||||
| NHN | 6 | 2 | 1 | 0 | Unofficial | CLI |
|
||||
|
||||
> [!Note]
|
||||
|
||||
@@ -9,6 +9,7 @@ All notable changes to the **Prowler API** are documented in this file.
|
||||
- Opt-in automatic recovery of allowlisted idempotent background tasks whose worker died during a deploy or crash: when enabled via `DJANGO_TASK_RECOVERY_ENABLED` (off by default), stuck summary and deletion tasks are detected and re-run instead of staying pending forever (scan and Jira tasks are excluded), with a `reconcile_orphan_tasks` management command for on-demand recovery [(#11416)](https://github.com/prowler-cloud/prowler/pull/11416)
|
||||
- DORA compliance framework support [(#11131)](https://github.com/prowler-cloud/prowler/pull/11131)
|
||||
- Label Postgres connections with `application_name="<component>:<alias>"` (component injected per process via `DJANGO_APP_COMPONENT`) so connections are attributable by component in `pg_stat_activity` [(#11494)](https://github.com/prowler-cloud/prowler/pull/11494)
|
||||
- DISA Okta IDaaS STIG V1R2 compliance framework export support for the Okta provider [(#11428)](https://github.com/prowler-cloud/prowler/pull/11428)
|
||||
|
||||
### 🔄 Changed
|
||||
|
||||
@@ -17,6 +18,8 @@ All notable changes to the **Prowler API** are documented in this file.
|
||||
### 🐞 Fixed
|
||||
|
||||
- Workers now shut down gracefully on deploy or restart, finishing or re-queueing in-flight tasks instead of being force-killed and leaving them stuck [(#11416)](https://github.com/prowler-cloud/prowler/pull/11416)
|
||||
- Resource `name` is now stored and refreshed on every scan, so resources no longer keep an empty name [(#11476)](https://github.com/prowler-cloud/prowler/pull/11476)
|
||||
- Compliance catalog now warms in a background thread after each worker forks, and `compliance-overviews/attributes` returns `503` while warming, so the first request after a deploy no longer trips the Gunicorn worker timeout [(#4554)](https://github.com/prowler-cloud/prowler-cloud/pull/4554)
|
||||
|
||||
### 🔐 Security
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
import threading
|
||||
from collections.abc import Iterable, Mapping
|
||||
|
||||
from api.models import Provider
|
||||
@@ -6,8 +8,19 @@ from prowler.lib.check.compliance_models import (
|
||||
)
|
||||
from prowler.lib.check.models import CheckMetadata
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
AVAILABLE_COMPLIANCE_FRAMEWORKS = {}
|
||||
|
||||
# Per-process readiness flags for the background compliance warm-up.
|
||||
# `STARTED` is set as soon as warming begins (only happens under Gunicorn via
|
||||
# the post_fork hook); `WARMED` is set when it finishes. The attributes
|
||||
# endpoint checks both: it returns 503 only while warming is in progress.
|
||||
# Under `runserver` warming never runs, so `STARTED` stays clear and the
|
||||
# endpoint keeps lazy-loading as before.
|
||||
COMPLIANCE_WARMING_STARTED = threading.Event()
|
||||
COMPLIANCE_WARMED = threading.Event()
|
||||
|
||||
|
||||
class LazyComplianceTemplate(Mapping):
|
||||
"""Lazy-load compliance templates per provider on first access."""
|
||||
@@ -174,6 +187,56 @@ def _ensure_provider_loaded(provider_type: Provider.ProviderChoices) -> None:
|
||||
PROWLER_CHECKS._cache[provider_type] = checks
|
||||
|
||||
|
||||
def warm_compliance_caches(
|
||||
provider_types: Iterable[str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
Eagerly populate the per-process compliance caches at server startup.
|
||||
|
||||
Moves the cold-cache catalog load off the request thread so the first
|
||||
request does not trip the Gunicorn worker timeout. Reads only on-disk
|
||||
metadata (no database access). Each provider is warmed in isolation;
|
||||
failures are logged and fall back to lazy loading.
|
||||
|
||||
Args:
|
||||
provider_types (Iterable[str] | None): Subset to warm. Defaults to all.
|
||||
|
||||
Returns:
|
||||
list[str]: Provider types that could not be warmed.
|
||||
"""
|
||||
if provider_types is None:
|
||||
provider_types = Provider.ProviderChoices.values
|
||||
provider_types = list(provider_types)
|
||||
|
||||
COMPLIANCE_WARMING_STARTED.set()
|
||||
logger.info("Compliance cache warm-up started for providers: %s", provider_types)
|
||||
|
||||
failed = []
|
||||
for provider_type in provider_types:
|
||||
try:
|
||||
get_compliance_frameworks(provider_type)
|
||||
_ensure_provider_loaded(provider_type)
|
||||
# Prowler check loading may sys.exit (SystemExit, not Exception).
|
||||
except (Exception, SystemExit):
|
||||
logger.warning(
|
||||
"Failed to warm compliance caches for provider '%s'; "
|
||||
"loading lazily on first request",
|
||||
provider_type,
|
||||
exc_info=True,
|
||||
)
|
||||
failed.append(provider_type)
|
||||
|
||||
# Mark as warmed even when some providers failed: a failed provider falls
|
||||
# back to a single-provider lazy load, which stays under the worker timeout.
|
||||
COMPLIANCE_WARMED.set()
|
||||
logger.info(
|
||||
"Compliance cache warm-up finished (providers warmed: %d, failed: %s)",
|
||||
len(provider_types) - len(failed),
|
||||
failed,
|
||||
)
|
||||
return failed
|
||||
|
||||
|
||||
def load_prowler_checks(
|
||||
prowler_compliance, provider_types: Iterable[str] | None = None
|
||||
):
|
||||
|
||||
@@ -187,6 +187,32 @@ class UpstreamServiceUnavailableError(APIException):
|
||||
)
|
||||
|
||||
|
||||
class ComplianceWarmingError(APIException):
|
||||
"""Compliance catalog is still warming (503 Service Unavailable).
|
||||
|
||||
Returned by the compliance attributes endpoint while the per-process
|
||||
catalog warm-up is in progress, so the request thread never triggers the
|
||||
slow cold load that would trip the Gunicorn worker timeout.
|
||||
"""
|
||||
|
||||
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
|
||||
default_detail = (
|
||||
"Compliance data is still loading. Please try again in a few seconds."
|
||||
)
|
||||
default_code = "compliance_warming"
|
||||
|
||||
def __init__(self, detail=None):
|
||||
super().__init__(
|
||||
detail=[
|
||||
{
|
||||
"detail": detail or self.default_detail,
|
||||
"status": str(self.status_code),
|
||||
"code": self.default_code,
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class UpstreamInternalError(APIException):
|
||||
"""Unexpected error communicating with provider (500 Internal Server Error).
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from api.compliance import (
|
||||
get_prowler_provider_checks,
|
||||
get_prowler_provider_compliance,
|
||||
load_prowler_checks,
|
||||
warm_compliance_caches,
|
||||
)
|
||||
from api.models import Provider
|
||||
from prowler.lib.check.compliance_models import (
|
||||
@@ -267,11 +268,17 @@ def reset_compliance_cache():
|
||||
"""Reset the module-level cache so each test starts cold."""
|
||||
previous = dict(compliance_module.AVAILABLE_COMPLIANCE_FRAMEWORKS)
|
||||
compliance_module.AVAILABLE_COMPLIANCE_FRAMEWORKS.clear()
|
||||
# The warming flags are module-global; clear them so they do not leak
|
||||
# between tests that call warm_compliance_caches.
|
||||
compliance_module.COMPLIANCE_WARMING_STARTED.clear()
|
||||
compliance_module.COMPLIANCE_WARMED.clear()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
compliance_module.AVAILABLE_COMPLIANCE_FRAMEWORKS.clear()
|
||||
compliance_module.AVAILABLE_COMPLIANCE_FRAMEWORKS.update(previous)
|
||||
compliance_module.COMPLIANCE_WARMING_STARTED.clear()
|
||||
compliance_module.COMPLIANCE_WARMED.clear()
|
||||
|
||||
|
||||
class TestGetComplianceFrameworks:
|
||||
@@ -321,3 +328,89 @@ class TestGetComplianceFrameworks:
|
||||
f"loadable by get_bulk_compliance_frameworks_universal: "
|
||||
f"{sorted(missing)}"
|
||||
)
|
||||
|
||||
|
||||
class TestWarmComplianceCaches:
|
||||
def test_warms_all_provider_types_by_default(self, reset_compliance_cache):
|
||||
provider_types = list(Provider.ProviderChoices.values)
|
||||
with (
|
||||
patch("api.compliance.get_compliance_frameworks") as mock_frameworks,
|
||||
patch("api.compliance._ensure_provider_loaded") as mock_ensure,
|
||||
):
|
||||
warm_compliance_caches()
|
||||
|
||||
warmed = {call.args[0] for call in mock_frameworks.call_args_list}
|
||||
assert warmed == set(provider_types)
|
||||
assert mock_frameworks.call_count == len(provider_types)
|
||||
assert mock_ensure.call_count == len(provider_types)
|
||||
|
||||
def test_warms_only_requested_provider_types(self, reset_compliance_cache):
|
||||
with (
|
||||
patch("api.compliance.get_compliance_frameworks") as mock_frameworks,
|
||||
patch("api.compliance._ensure_provider_loaded") as mock_ensure,
|
||||
):
|
||||
warm_compliance_caches([Provider.ProviderChoices.AWS])
|
||||
|
||||
mock_frameworks.assert_called_once_with(Provider.ProviderChoices.AWS)
|
||||
mock_ensure.assert_called_once_with(Provider.ProviderChoices.AWS)
|
||||
|
||||
def test_populates_module_cache(self, reset_compliance_cache):
|
||||
with (
|
||||
patch(
|
||||
"api.compliance.get_bulk_compliance_frameworks_universal"
|
||||
) as mock_get_bulk,
|
||||
patch("api.compliance._ensure_provider_loaded"),
|
||||
):
|
||||
mock_get_bulk.return_value = {"cis_1.4_aws": MagicMock()}
|
||||
warm_compliance_caches([Provider.ProviderChoices.AWS])
|
||||
|
||||
assert (
|
||||
Provider.ProviderChoices.AWS
|
||||
in compliance_module.AVAILABLE_COMPLIANCE_FRAMEWORKS
|
||||
)
|
||||
|
||||
def test_failing_provider_does_not_abort_the_rest(self, reset_compliance_cache):
|
||||
"""A failing provider (even on SystemExit) is isolated; others warm."""
|
||||
providers = [Provider.ProviderChoices.AWS, Provider.ProviderChoices.OKTA]
|
||||
|
||||
def fake_frameworks(provider_type):
|
||||
if provider_type == Provider.ProviderChoices.OKTA:
|
||||
raise SystemExit(1)
|
||||
return []
|
||||
|
||||
with (
|
||||
patch(
|
||||
"api.compliance.get_compliance_frameworks", side_effect=fake_frameworks
|
||||
),
|
||||
patch("api.compliance._ensure_provider_loaded") as mock_ensure,
|
||||
):
|
||||
failed = warm_compliance_caches(providers)
|
||||
|
||||
assert failed == [Provider.ProviderChoices.OKTA]
|
||||
mock_ensure.assert_called_once_with(Provider.ProviderChoices.AWS)
|
||||
|
||||
def test_sets_readiness_flags(self, reset_compliance_cache):
|
||||
assert not compliance_module.COMPLIANCE_WARMING_STARTED.is_set()
|
||||
assert not compliance_module.COMPLIANCE_WARMED.is_set()
|
||||
|
||||
with (
|
||||
patch("api.compliance.get_compliance_frameworks"),
|
||||
patch("api.compliance._ensure_provider_loaded"),
|
||||
):
|
||||
warm_compliance_caches([Provider.ProviderChoices.AWS])
|
||||
|
||||
assert compliance_module.COMPLIANCE_WARMING_STARTED.is_set()
|
||||
assert compliance_module.COMPLIANCE_WARMED.is_set()
|
||||
|
||||
def test_marks_warmed_even_when_a_provider_fails(self, reset_compliance_cache):
|
||||
"""A failed provider still leaves the caches flagged as warmed."""
|
||||
with (
|
||||
patch(
|
||||
"api.compliance.get_compliance_frameworks",
|
||||
side_effect=SystemExit(1),
|
||||
),
|
||||
patch("api.compliance._ensure_provider_loaded"),
|
||||
):
|
||||
warm_compliance_caches([Provider.ProviderChoices.AWS])
|
||||
|
||||
assert compliance_module.COMPLIANCE_WARMED.is_set()
|
||||
|
||||
@@ -9578,6 +9578,39 @@ class TestComplianceOverviewViewSet:
|
||||
)
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
def test_compliance_overview_attributes_503_while_warming(
|
||||
self, authenticated_client
|
||||
):
|
||||
from api.compliance import COMPLIANCE_WARMED, COMPLIANCE_WARMING_STARTED
|
||||
|
||||
COMPLIANCE_WARMING_STARTED.set()
|
||||
COMPLIANCE_WARMED.clear()
|
||||
try:
|
||||
response = authenticated_client.get(
|
||||
reverse("complianceoverview-attributes"),
|
||||
{"filter[compliance_id]": "aws_account_security_onboarding_aws"},
|
||||
)
|
||||
finally:
|
||||
COMPLIANCE_WARMING_STARTED.clear()
|
||||
|
||||
assert response.status_code == status.HTTP_503_SERVICE_UNAVAILABLE
|
||||
assert response.json()["errors"][0]["code"] == "compliance_warming"
|
||||
|
||||
def test_compliance_overview_attributes_serves_when_warming_not_started(
|
||||
self, authenticated_client
|
||||
):
|
||||
# Dev fallback: under runserver warming never runs, so the guard must
|
||||
# not refuse — the endpoint lazily loads and serves as before.
|
||||
from api.compliance import COMPLIANCE_WARMED, COMPLIANCE_WARMING_STARTED
|
||||
|
||||
COMPLIANCE_WARMING_STARTED.clear()
|
||||
COMPLIANCE_WARMED.clear()
|
||||
response = authenticated_client.get(
|
||||
reverse("complianceoverview-attributes"),
|
||||
{"filter[compliance_id]": "aws_account_security_onboarding_aws"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
def test_compliance_overview_task_management_integration(
|
||||
self, authenticated_client, compliance_requirements_overviews_fixture
|
||||
):
|
||||
|
||||
@@ -114,6 +114,8 @@ from api.attack_paths import get_queries_for_provider, get_query_by_id
|
||||
from api.attack_paths import views_helpers as attack_paths_views_helpers
|
||||
from api.base_views import BaseRLSViewSet, BaseTenantViewset, BaseUserViewset
|
||||
from api.compliance import (
|
||||
COMPLIANCE_WARMED,
|
||||
COMPLIANCE_WARMING_STARTED,
|
||||
PROWLER_COMPLIANCE_OVERVIEW_TEMPLATE,
|
||||
get_compliance_frameworks,
|
||||
get_prowler_provider_compliance,
|
||||
@@ -122,6 +124,7 @@ from api.constants import SEVERITY_ORDER
|
||||
from api.db_router import MainRouter
|
||||
from api.db_utils import rls_transaction
|
||||
from api.exceptions import (
|
||||
ComplianceWarmingError,
|
||||
TaskFailedException,
|
||||
UpstreamAccessDeniedError,
|
||||
UpstreamAuthenticationError,
|
||||
@@ -5059,6 +5062,13 @@ class ComplianceOverviewViewSet(BaseRLSViewSet, TaskManagementMixin):
|
||||
|
||||
@action(detail=False, methods=["get"], url_name="attributes")
|
||||
def attributes(self, request):
|
||||
# While the background warm-up is in progress, refuse immediately
|
||||
# instead of falling through to the slow cold load on the request
|
||||
# thread (which would trip the Gunicorn worker timeout). `is_set()` is
|
||||
# a non-blocking flag read, so this never touches the loader.
|
||||
if COMPLIANCE_WARMING_STARTED.is_set() and not COMPLIANCE_WARMED.is_set():
|
||||
raise ComplianceWarmingError()
|
||||
|
||||
compliance_id = request.query_params.get("filter[compliance_id]")
|
||||
if not compliance_id:
|
||||
raise ValidationError(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import threading
|
||||
|
||||
from config.env import env
|
||||
|
||||
@@ -11,6 +12,7 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.production")
|
||||
import django # noqa: E402
|
||||
|
||||
django.setup()
|
||||
from api.compliance import warm_compliance_caches # noqa: E402
|
||||
from config.django.production import LOGGING as DJANGO_LOGGERS, DEBUG # noqa: E402
|
||||
from config.custom_logging import BackendLogger # noqa: E402
|
||||
|
||||
@@ -41,3 +43,26 @@ def on_reload(_):
|
||||
|
||||
def when_ready(_):
|
||||
gunicorn_logger.info("Gunicorn server is ready")
|
||||
|
||||
|
||||
def _warm_compliance_caches_in_background():
|
||||
"""Warm compliance caches off the request path and log the outcome."""
|
||||
failed = warm_compliance_caches()
|
||||
if failed:
|
||||
gunicorn_logger.warning("Compliance caches warmed (skipped: %s)", failed)
|
||||
else:
|
||||
gunicorn_logger.info("Compliance caches warmed")
|
||||
|
||||
|
||||
def post_fork(_server, worker):
|
||||
"""Warm compliance caches after each worker fork.
|
||||
|
||||
Warm compliance caches in a background thread so the worker becomes ready
|
||||
immediately. A request for a not-yet-warmed provider lazily loads just that
|
||||
provider, which stays well under the worker timeout.
|
||||
"""
|
||||
threading.Thread(
|
||||
target=_warm_compliance_caches_in_background,
|
||||
name="warm-compliance-caches",
|
||||
daemon=True,
|
||||
).start()
|
||||
|
||||
@@ -58,6 +58,9 @@ from prowler.lib.outputs.compliance.mitre_attack.mitre_attack_azure import (
|
||||
AzureMitreAttack,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.mitre_attack.mitre_attack_gcp import GCPMitreAttack
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.okta_idaas_stig_okta import (
|
||||
OktaIDaaSSTIG,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.prowler_threatscore.prowler_threatscore_alibaba import (
|
||||
ProwlerThreatScoreAlibaba,
|
||||
)
|
||||
@@ -152,6 +155,9 @@ COMPLIANCE_CLASS_MAP = {
|
||||
ProwlerThreatScoreAlibaba,
|
||||
),
|
||||
],
|
||||
"okta": [
|
||||
(lambda name: name.startswith("okta_idaas_stig"), OktaIDaaSSTIG),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -269,6 +269,7 @@ def _store_resources(
|
||||
provider=provider_instance,
|
||||
uid=finding.resource_uid,
|
||||
defaults={
|
||||
"name": finding.resource_name,
|
||||
"region": finding.region,
|
||||
"service": finding.service_name,
|
||||
"type": finding.resource_type,
|
||||
@@ -276,6 +277,7 @@ def _store_resources(
|
||||
)
|
||||
|
||||
if not created:
|
||||
resource_instance.name = finding.resource_name
|
||||
resource_instance.region = finding.region
|
||||
resource_instance.service = finding.service_name
|
||||
resource_instance.type = finding.resource_type
|
||||
@@ -704,6 +706,12 @@ def _process_finding_micro_batch(
|
||||
if finding.region and resource_instance.region != finding.region:
|
||||
resource_instance.region = finding.region
|
||||
updated = True
|
||||
if (
|
||||
finding.resource_name
|
||||
and resource_instance.name != finding.resource_name
|
||||
):
|
||||
resource_instance.name = finding.resource_name
|
||||
updated = True
|
||||
if resource_instance.service != finding.service_name:
|
||||
resource_instance.service = finding.service_name
|
||||
updated = True
|
||||
@@ -945,6 +953,7 @@ def _process_finding_micro_batch(
|
||||
Resource.objects.bulk_update(
|
||||
resources_to_bulk_update,
|
||||
[
|
||||
"name",
|
||||
"metadata",
|
||||
"details",
|
||||
"partition",
|
||||
|
||||
@@ -315,6 +315,7 @@ class TestPerformScan:
|
||||
provider=provider_instance,
|
||||
uid=finding.resource_uid,
|
||||
defaults={
|
||||
"name": finding.resource_name,
|
||||
"region": finding.region,
|
||||
"service": finding.service_name,
|
||||
"type": finding.resource_type,
|
||||
@@ -348,6 +349,7 @@ class TestPerformScan:
|
||||
|
||||
resource_instance = MagicMock()
|
||||
resource_instance.uid = finding.resource_uid
|
||||
resource_instance.name = "old_name"
|
||||
resource_instance.region = "us-west-1"
|
||||
resource_instance.service = "old_service"
|
||||
resource_instance.type = "old_type"
|
||||
@@ -366,6 +368,7 @@ class TestPerformScan:
|
||||
provider=provider_instance,
|
||||
uid=finding.resource_uid,
|
||||
defaults={
|
||||
"name": finding.resource_name,
|
||||
"region": finding.region,
|
||||
"service": finding.service_name,
|
||||
"type": finding.resource_type,
|
||||
@@ -373,6 +376,7 @@ class TestPerformScan:
|
||||
)
|
||||
|
||||
# Check that resource fields were updated
|
||||
assert resource_instance.name == finding.resource_name
|
||||
assert resource_instance.region == finding.region
|
||||
assert resource_instance.service == finding.service_name
|
||||
assert resource_instance.type == finding.resource_type
|
||||
@@ -1565,6 +1569,75 @@ class TestProcessFindingMicroBatch:
|
||||
assert resource_cache[finding.resource_uid].service == finding.service_name
|
||||
assert tag_cache.keys() == {("team", "devsec")}
|
||||
|
||||
def test_process_finding_micro_batch_refreshes_empty_resource_name(
|
||||
self, tenants_fixture, scans_fixture
|
||||
):
|
||||
tenant = tenants_fixture[0]
|
||||
scan = scans_fixture[0]
|
||||
provider = scan.provider
|
||||
|
||||
# Old resource stored before names were persisted: empty name.
|
||||
existing_resource = Resource.objects.create(
|
||||
tenant_id=tenant.id,
|
||||
provider=provider,
|
||||
uid="arn:aws:s3:::my-bucket",
|
||||
name="",
|
||||
region="us-east-1",
|
||||
service="s3",
|
||||
type="bucket",
|
||||
)
|
||||
|
||||
finding = FakeFinding(
|
||||
uid="finding-empty-name",
|
||||
status=StatusChoices.PASS,
|
||||
status_extended="passing",
|
||||
severity=Severity.low,
|
||||
check_id="s3_bucket_public_access",
|
||||
resource_uid=existing_resource.uid,
|
||||
resource_name="my-bucket",
|
||||
region="us-east-1",
|
||||
service_name="s3",
|
||||
resource_type="bucket",
|
||||
partition="aws",
|
||||
raw={"status": "PASS"},
|
||||
metadata={"source": "prowler"},
|
||||
)
|
||||
|
||||
resource_cache = {existing_resource.uid: existing_resource}
|
||||
tag_cache = {}
|
||||
last_status_cache = {}
|
||||
resource_failed_findings_cache = {existing_resource.uid: 0}
|
||||
unique_resources: set[tuple[str, str]] = set()
|
||||
scan_resource_cache: set[tuple[str, str, str, str]] = set()
|
||||
mute_rules_cache = {}
|
||||
scan_categories_cache: dict[tuple[str, str], dict[str, int]] = {}
|
||||
scan_resource_groups_cache: dict[tuple[str, str], dict[str, int]] = {}
|
||||
group_resources_cache: dict[str, set] = {}
|
||||
|
||||
with (
|
||||
patch("tasks.jobs.scan.rls_transaction", new=noop_rls_transaction),
|
||||
patch("api.db_utils.rls_transaction", new=noop_rls_transaction),
|
||||
):
|
||||
_process_finding_micro_batch(
|
||||
str(tenant.id),
|
||||
[finding],
|
||||
scan,
|
||||
provider,
|
||||
resource_cache,
|
||||
tag_cache,
|
||||
last_status_cache,
|
||||
resource_failed_findings_cache,
|
||||
unique_resources,
|
||||
scan_resource_cache,
|
||||
mute_rules_cache,
|
||||
scan_categories_cache,
|
||||
scan_resource_groups_cache,
|
||||
group_resources_cache,
|
||||
)
|
||||
|
||||
existing_resource.refresh_from_db()
|
||||
assert existing_resource.name == finding.resource_name
|
||||
|
||||
def test_process_finding_micro_batch_skips_long_uid(
|
||||
self, tenants_fixture, scans_fixture
|
||||
):
|
||||
|
||||
@@ -1538,6 +1538,186 @@ def get_section_container_iso(data, section_1, section_2):
|
||||
return html.Div(section_containers, className="compliance-data-layout")
|
||||
|
||||
|
||||
def _status_bar(success, failed, classname):
|
||||
"""Build the stacked PASS/FAIL bar shown next to an accordion title."""
|
||||
fig = go.Figure(
|
||||
data=[
|
||||
go.Bar(
|
||||
name="Failed",
|
||||
x=[failed],
|
||||
y=[""],
|
||||
orientation="h",
|
||||
marker=dict(color="#e77676"),
|
||||
width=[0.8],
|
||||
),
|
||||
go.Bar(
|
||||
name="Success",
|
||||
x=[success],
|
||||
y=[""],
|
||||
orientation="h",
|
||||
marker=dict(color="#45cc6e"),
|
||||
width=[0.8],
|
||||
),
|
||||
]
|
||||
)
|
||||
fig.update_layout(
|
||||
barmode="stack",
|
||||
margin=dict(l=10, r=10, t=10, b=10),
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
showlegend=False,
|
||||
width=350,
|
||||
height=30,
|
||||
xaxis=dict(showticklabels=False, showgrid=False, zeroline=False),
|
||||
yaxis=dict(showticklabels=False, showgrid=False, zeroline=False),
|
||||
annotations=[
|
||||
dict(
|
||||
x=success + failed,
|
||||
y=0,
|
||||
xref="x",
|
||||
yref="y",
|
||||
text=str(success),
|
||||
showarrow=False,
|
||||
font=dict(color="#45cc6e", size=14),
|
||||
xanchor="left",
|
||||
yanchor="middle",
|
||||
),
|
||||
dict(
|
||||
x=0,
|
||||
y=0,
|
||||
xref="x",
|
||||
yref="y",
|
||||
text=str(failed),
|
||||
showarrow=False,
|
||||
font=dict(color="#e77676", size=14),
|
||||
xanchor="right",
|
||||
yanchor="middle",
|
||||
),
|
||||
],
|
||||
)
|
||||
fig.add_annotation(
|
||||
x=failed,
|
||||
y=0.3,
|
||||
text="|",
|
||||
showarrow=False,
|
||||
xanchor="center",
|
||||
yanchor="middle",
|
||||
font=dict(size=20),
|
||||
)
|
||||
return dcc.Graph(figure=fig, config={"staticPlot": True}, className=classname)
|
||||
|
||||
|
||||
def get_section_containers_generic(data, section_col, id_col):
|
||||
"""Two-level view: section -> requirement id (+ description) -> checks.
|
||||
|
||||
Sorts lexicographically so arbitrary requirement IDs never crash the
|
||||
version-aware sort used by the CIS renderer.
|
||||
"""
|
||||
data["STATUS"] = data["STATUS"].apply(map_status_to_icon)
|
||||
data[section_col] = data[section_col].astype(str)
|
||||
data[id_col] = data[id_col].astype(str)
|
||||
data.sort_values(by=[section_col, id_col], inplace=True)
|
||||
|
||||
counts_section = data.groupby([section_col, "STATUS"]).size().unstack(fill_value=0)
|
||||
counts_id = (
|
||||
data.groupby([section_col, id_col, "STATUS"]).size().unstack(fill_value=0)
|
||||
)
|
||||
|
||||
def count(counts, key, emoji):
|
||||
return counts.loc[key, emoji] if emoji in counts.columns else 0
|
||||
|
||||
has_description = "REQUIREMENTS_DESCRIPTION" in data.columns
|
||||
table_cols = ["CHECKID", "STATUS", "REGION", "ACCOUNTID", "RESOURCEID"]
|
||||
|
||||
section_containers = []
|
||||
for section in data[section_col].unique():
|
||||
graph_div = html.Div(
|
||||
_status_bar(
|
||||
count(counts_section, section, pass_emoji),
|
||||
count(counts_section, section, fail_emoji),
|
||||
"info-bar",
|
||||
),
|
||||
className="graph-section",
|
||||
)
|
||||
|
||||
internal_items = []
|
||||
for req_id in data[data[section_col] == section][id_col].unique():
|
||||
specific_data = data[
|
||||
(data[section_col] == section) & (data[id_col] == req_id)
|
||||
]
|
||||
data_table = dash_table.DataTable(
|
||||
data=specific_data.to_dict("records"),
|
||||
columns=[
|
||||
{"name": i, "id": i}
|
||||
for i in table_cols
|
||||
if i in specific_data.columns
|
||||
],
|
||||
style_table={"overflowX": "auto"},
|
||||
style_as_list_view=True,
|
||||
style_cell={"textAlign": "left", "padding": "5px"},
|
||||
)
|
||||
graph_div_req = html.Div(
|
||||
_status_bar(
|
||||
count(counts_id, (section, req_id), pass_emoji),
|
||||
count(counts_id, (section, req_id), fail_emoji),
|
||||
"info-bar-child",
|
||||
),
|
||||
className="graph-section-req",
|
||||
)
|
||||
|
||||
title = req_id
|
||||
if has_description:
|
||||
title = (
|
||||
f"{req_id} - {specific_data['REQUIREMENTS_DESCRIPTION'].iloc[0]}"
|
||||
)
|
||||
if len(title) > 130:
|
||||
title = title[:130] + " ..."
|
||||
|
||||
internal_items.append(
|
||||
html.Div(
|
||||
[
|
||||
graph_div_req,
|
||||
dbc.Accordion(
|
||||
[
|
||||
dbc.AccordionItem(
|
||||
title=title,
|
||||
children=[
|
||||
html.Div(
|
||||
[data_table],
|
||||
className="inner-accordion-content",
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
start_collapsed=True,
|
||||
flush=True,
|
||||
),
|
||||
],
|
||||
className="accordion-inner--child",
|
||||
)
|
||||
)
|
||||
|
||||
section_containers.append(
|
||||
html.Div(
|
||||
[
|
||||
graph_div,
|
||||
dbc.Accordion(
|
||||
[
|
||||
dbc.AccordionItem(
|
||||
title=f"{section}", children=internal_items
|
||||
)
|
||||
],
|
||||
start_collapsed=True,
|
||||
flush=True,
|
||||
),
|
||||
],
|
||||
className="accordion-inner",
|
||||
)
|
||||
)
|
||||
|
||||
return html.Div(section_containers, className="compliance-data-layout")
|
||||
|
||||
|
||||
def get_section_containers_format4(data, section_1):
|
||||
|
||||
data["STATUS"] = data["STATUS"].apply(map_status_to_icon)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import warnings
|
||||
|
||||
from dashboard.common_methods import (
|
||||
get_section_containers_format4,
|
||||
get_section_containers_generic,
|
||||
)
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
|
||||
def get_table(data):
|
||||
# Discover REQUIREMENTS_ATTRIBUTES_* columns at runtime.
|
||||
attr_cols = [c for c in data.columns if c.startswith("REQUIREMENTS_ATTRIBUTES_")]
|
||||
|
||||
# Section column (in priority order):
|
||||
# 1. REQUIREMENTS_ATTRIBUTES_SECTION — most common convention
|
||||
# 2. First discovered attribute column — covers novel schemas
|
||||
# 3. None — no section, group flat by requirement id
|
||||
if "REQUIREMENTS_ATTRIBUTES_SECTION" in attr_cols:
|
||||
section_col = "REQUIREMENTS_ATTRIBUTES_SECTION"
|
||||
elif attr_cols:
|
||||
section_col = attr_cols[0]
|
||||
else:
|
||||
section_col = None
|
||||
|
||||
base_cols = [
|
||||
"REQUIREMENTS_ID",
|
||||
"REQUIREMENTS_DESCRIPTION",
|
||||
"STATUS",
|
||||
"CHECKID",
|
||||
"REGION",
|
||||
"ACCOUNTID",
|
||||
"RESOURCEID",
|
||||
]
|
||||
|
||||
# Two levels (section -> requirement id) when a section distinct from the
|
||||
# id exists; otherwise group flat by requirement id.
|
||||
if section_col and section_col != "REQUIREMENTS_ID":
|
||||
needed = [section_col] + base_cols
|
||||
aux = data[[c for c in needed if c in data.columns]].copy()
|
||||
return get_section_containers_generic(aux, section_col, "REQUIREMENTS_ID")
|
||||
|
||||
aux = data[[c for c in base_cols if c in data.columns]].copy()
|
||||
return get_section_containers_format4(aux, "REQUIREMENTS_ID")
|
||||
@@ -156,7 +156,7 @@ def create_layout_compliance(
|
||||
html.Img(src="assets/favicon.ico", className="w-5 mr-3"),
|
||||
html.Span("Subscribe to Prowler Cloud"),
|
||||
],
|
||||
href="https://prowler.pro/",
|
||||
href="https://cloud.prowler.com/",
|
||||
target="_blank",
|
||||
className="text-prowler-stone-900 inline-flex px-4 py-2 text-xs font-bold uppercase transition-all rounded-lg text-gray-900 hover:bg-prowler-stone-900/10 border-solid border-1 hover:border-prowler-stone-900/10 hover:border-solid hover:border-1 border-prowler-stone-900/10",
|
||||
),
|
||||
|
||||
@@ -215,6 +215,58 @@ else:
|
||||
)
|
||||
|
||||
|
||||
def _ensure_scope_columns(data):
|
||||
"""Guarantee ACCOUNTID and REGION exist.
|
||||
|
||||
Scope columns always sit between DESCRIPTION and ASSESSMENTDATE, so derive
|
||||
them positionally for any provider (e.g. Okta's ORGANIZATIONDOMAIN) and
|
||||
fall back to "-" to avoid a KeyError.
|
||||
"""
|
||||
cols = list(data.columns)
|
||||
scope = []
|
||||
if "DESCRIPTION" in cols and "ASSESSMENTDATE" in cols:
|
||||
start, end = cols.index("DESCRIPTION") + 1, cols.index("ASSESSMENTDATE")
|
||||
scope = [c for c in cols[start:end] if c not in ("ACCOUNTID", "REGION")]
|
||||
|
||||
if "ACCOUNTID" not in data.columns:
|
||||
if scope:
|
||||
data.rename(columns={scope.pop(0): "ACCOUNTID"}, inplace=True)
|
||||
else:
|
||||
data["ACCOUNTID"] = "-"
|
||||
if "REGION" not in data.columns:
|
||||
if scope:
|
||||
data.rename(columns={scope.pop(0): "REGION"}, inplace=True)
|
||||
else:
|
||||
data["REGION"] = "-"
|
||||
return data
|
||||
|
||||
|
||||
def _dispatch_compliance_renderer(data, analytics_input):
|
||||
"""Resolve the compliance renderer module and return (table, deduped_data).
|
||||
|
||||
Tries to import the framework-specific builtin module. On
|
||||
ModuleNotFoundError (dynamic/external provider with no dedicated module),
|
||||
falls back to the generic renderer. Any other ImportError is re-raised.
|
||||
get_table() is called OUTSIDE the try block so errors inside the renderer
|
||||
surface as real exceptions rather than being swallowed.
|
||||
"""
|
||||
current = analytics_input.replace(".", "_")
|
||||
target = f"dashboard.compliance.{current}"
|
||||
try:
|
||||
module = importlib.import_module(target)
|
||||
except ModuleNotFoundError as exc:
|
||||
if exc.name != target:
|
||||
raise
|
||||
from dashboard.compliance import generic as module
|
||||
dedup_columns = ["CHECKID", "STATUS", "RESOURCEID", "STATUSEXTENDED"]
|
||||
if "MUTED" in data.columns:
|
||||
dedup_columns.insert(2, "MUTED")
|
||||
data = data.drop_duplicates(subset=dedup_columns)
|
||||
if "threatscore" in analytics_input:
|
||||
data = get_threatscore_mean_by_pillar(data)
|
||||
return module.get_table(data), data
|
||||
|
||||
|
||||
@callback(
|
||||
[
|
||||
Output("output", "children"),
|
||||
@@ -292,7 +344,7 @@ def display_data(
|
||||
data.rename(columns={"TENANCYID": "ACCOUNTID"}, inplace=True)
|
||||
|
||||
# Filter the chosen level of the CIS
|
||||
if is_level_1:
|
||||
if is_level_1 and "REQUIREMENTS_ATTRIBUTES_PROFILE" in data.columns:
|
||||
data = data[data["REQUIREMENTS_ATTRIBUTES_PROFILE"].str.contains("Level 1")]
|
||||
|
||||
# Rename the column PROJECTID to ACCOUNTID for GCP
|
||||
@@ -314,6 +366,9 @@ def display_data(
|
||||
data.rename(columns={"SUBSCRIPTION": "ACCOUNTID"}, inplace=True)
|
||||
data["REGION"] = "-"
|
||||
|
||||
# Normalize scope columns for any remaining (e.g. dynamic) provider.
|
||||
data = _ensure_scope_columns(data)
|
||||
|
||||
# Filter ACCOUNT
|
||||
if account_filter == ["All"]:
|
||||
updated_cloud_account_values = data["ACCOUNTID"].unique()
|
||||
@@ -409,36 +464,7 @@ def display_data(
|
||||
# Check cases where the compliance start with AWS_
|
||||
if "aws_" in analytics_input:
|
||||
analytics_input = analytics_input + "_aws"
|
||||
try:
|
||||
current = analytics_input.replace(".", "_")
|
||||
compliance_module = importlib.import_module(
|
||||
f"dashboard.compliance.{current}"
|
||||
)
|
||||
# Build subset list based on available columns
|
||||
dedup_columns = ["CHECKID", "STATUS", "RESOURCEID", "STATUSEXTENDED"]
|
||||
if "MUTED" in data.columns:
|
||||
dedup_columns.insert(2, "MUTED")
|
||||
data = data.drop_duplicates(subset=dedup_columns)
|
||||
|
||||
if "threatscore" in analytics_input:
|
||||
data = get_threatscore_mean_by_pillar(data)
|
||||
|
||||
table = compliance_module.get_table(data)
|
||||
except ModuleNotFoundError:
|
||||
table = html.Div(
|
||||
[
|
||||
html.H5(
|
||||
"No data found for this compliance",
|
||||
className="card-title",
|
||||
style={"text-align": "left", "color": "black"},
|
||||
)
|
||||
],
|
||||
style={
|
||||
"width": "99%",
|
||||
"margin-right": "0.8%",
|
||||
"margin-bottom": "10px",
|
||||
},
|
||||
)
|
||||
table, data = _dispatch_compliance_renderer(data, analytics_input)
|
||||
|
||||
df = data.copy()
|
||||
# Remove Muted rows
|
||||
|
||||
@@ -1538,7 +1538,7 @@ def filter_data(
|
||||
html.Img(src="assets/favicon.ico", className="w-5 mr-3"),
|
||||
html.Span("Subscribe to Prowler Cloud"),
|
||||
],
|
||||
href="https://prowler.pro/",
|
||||
href="https://cloud.prowler.com/",
|
||||
target="_blank",
|
||||
className="text-prowler-stone-900 inline-flex px-4 py-2 text-xs font-bold uppercase transition-all rounded-lg text-gray-900 hover:bg-prowler-stone-900/10 border-solid border-1 hover:border-prowler-stone-900/10 hover:border-solid hover:border-1 border-prowler-stone-900/10",
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
|
||||
|
||||
### 🚀 Added
|
||||
|
||||
- DISA Okta IDaaS STIG V1R2 compliance framework for the Okta provider, with a dedicated CSV output formatter and terminal summary table [(#11428)](https://github.com/prowler-cloud/prowler/pull/11428)
|
||||
- `sagemaker_models_monitor_enabled` check for AWS provider, verifying that each SageMaker monitoring schedule is in the `Scheduled` state so data and model drift is actively detected [(#11278)](https://github.com/prowler-cloud/prowler/pull/11278)
|
||||
- DORA (Digital Operational Resilience Act, Regulation (EU) 2022/2554) universal compliance framework with AWS provider coverage across the five DORA pillars [(#11131)](https://github.com/prowler-cloud/prowler/pull/11131)
|
||||
- Okta authenticator and password policy checks for STIG-aligned hardening requirements [(#11465)](https://github.com/prowler-cloud/prowler/pull/11465)
|
||||
@@ -19,6 +20,8 @@ All notable changes to the **Prowler SDK** are documented in this file.
|
||||
- `entra_service_principal_privileged_role_no_owners` check for M365 provider, failing when a service principal with a permanent Tier 0 directory role has owners on the service principal or its parent app registration [(#11070)](https://github.com/prowler-cloud/prowler/issues/11070)
|
||||
- `kms_key_rotation_max_90_days` check for GCP provider, verifying KMS customer-managed keys are rotated every 90 days or less in line with the CIS Benchmark [(#11516)](https://github.com/prowler-cloud/prowler/pull/11516)
|
||||
- `exchange_mailbox_primary_smtp_uses_custom_domain` check for M365 provider [(#11215)](https://github.com/prowler-cloud/prowler/pull/11215)
|
||||
- `bedrock_agent_role_least_privilege` check for AWS provider, flagging Bedrock Agent execution roles with full-access managed policies, broad `Resource:*` inline statements, or missing permissions boundaries [(#11335)](https://github.com/prowler-cloud/prowler/pull/11335)
|
||||
- STACKIT ObjectStorage service with Object Lock, default retention policy, and access key expiration checks [(#11397)](https://github.com/prowler-cloud/prowler/pull/11397)
|
||||
|
||||
### 🐞 Fixed
|
||||
|
||||
@@ -26,6 +29,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
|
||||
- `entra_users_mfa_capable` no longer flags pre-provisioned users with future `employeeHireDate`; future-hire date comparisons now tolerate naive datetimes [(#11511)](https://github.com/prowler-cloud/prowler/pull/11511)
|
||||
- M365 Admin Center group enumeration now follows Microsoft Graph pagination so group-scoped checks include groups beyond the first page [(#11510)](https://github.com/prowler-cloud/prowler/pull/11510)
|
||||
- GCP `kms_key_rotation_enabled` check now only verifies that automatic key rotation is enabled (any interval) instead of enforcing a 90-day period, resolving the mismatch between the check and its documentation; the CIS, Prowler ThreatScore, and CCC requirements that mandate a 90-day maximum were remapped to the new `kms_key_rotation_max_90_days` check [(#11516)](https://github.com/prowler-cloud/prowler/pull/11516)
|
||||
- AWS CloudWatch log metric filter checks now validate `filterPattern` clauses regardless of order [(#11345)](https://github.com/prowler-cloud/prowler/pull/11345)
|
||||
|
||||
---
|
||||
|
||||
|
||||
+36
-2
@@ -19,7 +19,7 @@ from prowler.config.config import (
|
||||
orange_color,
|
||||
sarif_file_suffix,
|
||||
)
|
||||
from prowler.lib.banner import print_banner
|
||||
from prowler.lib.banner import print_banner, print_prowler_cloud_banner
|
||||
from prowler.lib.check.check import (
|
||||
exclude_checks_to_run,
|
||||
exclude_services_to_run,
|
||||
@@ -102,6 +102,9 @@ from prowler.lib.outputs.compliance.mitre_attack.mitre_attack_azure import (
|
||||
AzureMitreAttack,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.mitre_attack.mitre_attack_gcp import GCPMitreAttack
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.okta_idaas_stig_okta import (
|
||||
OktaIDaaSSTIG,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.prowler_threatscore.prowler_threatscore_alibaba import (
|
||||
ProwlerThreatScoreAlibaba,
|
||||
)
|
||||
@@ -199,7 +202,7 @@ def prowler():
|
||||
|
||||
if not args.no_banner:
|
||||
legend = args.verbose or getattr(args, "fixer", None)
|
||||
print_banner(legend)
|
||||
print_banner(legend, provider)
|
||||
|
||||
# We treat the compliance framework as another output format
|
||||
if compliance_framework:
|
||||
@@ -1314,6 +1317,33 @@ def prowler():
|
||||
)
|
||||
generated_outputs["compliance"].append(generic_compliance)
|
||||
generic_compliance.batch_write_data_to_file()
|
||||
elif provider == "okta":
|
||||
for compliance_name in input_compliance_frameworks:
|
||||
if compliance_name.startswith("okta_idaas_stig"):
|
||||
# Generate Okta IDaaS STIG Finding Object
|
||||
filename = (
|
||||
f"{output_options.output_directory}/compliance/"
|
||||
f"{output_options.output_filename}_{compliance_name}.csv"
|
||||
)
|
||||
okta_idaas_stig = OktaIDaaSSTIG(
|
||||
findings=finding_outputs,
|
||||
compliance=bulk_compliance_frameworks[compliance_name],
|
||||
file_path=filename,
|
||||
)
|
||||
generated_outputs["compliance"].append(okta_idaas_stig)
|
||||
okta_idaas_stig.batch_write_data_to_file()
|
||||
else:
|
||||
filename = (
|
||||
f"{output_options.output_directory}/compliance/"
|
||||
f"{output_options.output_filename}_{compliance_name}.csv"
|
||||
)
|
||||
generic_compliance = GenericCompliance(
|
||||
findings=finding_outputs,
|
||||
compliance=bulk_compliance_frameworks[compliance_name],
|
||||
file_path=filename,
|
||||
)
|
||||
generated_outputs["compliance"].append(generic_compliance)
|
||||
generic_compliance.batch_write_data_to_file()
|
||||
else:
|
||||
# Dynamic fallback: any external/custom provider
|
||||
try:
|
||||
@@ -1446,6 +1476,10 @@ def prowler():
|
||||
f"\nDetailed compliance results are in {Fore.YELLOW}{output_options.output_directory}/compliance/{Style.RESET_ALL}\n"
|
||||
)
|
||||
|
||||
# Promote Prowler Cloud as the last thing the user sees after the results
|
||||
if not args.no_banner and not args.only_logs:
|
||||
print_prowler_cloud_banner(provider)
|
||||
|
||||
# If custom checks were passed, remove the modules
|
||||
if checks_folder:
|
||||
remove_custom_checks_module(checks_folder, provider)
|
||||
|
||||
@@ -0,0 +1,638 @@
|
||||
{
|
||||
"Framework": "Okta-IDaaS-STIG",
|
||||
"Name": "DISA Okta Identity as a Service (IDaaS) STIG V1R2",
|
||||
"Version": "1R2",
|
||||
"Provider": "Okta",
|
||||
"Description": "Defense Information Systems Agency (DISA) Security Technical Implementation Guide (STIG) for Okta Identity as a Service (IDaaS), Version 1 Release 2 (Benchmark Date: 05 Jan 2026).",
|
||||
"Requirements": [
|
||||
{
|
||||
"Id": "OKTA-APP-000020",
|
||||
"Name": "Okta must log out a session after a 15-minute period of inactivity.",
|
||||
"Description": "A session timeout lock is a temporary action taken when a user stops work and moves away from the immediate physical vicinity of the information system but does not log out because of the temporary nature of the absence. Rather than relying on the user to manually lock their application session prior to vacating the vicinity, applications must be able to identify when a user's application session has idled and take action to initiate the session lock. The session lock is implemented at the point where session activity can be determined and/or controlled. This is typically at the operating system level and results in a system lock. However, it may be at the application level where the application interface window is secured instead. Satisfies: SRG-APP-000003, SRG-APP-000190",
|
||||
"Checks": [
|
||||
"signon_global_session_idle_timeout_15min"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273186r1098825_rule",
|
||||
"StigID": "OKTA-APP-000020",
|
||||
"CCI": [
|
||||
"CCI-000057",
|
||||
"CCI-001133"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Global Session Policy. 2. In the Default Policy, verify a rule is configured at Priority 1 that is not named \"Default Rule\". 3. Click the edit icon next to the Priority 1 rule. 4. Verify the \"Maximum Okta global session idle time\" is set to 15 minutes. If \"Maximum Okta global session idle time\" is not set to 15 minutes, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Global Session Policy. 2. Select the Default Policy. 3. In the Rules table, make these updates: - Click \"Add rule\". - Set \"Maximum Okta global session idle time\" to 15 minutes."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000025",
|
||||
"Name": "The Okta Admin Console must log out a session after a 15-minute period of inactivity.",
|
||||
"Description": "A session timeout lock is a temporary action taken when a user stops work and moves away from the immediate physical vicinity of the information system but does not log out because of the temporary nature of the absence. Rather than relying on the user to manually lock their application session prior to vacating the vicinity, applications must be able to identify when a user's application session has idled and take action to initiate the session lock. The session lock is implemented at the point where session activity can be determined and/or controlled. This is typically at the operating system level and results in a system lock. However, it may be at the application level where the application interface window is secured instead.",
|
||||
"Checks": [
|
||||
"application_admin_console_session_idle_timeout_15min"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273187r1098828_rule",
|
||||
"StigID": "OKTA-APP-000025",
|
||||
"CCI": [
|
||||
"CCI-000057"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Applications >> Applications >> Okta Admin Console. 2. In the Sign On tab, under \"Okta Admin Console session\", verify the \"Maximum app session idle time\" is set to 15 minutes. If the \"Maximum app session idle time\" is not set to 15 minutes, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Applications >> Applications >> Okta Admin Console. 2. In the Sign On tab, under \"Okta Admin Console session\", set the \"Maximum app session idle time\" to 15 minutes."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000090",
|
||||
"Name": "Okta must automatically disable accounts after a 35-day period of account inactivity.",
|
||||
"Description": "Attackers that are able to exploit an inactive account can potentially obtain and maintain undetected access to an application. Owners of inactive accounts will not notice if unauthorized access to their user account has been obtained. Applications must track periods of user inactivity and disable accounts after 35 days of inactivity. Such a process greatly reduces the risk that accounts will be hijacked, leading to a data compromise. To address access requirements, many application developers choose to integrate their applications with enterprise-level authentication/access mechanisms that meet or exceed access control policy requirements. Such integration allows the application developer to off-load those access control functions and focus on core application features and functionality. This policy does not apply to emergency accounts or infrequently used accounts. Infrequently used accounts are local login administrator accounts used by system administrators when network or normal login/access is not available. Emergency accounts are administrator accounts created in response to crisis situations. Satisfies: SRG-APP-000025, SRG-APP-000163, SRG-APP-000700",
|
||||
"Checks": [
|
||||
"user_inactivity_automation_35d_enabled"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273188r1098831_rule",
|
||||
"StigID": "OKTA-APP-000090",
|
||||
"CCI": [
|
||||
"CCI-000017",
|
||||
"CCI-000795",
|
||||
"CCI-003627"
|
||||
],
|
||||
"CheckText": "If Okta Services rely on external directory services for user sourcing, this is not applicable, and the connected directory services must perform this function. Go to Workflows >> Automations and verify that an Automation has been created to disable accounts after 35 days of inactivity. If the Okta configuration does not automatically disable accounts after a 35-day period of account inactivity, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Workflow >> Automations and select \"Add Automation\". 2. Create a name for the Automation (e.g., \"User Inactivity\"). 3. Click \"Add Condition\" and select \"User Inactivity in Okta\". 4. In the duration field, enter 35 days and click \"Save\". 5 Click the edit button next to \"Select Schedule\". 6. Configure the \"Schedule\" field for \"Run Daily\" and set the \"Time\" field to an organizationally defined time to run this automation. Click \"Save\". 7. Click the edit button next to \"Select group membership\". 8. In the \"Applies to\" field, select the group \"Everyone\" by typing it into the field. Click \"Save\". 9. Click \"Add Action\" and select \"Change User lifecycle state in Okta\". 10. In the \"Change user state to\" field, select \"Suspended\" and click \"Save\". 11. Click the \"Inactive\" button near the top of the section screen and select \"Activate\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000170",
|
||||
"Name": "Okta must enforce the limit of three consecutive invalid login attempts by a user during a 15-minute time period.",
|
||||
"Description": "By limiting the number of failed login attempts, the risk of unauthorized system access via user password guessing, otherwise known as brute forcing, is reduced. Limits are imposed by locking the account. Satisfies: SRG-APP-000065, SRG-APP-000345",
|
||||
"Checks": [
|
||||
"authenticator_password_lockout_threshold_3"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273189r1098834_rule",
|
||||
"StigID": "OKTA-APP-000170",
|
||||
"CCI": [
|
||||
"CCI-000044",
|
||||
"CCI-002238"
|
||||
],
|
||||
"CheckText": "If Okta Services rely on external directory services for user sourcing, this check is not applicable, and the connected directory services must perform this function. From the Admin Console: 1. Go to Security >> Authenticators. 2. Click the \"Actions\" button next to \"Password\" and select \"Edit\". 3. For each Password Policy, verify the \"Lock Out\" section has the following values: - \"Lock out after 3 unsuccessful attempts\" is checked. - The value is set to \"3\". If Okta Services are not configured to automatically lock user accounts after three consecutive invalid login attempts, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authenticators. 2. Click the \"Actions\" button next to \"Password\" and select \"Edit\". 3. For each Password Policy, ensure the \"Lock Out\" section has the following values: - \"Lock out after 3 unsuccessful attempts\" is checked. - The value is set to \"3\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000180",
|
||||
"Name": "The Okta Dashboard application must be configured to allow authentication only via non-phishable authenticators.",
|
||||
"Description": "Requiring the use of non-phishable authenticators protects against brute force/password dictionary attacks. This provides a better level of security while removing the need to lock out accounts after three attempts in 15 minutes.",
|
||||
"Checks": [
|
||||
"application_dashboard_phishing_resistant_authentication"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273190r1099763_rule",
|
||||
"StigID": "OKTA-APP-000180",
|
||||
"CCI": [
|
||||
"CCI-000044"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Dashboard\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"Possession factor constraints are\" section, verify the \"Phishing resistant\" box is checked. This will ensure that only phishing-resistant factors are used to access the Okta Dashboard. If in the \"Possession factor constraints are\" section the \"Phishing resistant\" box is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Dashboard\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"Possession factor constraints are\" section, ensure the \"Phishing resistant\" box is checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000190",
|
||||
"Name": "The Okta Admin Console application must be configured to allow authentication only via non-phishable authenticators.",
|
||||
"Description": "Requiring the use of non-phishable authenticators protects against brute force/password dictionary attacks. This provides a better level of security while removing the need to lock out accounts after three attempts in 15 minutes.",
|
||||
"Checks": [
|
||||
"application_admin_console_phishing_resistant_authentication"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273191r1099764_rule",
|
||||
"StigID": "OKTA-APP-000190",
|
||||
"CCI": [
|
||||
"CCI-000044"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Admin Console\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"Possession factor constraints are\" section, verify the \"Phishing resistant\" box is checked. This will ensure that only phishing-resistant factors are used to access the Okta Dashboard. If in the \"Possession factor constraints are\" section the \"Phishing resistant\" box is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Admin Console\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"Possession factor constraints are\" section, ensure the \"Phishing resistant\" box is checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000200",
|
||||
"Name": "Okta must display the Standard Mandatory DOD Notice and Consent Banner before granting access to the application.",
|
||||
"Description": "Display of the DOD-approved use notification before granting access to the application ensures that privacy and security notification verbiage used is consistent with applicable federal laws, Executive Orders, directives, policies, regulations, standards, and guidance. System use notifications are required only for access via login interfaces with human users and are not required when such human interfaces do not exist. The banner must be formatted in accordance with DTM-08-060. Use the following verbiage for applications that can accommodate banners of 1300 characters: \"You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only. By using this IS (which includes any device attached to this IS), you consent to the following conditions: -The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations. -At any time, the USG may inspect and seize data stored on this IS. -Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose. -This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy. -Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.\" Use the following verbiage for operating systems that have severe limitations on the number of characters that can be displayed in the banner: \"I've read & consent to terms in IS user agreem't.\" Satisfies: SRG-APP-000068, SRG-APP-000069, SRG-APP-000070",
|
||||
"Checks": [
|
||||
"signon_dod_warning_banner_configured"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273192r1098843_rule",
|
||||
"StigID": "OKTA-APP-000200",
|
||||
"CCI": [
|
||||
"CCI-000048",
|
||||
"CCI-000050",
|
||||
"CCI-001384",
|
||||
"CCI-001385",
|
||||
"CCI-001386",
|
||||
"CCI-001387",
|
||||
"CCI-001388"
|
||||
],
|
||||
"CheckText": "Attempt to log in to the Okta tenant and verify the DOD-approved warning banner is in place. If the required warning banner is not present and complete, this is a finding.",
|
||||
"FixText": "Follow the supplemental instructions in the \"Okta DOD Warning Banner Configuration Guide\" provided with this STIG package."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000560",
|
||||
"Name": "The Okta Admin Console application must be configured to use multifactor authentication.",
|
||||
"Description": "Without the use of multifactor authentication, the ease of access to privileged functions is greatly increased. Multifactor authentication requires using two or more factors to achieve authentication. Factors include: (i) something a user knows (e.g., password/PIN); (ii) something a user has (e.g., cryptographic identification device, token); or (iii) something a user is (e.g., biometric). A privileged account is defined as an information system account with authorizations of a privileged user. Network access is defined as access to an information system by a user (or a process acting on behalf of a user) communicating through a network (e.g., local area network, wide area network, or the internet). Satisfies: SRG-APP-000149, SRG-APP-000154",
|
||||
"Checks": [
|
||||
"application_admin_console_mfa_required"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT I (High)",
|
||||
"Severity": "high",
|
||||
"RuleID": "SV-273193r1098846_rule",
|
||||
"StigID": "OKTA-APP-000560",
|
||||
"CCI": [
|
||||
"CCI-000765",
|
||||
"CCI-004046"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Admin Console\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"User must authenticate with\" field, verify that either \"Password/IdP + Another factor\" or \"Any 2 factor types\" is selected. If either of these settings is incorrect, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Admin Console\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"User must authenticate with\" field, select either \"Password/IdP + Another factor\" or \"Any 2 factor types\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000570",
|
||||
"Name": "The Okta Dashboard application must be configured to use multifactor authentication.",
|
||||
"Description": "To ensure accountability and prevent unauthenticated access, nonprivileged users must use multifactor authentication to prevent potential misuse and compromise of the system. Multifactor authentication uses two or more factors to achieve authentication. Factors include: (i) Something you know (e.g., password/PIN); (ii) Something you have (e.g., cryptographic identification device, token); or (iii) Something you are (e.g., biometric). A nonprivileged account is any information system account with authorizations of a nonprivileged user. Network access is any access to an application by a user (or process acting on behalf of a user) where the access is obtained through a network connection. Applications integrating with the DOD Active Directory and using the DOD CAC are examples of compliant multifactor authentication solutions. Satisfies: SRG-APP-000150, SRG-APP-000155",
|
||||
"Checks": [
|
||||
"application_dashboard_mfa_required"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT I (High)",
|
||||
"Severity": "high",
|
||||
"RuleID": "SV-273194r1098849_rule",
|
||||
"StigID": "OKTA-APP-000570",
|
||||
"CCI": [
|
||||
"CCI-000766",
|
||||
"CCI-004046"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Dashboard\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"User must authenticate with\" field, verify that either \"Password/IdP + Another factor\" or \"Any 2 factor types\" is selected. If either of these settings is incorrect, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authentication Policies. 2. Click the \"Okta Dashboard\" policy. 3. Click the \"Actions\" button next to the top rule and select \"Edit\". 4. In the \"User must authenticate with\" field, select either \"Password/IdP + Another factor\" or \"Any 2 factor types\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000650",
|
||||
"Name": "Okta must enforce a minimum 15-character password length.",
|
||||
"Description": "Password complexity, or strength, is a measure of the effectiveness of a password in resisting attempts at guessing and brute-force attacks. Password length is one factor of several that helps to determine strength and how long it takes to crack a password. The shorter the password, the lower the number of possible combinations that need to be tested before the password is compromised. Use of more characters in a password helps to exponentially increase the time and/or resources required to compromise the password.",
|
||||
"Checks": [
|
||||
"authenticator_password_minimum_length_15"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273195r1098852_rule",
|
||||
"StigID": "OKTA-APP-000650",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify the \"Minimum Length\" field is set to at least \"15\" characters. If any policy is not set to at least \"15\", this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set the \"Minimum Length\" field to at least \"15\" characters."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000670",
|
||||
"Name": "Okta must enforce password complexity by requiring that at least one uppercase character be used.",
|
||||
"Description": "Use of a complex password helps to increase the time and resources required to compromise the password. Password complexity, or strength, is a measure of the effectiveness of a password in resisting attempts at guessing and brute-force attacks. Password complexity is one factor of several that determine how long it takes to crack a password. The more complex the password is, the greater the number of possible combinations that need to be tested before the password is compromised.",
|
||||
"Checks": [
|
||||
"authenticator_password_complexity_uppercase"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273196r1098855_rule",
|
||||
"StigID": "OKTA-APP-000670",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Upper case letter\" is checked. For each policy, if \"Upper case letter\" is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Upper case letter\" to checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000680",
|
||||
"Name": "Okta must enforce password complexity by requiring that at least one lowercase character be used.",
|
||||
"Description": "Use of a complex password helps to increase the time and resources required to compromise the password. Password complexity, or strength, is a measure of the effectiveness of a password in resisting attempts at guessing and brute-force attacks. Password complexity is one factor of several that determine how long it takes to crack a password. The more complex the password, the greater the number of possible combinations that need to be tested before the password is compromised.",
|
||||
"Checks": [
|
||||
"authenticator_password_complexity_lowercase"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273197r1098858_rule",
|
||||
"StigID": "OKTA-APP-000680",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Lower case letter\" is checked. For each policy, if \"Lower case letter\" is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Lower case letter\" to checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000690",
|
||||
"Name": "Okta must enforce password complexity by requiring that at least one numeric character be used.",
|
||||
"Description": "Use of a complex password helps to increase the time and resources required to compromise the password. Password complexity, or strength, is a measure of the effectiveness of a password in resisting attempts at guessing and brute-force attacks. Password complexity is one factor of several that determine how long it takes to crack a password. The more complex the password, the greater the number of possible combinations that need to be tested before the password is compromised.",
|
||||
"Checks": [
|
||||
"authenticator_password_complexity_number"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273198r1098861_rule",
|
||||
"StigID": "OKTA-APP-000690",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Number (0-9)\" is checked. For each policy, if \"Number (0-9)\" is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Number (0-9)\" to checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000700",
|
||||
"Name": "Okta must enforce password complexity by requiring that at least one special character be used.",
|
||||
"Description": "Use of a complex password helps to increase the time and resources required to compromise the password. Password complexity, or strength, is a measure of the effectiveness of a password in resisting attempts at guessing and brute-force attacks. Password complexity is one factor in determining how long it takes to crack a password. The more complex the password, the greater the number of possible combinations that need to be tested before the password is compromised. Special characters are not alphanumeric. Examples include: ~ ! @ # $ % ^ *.",
|
||||
"Checks": [
|
||||
"authenticator_password_complexity_symbol"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273199r1098864_rule",
|
||||
"StigID": "OKTA-APP-000700",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Symbol (e.g., !@#$%^&*)\" is checked. For each policy, if \"Symbol (e.g., !@#$%^&*)\" is not checked, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Symbol (e.g., !@#$%^&*)\" to checked."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000740",
|
||||
"Name": "Okta must enforce 24 hours/one day as the minimum password lifetime.",
|
||||
"Description": "Enforcing a minimum password lifetime helps prevent repeated password changes to defeat the password reuse or history enforcement requirement. Restricting this setting limits the user's ability to change their password. Passwords must be changed at specific policy-based intervals; however, if the application allows the user to immediately and continually change their password, it could be changed repeatedly in a short period of time to defeat the organization's policy regarding password reuse. Satisfies: SRG-APP-000173, SRG-APP-000870",
|
||||
"Checks": [
|
||||
"authenticator_password_minimum_age_24h"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273200r1098867_rule",
|
||||
"StigID": "OKTA-APP-000740",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Minimum password age is XX hours\" is set to at least \"24\". For each policy, if \"Minimum password age is XX hours\" is not set to at least \"24\", this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Minimum password age is XX hours\" to at least \"24\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-000745",
|
||||
"Name": "Okta must enforce a 60-day maximum password lifetime restriction.",
|
||||
"Description": "Any password, no matter how complex, can eventually be cracked. Therefore, passwords must be changed at specific intervals. One method of minimizing this risk is to use complex passwords and periodically change them. If the application does not limit the lifetime of passwords and force users to change their passwords, there is the risk that the system and/or application passwords could be compromised. This requirement does not include emergency administration accounts, which are meant for access to the application in case of failure. These accounts are not required to have maximum password lifetime restrictions.",
|
||||
"Checks": [
|
||||
"authenticator_password_maximum_age_60d"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273201r1098870_rule",
|
||||
"StigID": "OKTA-APP-000745",
|
||||
"CCI": [
|
||||
"CCI-004066"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy, verify \"Password expires after XX days\" is set to \"60\". For each policy, if \"Password expires after XX days\" is not set to \"60\", this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Password expires after XX days\" to \"60\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001430",
|
||||
"Name": "Okta must off-load audit records onto a central log server.",
|
||||
"Description": "Information stored in one location is vulnerable to accidental or incidental deletion or alteration. Off-loading is a common process in information systems with limited audit storage capacity. Satisfies: SRG-APP-000358, SRG-APP-000080, SRG-APP-000125",
|
||||
"Checks": [
|
||||
"systemlog_streaming_enabled"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT I (High)",
|
||||
"Severity": "high",
|
||||
"RuleID": "SV-273202r1099766_rule",
|
||||
"StigID": "OKTA-APP-001430",
|
||||
"CCI": [
|
||||
"CCI-001851",
|
||||
"CCI-000166",
|
||||
"CCI-001348"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Reports >> Log Streaming. 2. Verify that a Log Stream connection is configured and active. Alternately, interview the information system security manager (ISSM) and verify that an external Security Information and Event Management (SIEM) system is pulling Okta logs via an Application Programming Interface (API). If either of these is not configured, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Reports >> Log Streaming. 2. Select either \"AWS EventBridge\" or \"Splunk Cloud\" and click \"Next\". 3. Complete the necessary fields and click \"Save\". If Log Streaming is not an option because the SIEM required is not an option, customers can use the Okta Log API to export system logs in real time."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001665",
|
||||
"Name": "Okta must be configured to limit the global session lifetime to 18 hours.",
|
||||
"Description": "Without reauthentication, users may access resources or perform tasks for which they do not have authorization. When applications provide the capability to change security roles or escalate the functional capability of the application, it is critical the user reauthenticate. In addition to the reauthentication requirements associated with session locks, organizations may require reauthentication of individuals and/or devices in other situations, including (but not limited to) the following circumstances. (i) When authenticators change; (ii) When roles change; (iii) When security categories of information systems change; (iv) When the execution of privileged functions occurs; (v) After a fixed period of time; or (vi) Periodically. Within the DOD, the minimum circumstances requiring reauthentication are privilege escalation and role changes.",
|
||||
"Checks": [
|
||||
"signon_global_session_lifetime_18h"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273203r1099958_rule",
|
||||
"StigID": "OKTA-APP-001665",
|
||||
"CCI": [
|
||||
"CCI-002038"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Global Session Policy. 2. In the Default Policy, verify a rule is configured at Priority 1 that is not named \"Default Rule\". 3. Click the \"Edit\" icon next to the Priority 1 rule. 4. Verify \"Maximum Okta global session lifetime\" is set to 18 hours. If the above is not set, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Global Session Policy. 2. Select the Default Policy. 3. In the Rules table, make these updates: - Click \"Add rule\". - Set \"Maximum Okta global session lifetime\" to 18 hours."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001670",
|
||||
"Name": "Okta must be configured to accept Personal Identity Verification (PIV) credentials.",
|
||||
"Description": "The use of PIV credentials facilitates standardization and reduces the risk of unauthorized access. DOD has mandated the use of the common access card (CAC) to support identity management and personal authentication for systems covered under HSPD 12, as well as a primary component of layered protection for national security systems. Satisfies: SRG-APP-000391, SRG-APP-000402, SRG-APP-000403",
|
||||
"Checks": [
|
||||
"authenticator_smart_card_active"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273204r1098879_rule",
|
||||
"StigID": "OKTA-APP-001670",
|
||||
"CCI": [
|
||||
"CCI-001953",
|
||||
"CCI-002009",
|
||||
"CCI-002010"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authenticators. 2. Verify that \"Smart Card Authenticator\" is listed and has \"Status\" listed as \"Active\". If \"Smart Card Authenticator\" is not listed or is not listed as \"Active\", this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authenticators. 2. In the \"Setup\" tab, click \"Add authenticator\". 3. Select the configured Smart Card Identity Provider and finish configuration."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001700",
|
||||
"Name": "The Okta Verify application must be configured to connect only to FIPS-compliant devices.",
|
||||
"Description": "Without device-to-device authentication, communications with malicious devices may be established. Bidirectional authentication provides stronger safeguards to validate the identity of other devices for connections that are of greater risk. Currently, DOD requires the use of AES for bidirectional authentication because it is the only FIPS-validated AES cipher block algorithm. For distributed architectures (e.g., service-oriented architectures), the decisions regarding the validation of authentication claims may be made by services separate from the services acting on those decisions. In such situations, it is necessary to provide authentication decisions (as opposed to the actual authenticators) to the services that need to act on those decisions. A local connection is any connection with a device communicating without the use of a network. A network connection is any connection with a device that communicates through a network (e.g., local area or wide area network; the internet). A remote connection is any connection with a device communicating through an external network (e.g., the internet). Because of the challenges of applying this requirement on a large scale, organizations are encouraged to apply the requirement only to those limited number (and type) of devices that truly need to support this capability.",
|
||||
"Checks": [
|
||||
"authenticator_okta_verify_fips_compliant"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273205r1098882_rule",
|
||||
"StigID": "OKTA-APP-001700",
|
||||
"CCI": [
|
||||
"CCI-001967"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Go to Security >> Authenticators. 2. From the \"Setup\" tab, select \"Edit Okta Verify\". 3. Review the \"FIPS Compliance\" field. If FIPS-compliant authentication is not enabled, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Authenticators. 2. From the \"Setup\" tab, select \"Edit Okta Verify\". 3. In the \"FIPS Compliance\" field, choose whether users enrolling in Okta Verify can use FIPS-compliant devices only or any device. 4. Click \"Save\" after making any changes."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001710",
|
||||
"Name": "Okta must be configured to disable persistent global session cookies.",
|
||||
"Description": "If cached authentication information is out of date, the validity of the authentication information may be questionable. Satisfies: SRG-APP-000400, SRG-APP-000157",
|
||||
"Checks": [
|
||||
"signon_global_session_cookies_not_persistent"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273206r1098885_rule",
|
||||
"StigID": "OKTA-APP-001710",
|
||||
"CCI": [
|
||||
"CCI-002007",
|
||||
"CCI-001942"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Global Session Policy. 2. In the Default Policy, verify a rule is configured at Priority 1 that is not named \"Default Rule\". 3. Click the \"Edit\" icon next to the Priority 1 rule. 4. Verify \"Okta global session cookies persist across browser sessions\" is set to \"Disabled\". If the above it not set, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Global Session Policy. 2. Select the Default Policy. 3. In the \"Rules\" table, make these updates: - Click \"Add rule\". - Set \"Okta global session cookies persist across browser sessions\" to Disable."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-001920",
|
||||
"Name": "Okta must be configured to use only DOD-approved certificate authorities.",
|
||||
"Description": "Untrusted Certificate Authorities (CA) can issue certificates, but they may be issued by organizations or individuals that seek to compromise DOD systems or by organizations with insufficient security controls. If the CA used for verifying the certificate is not DOD approved, trust of this CA has not been established. The DOD will accept only PKI certificates obtained from a DOD-approved internal or external CA. Reliance on CAs for the establishment of secure sessions includes, for example, the use of Transport Layer Security (TLS) certificates. This requirement focuses on communications protection for the application session rather than for the network packet. This requirement applies to applications that use communications sessions. This includes, but is not limited to, web-based applications and Service-Oriented Architectures (SOA). Satisfies: SRG-APP-000427, SRG-APP-000910",
|
||||
"Checks": [
|
||||
"idp_smart_card_dod_approved_ca"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273207r1098888_rule",
|
||||
"StigID": "OKTA-APP-001920",
|
||||
"CCI": [
|
||||
"CCI-002470",
|
||||
"CCI-004909"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Identity Providers (IdPs). 2. Review the list of IdPs with \"Type\" as \"Smart Card\". If the IdP is not listed as \"Active\", this is a finding. 3. Select Actions >> Configure. 4. Under \"Certificate chain\", verify the certificate is from a DOD-approved CA. If the certificate is not from a DOD-approved CA, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Go to Security >> Identity Providers. 2. Click \"Add identity provider.\" 3. Click \"Smart Card IdP\". Click \"Next\". 4. Enter the name of the identity provider. 5. Build a certificate chain: - Click \"Browse\" to open a file explorer. Select the certificate file to add and click \"Open\". - To add another certificate, click \"Add Another\" and repeat step 1. - Click \"Build certificate chain\". On success, the chain and its certificates are shown. If the build failed, correct any issues and try again. - Click \"Reset certificate chain\" if replacing the current chain with a new one. 6. In \"IdP username\", select the \"idpuser.subjectAltNameUpn\" attribute. This is the attribute that stores the Electronic Data Interchange Personnel Identifier (EDIPI) on the CAC. 7. In the \"Match Against\" field, select the Okta Profile Attribute in which the EDIPI is to be stored."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-002980",
|
||||
"Name": "Okta must validate passwords against a list of commonly used, expected, or compromised passwords.",
|
||||
"Description": "Password-based authentication applies to passwords regardless of whether they are used in single-factor or multifactor authentication. Long passwords or passphrases are preferable over shorter passwords. Enforced composition rules provide marginal security benefits while decreasing usability. However, organizations may choose to establish certain rules for password generation (e.g., minimum character length for long passwords) under certain circumstances and can enforce this requirement in IA-5(1)(h). Account recovery can occur, for example, in situations when a password is forgotten. Cryptographically protected passwords include salted one-way cryptographic hashes of passwords. The list of commonly used, compromised, or expected passwords includes passwords obtained from previous breach corpuses, dictionary words, and repetitive or sequential characters. The list includes context-specific words, such as the name of the service, username, and derivatives thereof.",
|
||||
"Checks": [
|
||||
"authenticator_password_common_password_check"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273208r1099769_rule",
|
||||
"StigID": "OKTA-APP-002980",
|
||||
"CCI": [
|
||||
"CCI-004058"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Navigate to Security >> Authenticators. 2. Click the \"Actions\" button next to the Password authenticator and select \"Edit\". 3. Under the \"Password Settings\" section, verify the \"Common Password Check\" box is checked. If \"Common Password Check\" is not selected, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Navigate to Security >> Authenticators. 2. Click the \"Actions\" button next to the Password authenticator and select \"Edit\". 3. Under the \"Password Settings\" section, check the \"Common Password Check\" box."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003010",
|
||||
"Name": "Okta must prohibit password reuse for a minimum of five generations.",
|
||||
"Description": "Password-based authentication applies to passwords regardless of whether they are used in single-factor or multifactor authentication. Long passwords or passphrases are preferable over shorter passwords. Enforced composition rules provide marginal security benefits while decreasing usability. However, organizations may choose to establish certain rules for password generation (e.g., minimum character length for long passwords) under certain circumstances and can enforce this requirement in IA-5(1)(h). Account recovery can occur, for example, in situations when a password is forgotten. Cryptographically protected passwords include salted one-way cryptographic hashes of passwords. The list of commonly used, compromised, or expected passwords includes passwords obtained from previous breach corpuses, dictionary words, and repetitive or sequential characters. The list includes context-specific words, such as the name of the service, username, and derivatives thereof.",
|
||||
"Checks": [
|
||||
"authenticator_password_history_5"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-273209r1098894_rule",
|
||||
"StigID": "OKTA-APP-003010",
|
||||
"CCI": [
|
||||
"CCI-004061"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password row\" and select \"Edit\". 3. For each listed policy, verify \"Enforce password history for last XX passwords\" is set to \"5\". If any policy is not set to at least \"5\", this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select Security >> Authenticators. 2. Click the \"Actions\" button next to the \"Password\" row and select \"Edit\". 3. For each listed policy: - Click \"Edit\". - Set \"Enforce password history for last XX passwords\" to \"5\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003240",
|
||||
"Name": "Okta API tokens must be configured with Network Zones to restrict authorization from known networks.",
|
||||
"Description": "An access token is a piece of data that represents the authorization granted to a user or NPE to access specific systems or information resources. Access tokens enable controlled access to services and resources. Properly managing the lifecycle of access tokens, including their issuance, validation, and revocation, is crucial to maintaining confidentiality of data and systems. Restricting token validity to a specific audience, e.g., an application or security domain, and restricting token validity lifetimes are important practices. Access tokens are revoked or invalidated if they are compromised, lost, or are no longer needed to mitigate the risks associated with stolen or misused tokens. API tokens have the potential to be replicated or stolen (just like a password). Because of this, it is important to only allow API tokens to authenticate from known IP ranges as this limits an adversary's ability to use a token to gain access.",
|
||||
"Checks": [
|
||||
"apitoken_restricted_to_network_zone"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-279689r1155066_rule",
|
||||
"StigID": "OKTA-APP-003240",
|
||||
"CCI": [
|
||||
"CCI-005165",
|
||||
"CCI-000366"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"API\" item. 2. Click the \"Tokens\" tab. 3. For each token listed, click the token name link. 4. In the \"Security\" section, verify the \"Token can be used from\" setting is mapped to a known network zone for the application calling the API. If a network zone for each API access token is not defined, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"API\" item. 2. Click the \"Tokens\" tab. 3. For each token listed, click the token name link. 4. In the \"Security\" section, click \"Edit\". 5. Set the \"Token can be used from\" setting to the known network zone for the application calling the API. 6. Click \"Save\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003241",
|
||||
"Name": "Okta API tokens must be created under new dedicated user accounts.",
|
||||
"Description": "An access token is a piece of data that represents the authorization granted to a user or NPE to access specific systems or information resources. Access tokens enable controlled access to services and resources. Properly managing the lifecycle of access tokens, including their issuance, validation, and revocation, is crucial to maintaining confidentiality of data and systems. Restricting token validity to a specific audience, e.g., an application or security domain, and restricting token validity lifetimes are important practices. Access tokens are revoked or invalidated if they are compromised, lost, or are no longer needed to mitigate the risks associated with stolen or misused tokens. When API tokens are created, they inherit the permissions of the user that created them. Therefore, API tokens should only be created from dedicated accounts and permissions must be constrained to least privilege for that dedicated user account and token. No API tokens should be created using a Super Admin account.",
|
||||
"Checks": [
|
||||
"apitoken_not_super_admin"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-279690r1155069_rule",
|
||||
"StigID": "OKTA-APP-003241",
|
||||
"CCI": [
|
||||
"CCI-005165",
|
||||
"CCI-000366"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"API\" item. 2. Click the \"Tokens\" tab. 3. For each token listed, verify that the Role listed is not \"Super Admin\", and that the account has been specifically created for that token. 4. Click the account name to be token to the user profile for that user. 5. Verify the user only has an administrator role (standard or customer) applied that is correctly scoped as required and documented in the Okta Access Control policy. If the token is using a Super Administrator account, or one that is not properly scoped per the Access Control policy, this is a finding. Note: If a Super Admin token is required for system operation, then this permanent finding.",
|
||||
"FixText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"API\" item. 2. Click the \"Tokens\" tab. 3. For each token listed that has \"Super Admin\" or an improperly scoped Admin account, delete the token and create a new one with the appropriately scoped permissions. 4. Verify the application performing the API calls with the new token has been updated."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003242",
|
||||
"Name": "The Okta Global Session policy must be configured to allow or deny IP based access in accordance with the Access Control policy for Okta.",
|
||||
"Description": "To mitigate the risk of unauthorized access to sensitive information by entities that have been issued certificates by DOD-approved PKIs, all DOD systems (e.g., networks, web servers, and web portals) must be properly configured to incorporate access control methods that do not rely solely on the possession of a certificate for access. Successful authentication must not automatically give an entity access to an asset or security boundary. Authorization procedures and controls must be implemented to ensure each authenticated entity also has a validated and current authorization. Authorization is the process of determining whether an entity, once authenticated, is permitted to access a specific asset. Information systems use access control policies and enforcement mechanisms to implement this requirement. Access Control policies include identity-based policies, role-based policies, and attribute-based policies. Access enforcement mechanisms include access control lists, access control matrices, and cryptography. These policies and mechanisms must be employed by the application to control access between users (or processes acting on behalf of users) and objects (e.g., devices, files, records, processes, programs, and domains) in the information system. The Okta Global Session Policy is applied at the organization level and before any application-specific authentication policies are processed. The Okta authorization package should contain an access control policy that defines IP ranges from which to either allow or deny access. This list (either as an explicit allow or explicit deny) can be implemented in the Global Session Policy.",
|
||||
"Checks": [
|
||||
"signon_global_session_policy_network_zone_enforced"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-279691r1155072_rule",
|
||||
"StigID": "OKTA-APP-003242",
|
||||
"CCI": [
|
||||
"CCI-000213"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"Global Session Policy\" item. 2. In the \"Policy Settings\" section, verify the \"IF User's IP is\" setting is correctly set to either allow or deny based on the organization defined policy. If the Okta Global Session Policy is not configured to restrict access to specific IP ranges, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"Global Session Policy\" item. 2. In the Policy Settings section, configure the \"IF User's IP is\" setting to correctly set the appropriate network to either allow or deny based on the Access Control Policy."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003243",
|
||||
"Name": "Okta must be configured with Network Zones defined to block anonymized proxies according to organizationally defined policy.",
|
||||
"Description": "A mechanism to detect and prevent unauthorized communication flow must be configured or provided as part of the system design. If information flow is not enforced based on approved authorizations, the system may become compromised. Information flow control regulates where information is allowed to travel within a system and between interconnected systems. The flow of all application information must be monitored and controlled so it does not introduce any unacceptable risk to the systems or data. Application-specific examples of enforcement occurs in systems that employ rule sets or establish configuration settings that restrict information system services, or provide a message filtering capability based on message content (e.g., implementing key word searches or using document characteristics). Applications providing information flow control must be able to enforce approved authorizations for controlling the flow of information between interconnected systems in accordance with applicable policy. Working with the organizational CSSP, the ISSM should obtain a list of known anonymizer proxies that exist on the commercial internet. If this is not available from the CSSP, then the Okta-provided \"Enhanced dynamic zone blocklist\" should be activated.",
|
||||
"Checks": [
|
||||
"network_zone_block_anonymized_proxies"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-279692r1155075_rule",
|
||||
"StigID": "OKTA-APP-003243",
|
||||
"CCI": [
|
||||
"CCI-001414"
|
||||
],
|
||||
"CheckText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"Networks' item. 2. If the CSSP has provided a list of anonymizers to block, verify the \"IP Block list\" is configured with them. a. Click the pencil icon next to IP Block list. b. Verify the \"Gateway IPs\" section contains all of the IP ranges in the provided list. 3. If the CSSP is not able to provide a list, then implement the Okta managed list. a. Verify the \"Enhanced dynamic zone blocklist\" is set to \"Active\". If Network Zones are not configured to block anonymous proxies, this is a finding.",
|
||||
"FixText": "From the Admin Console: 1. Select the \"Security\" menu, and then click the \"Networks\" item. 2. If the CSSP has provided a list of anonymizers to block, add the IP ranges to the \"IP Block list\". a. Click the pencil icon next to IP Block list. b. Add the IP ranges to the \"Gateway IPs\" section and click \"Save\". 3. If the CSSP is not able to provide a list, then implement the Okta managed list. a. Set the \"Enhanced dynamic zone blocklist\" to \"Active\"."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": "OKTA-APP-003244",
|
||||
"Name": "For each application integrated with Okta, network zones must be defined in its authentication policy.",
|
||||
"Description": "A mechanism to detect and prevent unauthorized communication flow must be configured or provided as part of the system design. If information flow is not enforced based on approved authorizations, the system may become compromised. Information flow control regulates where information is allowed to travel within a system and between interconnected systems. The flow of all application information must be monitored and controlled so it does not introduce any unacceptable risk to the systems or data. Application-specific examples of enforcement occurs in systems that employ rule sets or establish configuration settings that restrict information system services, or provide a message filtering capability based on message content (e.g., implementing key word searches or using document characteristics). Applications providing information flow control must be able to enforce approved authorizations for controlling the flow of information between interconnected systems in accordance with applicable policy. Each application in Okta should have a well defined access control policy that takes into account the end user network. This should be documented in the Access Control policy for each application. As an example, access to an application may be restricted to a specific location by policy. In this case, a network defining that specific location should be created.",
|
||||
"Checks": [
|
||||
"application_authentication_policy_network_zone_enforced"
|
||||
],
|
||||
"Attributes": [
|
||||
{
|
||||
"Section": "CAT II (Medium)",
|
||||
"Severity": "medium",
|
||||
"RuleID": "SV-279693r1155078_rule",
|
||||
"StigID": "OKTA-APP-003244",
|
||||
"CCI": [
|
||||
"CCI-001414"
|
||||
],
|
||||
"CheckText": "For each application integrated into Okta: 1. From the Admin console, open the \"Security\" menu, and then select \"Networks\". 2. Verify the list of networks includes all necessary allow or block lists. If any application is not configured with network zones, this is a finding.",
|
||||
"FixText": "For each application, starting at the admin console: 1. Open the \"Applications\" group from the Menu, and then click the \"Applications\" menu item. 2. Click the application name. 3. Click the \"Sign On\" tab. 4. Scroll to the \"User Authentication\" section, and then click \"Edit\". 5. Select the appropriate Authentication policy from the pull down, and then click \"Save\". 6. Click \"View Policy Details\". 7. For each nondefault rule: a. Select \"Edit\" from the Actions menu. b. In the \"IF\" section, verify the \"User is\" setting has the appropriate allow or deny range has been selected based on the Access Control policy for the application. c. Scroll down to the bottom and click \"Save\". 8. For the Catch-All rule: a. Select \"Edit\" from the Actions menu. b. Scroll down to the \"Then\" section. c. For the \"Access is\" setting, select \"Denied\", and then click \"Save\"."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+38
-4
@@ -3,12 +3,13 @@ from colorama import Fore, Style
|
||||
from prowler.config.config import banner_color, orange_color, prowler_version, timestamp
|
||||
|
||||
|
||||
def print_banner(legend: bool = False):
|
||||
def print_banner(legend: bool = False, provider: str = None):
|
||||
"""
|
||||
Prints the banner with optional legend for color codes.
|
||||
|
||||
Parameters:
|
||||
- legend (bool): Flag to indicate whether to print the color legend or not. Default is False.
|
||||
- provider (str): The provider being scanned, used to tailor the Prowler Cloud banner.
|
||||
|
||||
Returns:
|
||||
- None
|
||||
@@ -20,13 +21,12 @@ def print_banner(legend: bool = False):
|
||||
| .__/|_| \___/ \_/\_/ |_|\___|_|v{prowler_version}
|
||||
|_|{Fore.BLUE} Get the most at https://cloud.prowler.com {Style.RESET_ALL}
|
||||
|
||||
{Fore.GREEN}New! Send findings from Prowler CLI to Prowler Cloud{Style.RESET_ALL}
|
||||
{Fore.GREEN}More details here: goto.prowler.com/import-findings{Style.RESET_ALL}
|
||||
|
||||
{Fore.YELLOW}Date: {timestamp.strftime("%Y-%m-%d %H:%M:%S")}{Style.RESET_ALL}
|
||||
"""
|
||||
print(banner)
|
||||
|
||||
print_prowler_cloud_banner(provider)
|
||||
|
||||
if legend:
|
||||
print(
|
||||
f"""
|
||||
@@ -37,3 +37,37 @@ def print_banner(legend: bool = False):
|
||||
- {Fore.RED}FAIL (Fix required){Style.RESET_ALL}
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def print_prowler_cloud_banner(provider: str = None):
|
||||
"""
|
||||
Prints a promotional banner highlighting what Prowler Cloud adds on top of
|
||||
the open-source CLI.
|
||||
|
||||
Shown at the start and end of a scan to let users know about the managed
|
||||
platform capabilities they are missing (attack paths, AI, organizations,
|
||||
continuous scanning, integrations and live compliance dashboards).
|
||||
|
||||
Parameters:
|
||||
- provider (str): The provider that was scanned, used to tailor the message.
|
||||
|
||||
Returns:
|
||||
- None
|
||||
"""
|
||||
check = f"{Fore.GREEN}✓{Style.RESET_ALL}"
|
||||
bar = f"{banner_color}│{Style.RESET_ALL}"
|
||||
print(
|
||||
f"""
|
||||
{bar} {Style.BRIGHT}You're getting a snapshot. Prowler Cloud gives you the full picture.{Style.RESET_ALL}
|
||||
{bar}
|
||||
{bar} {check} {Style.BRIGHT}Attack Path Visualization{Style.RESET_ALL} - see how attackers chain risks to reach your crown jewels
|
||||
{bar} {check} {Style.BRIGHT}Lighthouse AI + MCP{Style.RESET_ALL} - autonomous triage, prioritization and remediation
|
||||
{bar} {check} {Style.BRIGHT}Organizations{Style.RESET_ALL} - all your AWS accounts under one organization
|
||||
{bar} {check} {Style.BRIGHT}Continuous scanning{Style.RESET_ALL} - scheduled scans with history, trends and alerts
|
||||
{bar} {check} {Style.BRIGHT}Integrations{Style.RESET_ALL} - Jira, Slack, AWS Security Hub, Amazon S3, SSO and RBAC
|
||||
{bar} {check} {Style.BRIGHT}Reports{Style.RESET_ALL} - download ready-to-share PDF reports
|
||||
{bar} {check} {Style.BRIGHT}Live compliance{Style.RESET_ALL} - dashboards for 50+ frameworks, always up to date
|
||||
{bar}
|
||||
{bar} {Fore.BLUE}Start free at cloud.prowler.com{Style.RESET_ALL}
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -283,6 +283,26 @@ class CSA_CCM_Requirement_Attribute(BaseModel):
|
||||
ScopeApplicability: list[dict]
|
||||
|
||||
|
||||
class STIG_Requirement_Attribute_Severity(str, Enum):
|
||||
"""DISA STIG Requirement Attribute Severity (maps to CAT I/II/III)"""
|
||||
|
||||
high = "high"
|
||||
medium = "medium"
|
||||
low = "low"
|
||||
|
||||
|
||||
class STIG_Requirement_Attribute(BaseModel):
|
||||
"""DISA STIG Requirement Attribute"""
|
||||
|
||||
Section: str
|
||||
Severity: STIG_Requirement_Attribute_Severity
|
||||
RuleID: str
|
||||
StigID: str
|
||||
CCI: Optional[list[str]] = None
|
||||
CheckText: Optional[str] = None
|
||||
FixText: Optional[str] = None
|
||||
|
||||
|
||||
# Base Compliance Model
|
||||
# TODO: move this to compliance folder
|
||||
class Compliance_Requirement(BaseModel):
|
||||
@@ -303,6 +323,7 @@ class Compliance_Requirement(BaseModel):
|
||||
CCC_Requirement_Attribute,
|
||||
C5Germany_Requirement_Attribute,
|
||||
CSA_CCM_Requirement_Attribute,
|
||||
STIG_Requirement_Attribute,
|
||||
# Generic_Compliance_Requirement_Attribute must be the last one since it is the fallback for generic compliance framework
|
||||
Generic_Compliance_Requirement_Attribute,
|
||||
]
|
||||
|
||||
@@ -18,6 +18,9 @@ from prowler.lib.outputs.compliance.kisa_ismsp.kisa_ismsp import get_kisa_ismsp_
|
||||
from prowler.lib.outputs.compliance.mitre_attack.mitre_attack import (
|
||||
get_mitre_attack_table,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.okta_idaas_stig import (
|
||||
get_okta_idaas_stig_table,
|
||||
)
|
||||
from prowler.lib.outputs.compliance.prowler_threatscore.prowler_threatscore import (
|
||||
get_prowler_threatscore_table,
|
||||
)
|
||||
@@ -252,6 +255,15 @@ def display_compliance_table(
|
||||
output_directory,
|
||||
compliance_overview,
|
||||
)
|
||||
elif compliance_framework.startswith("okta_idaas_stig"):
|
||||
get_okta_idaas_stig_table(
|
||||
findings,
|
||||
bulk_checks_metadata,
|
||||
compliance_framework,
|
||||
output_filename,
|
||||
output_directory,
|
||||
compliance_overview,
|
||||
)
|
||||
else:
|
||||
# Try provider-specific table first, fall back to generic
|
||||
from prowler.providers.common.provider import Provider
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic.v1 import BaseModel
|
||||
|
||||
|
||||
class OktaIDaaSSTIGModel(BaseModel):
|
||||
"""
|
||||
OktaIDaaSSTIGModel generates a finding's output in DISA Okta IDaaS STIG Compliance format.
|
||||
"""
|
||||
|
||||
Provider: str
|
||||
Description: str
|
||||
OrganizationDomain: str
|
||||
AssessmentDate: str
|
||||
Requirements_Id: str
|
||||
Requirements_Name: str
|
||||
Requirements_Description: str
|
||||
Requirements_Attributes_Section: str
|
||||
Requirements_Attributes_Severity: str
|
||||
Requirements_Attributes_RuleID: str
|
||||
Requirements_Attributes_StigID: str
|
||||
Requirements_Attributes_CCI: Optional[list[str]] = None
|
||||
Requirements_Attributes_CheckText: Optional[str] = None
|
||||
Requirements_Attributes_FixText: Optional[str] = None
|
||||
Status: str
|
||||
StatusExtended: str
|
||||
ResourceId: str
|
||||
ResourceName: str
|
||||
CheckId: str
|
||||
Muted: bool
|
||||
Framework: str
|
||||
Name: str
|
||||
@@ -0,0 +1,98 @@
|
||||
from colorama import Fore, Style
|
||||
from tabulate import tabulate
|
||||
|
||||
from prowler.config.config import orange_color
|
||||
|
||||
|
||||
def get_okta_idaas_stig_table(
|
||||
findings: list,
|
||||
bulk_checks_metadata: dict,
|
||||
compliance_framework: str,
|
||||
output_filename: str,
|
||||
output_directory: str,
|
||||
compliance_overview: bool,
|
||||
):
|
||||
section_table = {
|
||||
"Provider": [],
|
||||
"Section": [],
|
||||
"Status": [],
|
||||
"Muted": [],
|
||||
}
|
||||
pass_count = []
|
||||
fail_count = []
|
||||
muted_count = []
|
||||
sections = {}
|
||||
for index, finding in enumerate(findings):
|
||||
check = bulk_checks_metadata[finding.check_metadata.CheckID]
|
||||
check_compliances = check.Compliance
|
||||
for compliance in check_compliances:
|
||||
if compliance.Framework == "Okta-IDaaS-STIG":
|
||||
for requirement in compliance.Requirements:
|
||||
for attribute in requirement.Attributes:
|
||||
section = attribute.Section
|
||||
|
||||
if section not in sections:
|
||||
sections[section] = {"FAIL": 0, "PASS": 0, "Muted": 0}
|
||||
|
||||
if finding.muted:
|
||||
if index not in muted_count:
|
||||
muted_count.append(index)
|
||||
sections[section]["Muted"] += 1
|
||||
else:
|
||||
if finding.status == "FAIL" and index not in fail_count:
|
||||
fail_count.append(index)
|
||||
sections[section]["FAIL"] += 1
|
||||
elif finding.status == "PASS" and index not in pass_count:
|
||||
pass_count.append(index)
|
||||
sections[section]["PASS"] += 1
|
||||
|
||||
sections = dict(sorted(sections.items()))
|
||||
for section in sections:
|
||||
section_table["Provider"].append(compliance.Provider)
|
||||
section_table["Section"].append(section)
|
||||
if sections[section]["FAIL"] > 0:
|
||||
section_table["Status"].append(
|
||||
f"{Fore.RED}FAIL({sections[section]['FAIL']}){Style.RESET_ALL}"
|
||||
)
|
||||
else:
|
||||
if sections[section]["PASS"] > 0:
|
||||
section_table["Status"].append(
|
||||
f"{Fore.GREEN}PASS({sections[section]['PASS']}){Style.RESET_ALL}"
|
||||
)
|
||||
else:
|
||||
section_table["Status"].append(f"{Fore.GREEN}PASS{Style.RESET_ALL}")
|
||||
section_table["Muted"].append(
|
||||
f"{orange_color}{sections[section]['Muted']}{Style.RESET_ALL}"
|
||||
)
|
||||
|
||||
if (
|
||||
len(fail_count) + len(pass_count) + len(muted_count) > 1
|
||||
): # If there are no resources, don't print the compliance table
|
||||
print(
|
||||
f"\nCompliance Status of {Fore.YELLOW}{compliance_framework.upper()}{Style.RESET_ALL} Framework:"
|
||||
)
|
||||
total_findings_count = len(fail_count) + len(pass_count) + len(muted_count)
|
||||
overview_table = [
|
||||
[
|
||||
f"{Fore.RED}{round(len(fail_count) / total_findings_count * 100, 2)}% ({len(fail_count)}) FAIL{Style.RESET_ALL}",
|
||||
f"{Fore.GREEN}{round(len(pass_count) / total_findings_count * 100, 2)}% ({len(pass_count)}) PASS{Style.RESET_ALL}",
|
||||
f"{orange_color}{round(len(muted_count) / total_findings_count * 100, 2)}% ({len(muted_count)}) MUTED{Style.RESET_ALL}",
|
||||
]
|
||||
]
|
||||
print(tabulate(overview_table, tablefmt="rounded_grid"))
|
||||
if not compliance_overview:
|
||||
if len(fail_count) > 0 and len(section_table["Section"]) > 0:
|
||||
print(
|
||||
f"\nFramework {Fore.YELLOW}{compliance_framework.upper()}{Style.RESET_ALL} Results:"
|
||||
)
|
||||
print(
|
||||
tabulate(
|
||||
section_table,
|
||||
tablefmt="rounded_grid",
|
||||
headers="keys",
|
||||
)
|
||||
)
|
||||
print(f"\nDetailed results of {compliance_framework.upper()} are in:")
|
||||
print(
|
||||
f" - CSV: {output_directory}/compliance/{output_filename}_{compliance_framework}.csv\n"
|
||||
)
|
||||
@@ -0,0 +1,95 @@
|
||||
from prowler.config.config import timestamp
|
||||
from prowler.lib.check.compliance_models import Compliance
|
||||
from prowler.lib.outputs.compliance.compliance_output import ComplianceOutput
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.models import OktaIDaaSSTIGModel
|
||||
from prowler.lib.outputs.finding import Finding
|
||||
|
||||
|
||||
class OktaIDaaSSTIG(ComplianceOutput):
|
||||
"""
|
||||
This class represents the Okta IDaaS STIG compliance output.
|
||||
|
||||
Attributes:
|
||||
- _data (list): A list to store transformed data from findings.
|
||||
- _file_descriptor (TextIOWrapper): A file descriptor to write data to a file.
|
||||
|
||||
Methods:
|
||||
- transform: Transforms findings into Okta IDaaS STIG compliance format.
|
||||
"""
|
||||
|
||||
def transform(
|
||||
self,
|
||||
findings: list[Finding],
|
||||
compliance: Compliance,
|
||||
_compliance_name: str,
|
||||
) -> None:
|
||||
"""
|
||||
Transforms a list of findings into Okta IDaaS STIG compliance format.
|
||||
|
||||
Parameters:
|
||||
- findings (list): A list of findings.
|
||||
- compliance (Compliance): A compliance model.
|
||||
- _compliance_name (str): The name of the compliance model (unused).
|
||||
|
||||
Returns:
|
||||
- None
|
||||
"""
|
||||
for finding in findings:
|
||||
for requirement in compliance.Requirements:
|
||||
# Source of truth: framework JSON, not finding.compliance snapshot (avoids CSV/UI count drift).
|
||||
if finding.check_id in requirement.Checks:
|
||||
for attribute in requirement.Attributes:
|
||||
compliance_row = OktaIDaaSSTIGModel(
|
||||
Provider=finding.provider,
|
||||
Description=compliance.Description,
|
||||
OrganizationDomain=finding.account_name,
|
||||
AssessmentDate=str(timestamp),
|
||||
Requirements_Id=requirement.Id,
|
||||
Requirements_Name=requirement.Name,
|
||||
Requirements_Description=requirement.Description,
|
||||
Requirements_Attributes_Section=attribute.Section,
|
||||
Requirements_Attributes_Severity=attribute.Severity.value,
|
||||
Requirements_Attributes_RuleID=attribute.RuleID,
|
||||
Requirements_Attributes_StigID=attribute.StigID,
|
||||
Requirements_Attributes_CCI=attribute.CCI,
|
||||
Requirements_Attributes_CheckText=attribute.CheckText,
|
||||
Requirements_Attributes_FixText=attribute.FixText,
|
||||
Status=finding.status,
|
||||
StatusExtended=finding.status_extended,
|
||||
ResourceId=finding.resource_uid,
|
||||
ResourceName=finding.resource_name,
|
||||
CheckId=finding.check_id,
|
||||
Muted=finding.muted,
|
||||
Framework=compliance.Framework,
|
||||
Name=compliance.Name,
|
||||
)
|
||||
self._data.append(compliance_row)
|
||||
# Add manual requirements to the compliance output
|
||||
for requirement in compliance.Requirements:
|
||||
if not requirement.Checks:
|
||||
for attribute in requirement.Attributes:
|
||||
compliance_row = OktaIDaaSSTIGModel(
|
||||
Provider=compliance.Provider.lower(),
|
||||
Description=compliance.Description,
|
||||
OrganizationDomain="",
|
||||
AssessmentDate=str(timestamp),
|
||||
Requirements_Id=requirement.Id,
|
||||
Requirements_Name=requirement.Name,
|
||||
Requirements_Description=requirement.Description,
|
||||
Requirements_Attributes_Section=attribute.Section,
|
||||
Requirements_Attributes_Severity=attribute.Severity.value,
|
||||
Requirements_Attributes_RuleID=attribute.RuleID,
|
||||
Requirements_Attributes_StigID=attribute.StigID,
|
||||
Requirements_Attributes_CCI=attribute.CCI,
|
||||
Requirements_Attributes_CheckText=attribute.CheckText,
|
||||
Requirements_Attributes_FixText=attribute.FixText,
|
||||
Status="MANUAL",
|
||||
StatusExtended="Manual check",
|
||||
ResourceId="manual_check",
|
||||
ResourceName="Manual check",
|
||||
CheckId="manual",
|
||||
Muted=False,
|
||||
Framework=compliance.Framework,
|
||||
Name=compliance.Name,
|
||||
)
|
||||
self._data.append(compliance_row)
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"Provider": "aws",
|
||||
"CheckID": "bedrock_agent_role_least_privilege",
|
||||
"CheckTitle": "Amazon Bedrock agent execution role follows least privilege",
|
||||
"CheckType": [
|
||||
"Software and Configuration Checks/AWS Security Best Practices/Runtime Behavior Analysis",
|
||||
"TTPs/Privilege Escalation"
|
||||
],
|
||||
"ServiceName": "bedrock",
|
||||
"SubServiceName": "",
|
||||
"ResourceIdTemplate": "",
|
||||
"Severity": "high",
|
||||
"ResourceType": "Other",
|
||||
"ResourceGroup": "ai_ml",
|
||||
"Description": "**Bedrock Agent** execution roles (`agentResourceRoleArn`) should grant only the minimum permissions the agent needs. The evaluation FAILs when the role has an AWS-managed `*FullAccess` policy attached, has an inline statement allowing broad actions on `Resource: \"*\"`, or has no permissions boundary configured.",
|
||||
"Risk": "An overly permissive **Bedrock Agent** execution role turns a successful **prompt injection** into AWS privilege escalation. A model coerced into calling tools can invoke any API the role allows — reading secrets, modifying IAM, exfiltrating data from S3, or pivoting laterally. **Least privilege** plus a **permissions boundary** keeps the blast radius bounded even when guardrails fail.",
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.aws.amazon.com/bedrock/latest/userguide/agents-permissions.html",
|
||||
"https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html",
|
||||
"https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege"
|
||||
],
|
||||
"Remediation": {
|
||||
"Code": {
|
||||
"CLI": "aws iam put-role-permissions-boundary --role-name <execution_role_name> --permissions-boundary <boundary_policy_arn>",
|
||||
"NativeIaC": "",
|
||||
"Other": "1. Identify the Bedrock Agent's execution role (agentResourceRoleArn) in the IAM console\n2. Detach any AWS-managed *FullAccess policies (e.g. AmazonBedrockFullAccess, AdministratorAccess)\n3. Replace inline policies that use Resource: \"*\" with statements scoped to specific resource ARNs and minimal action sets\n4. Attach a permissions boundary that caps what the role can ever do, even if a future policy is added\n5. Re-run Prowler to confirm the check passes",
|
||||
"Terraform": "```hcl\nresource \"aws_iam_role\" \"bedrock_agent\" {\n name = \"<execution_role_name>\"\n assume_role_policy = data.aws_iam_policy_document.trust.json\n permissions_boundary = aws_iam_policy.bedrock_agent_boundary.arn # CRITICAL: caps maximum privileges\n}\n\nresource \"aws_iam_role_policy\" \"bedrock_agent_inline\" {\n role = aws_iam_role.bedrock_agent.name\n policy = jsonencode({\n Version = \"2012-10-17\",\n Statement = [{\n Effect = \"Allow\",\n Action = [\"s3:GetObject\"], # CRITICAL: narrow action\n Resource = [\"arn:aws:s3:::my-rag-bucket/*\"] # CRITICAL: narrow resource\n }]\n })\n}\n```"
|
||||
},
|
||||
"Recommendation": {
|
||||
"Text": "Apply **least privilege** to every Bedrock Agent execution role: scope `Action` and `Resource` to exactly what the agent needs, avoid AWS-managed `*FullAccess` policies, and always attach a **permissions boundary** so that future policy edits cannot exceed an approved ceiling. Treat agent roles as high-risk because prompt injection can weaponize any granted permission.",
|
||||
"Url": "https://hub.prowler.com/check/bedrock_agent_role_least_privilege"
|
||||
}
|
||||
},
|
||||
"Categories": [
|
||||
"gen-ai"
|
||||
],
|
||||
"DependsOn": [],
|
||||
"RelatedTo": [],
|
||||
"Notes": ""
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
from prowler.lib.check.models import Check, Check_Report_AWS
|
||||
from prowler.providers.aws.services.bedrock.bedrock_agent_client import (
|
||||
bedrock_agent_client,
|
||||
)
|
||||
from prowler.providers.aws.services.iam.iam_client import iam_client
|
||||
from prowler.providers.aws.services.iam.lib.policy import check_admin_access
|
||||
from prowler.providers.aws.services.iam.lib.privilege_escalation import (
|
||||
check_privilege_escalation,
|
||||
)
|
||||
|
||||
|
||||
class bedrock_agent_role_least_privilege(Check):
|
||||
"""Ensure Bedrock Agent execution roles follow least privilege.
|
||||
|
||||
A Bedrock Agent's execution role is evaluated against three criteria:
|
||||
- No AWS-managed ``*FullAccess`` policy attached.
|
||||
- No attached or inline policy granting administrative access or known
|
||||
privilege escalation combinations.
|
||||
- A permissions boundary is configured on the role.
|
||||
"""
|
||||
|
||||
def execute(self) -> list[Check_Report_AWS]:
|
||||
"""Run the least-privilege evaluation across all Bedrock Agents.
|
||||
|
||||
Returns:
|
||||
A list of ``Check_Report_AWS`` with one entry per agent. The
|
||||
status is ``FAIL`` when any of the criteria above is violated,
|
||||
or when the execution role cannot be resolved in IAM.
|
||||
"""
|
||||
findings = []
|
||||
roles_by_arn = {role.arn: role for role in (iam_client.roles or [])}
|
||||
|
||||
for agent in bedrock_agent_client.agents.values():
|
||||
report = Check_Report_AWS(metadata=self.metadata(), resource=agent)
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"Bedrock Agent {agent.name} execution role follows least privilege."
|
||||
)
|
||||
|
||||
role = roles_by_arn.get(agent.role_arn) if agent.role_arn else None
|
||||
if role is None:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"Bedrock Agent {agent.name} execution role could not be "
|
||||
f"resolved in IAM and cannot be evaluated for least privilege."
|
||||
)
|
||||
findings.append(report)
|
||||
continue
|
||||
|
||||
violations = []
|
||||
|
||||
for policy in role.attached_policies:
|
||||
policy_arn = policy.get("PolicyArn", "")
|
||||
policy_name = policy.get("PolicyName") or policy_arn
|
||||
if policy_arn.startswith(
|
||||
"arn:aws:iam::aws:policy/"
|
||||
) and policy_arn.endswith("FullAccess"):
|
||||
violations.append(
|
||||
f"managed policy {policy_name} grants full access"
|
||||
)
|
||||
continue
|
||||
policy_obj = iam_client.policies.get(policy_arn)
|
||||
if policy_obj is None or not policy_obj.document:
|
||||
continue
|
||||
document = policy_obj.document
|
||||
if check_admin_access(document):
|
||||
violations.append(
|
||||
f"managed policy {policy_name} grants administrative access"
|
||||
)
|
||||
elif check_privilege_escalation(document):
|
||||
violations.append(
|
||||
f"managed policy {policy_name} allows privilege escalation"
|
||||
)
|
||||
|
||||
for inline_name in role.inline_policies:
|
||||
policy_obj = iam_client.policies.get(f"{role.arn}:policy/{inline_name}")
|
||||
if policy_obj is None or not policy_obj.document:
|
||||
continue
|
||||
document = policy_obj.document
|
||||
if check_admin_access(document):
|
||||
violations.append(
|
||||
f"inline policy {inline_name} grants administrative access"
|
||||
)
|
||||
elif check_privilege_escalation(document):
|
||||
violations.append(
|
||||
f"inline policy {inline_name} allows privilege escalation"
|
||||
)
|
||||
|
||||
if not role.permissions_boundary:
|
||||
violations.append("no permissions boundary configured")
|
||||
|
||||
if violations:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"Bedrock Agent {agent.name} execution role violates least "
|
||||
f"privilege: {'; '.join(violations)}."
|
||||
)
|
||||
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
@@ -146,6 +146,7 @@ class BedrockAgent(AWSService):
|
||||
self.prompts = {}
|
||||
self.prompt_scanned_regions: set = set()
|
||||
self.__threading_call__(self._list_agents)
|
||||
self.__threading_call__(self._get_agent, self.agents.values())
|
||||
self.__threading_call__(self._list_prompts)
|
||||
self.__threading_call__(self._get_prompt, self.prompts.values())
|
||||
self.__threading_call__(self._list_tags_for_resource, self.agents.values())
|
||||
@@ -174,6 +175,22 @@ class BedrockAgent(AWSService):
|
||||
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
|
||||
def _get_agent(self, agent):
|
||||
"""Fetch full agent details to capture the execution role ARN.
|
||||
|
||||
list_agents only returns summaries (no agentResourceRoleArn), so we
|
||||
need a per-agent GetAgent call. Stored on the Agent model for use by
|
||||
checks like bedrock_agent_role_least_privilege.
|
||||
"""
|
||||
logger.info("Bedrock Agent - Getting Agent...")
|
||||
try:
|
||||
agent_info = self.regional_clients[agent.region].get_agent(agentId=agent.id)
|
||||
agent.role_arn = agent_info.get("agent", {}).get("agentResourceRoleArn")
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{agent.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
|
||||
def _list_prompts(self, regional_client):
|
||||
"""List all prompts in a region."""
|
||||
logger.info("Bedrock Agent - Listing Prompts...")
|
||||
@@ -236,6 +253,7 @@ class Agent(BaseModel):
|
||||
name: str
|
||||
arn: str
|
||||
guardrail_id: Optional[str] = None
|
||||
role_arn: Optional[str] = None
|
||||
region: str
|
||||
tags: Optional[list] = []
|
||||
|
||||
|
||||
+1
-2
@@ -17,9 +17,8 @@
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html",
|
||||
"https://www.clouddefense.ai/compliance-rules/cis-v130/monitoring/cis-v130-4-11",
|
||||
"https://support.icompaas.com/support/solutions/articles/62000084031-ensure-a-log-metric-filter-and-alarm-exist-for-changes-to-network-access-control-lists-nacl-",
|
||||
"https://trendmicro.com/trendaivisiononecloudriskmanagement/knowledge-base/aws/CloudWatchLogs/network-acl-changes-alarm.html",
|
||||
"https://www.trendmicro.com/trendaivisiononecloudriskmanagement/knowledge-base/aws/CloudWatchLogs/network-acl-changes-alarm.html",
|
||||
"https://support.icompaas.com/support/solutions/articles/62000233134-4-11-ensure-network-access-control-list-nacl-changes-are-monitored-manual-"
|
||||
],
|
||||
"Remediation": {
|
||||
|
||||
+11
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,16 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_changes_to_network_acls_alarm_configured(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?CreateNetworkAcl.+\$\.eventName\s*=\s*.?CreateNetworkAclEntry.+\$\.eventName\s*=\s*.?DeleteNetworkAcl.+\$\.eventName\s*=\s*.?DeleteNetworkAclEntry.+\$\.eventName\s*=\s*.?ReplaceNetworkAclEntry.+\$\.eventName\s*=\s*.?ReplaceNetworkAclAssociation.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"CreateNetworkAcl",
|
||||
"CreateNetworkAclEntry",
|
||||
"DeleteNetworkAcl",
|
||||
"DeleteNetworkAclEntry",
|
||||
"ReplaceNetworkAclEntry",
|
||||
"ReplaceNetworkAclAssociation",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+11
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,16 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_changes_to_network_gateways_alarm_configured(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?CreateCustomerGateway.+\$\.eventName\s*=\s*.?DeleteCustomerGateway.+\$\.eventName\s*=\s*.?AttachInternetGateway.+\$\.eventName\s*=\s*.?CreateInternetGateway.+\$\.eventName\s*=\s*.?DeleteInternetGateway.+\$\.eventName\s*=\s*.?DetachInternetGateway.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"CreateCustomerGateway",
|
||||
"DeleteCustomerGateway",
|
||||
"AttachInternetGateway",
|
||||
"CreateInternetGateway",
|
||||
"DeleteInternetGateway",
|
||||
"DetachInternetGateway",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+1
-1
@@ -37,5 +37,5 @@
|
||||
],
|
||||
"DependsOn": [],
|
||||
"RelatedTo": [],
|
||||
"Notes": ""
|
||||
"Notes": "Logging and Monitoring"
|
||||
}
|
||||
|
||||
+13
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,18 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_changes_to_network_route_tables_alarm_configured(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventSource\s*=\s*.?ec2.amazonaws.com.+\$\.eventName\s*=\s*.?CreateRoute.+\$\.eventName\s*=\s*.?CreateRouteTable.+\$\.eventName\s*=\s*.?ReplaceRoute.+\$\.eventName\s*=\s*.?ReplaceRouteTableAssociation.+\$\.eventName\s*=\s*.?DeleteRouteTable.+\$\.eventName\s*=\s*.?DeleteRoute.+\$\.eventName\s*=\s*.?DisassociateRouteTable.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_source="ec2.amazonaws.com",
|
||||
event_names=[
|
||||
"CreateRoute",
|
||||
"CreateRouteTable",
|
||||
"ReplaceRoute",
|
||||
"ReplaceRouteTableAssociation",
|
||||
"DeleteRouteTable",
|
||||
"DeleteRoute",
|
||||
"DisassociateRouteTable",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+16
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,21 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_changes_to_vpcs_alarm_configured(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?CreateVpc.+\$\.eventName\s*=\s*.?DeleteVpc.+\$\.eventName\s*=\s*.?ModifyVpcAttribute.+\$\.eventName\s*=\s*.?AcceptVpcPeeringConnection.+\$\.eventName\s*=\s*.?CreateVpcPeeringConnection.+\$\.eventName\s*=\s*.?DeleteVpcPeeringConnection.+\$\.eventName\s*=\s*.?RejectVpcPeeringConnection.+\$\.eventName\s*=\s*.?AttachClassicLinkVpc.+\$\.eventName\s*=\s*.?DetachClassicLinkVpc.+\$\.eventName\s*=\s*.?DisableVpcClassicLink.+\$\.eventName\s*=\s*.?EnableVpcClassicLink.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"CreateVpc",
|
||||
"DeleteVpc",
|
||||
"ModifyVpcAttribute",
|
||||
"AcceptVpcPeeringConnection",
|
||||
"CreateVpcPeeringConnection",
|
||||
"DeleteVpcPeeringConnection",
|
||||
"RejectVpcPeeringConnection",
|
||||
"AttachClassicLinkVpc",
|
||||
"DetachClassicLinkVpc",
|
||||
"DisableVpcClassicLink",
|
||||
"EnableVpcClassicLink",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+10
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -15,7 +16,15 @@ class cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_change
|
||||
Check
|
||||
):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventSource\s*=\s*.?config.amazonaws.com.+\$\.eventName\s*=\s*.?StopConfigurationRecorder.+\$\.eventName\s*=\s*.?DeleteDeliveryChannel.+\$\.eventName\s*=\s*.?PutDeliveryChannel.+\$\.eventName\s*=\s*.?PutConfigurationRecorder.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_source="config.amazonaws.com",
|
||||
event_names=[
|
||||
"StopConfigurationRecorder",
|
||||
"DeleteDeliveryChannel",
|
||||
"PutDeliveryChannel",
|
||||
"PutConfigurationRecorder",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+10
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -15,7 +16,15 @@ class cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_change
|
||||
Check
|
||||
):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?CreateTrail.+\$\.eventName\s*=\s*.?UpdateTrail.+\$\.eventName\s*=\s*.?DeleteTrail.+\$\.eventName\s*=\s*.?StartLogging.+\$\.eventName\s*=\s*.?StopLogging.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"CreateTrail",
|
||||
"UpdateTrail",
|
||||
"DeleteTrail",
|
||||
"StartLogging",
|
||||
"StopLogging",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,10 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_authentication_failures(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?ConsoleLogin.+\$\.errorMessage\s*=\s*.?Failed authentication.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=["ConsoleLogin"],
|
||||
extra_clauses=[("errorMessage", "=", "Failed authentication")],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+27
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,32 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_aws_organizations_changes(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventSource\s*=\s*.?organizations\.amazonaws\.com.+\$\.eventName\s*=\s*.?AcceptHandshake.+\$\.eventName\s*=\s*.?AttachPolicy.+\$\.eventName\s*=\s*.?CancelHandshake.+\$\.eventName\s*=\s*.?CreateAccount.+\$\.eventName\s*=\s*.?CreateOrganization.+\$\.eventName\s*=\s*.?CreateOrganizationalUnit.+\$\.eventName\s*=\s*.?CreatePolicy.+\$\.eventName\s*=\s*.?DeclineHandshake.+\$\.eventName\s*=\s*.?DeleteOrganization.+\$\.eventName\s*=\s*.?DeleteOrganizationalUnit.+\$\.eventName\s*=\s*.?DeletePolicy.+\$\.eventName\s*=\s*.?EnableAllFeatures.+\$\.eventName\s*=\s*.?EnablePolicyType.+\$\.eventName\s*=\s*.?InviteAccountToOrganization.+\$\.eventName\s*=\s*.?LeaveOrganization.+\$\.eventName\s*=\s*.?DetachPolicy.+\$\.eventName\s*=\s*.?DisablePolicyType.+\$\.eventName\s*=\s*.?MoveAccount.+\$\.eventName\s*=\s*.?RemoveAccountFromOrganization.+\$\.eventName\s*=\s*.?UpdateOrganizationalUnit.+\$\.eventName\s*=\s*.?UpdatePolicy.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_source="organizations.amazonaws.com",
|
||||
event_names=[
|
||||
"AcceptHandshake",
|
||||
"AttachPolicy",
|
||||
"CancelHandshake",
|
||||
"CreateAccount",
|
||||
"CreateOrganization",
|
||||
"CreateOrganizationalUnit",
|
||||
"CreatePolicy",
|
||||
"DeclineHandshake",
|
||||
"DeleteOrganization",
|
||||
"DeleteOrganizationalUnit",
|
||||
"DeletePolicy",
|
||||
"EnableAllFeatures",
|
||||
"EnablePolicyType",
|
||||
"InviteAccountToOrganization",
|
||||
"LeaveOrganization",
|
||||
"DetachPolicy",
|
||||
"DisablePolicyType",
|
||||
"MoveAccount",
|
||||
"RemoveAccountFromOrganization",
|
||||
"UpdateOrganizationalUnit",
|
||||
"UpdatePolicy",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,10 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventSource\s*=\s*.?kms.amazonaws.com.+\$\.eventName\s*=\s*.?DisableKey.+\$\.eventName\s*=\s*.?ScheduleKeyDeletion.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_source="kms.amazonaws.com",
|
||||
event_names=["DisableKey", "ScheduleKeyDeletion"],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+1
-2
@@ -17,8 +17,7 @@
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html",
|
||||
"https://support.icompaas.com/support/solutions/articles/62000086674-ensure-a-log-metric-filter-and-alarm-exist-for-s3-bucket-policy-changes",
|
||||
"https://www.tenable.com/audits/items/CIS_Amazon_Web_Services_Foundations_v5.0.0_L1.audit:8101350d6907e07863ac6748689b3e12"
|
||||
"https://support.icompaas.com/support/solutions/articles/62000086674-ensure-a-log-metric-filter-and-alarm-exist-for-s3-bucket-policy-changes"
|
||||
],
|
||||
"Remediation": {
|
||||
"Code": {
|
||||
|
||||
+15
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,20 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_for_s3_bucket_policy_changes(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventSource\s*=\s*.?s3.amazonaws.com.+\$\.eventName\s*=\s*.?PutBucketAcl.+\$\.eventName\s*=\s*.?PutBucketPolicy.+\$\.eventName\s*=\s*.?PutBucketCors.+\$\.eventName\s*=\s*.?PutBucketLifecycle.+\$\.eventName\s*=\s*.?PutBucketReplication.+\$\.eventName\s*=\s*.?DeleteBucketPolicy.+\$\.eventName\s*=\s*.?DeleteBucketCors.+\$\.eventName\s*=\s*.?DeleteBucketLifecycle.+\$\.eventName\s*=\s*.?DeleteBucketReplication.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_source="s3.amazonaws.com",
|
||||
event_names=[
|
||||
"PutBucketAcl",
|
||||
"PutBucketPolicy",
|
||||
"PutBucketCors",
|
||||
"PutBucketLifecycle",
|
||||
"PutBucketReplication",
|
||||
"DeleteBucketPolicy",
|
||||
"DeleteBucketCors",
|
||||
"DeleteBucketLifecycle",
|
||||
"DeleteBucketReplication",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
-1
@@ -17,7 +17,6 @@
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html",
|
||||
"https://www.clouddefense.ai/compliance-rules/cis-v140/monitoring/cis-v140-4-4",
|
||||
"https://www.intelligentdiscovery.io/controls/cloudwatch/cloudwatch-alarm-iam-policy-change"
|
||||
],
|
||||
"Remediation": {
|
||||
|
||||
+21
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,26 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_policy_changes(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?DeleteGroupPolicy.+\$\.eventName\s*=\s*.?DeleteRolePolicy.+\$\.eventName\s*=\s*.?DeleteUserPolicy.+\$\.eventName\s*=\s*.?PutGroupPolicy.+\$\.eventName\s*=\s*.?PutRolePolicy.+\$\.eventName\s*=\s*.?PutUserPolicy.+\$\.eventName\s*=\s*.?CreatePolicy.+\$\.eventName\s*=\s*.?DeletePolicy.+\$\.eventName\s*=\s*.?CreatePolicyVersion.+\$\.eventName\s*=\s*.?DeletePolicyVersion.+\$\.eventName\s*=\s*.?AttachRolePolicy.+\$\.eventName\s*=\s*.?DetachRolePolicy.+\$\.eventName\s*=\s*.?AttachUserPolicy.+\$\.eventName\s*=\s*.?DetachUserPolicy.+\$\.eventName\s*=\s*.?AttachGroupPolicy.+\$\.eventName\s*=\s*.?DetachGroupPolicy.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"DeleteGroupPolicy",
|
||||
"DeleteRolePolicy",
|
||||
"DeleteUserPolicy",
|
||||
"PutGroupPolicy",
|
||||
"PutRolePolicy",
|
||||
"PutUserPolicy",
|
||||
"CreatePolicy",
|
||||
"DeletePolicy",
|
||||
"CreatePolicyVersion",
|
||||
"DeletePolicyVersion",
|
||||
"AttachRolePolicy",
|
||||
"DetachRolePolicy",
|
||||
"AttachUserPolicy",
|
||||
"DetachUserPolicy",
|
||||
"AttachGroupPolicy",
|
||||
"DetachGroupPolicy",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
+11
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,16 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_security_group_changes(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?AuthorizeSecurityGroupIngress.+\$\.eventName\s*=\s*.?AuthorizeSecurityGroupEgress.+\$\.eventName\s*=\s*.?RevokeSecurityGroupIngress.+\$\.eventName\s*=\s*.?RevokeSecurityGroupEgress.+\$\.eventName\s*=\s*.?CreateSecurityGroup.+\$\.eventName\s*=\s*.?DeleteSecurityGroup.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=[
|
||||
"AuthorizeSecurityGroupIngress",
|
||||
"AuthorizeSecurityGroupEgress",
|
||||
"RevokeSecurityGroupIngress",
|
||||
"RevokeSecurityGroupEgress",
|
||||
"CreateSecurityGroup",
|
||||
"DeleteSecurityGroup",
|
||||
],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
-1
@@ -21,7 +21,6 @@
|
||||
"https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html",
|
||||
"https://www.trendmicro.com/trendaivisiononecloudriskmanagement/knowledge-base/aws/CloudWatchLogs/console-sign-in-without-mfa.html",
|
||||
"https://www.tenable.com/audits/items/CIS_Amazon_Web_Services_Foundations_v3.0.0_L1.audit:1957056ee174cc38502d5f5f1864333b",
|
||||
"https://www.clouddefense.ai/compliance-rules/gdpr/data-protection/log-metric-filter-console-login-mfa",
|
||||
"https://www.intelligentdiscovery.io/controls/cloudwatch/cloudwatch-alarm-no-mfa",
|
||||
"https://support.icompaas.com/support/solutions/articles/62000083605-ensure-a-log-metric-filter-and-alarm-exist-for-management-console-sign-in-without-mfa"
|
||||
],
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_client import (
|
||||
cloudwatch_client,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
check_cloudwatch_log_metric_filter,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
@@ -13,7 +14,10 @@ from prowler.providers.aws.services.cloudwatch.logs_client import logs_client
|
||||
|
||||
class cloudwatch_log_metric_filter_sign_in_without_mfa(Check):
|
||||
def execute(self):
|
||||
pattern = r"\$\.eventName\s*=\s*.?ConsoleLogin.+\$\.additionalEventData\.MFAUsed\s*!=\s*.?Yes.?"
|
||||
pattern = build_metric_filter_pattern(
|
||||
event_names=["ConsoleLogin"],
|
||||
extra_clauses=[("additionalEventData.MFAUsed", "!=", "Yes")],
|
||||
)
|
||||
findings = []
|
||||
|
||||
report = check_cloudwatch_log_metric_filter(
|
||||
|
||||
@@ -3,6 +3,45 @@ import re
|
||||
from prowler.lib.check.models import Check_Report_AWS
|
||||
|
||||
|
||||
def build_metric_filter_pattern(
|
||||
*,
|
||||
event_names: list[str] | None = None,
|
||||
event_source: str | None = None,
|
||||
extra_clauses: list[tuple[str, str, str]] | None = None,
|
||||
) -> str:
|
||||
"""Build a regex pattern to match a CloudWatch Logs filterPattern string.
|
||||
|
||||
All clauses must be present for the pattern to match, regardless of the
|
||||
order in which AWS stores them. Event names are matched exactly, so a
|
||||
short name like ``CreateRoute`` will not be satisfied by a longer one
|
||||
like ``CreateRouteTable``.
|
||||
|
||||
Pass the result directly to ``check_cloudwatch_log_metric_filter``.
|
||||
|
||||
Args:
|
||||
event_names: AWS API action names to require (``$.eventName``).
|
||||
event_source: optional service principal to require (``$.eventSource``),
|
||||
e.g. ``"ec2.amazonaws.com"``.
|
||||
extra_clauses: additional conditions as ``(field, operator, value)``
|
||||
tuples, where ``operator`` is ``"="`` or ``"!="``. Example:
|
||||
``("additionalEventData.MFAUsed", "!=", "Yes")``.
|
||||
|
||||
Returns:
|
||||
A regex string for use with ``re.search(..., flags=re.DOTALL)``.
|
||||
"""
|
||||
parts: list[str] = []
|
||||
if event_source is not None:
|
||||
parts.append(rf"(?=.*\$\.eventSource\s*=\s*.?{re.escape(event_source)})")
|
||||
for name in event_names or []:
|
||||
parts.append(rf"(?=.*\$\.eventName\s*=\s*.?{re.escape(name)}\b)")
|
||||
for field, operator, value in extra_clauses or []:
|
||||
if operator not in ("=", "!="):
|
||||
raise ValueError(f"unsupported operator {operator!r}; expected '=' or '!='")
|
||||
op = r"\s*!=\s*" if operator == "!=" else r"\s*=\s*"
|
||||
parts.append(rf"(?=.*\$\.{re.escape(field)}{op}.?{re.escape(value)})")
|
||||
return "".join(parts)
|
||||
|
||||
|
||||
def check_cloudwatch_log_metric_filter(
|
||||
metric_filter_pattern: str,
|
||||
trails: list,
|
||||
|
||||
@@ -103,6 +103,9 @@ class IAM(AWSService):
|
||||
self._get_user_temporary_credentials_usage()
|
||||
self.organization_features = []
|
||||
self._list_organizations_features()
|
||||
# ListRoles does not echo PermissionsBoundary; backfill via GetRole.
|
||||
if self.roles:
|
||||
self.__threading_call__(self._get_role_permissions_boundary, self.roles)
|
||||
# List missing tags
|
||||
self.__threading_call__(self._list_tags, self.users)
|
||||
self.__threading_call__(self._list_tags, self.roles)
|
||||
@@ -133,6 +136,7 @@ class IAM(AWSService):
|
||||
arn=role["Arn"],
|
||||
assume_role_policy=role["AssumeRolePolicyDocument"],
|
||||
is_service_role=is_service_role(role),
|
||||
permissions_boundary=role.get("PermissionsBoundary"),
|
||||
)
|
||||
)
|
||||
except ClientError as error:
|
||||
@@ -460,6 +464,34 @@ class IAM(AWSService):
|
||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
|
||||
def _get_role_permissions_boundary(self, role):
|
||||
"""Backfill ``role.permissions_boundary`` via ``GetRole``.
|
||||
|
||||
``ListRoles`` does not return ``PermissionsBoundary`` in practice, so
|
||||
the value is fetched per role and stored on the ``Role`` model.
|
||||
|
||||
Args:
|
||||
role: The ``Role`` instance to enrich.
|
||||
"""
|
||||
try:
|
||||
response = self.client.get_role(RoleName=role.name)
|
||||
role.permissions_boundary = response.get("Role", {}).get(
|
||||
"PermissionsBoundary"
|
||||
)
|
||||
except ClientError as error:
|
||||
if error.response["Error"]["Code"] == "NoSuchEntity":
|
||||
logger.warning(
|
||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
|
||||
def _list_attached_role_policies(self):
|
||||
logger.info("IAM - List Attached Role Policies...")
|
||||
try:
|
||||
@@ -1139,6 +1171,7 @@ class Role(BaseModel):
|
||||
is_service_role: bool
|
||||
attached_policies: list[dict] = []
|
||||
inline_policies: list[str] = []
|
||||
permissions_boundary: Optional[dict] = None
|
||||
tags: Optional[list]
|
||||
|
||||
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"Provider": "stackit",
|
||||
"CheckID": "objectstorage_access_key_expiration",
|
||||
"CheckTitle": "ObjectStorage access keys should have an expiration date",
|
||||
"CheckType": [],
|
||||
"ServiceName": "objectstorage",
|
||||
"SubServiceName": "",
|
||||
"ResourceIdTemplate": "",
|
||||
"Severity": "high",
|
||||
"ResourceType": "NotDefined",
|
||||
"ResourceGroup": "IAM",
|
||||
"Description": "**ObjectStorage access keys** should have an explicit expiration date. Long-lived credentials increase the blast radius of a credential compromise because they cannot expire on their own. Setting an expiration date enforces periodic rotation and limits the exposure window if a key is leaked.",
|
||||
"Risk": "If an **ObjectStorage access key** is leaked, stolen, or forgotten without an expiration date, it remains usable indefinitely. An attacker can retain persistent access to object storage resources until the key is manually revoked.",
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/",
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/how-tos/create-and-delete-object-storage-credentials/"
|
||||
],
|
||||
"Remediation": {
|
||||
"Code": {
|
||||
"CLI": "",
|
||||
"NativeIaC": "",
|
||||
"Other": "1. In the STACKIT Portal navigate to Object Storage > Access Keys. 2. Delete the non-expiring access key. 3. Create a new access key with an expiration date appropriate for your rotation policy (e.g. 90 days). 4. Update all applications and services that use the old key with the new credentials.",
|
||||
"Terraform": ""
|
||||
},
|
||||
"Recommendation": {
|
||||
"Text": "Create **ObjectStorage access keys** with an explicit expiration date and establish a rotation process. Delete non-expiring keys and replace them with time-limited credentials. A rotation period of **90 days or less** is recommended.",
|
||||
"Url": "https://hub.prowler.com/check/objectstorage_access_key_expiration"
|
||||
}
|
||||
},
|
||||
"Categories": [
|
||||
"identity-access"
|
||||
],
|
||||
"DependsOn": [],
|
||||
"RelatedTo": [],
|
||||
"Notes": "Access keys are scoped to credentials groups. This check evaluates all access keys across all credentials groups in the project."
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
from prowler.lib.check.models import Check, CheckReportStackIT
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_client import (
|
||||
objectstorage_client,
|
||||
)
|
||||
|
||||
|
||||
class objectstorage_access_key_expiration(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for key in objectstorage_client.access_keys:
|
||||
report = CheckReportStackIT(
|
||||
metadata=self.metadata(),
|
||||
resource=key,
|
||||
)
|
||||
report.resource_id = key.key_id
|
||||
report.resource_name = key.display_name
|
||||
report.location = key.region
|
||||
|
||||
if key.has_expiration():
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Access key {key.display_name} has an expiration date set ({key.expires})."
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Access key {key.display_name} has no expiration date and never rotates."
|
||||
|
||||
findings.append(report)
|
||||
return findings
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"Provider": "stackit",
|
||||
"CheckID": "objectstorage_bucket_object_lock_enabled",
|
||||
"CheckTitle": "ObjectStorage buckets should have S3 Object Lock enabled",
|
||||
"CheckType": [],
|
||||
"ServiceName": "objectstorage",
|
||||
"SubServiceName": "",
|
||||
"ResourceIdTemplate": "",
|
||||
"Severity": "high",
|
||||
"ResourceType": "NotDefined",
|
||||
"ResourceGroup": "storage",
|
||||
"Description": "**S3 Object Lock** prevents objects from being deleted or overwritten for a fixed period or indefinitely. Enabling it protects against accidental deletion and ransomware by enforcing a **write-once-read-many (WORM)** model. Object Lock can only be enabled when the bucket is created.",
|
||||
"Risk": "Without **Object Lock**, objects can be deleted or overwritten at any time, increasing the risk of data loss from accidental deletion, malicious actors, or ransomware. Backups and compliance data are particularly vulnerable.",
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/",
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/how-tos/object-lock-bucket/"
|
||||
],
|
||||
"Remediation": {
|
||||
"Code": {
|
||||
"CLI": "",
|
||||
"NativeIaC": "",
|
||||
"Other": "Object Lock must be enabled at bucket creation time and cannot be enabled on an existing bucket. Create a new bucket with Object Lock enabled and migrate your data to it.",
|
||||
"Terraform": ""
|
||||
},
|
||||
"Recommendation": {
|
||||
"Text": "Create **ObjectStorage buckets** with S3 Object Lock enabled for workloads that require data immutability, compliance archiving, or ransomware protection. Object Lock cannot be retroactively enabled on existing buckets.",
|
||||
"Url": "https://hub.prowler.com/check/objectstorage_bucket_object_lock_enabled"
|
||||
}
|
||||
},
|
||||
"Categories": [
|
||||
"resilience"
|
||||
],
|
||||
"DependsOn": [],
|
||||
"RelatedTo": [],
|
||||
"Notes": "Object Lock can only be activated at bucket creation. Buckets without Object Lock are not necessarily misconfigured — evaluate based on the sensitivity and compliance requirements of the stored data."
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
from prowler.lib.check.models import Check, CheckReportStackIT
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_client import (
|
||||
objectstorage_client,
|
||||
)
|
||||
|
||||
|
||||
class objectstorage_bucket_object_lock_enabled(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for bucket in objectstorage_client.buckets:
|
||||
report = CheckReportStackIT(
|
||||
metadata=self.metadata(),
|
||||
resource=bucket,
|
||||
)
|
||||
report.resource_id = bucket.name
|
||||
report.resource_name = bucket.name
|
||||
report.location = bucket.region
|
||||
|
||||
if bucket.object_lock_enabled:
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"Bucket {bucket.name} has S3 Object Lock enabled."
|
||||
)
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"Bucket {bucket.name} does not have S3 Object Lock enabled."
|
||||
)
|
||||
|
||||
findings.append(report)
|
||||
return findings
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"Provider": "stackit",
|
||||
"CheckID": "objectstorage_bucket_retention_policy",
|
||||
"CheckTitle": "ObjectStorage buckets should have a default retention policy configured",
|
||||
"CheckType": [],
|
||||
"ServiceName": "objectstorage",
|
||||
"SubServiceName": "",
|
||||
"ResourceIdTemplate": "",
|
||||
"Severity": "medium",
|
||||
"ResourceType": "NotDefined",
|
||||
"ResourceGroup": "storage",
|
||||
"Description": "An **ObjectStorage default retention policy** automatically applies a minimum retention period to every object uploaded to the bucket, preventing deletion or overwriting before the period expires. Without it, objects can be removed immediately after upload, undermining compliance and data durability requirements.",
|
||||
"Risk": "Buckets without a **default retention policy** offer no automatic protection against premature object deletion. Compliance data, audit logs, and backups may be deleted before their required retention period elapses.",
|
||||
"RelatedUrl": "",
|
||||
"AdditionalURLs": [
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/",
|
||||
"https://docs.stackit.cloud/products/storage/object-storage/how-tos/object-lock-default-retention/"
|
||||
],
|
||||
"Remediation": {
|
||||
"Code": {
|
||||
"CLI": "",
|
||||
"NativeIaC": "",
|
||||
"Other": "Use the STACKIT Object Storage API or Portal to set a default retention policy on the bucket. Choose COMPLIANCE mode for strict immutability or GOVERNANCE mode to allow privileged users to override the policy.",
|
||||
"Terraform": ""
|
||||
},
|
||||
"Recommendation": {
|
||||
"Text": "Configure a **default retention policy** on every bucket that stores compliance-relevant or sensitive data. Choose `COMPLIANCE` mode for regulatory requirements and `GOVERNANCE` mode when administrative overrides are acceptable.",
|
||||
"Url": "https://hub.prowler.com/check/objectstorage_bucket_retention_policy"
|
||||
}
|
||||
},
|
||||
"Categories": [
|
||||
"resilience"
|
||||
],
|
||||
"DependsOn": [],
|
||||
"RelatedTo": [
|
||||
"objectstorage_bucket_object_lock_enabled"
|
||||
],
|
||||
"Notes": "A default retention policy requires Object Lock to be enabled on the bucket. Buckets without Object Lock cannot have a retention policy."
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
from prowler.lib.check.models import Check, CheckReportStackIT
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_client import (
|
||||
objectstorage_client,
|
||||
)
|
||||
|
||||
|
||||
class objectstorage_bucket_retention_policy(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for bucket in objectstorage_client.buckets:
|
||||
report = CheckReportStackIT(
|
||||
metadata=self.metadata(),
|
||||
resource=bucket,
|
||||
)
|
||||
report.resource_id = bucket.name
|
||||
report.resource_name = bucket.name
|
||||
report.location = bucket.region
|
||||
|
||||
if bucket.retention_days and bucket.retention_days > 0:
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"Bucket {bucket.name} has a default retention policy of "
|
||||
f"{bucket.retention_days} day(s) in {bucket.retention_mode} mode."
|
||||
)
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Bucket {bucket.name} does not have a default retention policy configured."
|
||||
|
||||
findings.append(report)
|
||||
return findings
|
||||
@@ -0,0 +1,6 @@
|
||||
from prowler.providers.common.provider import Provider
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_service import (
|
||||
ObjectStorageService,
|
||||
)
|
||||
|
||||
objectstorage_client = ObjectStorageService(Provider.get_global_provider())
|
||||
@@ -0,0 +1,306 @@
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from pydantic.v1 import BaseModel
|
||||
|
||||
from prowler.lib.logger import logger
|
||||
from prowler.providers.stackit.stackit_provider import StackitProvider, suppress_stderr
|
||||
|
||||
|
||||
class ObjectStorageService:
|
||||
def __init__(self, provider: StackitProvider):
|
||||
self.provider = provider
|
||||
self.project_id = provider.identity.project_id
|
||||
self.regional_clients = provider.generate_regional_clients("objectstorage")
|
||||
|
||||
self.buckets: list[Bucket] = []
|
||||
self.access_keys: list[AccessKey] = []
|
||||
|
||||
self._fetch_all_regions()
|
||||
|
||||
def _fetch_all_regions(self):
|
||||
for region, client in self.regional_clients.items():
|
||||
try:
|
||||
self._list_buckets(client, region)
|
||||
self._list_access_keys(client, region)
|
||||
except Exception as error:
|
||||
if getattr(error, "status", None) == 404:
|
||||
logger.info(
|
||||
f"StackIT project {self.project_id} has no ObjectStorage "
|
||||
f"presence in region {region}; skipping."
|
||||
)
|
||||
continue
|
||||
raise
|
||||
|
||||
def _handle_api_call(self, api_function, *args, **kwargs):
|
||||
try:
|
||||
with suppress_stderr():
|
||||
return api_function(*args, **kwargs)
|
||||
except Exception as e:
|
||||
self.provider.handle_api_error(e)
|
||||
raise
|
||||
|
||||
def _list_buckets(self, client, region: str):
|
||||
response = self._handle_api_call(
|
||||
client.list_buckets, project_id=self.project_id, region=region
|
||||
)
|
||||
|
||||
buckets_list = getattr(response, "buckets", None) or []
|
||||
if isinstance(response, dict):
|
||||
buckets_list = response.get("buckets", [])
|
||||
|
||||
for bucket_data in buckets_list:
|
||||
try:
|
||||
if hasattr(bucket_data, "name"):
|
||||
name = bucket_data.name
|
||||
object_lock_enabled = getattr(
|
||||
bucket_data, "object_lock_enabled", False
|
||||
)
|
||||
elif isinstance(bucket_data, dict):
|
||||
name = bucket_data.get("name", "")
|
||||
object_lock_enabled = bucket_data.get("objectLockEnabled", False)
|
||||
else:
|
||||
continue
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing bucket: {e}")
|
||||
continue
|
||||
|
||||
retention_days, retention_mode = self._get_default_retention(
|
||||
client, region, name
|
||||
)
|
||||
|
||||
self.buckets.append(
|
||||
Bucket(
|
||||
name=name,
|
||||
region=region,
|
||||
project_id=self.project_id,
|
||||
object_lock_enabled=object_lock_enabled,
|
||||
retention_days=retention_days,
|
||||
retention_mode=retention_mode,
|
||||
)
|
||||
)
|
||||
|
||||
logger.info(f"Listed {len(buckets_list)} buckets in {region}")
|
||||
|
||||
def _get_default_retention(
|
||||
self, client, region: str, bucket_name: str
|
||||
) -> tuple[Optional[int], Optional[str]]:
|
||||
try:
|
||||
response = self._handle_api_call(
|
||||
client.get_default_retention,
|
||||
project_id=self.project_id,
|
||||
region=region,
|
||||
bucket_name=bucket_name,
|
||||
)
|
||||
days = getattr(response, "days", None)
|
||||
mode = getattr(response, "mode", None)
|
||||
if isinstance(response, dict):
|
||||
days = response.get("days")
|
||||
mode = response.get("mode")
|
||||
return days, str(mode) if mode else None
|
||||
except Exception as e:
|
||||
if getattr(e, "status", None) == 404:
|
||||
return None, None
|
||||
raise
|
||||
|
||||
def _list_access_keys(self, client, region: str):
|
||||
credentials_groups_response = self._handle_api_call(
|
||||
client.list_credentials_groups, project_id=self.project_id, region=region
|
||||
)
|
||||
|
||||
credentials_groups = (
|
||||
getattr(credentials_groups_response, "credentials_groups", None) or []
|
||||
)
|
||||
if isinstance(credentials_groups_response, dict):
|
||||
credentials_groups = credentials_groups_response.get(
|
||||
"credentialsGroups",
|
||||
credentials_groups_response.get("credentials_groups", []),
|
||||
)
|
||||
|
||||
total_keys = 0
|
||||
|
||||
for credentials_group_data in credentials_groups:
|
||||
try:
|
||||
if isinstance(credentials_group_data, dict):
|
||||
credentials_group_id = credentials_group_data.get(
|
||||
"id",
|
||||
credentials_group_data.get(
|
||||
"groupId",
|
||||
credentials_group_data.get("credentialsGroupId", ""),
|
||||
),
|
||||
)
|
||||
credentials_group_name = credentials_group_data.get(
|
||||
"displayName",
|
||||
credentials_group_data.get("name", credentials_group_id),
|
||||
)
|
||||
else:
|
||||
credentials_group_id = (
|
||||
getattr(credentials_group_data, "id", None)
|
||||
or getattr(credentials_group_data, "group_id", None)
|
||||
or getattr(credentials_group_data, "credentials_group_id", "")
|
||||
)
|
||||
credentials_group_name = getattr(
|
||||
credentials_group_data,
|
||||
"display_name",
|
||||
getattr(credentials_group_data, "name", credentials_group_id),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing credentials group: {e}")
|
||||
continue
|
||||
|
||||
if not credentials_group_id:
|
||||
continue
|
||||
|
||||
response = self._list_access_keys_response(
|
||||
client, region, credentials_group_id
|
||||
)
|
||||
keys_list = self._extract_access_keys(response)
|
||||
|
||||
for key_data in keys_list:
|
||||
try:
|
||||
if hasattr(key_data, "key_id"):
|
||||
key_id = key_data.key_id
|
||||
display_name = getattr(key_data, "display_name", key_id)
|
||||
expires = getattr(key_data, "expires", None)
|
||||
elif isinstance(key_data, dict):
|
||||
key_id = key_data.get("keyId", key_data.get("key_id", ""))
|
||||
display_name = key_data.get(
|
||||
"displayName", key_data.get("display_name", key_id)
|
||||
)
|
||||
expires = key_data.get("expires")
|
||||
else:
|
||||
continue
|
||||
|
||||
if not key_id:
|
||||
continue
|
||||
|
||||
self.access_keys.append(
|
||||
AccessKey(
|
||||
key_id=key_id,
|
||||
display_name=display_name,
|
||||
expires=expires,
|
||||
region=region,
|
||||
project_id=self.project_id,
|
||||
credentials_group_id=credentials_group_id,
|
||||
credentials_group_name=credentials_group_name,
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing access key: {e}")
|
||||
continue
|
||||
|
||||
total_keys += len(keys_list)
|
||||
|
||||
logger.info(f"Listed {total_keys} access keys in {region}")
|
||||
|
||||
def _list_access_keys_response(
|
||||
self, client, region: str, credentials_group_id: str
|
||||
):
|
||||
raw_method = None
|
||||
if callable(
|
||||
getattr(type(client), "list_access_keys_without_preload_content", None)
|
||||
):
|
||||
raw_method = client.list_access_keys_without_preload_content
|
||||
elif callable(vars(client).get("list_access_keys_without_preload_content")):
|
||||
raw_method = vars(client)["list_access_keys_without_preload_content"]
|
||||
|
||||
if raw_method:
|
||||
response = self._handle_api_call(
|
||||
raw_method,
|
||||
project_id=self.project_id,
|
||||
region=region,
|
||||
credentials_group=credentials_group_id,
|
||||
)
|
||||
self._raise_for_raw_response_status(response)
|
||||
return response
|
||||
|
||||
return self._handle_api_call(
|
||||
client.list_access_keys,
|
||||
project_id=self.project_id,
|
||||
region=region,
|
||||
credentials_group=credentials_group_id,
|
||||
)
|
||||
|
||||
def _raise_for_raw_response_status(self, response):
|
||||
status = getattr(response, "status", None)
|
||||
if status is None:
|
||||
status = getattr(response, "status_code", None)
|
||||
if isinstance(status, int) and status >= 400:
|
||||
error = Exception(
|
||||
f"StackIT ObjectStorage list_access_keys failed with status {status}"
|
||||
)
|
||||
error.status = status
|
||||
self.provider.handle_api_error(error)
|
||||
raise error
|
||||
|
||||
@staticmethod
|
||||
def _extract_access_keys(response) -> list:
|
||||
payload = response
|
||||
if not isinstance(payload, (dict, list)):
|
||||
json_method = getattr(response, "json", None)
|
||||
if callable(json_method):
|
||||
payload = json_method()
|
||||
elif hasattr(response, "data"):
|
||||
payload = ObjectStorageService._parse_raw_json(response.data)
|
||||
elif hasattr(response, "text"):
|
||||
payload = ObjectStorageService._parse_raw_json(response.text)
|
||||
|
||||
if isinstance(payload, dict):
|
||||
return payload.get("accessKeys", payload.get("access_keys", []))
|
||||
if isinstance(payload, list):
|
||||
return payload
|
||||
return getattr(response, "access_keys", None) or []
|
||||
|
||||
@staticmethod
|
||||
def _parse_raw_json(raw):
|
||||
if raw in (None, b"", ""):
|
||||
return {}
|
||||
if isinstance(raw, (bytes, bytearray)):
|
||||
raw = raw.decode("utf-8")
|
||||
if isinstance(raw, str):
|
||||
return json.loads(raw)
|
||||
return raw
|
||||
|
||||
|
||||
class Bucket(BaseModel):
|
||||
name: str
|
||||
region: str
|
||||
project_id: str
|
||||
object_lock_enabled: bool = False
|
||||
retention_days: Optional[int] = None
|
||||
retention_mode: Optional[str] = None
|
||||
|
||||
|
||||
class AccessKey(BaseModel):
|
||||
key_id: str
|
||||
display_name: str
|
||||
# None or a sentinel year-0001 date string means the key never expires.
|
||||
expires: Optional[str] = None
|
||||
region: str
|
||||
project_id: str
|
||||
credentials_group_id: Optional[str] = None
|
||||
credentials_group_name: Optional[str] = None
|
||||
|
||||
def has_expiration(self) -> bool:
|
||||
"""Return True if the key has a real (non-sentinel) expiration date."""
|
||||
if not self.expires:
|
||||
return False
|
||||
try:
|
||||
expires_str = self.expires.replace("Z", "+00:00")
|
||||
dt = datetime.fromisoformat(expires_str)
|
||||
# Year 0001 (or earlier) is the SDK sentinel for "never expires"
|
||||
return dt.year > 1
|
||||
except (ValueError, AttributeError):
|
||||
return False
|
||||
|
||||
def expires_within_days(self, days: int) -> bool:
|
||||
"""Return True if the key expires within the given number of days from now."""
|
||||
if not self.has_expiration():
|
||||
return False
|
||||
expires_str = self.expires.replace("Z", "+00:00")
|
||||
dt = datetime.fromisoformat(expires_str)
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
delta = dt - datetime.now(tz=timezone.utc)
|
||||
return delta.days <= days
|
||||
@@ -15,6 +15,7 @@ from colorama import Style
|
||||
# loader and surfacing as a misleading empty report.
|
||||
from stackit.core.configuration import Configuration
|
||||
from stackit.iaas import DefaultApi as IaasDefaultApi
|
||||
from stackit.objectstorage import DefaultApi as ObjectStorageDefaultApi
|
||||
from stackit.resourcemanager import DefaultApi as ResourceManagerDefaultApi
|
||||
|
||||
from prowler.config.config import (
|
||||
@@ -224,11 +225,17 @@ class StackitProvider(Provider):
|
||||
return json_regions.intersection(audited_regions)
|
||||
return json_regions
|
||||
|
||||
_SERVICE_API_CLASS = {
|
||||
"iaas": IaasDefaultApi,
|
||||
"objectstorage": ObjectStorageDefaultApi,
|
||||
}
|
||||
|
||||
def generate_regional_clients(self, service: str = "iaas") -> dict:
|
||||
"""Generate regional API clients for the given service.
|
||||
|
||||
Returns dict: {"eu01": DefaultApi_client, "eu02": DefaultApi_client}
|
||||
"""
|
||||
api_class = self._SERVICE_API_CLASS.get(service, IaasDefaultApi)
|
||||
regional_clients = {}
|
||||
service_regions = self.get_available_service_regions(
|
||||
service, self._audited_regions
|
||||
@@ -240,7 +247,7 @@ class StackitProvider(Provider):
|
||||
self._service_account_key_path,
|
||||
self._service_account_key,
|
||||
)
|
||||
client = IaasDefaultApi(config)
|
||||
client = api_class(config)
|
||||
client.region = region # Attach region attribute
|
||||
regional_clients[region] = client
|
||||
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
"eu01",
|
||||
"eu02"
|
||||
]
|
||||
},
|
||||
"objectstorage": {
|
||||
"regions": [
|
||||
"eu01",
|
||||
"eu02"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ dependencies = [
|
||||
"slack-sdk==3.39.0",
|
||||
"stackit-core==0.2.0",
|
||||
"stackit-iaas==1.4.0",
|
||||
"stackit-objectstorage==1.4.0",
|
||||
"stackit-resourcemanager==0.8.0",
|
||||
"tabulate==0.9.0",
|
||||
"tzlocal==5.3.1",
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import pandas as pd
|
||||
from dash import dash_table
|
||||
|
||||
from dashboard.common_methods import get_section_containers_generic
|
||||
|
||||
|
||||
def _datatable_column_ids(component):
|
||||
"""Collect the column ids of every DataTable in a Dash component tree."""
|
||||
if isinstance(component, dash_table.DataTable):
|
||||
return [[c["id"] for c in component.columns]]
|
||||
children = getattr(component, "children", None)
|
||||
if children is None:
|
||||
return []
|
||||
if not isinstance(children, (list, tuple)):
|
||||
children = [children]
|
||||
return [cols for child in children for cols in _datatable_column_ids(child)]
|
||||
|
||||
|
||||
def _df(**extra):
|
||||
data = {
|
||||
"REQUIREMENTS_ID": ["req1"],
|
||||
"STATUS": ["PASS"],
|
||||
"CHECKID": ["check1"],
|
||||
"REGION": ["us-east-1"],
|
||||
"ACCOUNTID": ["123"],
|
||||
"RESOURCEID": ["res1"],
|
||||
}
|
||||
data.update(extra)
|
||||
return pd.DataFrame(data)
|
||||
|
||||
|
||||
class TestGetSectionContainersGeneric:
|
||||
def test_one_container_per_section(self):
|
||||
"""One outer container per distinct section value."""
|
||||
df = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec A", "Sec B"],
|
||||
"REQUIREMENTS_ID": ["req1", "req2", "req3"],
|
||||
"STATUS": ["PASS", "FAIL", "PASS"],
|
||||
"CHECKID": ["c1", "c2", "c3"],
|
||||
"REGION": ["-"] * 3,
|
||||
"ACCOUNTID": ["123"] * 3,
|
||||
"RESOURCEID": ["r1", "r2", "r3"],
|
||||
}
|
||||
)
|
||||
result = get_section_containers_generic(
|
||||
df, "REQUIREMENTS_ATTRIBUTES_SECTION", "REQUIREMENTS_ID"
|
||||
)
|
||||
assert len(result.children) == 2
|
||||
|
||||
def test_inner_title_includes_id_and_description(self):
|
||||
"""Inner accordion title is '<id> - <description>'."""
|
||||
df = _df(
|
||||
REQUIREMENTS_ATTRIBUTES_SECTION=["Sec A"],
|
||||
REQUIREMENTS_DESCRIPTION=["Ensure MFA"],
|
||||
)
|
||||
rendered = str(
|
||||
get_section_containers_generic(
|
||||
df, "REQUIREMENTS_ATTRIBUTES_SECTION", "REQUIREMENTS_ID"
|
||||
)
|
||||
)
|
||||
assert "req1 - Ensure MFA" in rendered
|
||||
|
||||
def test_arbitrary_ids_do_not_crash(self):
|
||||
"""Non-numeric ids are sorted lexicographically without raising."""
|
||||
df = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A"] * 3,
|
||||
"REQUIREMENTS_ID": ["AC-2(1)", "foo-bar", "step.1.2"],
|
||||
"STATUS": ["PASS", "FAIL", "PASS"],
|
||||
"CHECKID": ["c1", "c2", "c3"],
|
||||
"REGION": ["-"] * 3,
|
||||
"ACCOUNTID": ["123"] * 3,
|
||||
"RESOURCEID": ["r1", "r2", "r3"],
|
||||
}
|
||||
)
|
||||
result = get_section_containers_generic(
|
||||
df, "REQUIREMENTS_ATTRIBUTES_SECTION", "REQUIREMENTS_ID"
|
||||
)
|
||||
tables = _datatable_column_ids(result)
|
||||
assert tables and all("CHECKID" in cols for cols in tables)
|
||||
@@ -0,0 +1,204 @@
|
||||
import pandas as pd
|
||||
from dash import dash_table, html
|
||||
|
||||
from dashboard.compliance.generic import get_table
|
||||
|
||||
|
||||
def _make_minimal_df(**extra_cols):
|
||||
"""Create a minimal valid DataFrame for get_table tests."""
|
||||
data = {
|
||||
"REQUIREMENTS_ID": ["req1"],
|
||||
"STATUS": ["PASS"],
|
||||
"CHECKID": ["check1"],
|
||||
"REGION": ["us-east-1"],
|
||||
"ACCOUNTID": ["123456789"],
|
||||
"RESOURCEID": ["res1"],
|
||||
}
|
||||
data.update(extra_cols)
|
||||
return pd.DataFrame(data)
|
||||
|
||||
|
||||
def _datatable_column_ids(component):
|
||||
"""Collect the column ids of every DataTable in a Dash component tree."""
|
||||
if isinstance(component, dash_table.DataTable):
|
||||
return [[c["id"] for c in component.columns]]
|
||||
children = getattr(component, "children", None)
|
||||
if children is None:
|
||||
return []
|
||||
if not isinstance(children, (list, tuple)):
|
||||
children = [children]
|
||||
return [cols for child in children for cols in _datatable_column_ids(child)]
|
||||
|
||||
|
||||
class TestGetTable:
|
||||
def test_groups_by_section(self):
|
||||
"""SC-001a: df with REQUIREMENTS_ATTRIBUTES_SECTION returns Div grouped by section."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": [
|
||||
"Section A",
|
||||
"Section A",
|
||||
"Section A",
|
||||
"Section B",
|
||||
"Section B",
|
||||
],
|
||||
"REQUIREMENTS_ID": [
|
||||
"ctrl-alpha",
|
||||
"ctrl-alpha",
|
||||
"ctrl-alpha",
|
||||
"ctrl-beta",
|
||||
"ctrl-beta",
|
||||
],
|
||||
"STATUS": ["PASS", "FAIL", "PASS", "FAIL", "FAIL"],
|
||||
"CHECKID": ["check1", "check2", "check3", "check4", "check5"],
|
||||
"REGION": ["us-east-1"] * 5,
|
||||
"ACCOUNTID": ["123"] * 5,
|
||||
"RESOURCEID": ["res1", "res2", "res3", "res4", "res5"],
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
assert result.className == "compliance-data-layout"
|
||||
assert len(result.children) == 2 # one container per distinct section
|
||||
|
||||
def test_flat_fallback_no_attributes(self):
|
||||
"""SC-001b: No REQUIREMENTS_ATTRIBUTES_* cols → grouped by REQUIREMENTS_ID."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ID": ["req1", "req1", "req2"],
|
||||
"STATUS": ["PASS", "FAIL", "FAIL"],
|
||||
"CHECKID": ["check1", "check2", "check3"],
|
||||
"REGION": ["us-east-1"] * 3,
|
||||
"ACCOUNTID": ["123"] * 3,
|
||||
"RESOURCEID": ["res1", "res2", "res3"],
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
assert result.className == "compliance-data-layout"
|
||||
# 2 distinct REQUIREMENTS_ID values → 2 group containers
|
||||
assert len(result.children) == 2
|
||||
|
||||
def test_arbitrary_ids_no_crash(self):
|
||||
"""ADR-2 / R1 regression guard: non-numeric REQUIREMENTS_IDs must not raise ValueError.
|
||||
|
||||
get_section_containers_cis sorts by version_tuple which calls int() on each
|
||||
dotted/dashed segment and crashes on IDs like 'AC-2(1)'. Selecting format4
|
||||
(no version sort) is the fix. This test is a permanent guard against regression.
|
||||
"""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ID": ["AC-2(1)", "foo-bar", "step.1.2"],
|
||||
"STATUS": ["PASS", "FAIL", "PASS"],
|
||||
"CHECKID": ["check1", "check2", "check3"],
|
||||
"REGION": ["us-east-1"] * 3,
|
||||
"ACCOUNTID": ["123"] * 3,
|
||||
"RESOURCEID": ["res1", "res2", "res3"],
|
||||
}
|
||||
)
|
||||
# Must not raise ValueError
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
|
||||
def test_discovers_multiple_attribute_columns(self):
|
||||
"""SC-005a: Multiple REQUIREMENTS_ATTRIBUTES_* cols present → no AttributeError;
|
||||
component tree is non-empty."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec B"],
|
||||
"REQUIREMENTS_ATTRIBUTES_CATEGORY": ["Cat 1", "Cat 2"],
|
||||
"REQUIREMENTS_ATTRIBUTES_CONTROL_ID": ["C1", "C2"],
|
||||
"REQUIREMENTS_ID": ["req1", "req2"],
|
||||
"STATUS": ["PASS", "FAIL"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"REGION": ["us-east-1"] * 2,
|
||||
"ACCOUNTID": ["123"] * 2,
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
assert result.children # non-empty component tree
|
||||
|
||||
def test_novel_attribute_column_names(self):
|
||||
"""SC-005b: Novel attr col names without a SECTION col → first attr col used as
|
||||
grouping; returns a valid html.Div without any code change required."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_DOMAIN": ["Domain A", "Domain B"],
|
||||
"REQUIREMENTS_ATTRIBUTES_SUBDOMAIN": ["Sub 1", "Sub 2"],
|
||||
"REQUIREMENTS_ID": ["req1", "req2"],
|
||||
"STATUS": ["PASS", "FAIL"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"REGION": ["us-east-1"] * 2,
|
||||
"ACCOUNTID": ["123"] * 2,
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
assert len(result.children) > 0
|
||||
|
||||
def test_manual_only_requirements(self):
|
||||
"""SC-008a: All rows have STATUS='MANUAL' → returns html.Div with non-empty
|
||||
children; result is not the 'No data found' string."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec B"],
|
||||
"REQUIREMENTS_ID": ["req1", "req2"],
|
||||
"STATUS": ["MANUAL", "MANUAL"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"REGION": ["us-east-1"] * 2,
|
||||
"ACCOUNTID": ["123"] * 2,
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
assert not isinstance(result, str)
|
||||
assert result.children # non-empty
|
||||
|
||||
def test_empty_dataframe(self):
|
||||
"""SC-009a: Zero rows with correct column schema → valid html.Div; no exception."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": pd.Series([], dtype=str),
|
||||
"REQUIREMENTS_ID": pd.Series([], dtype=str),
|
||||
"STATUS": pd.Series([], dtype=str),
|
||||
"CHECKID": pd.Series([], dtype=str),
|
||||
"REGION": pd.Series([], dtype=str),
|
||||
"ACCOUNTID": pd.Series([], dtype=str),
|
||||
"RESOURCEID": pd.Series([], dtype=str),
|
||||
}
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
|
||||
def test_get_table_returns_html_div(self):
|
||||
"""SC-012a: Smoke test — isinstance(get_table(df), html.Div) is True."""
|
||||
data = _make_minimal_df(
|
||||
REQUIREMENTS_ATTRIBUTES_SECTION=["Sec A"],
|
||||
)
|
||||
result = get_table(data)
|
||||
assert isinstance(result, html.Div)
|
||||
|
||||
|
||||
class TestNestedRendering:
|
||||
def test_section_and_requirement_id_are_separate_levels(self):
|
||||
"""Section is the outer level; requirement id + description the inner."""
|
||||
data = _make_minimal_df(
|
||||
REQUIREMENTS_ATTRIBUTES_SECTION=["3 Compute Services"],
|
||||
REQUIREMENTS_DESCRIPTION=["Ensure only MFA enabled identities"],
|
||||
)
|
||||
rendered = str(get_table(data))
|
||||
assert "3 Compute Services" in rendered
|
||||
assert "req1 - Ensure only MFA enabled identities" in rendered
|
||||
|
||||
def test_checks_table_is_nested_under_requirement(self):
|
||||
"""The checks table sits at the innermost level."""
|
||||
data = _make_minimal_df(
|
||||
REQUIREMENTS_ATTRIBUTES_SECTION=["Sec A"],
|
||||
REQUIREMENTS_DESCRIPTION=["Some requirement"],
|
||||
)
|
||||
tables = _datatable_column_ids(get_table(data))
|
||||
assert tables and all("CHECKID" in cols for cols in tables)
|
||||
@@ -0,0 +1,179 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from dash import html
|
||||
|
||||
from dashboard.pages.compliance import _dispatch_compliance_renderer
|
||||
|
||||
|
||||
def _make_dispatch_df(**extra_cols):
|
||||
"""Minimal DataFrame with the columns required by the dedup step."""
|
||||
data = {
|
||||
"REQUIREMENTS_ID": ["req1", "req2"],
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec A"],
|
||||
"STATUS": ["PASS", "FAIL"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
"STATUSEXTENDED": ["", ""],
|
||||
"REGION": ["us-east-1", "us-east-1"],
|
||||
"ACCOUNTID": ["123456789", "123456789"],
|
||||
}
|
||||
data.update(extra_cols)
|
||||
return pd.DataFrame(data)
|
||||
|
||||
|
||||
class TestDispatchComplianceRenderer:
|
||||
def test_builtin_name_uses_builtin_module(self):
|
||||
"""SC-002a: analytics_input='cis_4_0_aws' resolves real builtin module;
|
||||
returns (html.Div, DataFrame) 2-tuple."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ID": ["1.1", "1.2"],
|
||||
"REQUIREMENTS_DESCRIPTION": ["Description 1", "Description 2"],
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Section A", "Section A"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"STATUS": ["PASS", "FAIL"],
|
||||
"REGION": ["us-east-1", "us-east-1"],
|
||||
"ACCOUNTID": ["123456789", "123456789"],
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
"STATUSEXTENDED": ["Pass", "Fail"],
|
||||
}
|
||||
)
|
||||
table, result_data = _dispatch_compliance_renderer(data, "cis_4_0_aws")
|
||||
assert isinstance(table, html.Div)
|
||||
assert isinstance(result_data, pd.DataFrame)
|
||||
|
||||
def test_unknown_name_falls_back_to_generic(self):
|
||||
"""SC-003a: Unknown analytics_input raises ModuleNotFoundError → generic
|
||||
fallback is called with the deduped dataframe."""
|
||||
data = _make_dispatch_df()
|
||||
sentinel = MagicMock(
|
||||
return_value=html.Div([], className="compliance-data-layout")
|
||||
)
|
||||
|
||||
with patch("dashboard.compliance.generic.get_table", sentinel):
|
||||
table, result_data = _dispatch_compliance_renderer(data, "myfw_dynprovider")
|
||||
|
||||
sentinel.assert_called_once()
|
||||
assert isinstance(table, html.Div)
|
||||
assert isinstance(result_data, pd.DataFrame)
|
||||
|
||||
def test_import_error_is_not_swallowed(self):
|
||||
"""SC-003b: ImportError (NOT ModuleNotFoundError) is re-raised; except clause
|
||||
is exact — only ModuleNotFoundError routes to generic."""
|
||||
data = _make_dispatch_df()
|
||||
|
||||
with patch(
|
||||
"dashboard.pages.compliance.importlib.import_module",
|
||||
side_effect=ImportError("custom error"),
|
||||
):
|
||||
with pytest.raises(ImportError, match="custom error"):
|
||||
_dispatch_compliance_renderer(data, "anything")
|
||||
|
||||
def test_get_table_error_in_generic_surfaces(self):
|
||||
"""SC-004a: ValueError from generic.get_table propagates (not swallowed);
|
||||
get_table is called OUTSIDE the try block."""
|
||||
data = _make_dispatch_df()
|
||||
|
||||
with patch(
|
||||
"dashboard.compliance.generic.get_table",
|
||||
side_effect=ValueError("boom"),
|
||||
):
|
||||
with pytest.raises(ValueError, match="boom"):
|
||||
_dispatch_compliance_renderer(data, "myfw_dynprovider")
|
||||
|
||||
def test_get_table_error_in_builtin_surfaces(self):
|
||||
"""REQ-004 / ADR-1: RuntimeError from a builtin get_table propagates;
|
||||
proving get_table is called outside the try block."""
|
||||
data = _make_dispatch_df()
|
||||
mock_module = MagicMock()
|
||||
mock_module.get_table.side_effect = RuntimeError("table error")
|
||||
|
||||
with patch(
|
||||
"dashboard.pages.compliance.importlib.import_module",
|
||||
return_value=mock_module,
|
||||
):
|
||||
with pytest.raises(RuntimeError, match="table error"):
|
||||
_dispatch_compliance_renderer(data, "some_builtin_fw")
|
||||
|
||||
def test_dedup_applied_before_get_table(self):
|
||||
"""ADR-1: Duplicate rows (identical CHECKID/STATUS/RESOURCEID/STATUSEXTENDED)
|
||||
are dropped; returned data has the deduplicated row count."""
|
||||
# Row 0 and row 1 are identical in all dedup-key columns; row 2 is unique.
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec A", "Sec B"],
|
||||
"REQUIREMENTS_ID": ["req1", "req1", "req2"],
|
||||
"STATUS": ["PASS", "PASS", "FAIL"],
|
||||
"CHECKID": ["check1", "check1", "check2"],
|
||||
"RESOURCEID": ["res1", "res1", "res2"],
|
||||
"STATUSEXTENDED": ["", "", ""],
|
||||
"REGION": ["us-east-1"] * 3,
|
||||
"ACCOUNTID": ["123"] * 3,
|
||||
}
|
||||
)
|
||||
mock_module = MagicMock()
|
||||
mock_module.get_table.return_value = html.Div([])
|
||||
|
||||
with patch(
|
||||
"dashboard.pages.compliance.importlib.import_module",
|
||||
return_value=mock_module,
|
||||
):
|
||||
table, result_data = _dispatch_compliance_renderer(data, "some_fw")
|
||||
|
||||
assert len(result_data) == 2 # one duplicate removed
|
||||
|
||||
def test_muted_column_added_to_dedup_when_present(self):
|
||||
"""ADR-1 edge case: When MUTED column is present, it is included in the dedup
|
||||
subset at index 2; rows differing only in MUTED are kept as distinct rows."""
|
||||
# Both rows share CHECKID/STATUS/RESOURCEID/STATUSEXTENDED but differ in MUTED.
|
||||
# With MUTED in dedup_columns, both rows are kept (2 rows after dedup).
|
||||
# Without MUTED in dedup_columns, they would be collapsed to 1 row.
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Sec A", "Sec A"],
|
||||
"REQUIREMENTS_ID": ["req1", "req1"],
|
||||
"STATUS": ["PASS", "PASS"],
|
||||
"CHECKID": ["check1", "check1"],
|
||||
"RESOURCEID": ["res1", "res1"],
|
||||
"STATUSEXTENDED": ["", ""],
|
||||
"MUTED": ["True", "False"],
|
||||
"REGION": ["us-east-1", "us-east-1"],
|
||||
"ACCOUNTID": ["123", "123"],
|
||||
}
|
||||
)
|
||||
mock_module = MagicMock()
|
||||
mock_module.get_table.return_value = html.Div([])
|
||||
|
||||
with patch(
|
||||
"dashboard.pages.compliance.importlib.import_module",
|
||||
return_value=mock_module,
|
||||
):
|
||||
table, result_data = _dispatch_compliance_renderer(data, "some_fw")
|
||||
|
||||
# MUTED at idx 2 means these two rows have different dedup keys → both kept
|
||||
assert len(result_data) == 2
|
||||
|
||||
def test_returns_table_and_data_tuple(self):
|
||||
"""ADR-1 interface contract: _dispatch_compliance_renderer returns a
|
||||
2-tuple (table, deduped_data)."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"REQUIREMENTS_ID": ["1.1", "1.2"],
|
||||
"REQUIREMENTS_DESCRIPTION": ["Desc 1", "Desc 2"],
|
||||
"REQUIREMENTS_ATTRIBUTES_SECTION": ["Section A", "Section A"],
|
||||
"CHECKID": ["check1", "check2"],
|
||||
"STATUS": ["PASS", "FAIL"],
|
||||
"REGION": ["us-east-1", "us-east-1"],
|
||||
"ACCOUNTID": ["123456789", "123456789"],
|
||||
"RESOURCEID": ["res1", "res2"],
|
||||
"STATUSEXTENDED": ["", ""],
|
||||
}
|
||||
)
|
||||
result = _dispatch_compliance_renderer(data, "cis_4_0_aws")
|
||||
assert isinstance(result, tuple)
|
||||
assert len(result) == 2
|
||||
table, deduped_data = result
|
||||
assert isinstance(table, html.Div)
|
||||
assert isinstance(deduped_data, pd.DataFrame)
|
||||
@@ -0,0 +1,7 @@
|
||||
import dash
|
||||
|
||||
# Initialize a minimal Dash app so that dashboard page modules can call
|
||||
# dash.register_page() during import without raising PageError.
|
||||
# This module-level initialization runs during pytest collection, before
|
||||
# any test file in this directory is imported.
|
||||
_test_app = dash.Dash("prowler_test_app", use_pages=True, pages_folder="")
|
||||
@@ -0,0 +1,60 @@
|
||||
import pandas as pd
|
||||
|
||||
from dashboard.pages.compliance import _ensure_scope_columns
|
||||
|
||||
|
||||
def _df(columns):
|
||||
"""Build a one-row DataFrame preserving the given column order."""
|
||||
return pd.DataFrame({col: ["x"] for col in columns})
|
||||
|
||||
|
||||
class TestEnsureScopeColumns:
|
||||
def test_aws_account_and_region_preserved(self):
|
||||
"""A provider that already emits ACCOUNTID and REGION is left untouched."""
|
||||
df = _df(["PROVIDER", "DESCRIPTION", "ACCOUNTID", "REGION", "ASSESSMENTDATE"])
|
||||
result = _ensure_scope_columns(df)
|
||||
assert "ACCOUNTID" in result.columns
|
||||
assert "REGION" in result.columns
|
||||
assert result["ACCOUNTID"].iloc[0] == "x"
|
||||
|
||||
def test_okta_single_scope_column_becomes_accountid(self):
|
||||
"""Okta's ORGANIZATIONDOMAIN becomes ACCOUNTID; REGION falls back."""
|
||||
df = _df(["PROVIDER", "DESCRIPTION", "ORGANIZATIONDOMAIN", "ASSESSMENTDATE"])
|
||||
df["ORGANIZATIONDOMAIN"] = ["trial-123.okta.com"]
|
||||
result = _ensure_scope_columns(df)
|
||||
assert "ACCOUNTID" in result.columns
|
||||
assert "ORGANIZATIONDOMAIN" not in result.columns
|
||||
assert result["ACCOUNTID"].iloc[0] == "trial-123.okta.com"
|
||||
assert result["REGION"].iloc[0] == "-"
|
||||
|
||||
def test_two_unknown_scope_columns_map_to_account_and_region(self):
|
||||
"""Two scope columns map positionally to ACCOUNTID and REGION."""
|
||||
df = _df(["PROVIDER", "DESCRIPTION", "TENANCYID", "LOCATION", "ASSESSMENTDATE"])
|
||||
df["TENANCYID"] = ["tenant-1"]
|
||||
df["LOCATION"] = ["eu-west-1"]
|
||||
result = _ensure_scope_columns(df)
|
||||
assert result["ACCOUNTID"].iloc[0] == "tenant-1"
|
||||
assert result["REGION"].iloc[0] == "eu-west-1"
|
||||
|
||||
def test_no_scope_columns_fall_back_to_dash(self):
|
||||
"""No scope columns → both ACCOUNTID and REGION fall back to '-'."""
|
||||
df = _df(["PROVIDER", "DESCRIPTION", "ASSESSMENTDATE"])
|
||||
result = _ensure_scope_columns(df)
|
||||
assert result["ACCOUNTID"].iloc[0] == "-"
|
||||
assert result["REGION"].iloc[0] == "-"
|
||||
|
||||
def test_missing_anchors_still_fall_back_to_dash(self):
|
||||
"""Without DESCRIPTION/ASSESSMENTDATE anchors, both fall back to '-'."""
|
||||
df = _df(["PROVIDER", "FOO", "BAR"])
|
||||
result = _ensure_scope_columns(df)
|
||||
assert result["ACCOUNTID"].iloc[0] == "-"
|
||||
assert result["REGION"].iloc[0] == "-"
|
||||
|
||||
def test_existing_accountid_does_not_consume_region_scope(self):
|
||||
"""An existing ACCOUNTID is kept; the leftover scope becomes REGION."""
|
||||
df = _df(["PROVIDER", "DESCRIPTION", "ACCOUNTID", "LOCATION", "ASSESSMENTDATE"])
|
||||
df["ACCOUNTID"] = ["acc-1"]
|
||||
df["LOCATION"] = ["us-east-2"]
|
||||
result = _ensure_scope_columns(df)
|
||||
assert result["ACCOUNTID"].iloc[0] == "acc-1"
|
||||
assert result["REGION"].iloc[0] == "us-east-2"
|
||||
@@ -103,6 +103,15 @@ class TestDispatchStartswith:
|
||||
display_compliance_table(compliance_framework=framework_name, **_COMMON)
|
||||
mock_fn.assert_called_once()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"framework_name",
|
||||
["okta_idaas_stig_v1r2_okta"],
|
||||
)
|
||||
@patch(f"{MODULE}.get_okta_idaas_stig_table")
|
||||
def test_okta_idaas_stig_dispatch(self, mock_fn, framework_name):
|
||||
display_compliance_table(compliance_framework=framework_name, **_COMMON)
|
||||
mock_fn.assert_called_once()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"framework_name",
|
||||
[
|
||||
|
||||
@@ -16,6 +16,7 @@ from prowler.lib.check.compliance_models import (
|
||||
Mitre_Requirement_Attribute_Azure,
|
||||
Mitre_Requirement_Attribute_GCP,
|
||||
Prowler_ThreatScore_Requirement_Attribute,
|
||||
STIG_Requirement_Attribute,
|
||||
)
|
||||
|
||||
CIS_1_4_AWS = Compliance(
|
||||
@@ -1258,3 +1259,47 @@ ASD_ESSENTIAL_EIGHT_AWS = Compliance(
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
OKTA_IDAAS_STIG_OKTA = Compliance(
|
||||
Framework="Okta-IDaaS-STIG",
|
||||
Name="DISA Okta Identity as a Service (IDaaS) STIG V1R2",
|
||||
Version="1R2",
|
||||
Provider="Okta",
|
||||
Description="Defense Information Systems Agency (DISA) Security Technical Implementation Guide (STIG) for Okta Identity as a Service (IDaaS).",
|
||||
Requirements=[
|
||||
Compliance_Requirement(
|
||||
Id="OKTA-APP-000020",
|
||||
Name="Okta must log out a session after a 15-minute period of inactivity.",
|
||||
Description="A session timeout lock is a temporary action taken when a user stops work and moves away from the immediate vicinity of the information system.",
|
||||
Attributes=[
|
||||
STIG_Requirement_Attribute(
|
||||
Section="CAT II (Medium)",
|
||||
Severity="medium",
|
||||
RuleID="SV-273186r1098825_rule",
|
||||
StigID="OKTA-APP-000020",
|
||||
CCI=["CCI-000057", "CCI-001133"],
|
||||
CheckText="Verify the Global Session Policy logs out a session after 15 minutes of inactivity.",
|
||||
FixText="From the Admin Console configure the Global Session Policy idle timeout to 15 minutes.",
|
||||
)
|
||||
],
|
||||
Checks=["signon_global_session_idle_timeout_15min"],
|
||||
),
|
||||
Compliance_Requirement(
|
||||
Id="OKTA-APP-000650",
|
||||
Name="Okta must enforce a minimum 15-character password length.",
|
||||
Description="The shorter the password, the lower the number of possible combinations that need to be tested before the password is compromised.",
|
||||
Attributes=[
|
||||
STIG_Requirement_Attribute(
|
||||
Section="CAT II (Medium)",
|
||||
Severity="medium",
|
||||
RuleID="SV-273209r1098894_rule",
|
||||
StigID="OKTA-APP-000650",
|
||||
CCI=["CCI-000205"],
|
||||
CheckText="Verify the password policy enforces a minimum length of 15 characters.",
|
||||
FixText="From the Admin Console set the minimum password length to 15 characters.",
|
||||
)
|
||||
],
|
||||
Checks=[],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
from datetime import datetime
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
|
||||
from freezegun import freeze_time
|
||||
from mock import patch
|
||||
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.models import OktaIDaaSSTIGModel
|
||||
from prowler.lib.outputs.compliance.okta_idaas_stig.okta_idaas_stig_okta import (
|
||||
OktaIDaaSSTIG,
|
||||
)
|
||||
from tests.lib.outputs.compliance.fixtures import OKTA_IDAAS_STIG_OKTA
|
||||
from tests.lib.outputs.fixtures.fixtures import generate_finding_output
|
||||
|
||||
OKTA_ORG_DOMAIN = "dev-12345.okta.com"
|
||||
|
||||
|
||||
class TestOktaIDaaSSTIG:
|
||||
def test_output_transform(self):
|
||||
findings = [
|
||||
generate_finding_output(
|
||||
provider="okta",
|
||||
account_uid=OKTA_ORG_DOMAIN,
|
||||
account_name=OKTA_ORG_DOMAIN,
|
||||
region="global",
|
||||
service_name="signon",
|
||||
check_id="signon_global_session_idle_timeout_15min",
|
||||
resource_uid="okta-global-session-policy",
|
||||
resource_name="Default Policy",
|
||||
compliance={"Okta-IDaaS-STIG-1R2": ["OKTA-APP-000020"]},
|
||||
)
|
||||
]
|
||||
|
||||
output = OktaIDaaSSTIG(findings, OKTA_IDAAS_STIG_OKTA)
|
||||
output_data = output.data[0]
|
||||
assert isinstance(output_data, OktaIDaaSSTIGModel)
|
||||
assert output_data.Provider == "okta"
|
||||
assert output_data.Framework == OKTA_IDAAS_STIG_OKTA.Framework
|
||||
assert output_data.Name == OKTA_IDAAS_STIG_OKTA.Name
|
||||
assert output_data.OrganizationDomain == OKTA_ORG_DOMAIN
|
||||
assert output_data.Description == OKTA_IDAAS_STIG_OKTA.Description
|
||||
assert output_data.Requirements_Id == OKTA_IDAAS_STIG_OKTA.Requirements[0].Id
|
||||
assert (
|
||||
output_data.Requirements_Name == OKTA_IDAAS_STIG_OKTA.Requirements[0].Name
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Description
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Description
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_Section
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].Section
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_Severity
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].Severity.value
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_RuleID
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].RuleID
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_StigID
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].StigID
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_CCI
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].CCI
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_CheckText
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].CheckText
|
||||
)
|
||||
assert (
|
||||
output_data.Requirements_Attributes_FixText
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[0].Attributes[0].FixText
|
||||
)
|
||||
assert output_data.Status == "PASS"
|
||||
assert output_data.StatusExtended == ""
|
||||
assert output_data.ResourceId == "okta-global-session-policy"
|
||||
assert output_data.ResourceName == "Default Policy"
|
||||
assert output_data.CheckId == "signon_global_session_idle_timeout_15min"
|
||||
assert output_data.Muted is False
|
||||
# Test manual check
|
||||
output_data_manual = output.data[1]
|
||||
assert output_data_manual.Provider == "okta"
|
||||
assert output_data_manual.Framework == OKTA_IDAAS_STIG_OKTA.Framework
|
||||
assert output_data_manual.Name == OKTA_IDAAS_STIG_OKTA.Name
|
||||
assert output_data_manual.OrganizationDomain == ""
|
||||
assert (
|
||||
output_data_manual.Requirements_Id
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[1].Id
|
||||
)
|
||||
assert (
|
||||
output_data_manual.Requirements_Attributes_Severity
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[1].Attributes[0].Severity.value
|
||||
)
|
||||
assert (
|
||||
output_data_manual.Requirements_Attributes_StigID
|
||||
== OKTA_IDAAS_STIG_OKTA.Requirements[1].Attributes[0].StigID
|
||||
)
|
||||
assert output_data_manual.Status == "MANUAL"
|
||||
assert output_data_manual.StatusExtended == "Manual check"
|
||||
assert output_data_manual.ResourceId == "manual_check"
|
||||
assert output_data_manual.ResourceName == "Manual check"
|
||||
assert output_data_manual.CheckId == "manual"
|
||||
assert output_data_manual.Muted is False
|
||||
|
||||
@freeze_time("2025-01-01 00:00:00")
|
||||
@mock.patch(
|
||||
"prowler.lib.outputs.compliance.okta_idaas_stig.okta_idaas_stig_okta.timestamp",
|
||||
"2025-01-01 00:00:00",
|
||||
)
|
||||
def test_batch_write_data_to_file(self):
|
||||
mock_file = StringIO()
|
||||
findings = [
|
||||
generate_finding_output(
|
||||
provider="okta",
|
||||
account_uid=OKTA_ORG_DOMAIN,
|
||||
account_name=OKTA_ORG_DOMAIN,
|
||||
region="global",
|
||||
service_name="signon",
|
||||
check_id="signon_global_session_idle_timeout_15min",
|
||||
resource_uid="okta-global-session-policy",
|
||||
resource_name="Default Policy",
|
||||
compliance={"Okta-IDaaS-STIG-1R2": ["OKTA-APP-000020"]},
|
||||
)
|
||||
]
|
||||
output = OktaIDaaSSTIG(findings, OKTA_IDAAS_STIG_OKTA)
|
||||
output._file_descriptor = mock_file
|
||||
|
||||
with patch.object(mock_file, "close", return_value=None):
|
||||
output.batch_write_data_to_file()
|
||||
|
||||
mock_file.seek(0)
|
||||
content = mock_file.read()
|
||||
expected_csv = f"PROVIDER;DESCRIPTION;ORGANIZATIONDOMAIN;ASSESSMENTDATE;REQUIREMENTS_ID;REQUIREMENTS_NAME;REQUIREMENTS_DESCRIPTION;REQUIREMENTS_ATTRIBUTES_SECTION;REQUIREMENTS_ATTRIBUTES_SEVERITY;REQUIREMENTS_ATTRIBUTES_RULEID;REQUIREMENTS_ATTRIBUTES_STIGID;REQUIREMENTS_ATTRIBUTES_CCI;REQUIREMENTS_ATTRIBUTES_CHECKTEXT;REQUIREMENTS_ATTRIBUTES_FIXTEXT;STATUS;STATUSEXTENDED;RESOURCEID;RESOURCENAME;CHECKID;MUTED;FRAMEWORK;NAME\r\nokta;Defense Information Systems Agency (DISA) Security Technical Implementation Guide (STIG) for Okta Identity as a Service (IDaaS).;{OKTA_ORG_DOMAIN};{datetime.now()};OKTA-APP-000020;Okta must log out a session after a 15-minute period of inactivity.;A session timeout lock is a temporary action taken when a user stops work and moves away from the immediate vicinity of the information system.;CAT II (Medium);medium;SV-273186r1098825_rule;OKTA-APP-000020;['CCI-000057', 'CCI-001133'];Verify the Global Session Policy logs out a session after 15 minutes of inactivity.;From the Admin Console configure the Global Session Policy idle timeout to 15 minutes.;PASS;;okta-global-session-policy;Default Policy;signon_global_session_idle_timeout_15min;False;Okta-IDaaS-STIG;DISA Okta Identity as a Service (IDaaS) STIG V1R2\r\nokta;Defense Information Systems Agency (DISA) Security Technical Implementation Guide (STIG) for Okta Identity as a Service (IDaaS).;;{datetime.now()};OKTA-APP-000650;Okta must enforce a minimum 15-character password length.;The shorter the password, the lower the number of possible combinations that need to be tested before the password is compromised.;CAT II (Medium);medium;SV-273209r1098894_rule;OKTA-APP-000650;['CCI-000205'];Verify the password policy enforces a minimum length of 15 characters.;From the Admin Console set the minimum password length to 15 characters.;MANUAL;Manual check;manual_check;Manual check;manual;False;Okta-IDaaS-STIG;DISA Okta Identity as a Service (IDaaS) STIG V1R2\r\n"
|
||||
|
||||
assert content == expected_csv
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
from json import dumps
|
||||
from unittest import mock
|
||||
|
||||
import botocore
|
||||
from boto3 import client
|
||||
from moto import mock_aws
|
||||
|
||||
from tests.providers.aws.utils import (
|
||||
AWS_ACCOUNT_NUMBER,
|
||||
AWS_REGION_US_EAST_1,
|
||||
set_mocked_aws_provider,
|
||||
)
|
||||
|
||||
AGENT_ID = "test-agent-id"
|
||||
AGENT_NAME = "test-agent-name"
|
||||
AGENT_ARN = (
|
||||
f"arn:aws:bedrock:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:agent/{AGENT_ID}"
|
||||
)
|
||||
ROLE_NAME = "AmazonBedrockExecutionRoleForAgents_test"
|
||||
ROLE_ARN = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:role/{ROLE_NAME}"
|
||||
BOUNDARY_ARN = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:policy/AgentBoundary"
|
||||
|
||||
ASSUME_ROLE_POLICY_DOCUMENT = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": {"Service": "bedrock.amazonaws.com"},
|
||||
"Action": "sts:AssumeRole",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
BOUNDARY_POLICY_DOCUMENT = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{"Effect": "Allow", "Action": "bedrock:*", "Resource": "*"}],
|
||||
}
|
||||
|
||||
NARROW_INLINE_POLICY = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject"],
|
||||
"Resource": ["arn:aws:s3:::my-rag-bucket/*"],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
BROAD_INLINE_POLICY = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{"Effect": "Allow", "Action": "*", "Resource": "*"}],
|
||||
}
|
||||
|
||||
|
||||
# Mock both ListAgents and GetAgent at the botocore level. moto's bedrock-agent
|
||||
# support is incomplete for our needs (GetAgent often doesn't echo back the
|
||||
# role ARN we set), so we control the responses directly. We also need to keep
|
||||
# IAM calls going to moto.
|
||||
make_api_call = botocore.client.BaseClient._make_api_call
|
||||
|
||||
|
||||
def _mock_bedrock_agent_factory(role_arn):
|
||||
"""Return a mock_make_api_call function that returns role_arn from GetAgent.
|
||||
|
||||
Pass role_arn=None to simulate an agent whose role can't be resolved.
|
||||
"""
|
||||
|
||||
def _mock_make_api_call(self, operation_name, kwarg):
|
||||
if operation_name == "ListAgents":
|
||||
return {
|
||||
"agentSummaries": [
|
||||
{"agentId": AGENT_ID, "agentName": AGENT_NAME},
|
||||
]
|
||||
}
|
||||
if operation_name == "GetAgent":
|
||||
return {
|
||||
"agent": {
|
||||
"agentId": AGENT_ID,
|
||||
"agentName": AGENT_NAME,
|
||||
"agentResourceRoleArn": role_arn,
|
||||
}
|
||||
}
|
||||
if operation_name == "ListTagsForResource":
|
||||
return {"tags": {}}
|
||||
if operation_name == "ListPrompts":
|
||||
return {"promptSummaries": []}
|
||||
return make_api_call(self, operation_name, kwarg)
|
||||
|
||||
return _mock_make_api_call
|
||||
|
||||
|
||||
def _setup_role(
|
||||
*,
|
||||
attached_policy_arns=(),
|
||||
inline_policies=None,
|
||||
permissions_boundary=None,
|
||||
):
|
||||
"""Create an IAM role in moto with the given configuration. Returns the role ARN."""
|
||||
iam = client("iam", region_name=AWS_REGION_US_EAST_1)
|
||||
|
||||
if permissions_boundary:
|
||||
iam.create_policy(
|
||||
PolicyName="AgentBoundary",
|
||||
PolicyDocument=dumps(BOUNDARY_POLICY_DOCUMENT),
|
||||
)
|
||||
|
||||
create_kwargs = {
|
||||
"RoleName": ROLE_NAME,
|
||||
"AssumeRolePolicyDocument": dumps(ASSUME_ROLE_POLICY_DOCUMENT),
|
||||
}
|
||||
if permissions_boundary:
|
||||
create_kwargs["PermissionsBoundary"] = permissions_boundary
|
||||
iam.create_role(**create_kwargs)
|
||||
|
||||
for policy_arn in attached_policy_arns:
|
||||
iam.attach_role_policy(RoleName=ROLE_NAME, PolicyArn=policy_arn)
|
||||
|
||||
for policy_name, policy_document in (inline_policies or {}).items():
|
||||
iam.put_role_policy(
|
||||
RoleName=ROLE_NAME,
|
||||
PolicyName=policy_name,
|
||||
PolicyDocument=dumps(policy_document),
|
||||
)
|
||||
|
||||
return ROLE_ARN
|
||||
|
||||
|
||||
def _run_check(role_arn_for_get_agent):
|
||||
"""Build the IAM + BedrockAgent services, patch them in, run the check."""
|
||||
from prowler.providers.aws.services.bedrock.bedrock_service import BedrockAgent
|
||||
from prowler.providers.aws.services.iam.iam_service import IAM
|
||||
|
||||
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
|
||||
|
||||
with mock.patch(
|
||||
"botocore.client.BaseClient._make_api_call",
|
||||
new=_mock_bedrock_agent_factory(role_arn_for_get_agent),
|
||||
):
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege.bedrock_agent_client",
|
||||
new=BedrockAgent(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege.iam_client",
|
||||
new=IAM(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege import (
|
||||
bedrock_agent_role_least_privilege,
|
||||
)
|
||||
|
||||
return bedrock_agent_role_least_privilege().execute()
|
||||
|
||||
|
||||
class Test_bedrock_agent_role_least_privilege:
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_no_agents(self):
|
||||
"""No agents in the account -> zero findings."""
|
||||
from prowler.providers.aws.services.bedrock.bedrock_service import BedrockAgent
|
||||
from prowler.providers.aws.services.iam.iam_service import IAM
|
||||
|
||||
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege.bedrock_agent_client",
|
||||
new=BedrockAgent(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege.iam_client",
|
||||
new=IAM(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.bedrock.bedrock_agent_role_least_privilege.bedrock_agent_role_least_privilege import (
|
||||
bedrock_agent_role_least_privilege,
|
||||
)
|
||||
|
||||
assert bedrock_agent_role_least_privilege().execute() == []
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_compliant(self):
|
||||
"""Narrow inline policy + boundary + no *FullAccess attached -> PASS."""
|
||||
role_arn = _setup_role(
|
||||
inline_policies={"NarrowAccess": NARROW_INLINE_POLICY},
|
||||
permissions_boundary=BOUNDARY_ARN,
|
||||
)
|
||||
|
||||
result = _run_check(role_arn_for_get_agent=role_arn)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert "follows least privilege" in result[0].status_extended
|
||||
assert result[0].resource_id == AGENT_ID
|
||||
assert result[0].resource_arn == AGENT_ARN
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_full_access_attached(self):
|
||||
"""AmazonBedrockFullAccess attached -> FAIL."""
|
||||
role_arn = _setup_role(
|
||||
attached_policy_arns=("arn:aws:iam::aws:policy/AmazonBedrockFullAccess",),
|
||||
inline_policies={"NarrowAccess": NARROW_INLINE_POLICY},
|
||||
permissions_boundary=BOUNDARY_ARN,
|
||||
)
|
||||
|
||||
result = _run_check(role_arn_for_get_agent=role_arn)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "grants full access" in result[0].status_extended
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_administrator_access_attached(self):
|
||||
"""AdministratorAccess attached (no FullAccess suffix) -> FAIL via doc-based admin check."""
|
||||
role_arn = _setup_role(
|
||||
attached_policy_arns=("arn:aws:iam::aws:policy/AdministratorAccess",),
|
||||
inline_policies={"NarrowAccess": NARROW_INLINE_POLICY},
|
||||
permissions_boundary=BOUNDARY_ARN,
|
||||
)
|
||||
|
||||
result = _run_check(role_arn_for_get_agent=role_arn)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
"managed policy AdministratorAccess grants administrative access"
|
||||
in result[0].status_extended
|
||||
)
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_resource_star_broad_action(self):
|
||||
"""Inline statement with Action:* on Resource:* -> FAIL."""
|
||||
role_arn = _setup_role(
|
||||
inline_policies={"BroadAccess": BROAD_INLINE_POLICY},
|
||||
permissions_boundary=BOUNDARY_ARN,
|
||||
)
|
||||
|
||||
result = _run_check(role_arn_for_get_agent=role_arn)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "grants administrative access" in result[0].status_extended
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_no_permissions_boundary(self):
|
||||
"""Otherwise clean role but missing permissions boundary -> FAIL."""
|
||||
role_arn = _setup_role(
|
||||
inline_policies={"NarrowAccess": NARROW_INLINE_POLICY},
|
||||
permissions_boundary=None,
|
||||
)
|
||||
|
||||
result = _run_check(role_arn_for_get_agent=role_arn)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "no permissions boundary configured" in result[0].status_extended
|
||||
|
||||
@mock_aws(config={"iam": {"load_aws_managed_policies": True}})
|
||||
def test_agent_role_not_resolvable(self):
|
||||
"""role_arn returned by GetAgent doesn't match any IAM role -> FAIL."""
|
||||
result = _run_check(
|
||||
role_arn_for_get_agent=f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:role/does-not-exist"
|
||||
)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "could not be resolved" in result[0].status_extended
|
||||
+182
@@ -674,3 +674,185 @@ class Test_cloudwatch_changes_to_network_acls_alarm_configured:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 0
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = ReplaceNetworkAclAssociation) || ($.eventName = ReplaceNetworkAclEntry) || ($.eventName = DeleteNetworkAclEntry) || ($.eventName = DeleteNetworkAcl) || ($.eventName = CreateNetworkAclEntry) || ($.eventName = CreateNetworkAcl) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured import (
|
||||
cloudwatch_changes_to_network_acls_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_network_acls_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_substring_only_no_match(self):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = CreateNetworkAclEntry) || ($.eventName = DeleteNetworkAclEntry) || ($.eventName = ReplaceNetworkAclEntry) || ($.eventName = ReplaceNetworkAclAssociation) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_acls_alarm_configured.cloudwatch_changes_to_network_acls_alarm_configured import (
|
||||
cloudwatch_changes_to_network_acls_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_network_acls_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "No CloudWatch log groups found with metric filters or alarms associated."
|
||||
)
|
||||
|
||||
+92
@@ -616,3 +616,95 @@ class Test_cloudwatch_changes_to_network_gateways_alarm_configured:
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
assert result[0].resource_tags == [{}]
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = DetachInternetGateway) || ($.eventName = DeleteInternetGateway) || ($.eventName = CreateInternetGateway) || ($.eventName = AttachInternetGateway) || ($.eventName = DeleteCustomerGateway) || ($.eventName = CreateCustomerGateway) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_gateways_alarm_configured.cloudwatch_changes_to_network_gateways_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_gateways_alarm_configured.cloudwatch_changes_to_network_gateways_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_gateways_alarm_configured.cloudwatch_changes_to_network_gateways_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_gateways_alarm_configured.cloudwatch_changes_to_network_gateways_alarm_configured import (
|
||||
cloudwatch_changes_to_network_gateways_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_network_gateways_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+182
@@ -596,3 +596,185 @@ class Test_cloudwatch_changes_to_network_route_tables_alarm_configured:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = ec2.amazonaws.com) && ($.eventName = DisassociateRouteTable) || ($.eventName = DeleteRoute) || ($.eventName = DeleteRouteTable) || ($.eventName = ReplaceRouteTableAssociation) || ($.eventName = ReplaceRoute) || ($.eventName = CreateRouteTable) || ($.eventName = CreateRoute) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured import (
|
||||
cloudwatch_changes_to_network_route_tables_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_network_route_tables_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_substring_only_no_match(self):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = ec2.amazonaws.com) && ($.eventName = CreateRouteTable) || ($.eventName = ReplaceRouteTableAssociation) || ($.eventName = DeleteRouteTable) || ($.eventName = DisassociateRouteTable) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_network_route_tables_alarm_configured.cloudwatch_changes_to_network_route_tables_alarm_configured import (
|
||||
cloudwatch_changes_to_network_route_tables_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_network_route_tables_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "No CloudWatch log groups found with metric filters or alarms associated."
|
||||
)
|
||||
|
||||
+182
@@ -596,3 +596,185 @@ class Test_cloudwatch_changes_to_vpcs_alarm_configured:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = EnableVpcClassicLink) || ($.eventName = DisableVpcClassicLink) || ($.eventName = DetachClassicLinkVpc) || ($.eventName = AttachClassicLinkVpc) || ($.eventName = RejectVpcPeeringConnection) || ($.eventName = DeleteVpcPeeringConnection) || ($.eventName = CreateVpcPeeringConnection) || ($.eventName = AcceptVpcPeeringConnection) || ($.eventName = ModifyVpcAttribute) || ($.eventName = DeleteVpc) || ($.eventName = CreateVpc) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured import (
|
||||
cloudwatch_changes_to_vpcs_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_vpcs_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_substring_only_no_match(self):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = ModifyVpcAttribute) || ($.eventName = AcceptVpcPeeringConnection) || ($.eventName = CreateVpcPeeringConnection) || ($.eventName = DeleteVpcPeeringConnection) || ($.eventName = RejectVpcPeeringConnection) || ($.eventName = AttachClassicLinkVpc) || ($.eventName = DetachClassicLinkVpc) || ($.eventName = DisableVpcClassicLink) || ($.eventName = EnableVpcClassicLink) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_changes_to_vpcs_alarm_configured.cloudwatch_changes_to_vpcs_alarm_configured import (
|
||||
cloudwatch_changes_to_vpcs_alarm_configured,
|
||||
)
|
||||
|
||||
check = cloudwatch_changes_to_vpcs_alarm_configured()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "No CloudWatch log groups found with metric filters or alarms associated."
|
||||
)
|
||||
|
||||
+94
@@ -665,3 +665,97 @@ class Test_cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_c
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 0
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = config.amazonaws.com) && (($.eventName = PutConfigurationRecorder) || ($.eventName = PutDeliveryChannel) || ($.eventName = DeleteDeliveryChannel) || ($.eventName = StopConfigurationRecorder)) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled import (
|
||||
cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled,
|
||||
)
|
||||
|
||||
check = (
|
||||
cloudwatch_log_metric_filter_and_alarm_for_aws_config_configuration_changes_enabled()
|
||||
)
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+94
@@ -610,3 +610,97 @@ class Test_cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_c
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = StopLogging) || ($.eventName = StartLogging) || ($.eventName = DeleteTrail) || ($.eventName = UpdateTrail) || ($.eventName = CreateTrail) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled.cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled import (
|
||||
cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled,
|
||||
)
|
||||
|
||||
check = (
|
||||
cloudwatch_log_metric_filter_and_alarm_for_cloudtrail_configuration_changes_enabled()
|
||||
)
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -596,3 +596,95 @@ class Test_cloudwatch_log_metric_filter_authentication_failures:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.errorMessage = Failed authentication) && ($.eventName = ConsoleLogin) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_authentication_failures.cloudwatch_log_metric_filter_authentication_failures.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_authentication_failures.cloudwatch_log_metric_filter_authentication_failures.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_authentication_failures.cloudwatch_log_metric_filter_authentication_failures.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_authentication_failures.cloudwatch_log_metric_filter_authentication_failures import (
|
||||
cloudwatch_log_metric_filter_authentication_failures,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_authentication_failures()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -596,3 +596,95 @@ class Test_cloudwatch_log_metric_filter_aws_organizations_changes:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = organizations.amazonaws.com) && ($.eventName = UpdatePolicy) || ($.eventName = UpdateOrganizationalUnit) || ($.eventName = RemoveAccountFromOrganization) || ($.eventName = MoveAccount) || ($.eventName = DisablePolicyType) || ($.eventName = DetachPolicy) || ($.eventName = LeaveOrganization) || ($.eventName = InviteAccountToOrganization) || ($.eventName = EnablePolicyType) || ($.eventName = EnableAllFeatures) || ($.eventName = DeletePolicy) || ($.eventName = DeleteOrganizationalUnit) || ($.eventName = DeleteOrganization) || ($.eventName = DeclineHandshake) || ($.eventName = CreatePolicy) || ($.eventName = CreateOrganizationalUnit) || ($.eventName = CreateOrganization) || ($.eventName = CreateAccount) || ($.eventName = CancelHandshake) || ($.eventName = AttachPolicy) || ($.eventName = AcceptHandshake) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_aws_organizations_changes.cloudwatch_log_metric_filter_aws_organizations_changes.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_aws_organizations_changes.cloudwatch_log_metric_filter_aws_organizations_changes.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_aws_organizations_changes.cloudwatch_log_metric_filter_aws_organizations_changes.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_aws_organizations_changes.cloudwatch_log_metric_filter_aws_organizations_changes import (
|
||||
cloudwatch_log_metric_filter_aws_organizations_changes,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_aws_organizations_changes()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+94
@@ -610,3 +610,97 @@ class Test_cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = kms.amazonaws.com) && (($.eventName = ScheduleKeyDeletion) || ($.eventName = DisableKey)) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk.cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk import (
|
||||
cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk,
|
||||
)
|
||||
|
||||
check = (
|
||||
cloudwatch_log_metric_filter_disable_or_scheduled_deletion_of_kms_cmk()
|
||||
)
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -596,3 +596,95 @@ class Test_cloudwatch_log_metric_filter_for_s3_bucket_policy_changes:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventSource = s3.amazonaws.com) && (($.eventName = DeleteBucketReplication) || ($.eventName = DeleteBucketLifecycle) || ($.eventName = DeleteBucketCors) || ($.eventName = DeleteBucketPolicy) || ($.eventName = PutBucketReplication) || ($.eventName = PutBucketLifecycle) || ($.eventName = PutBucketCors) || ($.eventName = PutBucketPolicy) || ($.eventName = PutBucketAcl)) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes.cloudwatch_log_metric_filter_for_s3_bucket_policy_changes import (
|
||||
cloudwatch_log_metric_filter_for_s3_bucket_policy_changes,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_for_s3_bucket_policy_changes()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -596,3 +596,95 @@ class Test_cloudwatch_log_metric_filter_unauthorized_api_calls:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = DetachGroupPolicy) || ($.eventName = AttachGroupPolicy) || ($.eventName = DetachUserPolicy) || ($.eventName = AttachUserPolicy) || ($.eventName = DetachRolePolicy) || ($.eventName = AttachRolePolicy) || ($.eventName = DeletePolicyVersion) || ($.eventName = CreatePolicyVersion) || ($.eventName = DeletePolicy) || ($.eventName = CreatePolicy) || ($.eventName = PutUserPolicy) || ($.eventName = PutRolePolicy) || ($.eventName = PutGroupPolicy) || ($.eventName = DeleteUserPolicy) || ($.eventName = DeleteRolePolicy) || ($.eventName = DeleteGroupPolicy) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_policy_changes.cloudwatch_log_metric_filter_policy_changes.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_policy_changes.cloudwatch_log_metric_filter_policy_changes.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_policy_changes.cloudwatch_log_metric_filter_policy_changes.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_policy_changes.cloudwatch_log_metric_filter_policy_changes import (
|
||||
cloudwatch_log_metric_filter_policy_changes,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_policy_changes()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -599,3 +599,95 @@ class Test_cloudwatch_log_metric_filter_unauthorized_api_calls:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.eventName = DeleteSecurityGroup) || ($.eventName = CreateSecurityGroup) || ($.eventName = RevokeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = AuthorizeSecurityGroupIngress) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_security_group_changes.cloudwatch_log_metric_filter_security_group_changes.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_security_group_changes.cloudwatch_log_metric_filter_security_group_changes.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_security_group_changes.cloudwatch_log_metric_filter_security_group_changes.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_security_group_changes.cloudwatch_log_metric_filter_security_group_changes import (
|
||||
cloudwatch_log_metric_filter_security_group_changes,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_security_group_changes()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
+92
@@ -596,3 +596,95 @@ class Test_cloudwatch_log_metric_filter_sign_in_without_mfa:
|
||||
== f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*"
|
||||
)
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
|
||||
@mock_aws
|
||||
def test_cloudwatch_trail_with_log_group_with_metric_and_alarm_reversed_clauses(
|
||||
self,
|
||||
):
|
||||
cloudtrail_client = client("cloudtrail", region_name=AWS_REGION_US_EAST_1)
|
||||
cloudwatch_client = client("cloudwatch", region_name=AWS_REGION_US_EAST_1)
|
||||
logs_client = client("logs", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
|
||||
s3_client.create_bucket(Bucket="test")
|
||||
logs_client.create_log_group(logGroupName="/log-group/test")
|
||||
cloudtrail_client.create_trail(
|
||||
Name="test_trail",
|
||||
S3BucketName="test",
|
||||
CloudWatchLogsLogGroupArn=f"arn:aws:logs:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:log-group:/log-group/test:*",
|
||||
)
|
||||
logs_client.put_metric_filter(
|
||||
logGroupName="/log-group/test",
|
||||
filterName="test-filter",
|
||||
filterPattern="{ ($.additionalEventData.MFAUsed != Yes) && ($.eventName = ConsoleLogin) }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
cloudwatch_client.put_metric_alarm(
|
||||
AlarmName="test-alarm",
|
||||
MetricName="my-metric",
|
||||
Namespace="my-namespace",
|
||||
Period=10,
|
||||
EvaluationPeriods=5,
|
||||
Statistic="Average",
|
||||
Threshold=2,
|
||||
ComparisonOperator="GreaterThanThreshold",
|
||||
ActionsEnabled=True,
|
||||
)
|
||||
|
||||
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
|
||||
Cloudtrail,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
|
||||
aws_provider = set_mocked_aws_provider(
|
||||
[AWS_REGION_US_EAST_1, AWS_REGION_EU_WEST_1]
|
||||
)
|
||||
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
aws_provider.audit_metadata = Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=["cloudwatch_log_group_no_secrets_in_logs"],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
)
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=aws_provider,
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudwatch_log_metric_filter_sign_in_without_mfa.logs_client",
|
||||
new=Logs(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudwatch_client",
|
||||
new=CloudWatch(aws_provider),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudtrail_client",
|
||||
new=Cloudtrail(aws_provider),
|
||||
),
|
||||
):
|
||||
from prowler.providers.aws.services.cloudwatch.cloudwatch_log_metric_filter_sign_in_without_mfa.cloudwatch_log_metric_filter_sign_in_without_mfa import (
|
||||
cloudwatch_log_metric_filter_sign_in_without_mfa,
|
||||
)
|
||||
|
||||
check = cloudwatch_log_metric_filter_sign_in_without_mfa()
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== "CloudWatch log group /log-group/test found with metric filter test-filter and alarms set."
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from boto3 import client
|
||||
from moto import mock_aws
|
||||
|
||||
@@ -5,6 +6,9 @@ from prowler.providers.aws.services.cloudwatch.cloudwatch_service import (
|
||||
CloudWatch,
|
||||
Logs,
|
||||
)
|
||||
from prowler.providers.aws.services.cloudwatch.lib.metric_filters import (
|
||||
build_metric_filter_pattern,
|
||||
)
|
||||
from tests.providers.aws.utils import (
|
||||
AWS_ACCOUNT_NUMBER,
|
||||
AWS_REGION_US_EAST_1,
|
||||
@@ -216,3 +220,13 @@ class Test_CloudWatch_Service:
|
||||
assert logs.log_groups[arn].kms_id == "test_kms_id"
|
||||
assert logs.log_groups[arn].region == AWS_REGION_US_EAST_1
|
||||
assert logs.log_groups[arn].tags == [{}]
|
||||
|
||||
|
||||
class Test_build_metric_filter_pattern:
|
||||
@pytest.mark.parametrize("bad_operator", ["==", "~=", "<", "<>", ">=", ""])
|
||||
def test_rejects_unsupported_operator(self, bad_operator):
|
||||
with pytest.raises(ValueError, match="unsupported operator"):
|
||||
build_metric_filter_pattern(
|
||||
event_names=["ConsoleLogin"],
|
||||
extra_clauses=[("errorMessage", bad_operator, "Failed authentication")],
|
||||
)
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
from unittest import mock
|
||||
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_service import (
|
||||
AccessKey,
|
||||
)
|
||||
from tests.providers.stackit.stackit_fixtures import (
|
||||
STACKIT_PROJECT_ID,
|
||||
set_mocked_stackit_provider,
|
||||
)
|
||||
|
||||
|
||||
class Test_objectstorage_access_key_expiration:
|
||||
def test_no_access_keys(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.access_keys = []
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_access_key_expiration.objectstorage_access_key_expiration import (
|
||||
objectstorage_access_key_expiration,
|
||||
)
|
||||
|
||||
check = objectstorage_access_key_expiration()
|
||||
result = check.execute()
|
||||
assert len(result) == 0
|
||||
|
||||
def test_access_key_with_expiration(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.access_keys = [
|
||||
AccessKey(
|
||||
key_id="key-123",
|
||||
display_name="my-key",
|
||||
expires="2027-01-01T00:00:00+00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_access_key_expiration.objectstorage_access_key_expiration import (
|
||||
objectstorage_access_key_expiration,
|
||||
)
|
||||
|
||||
check = objectstorage_access_key_expiration()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert "has an expiration date set" in result[0].status_extended
|
||||
assert result[0].resource_id == "key-123"
|
||||
assert result[0].resource_name == "my-key"
|
||||
assert result[0].location == "eu01"
|
||||
|
||||
def test_access_key_no_expiration_none(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.access_keys = [
|
||||
AccessKey(
|
||||
key_id="key-456",
|
||||
display_name="never-expiring-key",
|
||||
expires=None,
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_access_key_expiration.objectstorage_access_key_expiration import (
|
||||
objectstorage_access_key_expiration,
|
||||
)
|
||||
|
||||
check = objectstorage_access_key_expiration()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "no expiration date" in result[0].status_extended
|
||||
assert result[0].resource_id == "key-456"
|
||||
|
||||
def test_access_key_no_expiration_sentinel(self):
|
||||
"""Year-0001 date is the SDK sentinel for 'never expires'."""
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.access_keys = [
|
||||
AccessKey(
|
||||
key_id="key-789",
|
||||
display_name="sentinel-key",
|
||||
expires="0001-01-01T00:00:00+00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_access_key_expiration.objectstorage_access_key_expiration import (
|
||||
objectstorage_access_key_expiration,
|
||||
)
|
||||
|
||||
check = objectstorage_access_key_expiration()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "no expiration date" in result[0].status_extended
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
from unittest import mock
|
||||
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_service import (
|
||||
Bucket,
|
||||
)
|
||||
from tests.providers.stackit.stackit_fixtures import (
|
||||
STACKIT_PROJECT_ID,
|
||||
set_mocked_stackit_provider,
|
||||
)
|
||||
|
||||
|
||||
class Test_objectstorage_bucket_object_lock_enabled:
|
||||
def test_no_buckets(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = []
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_object_lock_enabled.objectstorage_bucket_object_lock_enabled import (
|
||||
objectstorage_bucket_object_lock_enabled,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_object_lock_enabled()
|
||||
result = check.execute()
|
||||
assert len(result) == 0
|
||||
|
||||
def test_bucket_object_lock_enabled(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = [
|
||||
Bucket(
|
||||
name="my-bucket",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
object_lock_enabled=True,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_object_lock_enabled.objectstorage_bucket_object_lock_enabled import (
|
||||
objectstorage_bucket_object_lock_enabled,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_object_lock_enabled()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert "has S3 Object Lock enabled" in result[0].status_extended
|
||||
assert result[0].resource_id == "my-bucket"
|
||||
assert result[0].resource_name == "my-bucket"
|
||||
assert result[0].location == "eu01"
|
||||
|
||||
def test_bucket_object_lock_disabled(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = [
|
||||
Bucket(
|
||||
name="my-bucket",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
object_lock_enabled=False,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_object_lock_enabled.objectstorage_bucket_object_lock_enabled import (
|
||||
objectstorage_bucket_object_lock_enabled,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_object_lock_enabled()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert "does not have S3 Object Lock enabled" in result[0].status_extended
|
||||
assert result[0].resource_id == "my-bucket"
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
from unittest import mock
|
||||
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_service import (
|
||||
Bucket,
|
||||
)
|
||||
from tests.providers.stackit.stackit_fixtures import (
|
||||
STACKIT_PROJECT_ID,
|
||||
set_mocked_stackit_provider,
|
||||
)
|
||||
|
||||
|
||||
class Test_objectstorage_bucket_retention_policy:
|
||||
def test_no_buckets(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = []
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_retention_policy.objectstorage_bucket_retention_policy import (
|
||||
objectstorage_bucket_retention_policy,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_retention_policy()
|
||||
result = check.execute()
|
||||
assert len(result) == 0
|
||||
|
||||
def test_bucket_with_retention_policy(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = [
|
||||
Bucket(
|
||||
name="my-bucket",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
object_lock_enabled=True,
|
||||
retention_days=30,
|
||||
retention_mode="COMPLIANCE",
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_retention_policy.objectstorage_bucket_retention_policy import (
|
||||
objectstorage_bucket_retention_policy,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_retention_policy()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert "30 day(s)" in result[0].status_extended
|
||||
assert "COMPLIANCE" in result[0].status_extended
|
||||
assert result[0].resource_id == "my-bucket"
|
||||
assert result[0].location == "eu01"
|
||||
|
||||
def test_bucket_without_retention_policy(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = [
|
||||
Bucket(
|
||||
name="my-bucket",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
object_lock_enabled=False,
|
||||
retention_days=None,
|
||||
retention_mode=None,
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_retention_policy.objectstorage_bucket_retention_policy import (
|
||||
objectstorage_bucket_retention_policy,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_retention_policy()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
"does not have a default retention policy" in result[0].status_extended
|
||||
)
|
||||
assert result[0].resource_id == "my-bucket"
|
||||
|
||||
def test_bucket_retention_zero_days(self):
|
||||
objectstorage_client = mock.MagicMock
|
||||
objectstorage_client.buckets = [
|
||||
Bucket(
|
||||
name="my-bucket",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
object_lock_enabled=True,
|
||||
retention_days=0,
|
||||
retention_mode="GOVERNANCE",
|
||||
)
|
||||
]
|
||||
|
||||
with (
|
||||
mock.patch(
|
||||
"prowler.providers.common.provider.Provider.get_global_provider",
|
||||
return_value=set_mocked_stackit_provider(),
|
||||
),
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_service.ObjectStorageService",
|
||||
new=objectstorage_client,
|
||||
) as service_client,
|
||||
mock.patch(
|
||||
"prowler.providers.stackit.services.objectstorage.objectstorage_client.objectstorage_client",
|
||||
new=service_client,
|
||||
),
|
||||
):
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_bucket_retention_policy.objectstorage_bucket_retention_policy import (
|
||||
objectstorage_bucket_retention_policy,
|
||||
)
|
||||
|
||||
check = objectstorage_bucket_retention_policy()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "FAIL"
|
||||
@@ -0,0 +1,645 @@
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from prowler.providers.stackit.services.objectstorage.objectstorage_service import (
|
||||
AccessKey,
|
||||
ObjectStorageService,
|
||||
)
|
||||
from tests.providers.stackit.stackit_fixtures import STACKIT_PROJECT_ID
|
||||
|
||||
|
||||
class TestObjectStorageService:
|
||||
def test_list_buckets_keeps_bucket_when_retention_not_configured(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
not_found_error = Exception("not found")
|
||||
not_found_error.status = 404
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = SimpleNamespace(
|
||||
buckets=[
|
||||
SimpleNamespace(
|
||||
name="my-bucket",
|
||||
object_lock_enabled=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
client.get_default_retention.side_effect = not_found_error
|
||||
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert len(service.buckets) == 1
|
||||
assert service.buckets[0].name == "my-bucket"
|
||||
assert service.buckets[0].object_lock_enabled is True
|
||||
assert service.buckets[0].retention_days is None
|
||||
assert service.buckets[0].retention_mode is None
|
||||
|
||||
def test_list_buckets_propagates_unexpected_retention_api_errors(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
api_error = Exception("service unavailable")
|
||||
api_error.status = 503
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = SimpleNamespace(
|
||||
buckets=[
|
||||
SimpleNamespace(
|
||||
name="my-bucket",
|
||||
object_lock_enabled=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
client.get_default_retention.side_effect = api_error
|
||||
|
||||
with pytest.raises(Exception, match="service unavailable"):
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert service.buckets == []
|
||||
service.provider.handle_api_error.assert_called_once_with(api_error)
|
||||
|
||||
def test_init_creates_service_with_no_regions(self):
|
||||
provider = mock.MagicMock()
|
||||
provider.identity.project_id = STACKIT_PROJECT_ID
|
||||
provider.generate_regional_clients.return_value = {}
|
||||
|
||||
service = ObjectStorageService(provider)
|
||||
|
||||
assert service.project_id == STACKIT_PROJECT_ID
|
||||
assert service.buckets == []
|
||||
assert service.access_keys == []
|
||||
provider.generate_regional_clients.assert_called_once_with("objectstorage")
|
||||
|
||||
def test_fetch_all_regions_skips_404_region(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
service.access_keys = []
|
||||
|
||||
not_found = Exception("not found")
|
||||
not_found.status = 404
|
||||
service.regional_clients = {"eu01": mock.MagicMock()}
|
||||
|
||||
with mock.patch.object(service, "_list_buckets", side_effect=not_found):
|
||||
service._fetch_all_regions()
|
||||
|
||||
assert service.buckets == []
|
||||
|
||||
def test_fetch_all_regions_reraises_non_404_error(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
service.access_keys = []
|
||||
|
||||
server_error = Exception("internal server error")
|
||||
server_error.status = 500
|
||||
service.regional_clients = {"eu01": mock.MagicMock()}
|
||||
|
||||
with mock.patch.object(service, "_list_buckets", side_effect=server_error):
|
||||
with pytest.raises(Exception, match="internal server error"):
|
||||
service._fetch_all_regions()
|
||||
|
||||
def test_list_buckets_with_dict_api_response(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
not_found = Exception("not found")
|
||||
not_found.status = 404
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = {
|
||||
"buckets": [
|
||||
SimpleNamespace(name="dict-response-bucket", object_lock_enabled=True)
|
||||
]
|
||||
}
|
||||
client.get_default_retention.side_effect = not_found
|
||||
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert len(service.buckets) == 1
|
||||
assert service.buckets[0].name == "dict-response-bucket"
|
||||
|
||||
def test_list_buckets_with_dict_bucket_data(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
not_found = Exception("not found")
|
||||
not_found.status = 404
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = SimpleNamespace(
|
||||
buckets=[{"name": "dict-bucket", "objectLockEnabled": True}]
|
||||
)
|
||||
client.get_default_retention.side_effect = not_found
|
||||
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert len(service.buckets) == 1
|
||||
assert service.buckets[0].name == "dict-bucket"
|
||||
assert service.buckets[0].object_lock_enabled is True
|
||||
|
||||
def test_list_buckets_skips_unknown_bucket_type(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = SimpleNamespace(buckets=[42])
|
||||
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert len(service.buckets) == 0
|
||||
|
||||
def test_get_default_retention_with_dict_response(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.get_default_retention.return_value = {"days": 14, "mode": "GOVERNANCE"}
|
||||
|
||||
days, mode = service._get_default_retention(client, "eu01", "my-bucket")
|
||||
|
||||
assert days == 14
|
||||
assert mode == "GOVERNANCE"
|
||||
|
||||
def test_list_access_keys_with_object_data(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-001", display_name="main-group")]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(
|
||||
access_keys=[
|
||||
SimpleNamespace(
|
||||
key_id="key-001",
|
||||
display_name="my-key",
|
||||
expires="2027-01-01T00:00:00+00:00",
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
client.list_credentials_groups.assert_called_once_with(
|
||||
project_id=STACKIT_PROJECT_ID, region="eu01"
|
||||
)
|
||||
client.list_access_keys.assert_called_once_with(
|
||||
project_id=STACKIT_PROJECT_ID, region="eu01", credentials_group="cg-001"
|
||||
)
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-001"
|
||||
assert service.access_keys[0].display_name == "my-key"
|
||||
assert service.access_keys[0].region == "eu01"
|
||||
assert service.access_keys[0].expires == "2027-01-01T00:00:00+00:00"
|
||||
assert service.access_keys[0].credentials_group_id == "cg-001"
|
||||
assert service.access_keys[0].credentials_group_name == "main-group"
|
||||
|
||||
def test_list_access_keys_with_credentials_group_id_object_data(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[
|
||||
SimpleNamespace(
|
||||
credentials_group_id="cg-sdk",
|
||||
display_name="sdk-group",
|
||||
)
|
||||
]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(access_keys=[])
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
client.list_access_keys.assert_called_once_with(
|
||||
project_id=STACKIT_PROJECT_ID, region="eu01", credentials_group="cg-sdk"
|
||||
)
|
||||
|
||||
def test_list_access_keys_collects_keys_from_multiple_credentials_groups(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[
|
||||
SimpleNamespace(id="cg-001", display_name="group-one"),
|
||||
SimpleNamespace(id="cg-002", display_name="group-two"),
|
||||
]
|
||||
)
|
||||
client.list_access_keys.side_effect = [
|
||||
SimpleNamespace(
|
||||
access_keys=[
|
||||
SimpleNamespace(
|
||||
key_id="key-001",
|
||||
display_name="key-one",
|
||||
expires="2027-01-01T00:00:00+00:00",
|
||||
)
|
||||
]
|
||||
),
|
||||
SimpleNamespace(
|
||||
access_keys=[
|
||||
SimpleNamespace(
|
||||
key_id="key-002",
|
||||
display_name="key-two",
|
||||
expires=None,
|
||||
)
|
||||
]
|
||||
),
|
||||
]
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert client.list_access_keys.call_args_list == [
|
||||
mock.call(
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
region="eu01",
|
||||
credentials_group="cg-001",
|
||||
),
|
||||
mock.call(
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
region="eu01",
|
||||
credentials_group="cg-002",
|
||||
),
|
||||
]
|
||||
assert [key.key_id for key in service.access_keys] == ["key-001", "key-002"]
|
||||
assert service.access_keys[1].expires is None
|
||||
assert service.access_keys[1].has_expiration() is False
|
||||
assert [key.credentials_group_id for key in service.access_keys] == [
|
||||
"cg-001",
|
||||
"cg-002",
|
||||
]
|
||||
|
||||
def test_list_access_keys_with_dict_api_response(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = {
|
||||
"credentialsGroups": [{"id": "cg-dict", "displayName": "dict-group"}]
|
||||
}
|
||||
client.list_access_keys.return_value = {
|
||||
"accessKeys": [
|
||||
{"keyId": "key-dict", "displayName": "dict-key", "expires": None}
|
||||
]
|
||||
}
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-dict"
|
||||
assert service.access_keys[0].display_name == "dict-key"
|
||||
assert service.access_keys[0].expires is None
|
||||
assert service.access_keys[0].has_expiration() is False
|
||||
assert service.access_keys[0].credentials_group_id == "cg-dict"
|
||||
assert service.access_keys[0].credentials_group_name == "dict-group"
|
||||
|
||||
def test_list_access_keys_with_raw_json_response_and_null_expires(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
class RawResponse:
|
||||
status = 200
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
"accessKeys": [
|
||||
{
|
||||
"keyId": "key-raw",
|
||||
"displayName": "raw-key",
|
||||
"expires": None,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self):
|
||||
self.list_credentials_groups = mock.MagicMock(
|
||||
return_value=SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-raw")]
|
||||
)
|
||||
)
|
||||
self.list_access_keys = mock.MagicMock()
|
||||
self.raw_call = None
|
||||
|
||||
def list_access_keys_without_preload_content(self, **kwargs):
|
||||
self.raw_call = kwargs
|
||||
return RawResponse()
|
||||
|
||||
client = FakeClient()
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert client.raw_call == {
|
||||
"project_id": STACKIT_PROJECT_ID,
|
||||
"region": "eu01",
|
||||
"credentials_group": "cg-raw",
|
||||
}
|
||||
client.list_access_keys.assert_not_called()
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-raw"
|
||||
assert service.access_keys[0].expires is None
|
||||
assert service.access_keys[0].has_expiration() is False
|
||||
|
||||
def test_list_access_keys_with_raw_data_response(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
class RawResponse:
|
||||
status = 200
|
||||
data = b'{"accessKeys":[{"keyId":"key-data","displayName":"data-key"}]}'
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self):
|
||||
self.list_credentials_groups = mock.MagicMock(
|
||||
return_value=SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-data")]
|
||||
)
|
||||
)
|
||||
|
||||
def list_access_keys_without_preload_content(self, **kwargs):
|
||||
return RawResponse()
|
||||
|
||||
service._list_access_keys(FakeClient(), "eu01")
|
||||
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-data"
|
||||
assert service.access_keys[0].display_name == "data-key"
|
||||
|
||||
def test_list_access_keys_raw_response_propagates_non_success_status(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
class RawResponse:
|
||||
status = 503
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self):
|
||||
self.list_credentials_groups = mock.MagicMock(
|
||||
return_value=SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-error")]
|
||||
)
|
||||
)
|
||||
|
||||
def list_access_keys_without_preload_content(self, **kwargs):
|
||||
return RawResponse()
|
||||
|
||||
with pytest.raises(Exception, match="status 503") as error:
|
||||
service._list_access_keys(FakeClient(), "eu01")
|
||||
|
||||
assert error.value.status == 503
|
||||
service.provider.handle_api_error.assert_called_once_with(error.value)
|
||||
|
||||
def test_list_access_keys_with_dict_key_data(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[{"id": "cg-456", "displayName": "group-456"}]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(
|
||||
access_keys=[
|
||||
{
|
||||
"keyId": "key-456",
|
||||
"displayName": "my-dict-key",
|
||||
"expires": "2028-06-01T00:00:00+00:00",
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-456"
|
||||
assert service.access_keys[0].display_name == "my-dict-key"
|
||||
assert service.access_keys[0].credentials_group_id == "cg-456"
|
||||
|
||||
def test_list_access_keys_skips_unknown_type(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-001")]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(access_keys=[42])
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 0
|
||||
|
||||
def test_list_access_keys_no_keys(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-empty")]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(access_keys=[])
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 0
|
||||
|
||||
def test_list_access_keys_no_credentials_groups(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[]
|
||||
)
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 0
|
||||
client.list_access_keys.assert_not_called()
|
||||
|
||||
def test_list_access_keys_skips_malformed_credentials_groups(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[
|
||||
42,
|
||||
{},
|
||||
SimpleNamespace(id="cg-valid", display_name="valid-group"),
|
||||
]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(
|
||||
access_keys=[SimpleNamespace(key_id="key-valid")]
|
||||
)
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
client.list_access_keys.assert_called_once_with(
|
||||
project_id=STACKIT_PROJECT_ID, region="eu01", credentials_group="cg-valid"
|
||||
)
|
||||
assert len(service.access_keys) == 1
|
||||
assert service.access_keys[0].key_id == "key-valid"
|
||||
|
||||
def test_fetch_all_regions_calls_both_list_methods(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
service.access_keys = []
|
||||
|
||||
service.regional_clients = {"eu01": mock.MagicMock()}
|
||||
|
||||
with (
|
||||
mock.patch.object(service, "_list_buckets") as mock_buckets,
|
||||
mock.patch.object(service, "_list_access_keys") as mock_keys,
|
||||
):
|
||||
service._fetch_all_regions()
|
||||
|
||||
mock_buckets.assert_called_once()
|
||||
mock_keys.assert_called_once()
|
||||
|
||||
def test_list_buckets_handles_bucket_processing_error(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.buckets = []
|
||||
|
||||
class BrokenBucket:
|
||||
@property
|
||||
def name(self):
|
||||
raise RuntimeError("broken bucket attribute")
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_buckets.return_value = SimpleNamespace(buckets=[BrokenBucket()])
|
||||
|
||||
service._list_buckets(client, "eu01")
|
||||
|
||||
assert len(service.buckets) == 0
|
||||
|
||||
def test_list_access_keys_handles_key_processing_error(self):
|
||||
service = ObjectStorageService.__new__(ObjectStorageService)
|
||||
service.provider = mock.MagicMock()
|
||||
service.project_id = STACKIT_PROJECT_ID
|
||||
service.access_keys = []
|
||||
|
||||
class BrokenKey:
|
||||
@property
|
||||
def key_id(self):
|
||||
raise RuntimeError("broken key attribute")
|
||||
|
||||
client = mock.MagicMock()
|
||||
client.list_credentials_groups.return_value = SimpleNamespace(
|
||||
credentials_groups=[SimpleNamespace(id="cg-001")]
|
||||
)
|
||||
client.list_access_keys.return_value = SimpleNamespace(
|
||||
access_keys=[BrokenKey()]
|
||||
)
|
||||
|
||||
service._list_access_keys(client, "eu01")
|
||||
|
||||
assert len(service.access_keys) == 0
|
||||
|
||||
|
||||
class TestAccessKeyModel:
|
||||
def test_has_expiration_with_invalid_date_string(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires="not-a-valid-date",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.has_expiration() is False
|
||||
|
||||
def test_expires_within_days_when_no_expiration(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires=None,
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.expires is None
|
||||
assert key.has_expiration() is False
|
||||
assert key.expires_within_days(90) is False
|
||||
|
||||
def test_expires_within_days_when_expiring_soon(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires="2026-06-15T00:00:00+00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.expires_within_days(90) is True
|
||||
|
||||
def test_expires_within_days_when_not_expiring_soon(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires="2030-01-01T00:00:00+00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.expires_within_days(30) is False
|
||||
|
||||
def test_expires_within_days_with_naive_datetime(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires="2026-06-10T00:00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.expires_within_days(90) is True
|
||||
|
||||
def test_expires_within_days_with_sentinel_key(self):
|
||||
key = AccessKey(
|
||||
key_id="k",
|
||||
display_name="k",
|
||||
expires="0001-01-01T00:00:00+00:00",
|
||||
region="eu01",
|
||||
project_id=STACKIT_PROJECT_ID,
|
||||
)
|
||||
assert key.expires_within_days(90) is False
|
||||
@@ -411,3 +411,68 @@ class Test_StackitProvider_Handle_API_Error:
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
StackitProvider.handle_api_error(original)
|
||||
assert excinfo.value is original
|
||||
|
||||
|
||||
class TestGenerateRegionalClients:
|
||||
"""Tests for StackitProvider.generate_regional_clients."""
|
||||
|
||||
def _make_provider(self):
|
||||
provider = object.__new__(StackitProvider)
|
||||
provider._service_account_key_path = "/tmp/sa-key.json"
|
||||
provider._service_account_key = None
|
||||
provider._audited_regions = None
|
||||
return provider
|
||||
|
||||
def _fake_classes(self):
|
||||
class FakeConfig:
|
||||
pass
|
||||
|
||||
class FakeIaasClient:
|
||||
def __init__(self, config):
|
||||
pass
|
||||
|
||||
class FakeObjStorageClient:
|
||||
def __init__(self, config):
|
||||
pass
|
||||
|
||||
return FakeConfig, FakeIaasClient, FakeObjStorageClient
|
||||
|
||||
def test_objectstorage_service_uses_objectstorage_api_class(self, monkeypatch):
|
||||
FakeConfig, FakeIaasClient, FakeObjStorageClient = self._fake_classes()
|
||||
|
||||
monkeypatch.setattr(
|
||||
StackitProvider,
|
||||
"_SERVICE_API_CLASS",
|
||||
{"iaas": FakeIaasClient, "objectstorage": FakeObjStorageClient},
|
||||
)
|
||||
provider = self._make_provider()
|
||||
monkeypatch.setattr(
|
||||
provider, "get_available_service_regions", lambda _s, _r: ["eu01"]
|
||||
)
|
||||
with patch.object(
|
||||
StackitProvider, "_build_sdk_configuration", return_value=FakeConfig()
|
||||
):
|
||||
clients = provider.generate_regional_clients("objectstorage")
|
||||
|
||||
assert "eu01" in clients
|
||||
assert isinstance(clients["eu01"], FakeObjStorageClient)
|
||||
|
||||
def test_iaas_service_uses_iaas_api_class(self, monkeypatch):
|
||||
FakeConfig, FakeIaasClient, FakeObjStorageClient = self._fake_classes()
|
||||
|
||||
monkeypatch.setattr(
|
||||
StackitProvider,
|
||||
"_SERVICE_API_CLASS",
|
||||
{"iaas": FakeIaasClient, "objectstorage": FakeObjStorageClient},
|
||||
)
|
||||
provider = self._make_provider()
|
||||
monkeypatch.setattr(
|
||||
provider, "get_available_service_regions", lambda _s, _r: ["eu01"]
|
||||
)
|
||||
with patch.object(
|
||||
StackitProvider, "_build_sdk_configuration", return_value=FakeConfig()
|
||||
):
|
||||
clients = provider.generate_regional_clients("iaas")
|
||||
|
||||
assert "eu01" in clients
|
||||
assert isinstance(clients["eu01"], FakeIaasClient)
|
||||
|
||||
@@ -6,11 +6,13 @@ All notable changes to the **Prowler UI** are documented in this file.
|
||||
|
||||
### 🚀 Added
|
||||
|
||||
- DISA Okta IDaaS STIG V1R2 compliance framework support with its dedicated mapper, details panel, and icon [(#11428)](https://github.com/prowler-cloud/prowler/pull/11428)
|
||||
- DORA compliance framework support [(#11131)](https://github.com/prowler-cloud/prowler/pull/11131)
|
||||
|
||||
### 🔄 Changed
|
||||
|
||||
- Renamed "Customer Support" to "Support Desk" in the side menu, showing it only in Prowler Cloud/Enterprise, while "Community Support" now shows only in Prowler OSS [(#11508)](https://github.com/prowler-cloud/prowler/pull/11508)
|
||||
- Compliance detail page now shows a "still loading" retry state while the API warms its compliance catalog, instead of rendering an empty page [(#4554)](https://github.com/prowler-cloud/prowler-cloud/pull/4554)
|
||||
|
||||
---
|
||||
|
||||
@@ -54,6 +56,7 @@ All notable changes to the **Prowler UI** are documented in this file.
|
||||
|
||||
- Compliance page now loads the most recent scan when opened from the sidebar instead of showing the "no compliance data available" alert [(#11374)](https://github.com/prowler-cloud/prowler/pull/11374)
|
||||
- Invitation links now show specific expired, no-longer-valid, and invalid-token messages based on API error responses [(#11376)](https://github.com/prowler-cloud/prowler/pull/11376)
|
||||
- Jira dispatch and provider connection-test polling no longer show a false timeout for longer-running tasks; both poll windows now extend to 60 seconds [(#11519)](https://github.com/prowler-cloud/prowler/pull/11519)
|
||||
|
||||
### 🔐 Security
|
||||
|
||||
|
||||
@@ -84,6 +84,13 @@ export const getComplianceAttributes = async (complianceId: string) => {
|
||||
headers,
|
||||
});
|
||||
|
||||
// The compliance catalog is still warming after a deploy/restart. Signal
|
||||
// the page to render the "still loading" state instead of letting this
|
||||
// become a thrown 5xx (which would be captured as a server error).
|
||||
if (response.status === 503) {
|
||||
return { warming: true as const, status: 503 };
|
||||
}
|
||||
|
||||
return handleApiResponse(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching compliance attributes:", error);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user