gitlabcis 1.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitlabcis/__init__.py +12 -0
- gitlabcis/__main__.py +7 -0
- gitlabcis/benchmarks/__init__.py +8 -0
- gitlabcis/benchmarks/artifacts_4/__init__.py +4 -0
- gitlabcis/benchmarks/artifacts_4/access_to_artifacts_4_2.py +139 -0
- gitlabcis/benchmarks/artifacts_4/origin_traceability_4_4.py +11 -0
- gitlabcis/benchmarks/artifacts_4/package_registries_4_3.py +105 -0
- gitlabcis/benchmarks/artifacts_4/verification_4_1.py +83 -0
- gitlabcis/benchmarks/build_pipelines_2/__init__.py +4 -0
- gitlabcis/benchmarks/build_pipelines_2/build_environment_2_1.py +268 -0
- gitlabcis/benchmarks/build_pipelines_2/build_worker_2_2.py +129 -0
- gitlabcis/benchmarks/build_pipelines_2/pipeline_instructions_2_3.py +444 -0
- gitlabcis/benchmarks/build_pipelines_2/pipeline_integrity_2_4.py +146 -0
- gitlabcis/benchmarks/dependencies_3/__init__.py +2 -0
- gitlabcis/benchmarks/dependencies_3/third_party_packages_3_1.py +171 -0
- gitlabcis/benchmarks/dependencies_3/validate_packages_3_2.py +182 -0
- gitlabcis/benchmarks/deployment_5/__init__.py +2 -0
- gitlabcis/benchmarks/deployment_5/deployment_configuration_5_1.py +165 -0
- gitlabcis/benchmarks/deployment_5/deployment_environment_5_2.py +66 -0
- gitlabcis/benchmarks/source_code_1/__init__.py +6 -0
- gitlabcis/benchmarks/source_code_1/code_changes_1_1.py +665 -0
- gitlabcis/benchmarks/source_code_1/code_risks_1_5.py +506 -0
- gitlabcis/benchmarks/source_code_1/contribution_access_1_3.py +334 -0
- gitlabcis/benchmarks/source_code_1/repository_management_1_2.py +168 -0
- gitlabcis/benchmarks/source_code_1/third_party_1_4.py +139 -0
- gitlabcis/cli/__init__.py +0 -0
- gitlabcis/cli/log.py +30 -0
- gitlabcis/cli/main.py +541 -0
- gitlabcis/cli/output.py +151 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/external_auth_server.yml +51 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_artifact_uploaders.yml +57 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_certifying_artifacts.yml +53 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/minimum_package_registry_admins.yml +54 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/readme.md +14 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/require_mfa_to_package_registry.yml +52 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/restrict_anonymous_access.yml +67 -0
- gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/artifact_origin_info.yml +56 -0
- gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/readme.md +7 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/all_artifact_versions_signed.yml +70 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/audit_package_registry_config.yml +46 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/readme.md +12 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/secure_repo_webhooks.yml +50 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/validate_signed_artifacts_on_upload.yml +72 -0
- gitlabcis/recommendations/artifacts_4/readme.md +12 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/encrypt_artifacts_before_distribution.yml +47 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/only_authorized_platforms_can_decrypt_artifacts.yml +59 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/readme.md +11 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/sign_artifacts_in_build_pipeline.yml +40 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/authenticate_build_access.yml +55 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_automation.yml +54 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_env_admins.yml +55 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_logging.yml +49 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/disable_build_tools_default_passwords.yml +54 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/immutable_pipeline_infrastructure.yml +60 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_access.yml +64 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_secrets_scope.yml +56 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/readme.md +19 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/secure_build_env_webhooks.yml +43 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/single_responsibility_pipeline.yml +58 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/vuln_scanning.yml +64 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/build_worker_vuln_scanning.yml +58 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/monitor_worker_resource_consumption.yml +59 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/pass_worker_envs_and_commands.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/readme.md +16 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/restrict_worker_connectivity.yml +61 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/segregate_worker_duties.yml +78 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/single_use_workers.yml +47 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/store_worker_config.yml +62 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/worker_runtime_security.yml +37 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_stage_io.yml +49 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_steps_as_code.yml +42 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/limit_pipeline_triggers.yml +76 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_misconfiguration_scanning.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_secret_scanning.yml +56 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_vuln_scanning.yml +44 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/readme.md +16 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/secure_pipeline_output.yml +52 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/track_pipeline_files.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/create_reproducible_artifacts.yml +52 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/lock_dependencies.yml +59 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_produces_sbom.yml +81 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_signs_sbom.yml +38 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/readme.md +14 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/sign_artifacts.yml +35 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/validate_dependencies.yml +63 -0
- gitlabcis/recommendations/build_pipelines_2/readme.md +12 -0
- gitlabcis/recommendations/dependencies_3/readme.md +10 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/define_package_managers.yml +84 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/dependency_sbom.yml +84 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/monitor_dependencies.yml +61 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/packages_over_60_days_old.yml +95 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/pin_dependency_version.yml +48 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/readme.md +14 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/third_party_sbom_required.yml +70 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_artifacts.yml +45 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_signed_metadata.yml +41 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/org_wide_dependency_policy.yml +47 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_license_scanning.yml +47 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_ownership_change.yml +42 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_vuln_scanning.yml +62 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/readme.md +10 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/audit_deployment_config.yml +46 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/limit_deployment_config_access.yml +51 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/pin_deployment_config_manifests.yml +59 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/readme.md +13 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/scan_iac.yml +72 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/secret_scan_deployment_config.yml +45 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/separate_deployment_config.yml +50 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/verify_deployment_config.yml +49 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/automate_deployment.yml +47 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/disable_default_passwords.yml +63 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/limit_prod_access.yml +45 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/readme.md +12 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/reproducible_deployment.yml +50 -0
- gitlabcis/recommendations/deployment_5/readme.md +10 -0
- gitlabcis/recommendations/readme.md +24 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/audit_branch_protections.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/auto_risk_scan_merges.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/branch_protections_for_admins.yml +60 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/branches_updated_before_merging.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/checks_pass_before_merging.yml +57 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approval_dismissals.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approvals.yml +65 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_changes_require_code_owners.yml +68 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_dismissal_restrictions.yml +69 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_owners.yml +61 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_tracing.yml +52 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/comments_resolved_before_merging.yml +59 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/commits_must_be_signed_before_merging.yml +63 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/default_branch_protected.yml +85 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/deny_branch_deletions.yml +76 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/ensure_force_push_is_denied.yml +59 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/linear_history_required.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/merging_restrictions.yml +65 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/readme.md +26 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/stale_branch_reviews.yml +72 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/version_control.yml +45 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_api_scanning.yml +50 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_web_scanning.yml +51 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dependency_scanning.yml +84 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/enable_secret_detection.yml +45 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/license_scanning.yml +47 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/readme.md +14 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_iac_instructions.yml +81 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_pipeline_instructions.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/vulnerability_scanning.yml +48 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/domain_verification.yml +65 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/ensure_2_admins_per_repo.yml +56 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_top_level_group_creation.yml +61 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_user_registration_domain.yml +58 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/minimum_number_of_admins.yml +56 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/org_provided_ssh_certs.yml +70 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/readme.md +21 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_at_org_level.yml +89 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_for_contributors.yml +76 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/restrict_ip_addresses.yml +84 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/review_and_remove_inactive_users.yml +62 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/scm_notification_restriction.yml +46 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/strict_permissions_for_repo.yml +62 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/track_code_anomalies.yml +43 -0
- gitlabcis/recommendations/source_code_1/readme.md +13 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_issue_deletions.yml +57 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_creations.yml +64 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_deletions.yml +57 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/public_repos_have_security_file.yml +59 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/readme.md +15 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/review_and_archive_stale_repos.yml +65 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/track_forks.yml +74 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/track_project_visibility_status.yml +74 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/README.md +12 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/admin_approval_for_app_installs.yml +83 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/least_privilge_app_permissions.yml +103 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/secure_webhooks.yml +73 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/stale_app_reviews.yml +66 -0
- gitlabcis/recommendations/template.yml +30 -0
- gitlabcis/tests/__init__.py +0 -0
- gitlabcis/tests/input/__init__.py +0 -0
- gitlabcis/tests/input/conftest.py +29 -0
- gitlabcis/tests/input/no_input_test.py +82 -0
- gitlabcis/tests/input/switch_test.py +19 -0
- gitlabcis/tests/input/version_test.py +7 -0
- gitlabcis/tests/unit/__init__.py +0 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/access_to_artifacts_4_2_test.py +131 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/origin_traceability_4_4_test.py +15 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/package_registries_4_3_test.py +102 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/verification_4_1_test.py +78 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_environment_2_1_test.py +239 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_worker_2_2_test.py +105 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_instructions_2_3_test.py +340 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_integrity_2_4_test.py +115 -0
- gitlabcis/tests/unit/benchmarks/conftest.py +47 -0
- gitlabcis/tests/unit/benchmarks/dependencies_3/third_party_packages_3_1_test.py +135 -0
- gitlabcis/tests/unit/benchmarks/dependencies_3/validate_packages_3_2_test.py +171 -0
- gitlabcis/tests/unit/benchmarks/deployment_5/deployment_configuration_5_1_test.py +140 -0
- gitlabcis/tests/unit/benchmarks/deployment_5/deployment_environment_5_2_test.py +60 -0
- gitlabcis/tests/unit/benchmarks/function_test.py +24 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/code_changes_1_1_test.py +565 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/code_risks_1_5_test.py +419 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/contribution_access_1_3_test.py +265 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/repository_management_1_2_test.py +142 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/third_party_1_4_test.py +119 -0
- gitlabcis/tests/unit/conftest.py +94 -0
- gitlabcis/tests/unit/log/log_test.py +23 -0
- gitlabcis/tests/unit/utils/argfilters_test.py +9 -0
- gitlabcis/tests/unit/utils/ci_test.py +156 -0
- gitlabcis/tests/unit/utils/output_test.py +95 -0
- gitlabcis/tests/unit/utils/utils_general_test.py +149 -0
- gitlabcis/tests/unit/utils/version_test.py +11 -0
- gitlabcis/tests/unit/yaml/bad_file_test.py +15 -0
- gitlabcis/tests/unit/yaml/recommendation_test.py +123 -0
- gitlabcis/utils/__init__.py +146 -0
- gitlabcis/utils/ci.py +132 -0
- gitlabcis-1.3.2.dist-info/LICENSE +21 -0
- gitlabcis-1.3.2.dist-info/METADATA +241 -0
- gitlabcis-1.3.2.dist-info/RECORD +218 -0
- gitlabcis-1.3.2.dist-info/WHEEL +5 -0
- gitlabcis-1.3.2.dist-info/entry_points.txt +2 -0
- gitlabcis-1.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def sign_artifacts(glEntity, glObject, **kwargs):
|
|
5
|
+
"""
|
|
6
|
+
id: 2.4.1
|
|
7
|
+
title: Ensure all artifacts on all releases are signed
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# We cannot automatically answer this check, thereforewe SKIP:
|
|
11
|
+
return {None: 'This check requires validation'}
|
|
12
|
+
|
|
13
|
+
# -------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def lock_dependencies(glEntity, glObject, **kwargs):
|
|
17
|
+
"""
|
|
18
|
+
id: 2.4.2
|
|
19
|
+
title: Ensure all external dependencies used in the build
|
|
20
|
+
process are locked
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
24
|
+
return {None: 'This check requires validation'}
|
|
25
|
+
|
|
26
|
+
# -------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def validate_dependencies(glEntity, glObject, **kwargs):
|
|
30
|
+
"""
|
|
31
|
+
id: 2.4.3
|
|
32
|
+
title: Ensure dependencies are validated before being used
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
36
|
+
GitlabHttpError)
|
|
37
|
+
|
|
38
|
+
from gitlabcis.utils import ci
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
return ci.searchConfig(
|
|
42
|
+
glEntity, glObject, 'dependency-scanning')
|
|
43
|
+
|
|
44
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
45
|
+
if e.response_code in [401, 403]:
|
|
46
|
+
return {None: 'Insufficient permissions'}
|
|
47
|
+
|
|
48
|
+
# -------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def create_reproducible_artifacts(glEntity, glObject, **kwargs):
|
|
52
|
+
"""
|
|
53
|
+
id: 2.4.4
|
|
54
|
+
title: Ensure the build pipeline creates reproducible artifacts
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
import base64
|
|
58
|
+
|
|
59
|
+
import yaml
|
|
60
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
61
|
+
GitlabHttpError)
|
|
62
|
+
|
|
63
|
+
from gitlabcis.utils import ci
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
gitlab_ci_yml = ci.getConfig(glEntity, glObject, **kwargs)
|
|
67
|
+
|
|
68
|
+
ciFile, reason = gitlab_ci_yml.popitem()
|
|
69
|
+
|
|
70
|
+
if ciFile in [None, False]:
|
|
71
|
+
return {ciFile: reason}
|
|
72
|
+
|
|
73
|
+
gl_ci_yml_content = ciFile.content
|
|
74
|
+
gl_ci_yml_decode = base64.b64decode(gl_ci_yml_content).decode('utf-8')
|
|
75
|
+
gitlab_ci_yml_dict = yaml.safe_load(gl_ci_yml_decode)
|
|
76
|
+
if gitlab_ci_yml_dict is None:
|
|
77
|
+
return {False: 'gitlab_ci_yml file not found'}
|
|
78
|
+
else:
|
|
79
|
+
if ('stages' in gitlab_ci_yml_dict
|
|
80
|
+
and 'build' in gitlab_ci_yml_dict['stages']):
|
|
81
|
+
build_jobs = [
|
|
82
|
+
job_name for job_name, job in gitlab_ci_yml_dict.items()
|
|
83
|
+
if isinstance(job, dict) and job.get('stage') == 'build'
|
|
84
|
+
]
|
|
85
|
+
if not build_jobs:
|
|
86
|
+
return {True: 'No built stage detected'
|
|
87
|
+
' in gitlab_ci_yml'}
|
|
88
|
+
for job_name in build_jobs:
|
|
89
|
+
job = gitlab_ci_yml_dict[job_name]
|
|
90
|
+
if 'artifacts' in job:
|
|
91
|
+
continue
|
|
92
|
+
else:
|
|
93
|
+
return {False: 'No artifacts found for a '
|
|
94
|
+
'job in the build stage'}
|
|
95
|
+
else:
|
|
96
|
+
return {True: 'No stages detected in gitlab_ci_yml'}
|
|
97
|
+
return {True: 'Build pipeline creates reproducible artifacts'}
|
|
98
|
+
|
|
99
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
100
|
+
if e.response_code in [401, 403]:
|
|
101
|
+
return {None: 'Insufficient permissions'}
|
|
102
|
+
|
|
103
|
+
# -------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def pipeline_produces_sbom(glEntity, glObject, **kwargs):
|
|
107
|
+
"""
|
|
108
|
+
id: 2.4.5
|
|
109
|
+
title: Ensure pipeline steps produce a Software Bill of Materials
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
113
|
+
GitlabHttpError)
|
|
114
|
+
|
|
115
|
+
from gitlabcis.utils import ci
|
|
116
|
+
|
|
117
|
+
try:
|
|
118
|
+
_result = ci.searchConfig(
|
|
119
|
+
glEntity, glObject, 'dependency-scanning')
|
|
120
|
+
|
|
121
|
+
result, reason = _result.popitem()
|
|
122
|
+
|
|
123
|
+
if result is True:
|
|
124
|
+
return {True: 'dependency-scanning is enabled,'
|
|
125
|
+
' review CycloneDX SBOMs which named '
|
|
126
|
+
'gl-sbom--.cdx.json, available as job '
|
|
127
|
+
'artifacts of the dependency scanning job.'}
|
|
128
|
+
else:
|
|
129
|
+
return {result: reason}
|
|
130
|
+
|
|
131
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
132
|
+
if e.response_code in [401, 403]:
|
|
133
|
+
return {None: 'Insufficient permissions'}
|
|
134
|
+
|
|
135
|
+
# -------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def pipeline_sign_sbom(glEntity, glObject, **kwargs):
|
|
139
|
+
"""
|
|
140
|
+
id: 2.4.6
|
|
141
|
+
title: Ensure pipeline steps sign the Software Bill of
|
|
142
|
+
Materials -(SBOM) produced
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
146
|
+
return {None: 'This check requires validation'}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def verify_artifacts(glEntity, glObject, **kwargs):
|
|
5
|
+
"""
|
|
6
|
+
id: 3.1.1
|
|
7
|
+
title: Ensure third-party artifacts and open-source
|
|
8
|
+
libraries are verified
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
12
|
+
return {None: 'This check requires validation'}
|
|
13
|
+
|
|
14
|
+
# -------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def third_party_sbom_required(glEntity, glObject, **kwargs):
|
|
18
|
+
"""
|
|
19
|
+
id: 3.1.2
|
|
20
|
+
title: Ensure Software Bill of Materials (SBOM) is required from
|
|
21
|
+
all third-party suppliers
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
25
|
+
return {None: 'This check requires validation'}
|
|
26
|
+
|
|
27
|
+
# -------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def verify_signed_metadata(glEntity, glObject, **kwargs):
|
|
31
|
+
"""
|
|
32
|
+
id: 3.1.3
|
|
33
|
+
title: Ensure signed metadata of the build process is required and
|
|
34
|
+
verified
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
38
|
+
return {None: 'This check requires validation'}
|
|
39
|
+
|
|
40
|
+
# -------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def monitor_dependencies(glEntity, glObject, **kwargs):
|
|
44
|
+
"""
|
|
45
|
+
id: 3.1.4
|
|
46
|
+
title: Ensure dependencies are monitored between open-source
|
|
47
|
+
components
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
from gitlab.exceptions import GitlabGetError, GitlabHttpError
|
|
51
|
+
from gitlab.exceptions import GitlabAuthenticationError
|
|
52
|
+
from gql import gql
|
|
53
|
+
from graphql import GraphQLError
|
|
54
|
+
from gql.transport.exceptions import TransportServerError
|
|
55
|
+
from gql.transport.exceptions import TransportAlreadyConnected
|
|
56
|
+
from gql import Client
|
|
57
|
+
from gql.transport.requests import RequestsHTTPTransport
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
|
|
61
|
+
variables = {
|
|
62
|
+
'fullPath': glEntity.path_with_namespace
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
66
|
+
if e.response_code in [401, 403]:
|
|
67
|
+
return {None: 'Insufficient permissions'}
|
|
68
|
+
|
|
69
|
+
client = Client(
|
|
70
|
+
transport=RequestsHTTPTransport(
|
|
71
|
+
url=kwargs.get('graphQLEndpoint'),
|
|
72
|
+
headers=kwargs.get('graphQLHeaders'),
|
|
73
|
+
use_json=True
|
|
74
|
+
),
|
|
75
|
+
fetch_schema_from_transport=True
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
query = gql('''
|
|
79
|
+
query GetSecurityScanners($fullPath: ID!) {
|
|
80
|
+
project(fullPath: $fullPath) {
|
|
81
|
+
securityScanners {
|
|
82
|
+
enabled
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
''')
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
|
|
90
|
+
results = client.execute(query, variable_values=variables)
|
|
91
|
+
|
|
92
|
+
except (GraphQLError, TransportServerError, TransportAlreadyConnected):
|
|
93
|
+
return {None: 'Error: Issue with GraphQL Query'}
|
|
94
|
+
|
|
95
|
+
# pytest no auth
|
|
96
|
+
except AttributeError:
|
|
97
|
+
return {None: 'Insufficient permissions'}
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
enabledScanners = results["project"]["securityScanners"]["enabled"]
|
|
101
|
+
dependencyScanningEnabled = "DEPENDENCY_SCANNING" in enabledScanners
|
|
102
|
+
containerScanningEnabled = "CONTAINER_SCANNING" in enabledScanners
|
|
103
|
+
if (dependencyScanningEnabled and containerScanningEnabled):
|
|
104
|
+
return {True: 'DEPENDENCY SCANNING and '
|
|
105
|
+
'CONTAINER SCANNING are enabled'}
|
|
106
|
+
elif (dependencyScanningEnabled and not containerScanningEnabled):
|
|
107
|
+
return {False: 'DEPENDENCY SCANNING is enabled but '
|
|
108
|
+
'CONTAINER SCANNING is not enabled'}
|
|
109
|
+
elif (containerScanningEnabled and not dependencyScanningEnabled):
|
|
110
|
+
return {False: 'CONTAINER SCANNING is enabled '
|
|
111
|
+
'but DEPENDENCY SCANNING is not enabled'}
|
|
112
|
+
return {False: 'CONTAINER SCANNING and DEPENDENCY SCANNING '
|
|
113
|
+
'are not enabled'}
|
|
114
|
+
|
|
115
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
116
|
+
if e.response_code in [401, 403]:
|
|
117
|
+
return {None: 'Insufficient permissions'}
|
|
118
|
+
|
|
119
|
+
except KeyError:
|
|
120
|
+
return {False: 'No scanners enabled'}
|
|
121
|
+
|
|
122
|
+
# -------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def define_package_managers(glEntity, glObject, **kwargs):
|
|
126
|
+
"""
|
|
127
|
+
id: 3.1.5
|
|
128
|
+
title: Ensure trusted package managers and repositories are
|
|
129
|
+
defined and prioritized
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
133
|
+
return {None: 'This check requires validation'}
|
|
134
|
+
|
|
135
|
+
# -------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def dependency_sbom(glEntity, glObject, **kwargs):
|
|
139
|
+
"""
|
|
140
|
+
id: 3.1.6
|
|
141
|
+
title: Ensure a signed Software Bill of Materials (SBOM) of the
|
|
142
|
+
code is supplied
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
146
|
+
return {None: 'This check requires validation'}
|
|
147
|
+
|
|
148
|
+
# -------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def pin_dependency_version(glEntity, glObject, **kwargs):
|
|
152
|
+
"""
|
|
153
|
+
id: 3.1.7
|
|
154
|
+
title: Ensure dependencies are pinned to a specific, verified
|
|
155
|
+
version
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
159
|
+
return {None: 'This check requires validation'}
|
|
160
|
+
|
|
161
|
+
# ------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def packages_over_60_days_old(glEntity, glObject, **kwargs):
|
|
165
|
+
"""
|
|
166
|
+
id: 3.1.8
|
|
167
|
+
title: Ensure all packages used are more than 60 days old
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
171
|
+
return {None: 'This check requires validation'}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def org_wide_dependency_policy(glEntity, glObject, **kwargs):
|
|
5
|
+
"""
|
|
6
|
+
id: 3.2.1
|
|
7
|
+
title: Ensure an organization-wide dependency usage policy
|
|
8
|
+
is enforced
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from gitlab.exceptions import GitlabGetError, GitlabHttpError
|
|
12
|
+
from gitlab.exceptions import GitlabAuthenticationError
|
|
13
|
+
from gql import gql
|
|
14
|
+
from graphql import GraphQLError
|
|
15
|
+
from gql.transport.exceptions import TransportServerError
|
|
16
|
+
import yaml
|
|
17
|
+
from gql.transport.exceptions import TransportAlreadyConnected
|
|
18
|
+
from gql import Client
|
|
19
|
+
from gql.transport.requests import RequestsHTTPTransport
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
|
|
23
|
+
variables = {
|
|
24
|
+
'fullPath': glEntity.path_with_namespace
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
28
|
+
if e.response_code in [401, 403]:
|
|
29
|
+
return {None: 'Insufficient permissions'}
|
|
30
|
+
|
|
31
|
+
client = Client(
|
|
32
|
+
transport=RequestsHTTPTransport(
|
|
33
|
+
url=kwargs.get('graphQLEndpoint'),
|
|
34
|
+
headers=kwargs.get('graphQLHeaders'),
|
|
35
|
+
use_json=True
|
|
36
|
+
),
|
|
37
|
+
fetch_schema_from_transport=True
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
query = gql('''
|
|
41
|
+
query GetSecurityScanners($fullPath: ID!) {
|
|
42
|
+
project(fullPath: $fullPath) {
|
|
43
|
+
scanExecutionPolicies {
|
|
44
|
+
nodes {
|
|
45
|
+
name
|
|
46
|
+
enabled
|
|
47
|
+
yaml
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
''')
|
|
53
|
+
|
|
54
|
+
try:
|
|
55
|
+
|
|
56
|
+
results = client.execute(query, variable_values=variables)
|
|
57
|
+
|
|
58
|
+
except (GraphQLError, TransportServerError, TransportAlreadyConnected):
|
|
59
|
+
return {None: 'Error: Issue with GraphQL Query'}
|
|
60
|
+
|
|
61
|
+
# pytest no auth:
|
|
62
|
+
except AttributeError:
|
|
63
|
+
return {None: 'Insufficient permissions'}
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
secret_detection_policy_found = False
|
|
67
|
+
for policy in results['project']['scanExecutionPolicies']['nodes']:
|
|
68
|
+
if policy.get('enabled') is True:
|
|
69
|
+
policy_yaml = yaml.safe_load(policy.get('yaml', ''))
|
|
70
|
+
actions = policy_yaml.get('actions', [])
|
|
71
|
+
for action in actions:
|
|
72
|
+
if action.get('scan') == 'dependency_scanning':
|
|
73
|
+
secret_detection_policy_found = True
|
|
74
|
+
|
|
75
|
+
if secret_detection_policy_found:
|
|
76
|
+
return {
|
|
77
|
+
True: (
|
|
78
|
+
'Scan Execution Policy for dependency_scanning is '
|
|
79
|
+
'enabled'
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
else:
|
|
83
|
+
return {
|
|
84
|
+
False: (
|
|
85
|
+
'Scan Execution Policy for dependency_scanning '
|
|
86
|
+
'is not enabled'
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
except KeyError:
|
|
91
|
+
return {False: 'Scan Execution Policy was not found'}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# -------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def package_vuln_scanning(glEntity, glObject, **kwargs):
|
|
98
|
+
"""
|
|
99
|
+
id: 3.2.2
|
|
100
|
+
title: Ensure packages are automatically scanned for known
|
|
101
|
+
vulnerabilities
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
from gitlab.exceptions import GitlabGetError, GitlabHttpError
|
|
105
|
+
from gitlab.exceptions import GitlabAuthenticationError
|
|
106
|
+
|
|
107
|
+
from gitlabcis.utils import ci
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
settings = glObject.settings.get()
|
|
111
|
+
|
|
112
|
+
if settings.auto_devops_enabled is True:
|
|
113
|
+
return {True: 'Dependency Scanning is '
|
|
114
|
+
'enabled via Auto DevOps'}
|
|
115
|
+
|
|
116
|
+
return ci.searchConfig(
|
|
117
|
+
glEntity, glObject, 'dependency_scanning')
|
|
118
|
+
|
|
119
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
120
|
+
if e.response_code in [401, 403]:
|
|
121
|
+
return {None: 'Insufficient permissions'}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# -------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def package_license_scanning(glEntity, glObject, **kwargs):
|
|
128
|
+
"""
|
|
129
|
+
id: 3.2.3
|
|
130
|
+
title: Ensure packages are automatically scanned
|
|
131
|
+
for license implications
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
from gitlab.exceptions import GitlabGetError, GitlabHttpError
|
|
135
|
+
from gitlab.exceptions import GitlabAuthenticationError
|
|
136
|
+
|
|
137
|
+
from gitlabcis.utils import ci
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
settings = glObject.settings.get()
|
|
141
|
+
|
|
142
|
+
_successAddon = ('On GitLab self-managed, you also can choose '
|
|
143
|
+
'package registry metadata to synchronize '
|
|
144
|
+
'in the Admin Area for the GitLab instance. '
|
|
145
|
+
'You also must allow outbound network traffic '
|
|
146
|
+
'from your GitLab instance to the domain '
|
|
147
|
+
'storage.googleapis.com.')
|
|
148
|
+
|
|
149
|
+
if settings.auto_devops_enabled is True:
|
|
150
|
+
return {True: 'Dependency Scanning which is required so '
|
|
151
|
+
'packages be automatically scanned is '
|
|
152
|
+
f'enabled via Auto DevOps. {_successAddon}'}
|
|
153
|
+
|
|
154
|
+
_result = ci.searchConfig(
|
|
155
|
+
glEntity, glObject, 'dependency_scanning')
|
|
156
|
+
|
|
157
|
+
result, reason = _result.popitem()
|
|
158
|
+
|
|
159
|
+
if result is True:
|
|
160
|
+
return {True: 'Dependency Scanning which is required for '
|
|
161
|
+
'packages to be automatically scanned is '
|
|
162
|
+
f'configured in .gitlab-ci.yml. {_successAddon}'}
|
|
163
|
+
else:
|
|
164
|
+
return {result: reason}
|
|
165
|
+
|
|
166
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
167
|
+
if e.response_code in [401, 403]:
|
|
168
|
+
return {None: 'Insufficient permissions'}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# -------------------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def package_ownership_change(glEntity, glObject, **kwargs):
|
|
175
|
+
"""
|
|
176
|
+
id: 3.2.4
|
|
177
|
+
title: Ensure packages are automatically scanned for
|
|
178
|
+
ownership change
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
182
|
+
return {None: 'This check requires validation'}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def separate_deployment_config(glEntity, glObject, **kwargs):
|
|
5
|
+
"""
|
|
6
|
+
id: 5.1.1
|
|
7
|
+
title: Ensure deployment configuration files are separated from
|
|
8
|
+
source code
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
12
|
+
GitlabHttpError)
|
|
13
|
+
|
|
14
|
+
from gitlabcis.utils import ci
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
# get the ci config file obj:
|
|
18
|
+
gitlab_ci_yml = ci.getConfig(glEntity, glObject, **kwargs)
|
|
19
|
+
|
|
20
|
+
ciFile, reason = gitlab_ci_yml.popitem()
|
|
21
|
+
|
|
22
|
+
if ciFile in [None, False]:
|
|
23
|
+
return {ciFile: reason}
|
|
24
|
+
|
|
25
|
+
# check its existance:
|
|
26
|
+
if ciFile.file_path is None:
|
|
27
|
+
return {False: 'separate ci config file not set for project'}
|
|
28
|
+
|
|
29
|
+
# check for sub dirs:
|
|
30
|
+
if '/' not in ciFile.file_path:
|
|
31
|
+
return {False: 'ci config file is available but not in '
|
|
32
|
+
'a separated path'}
|
|
33
|
+
|
|
34
|
+
return {True: 'ci config yml file is available, '
|
|
35
|
+
'and stored separately from this project '
|
|
36
|
+
'source code'}
|
|
37
|
+
|
|
38
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
39
|
+
if e.response_code in [401, 403]:
|
|
40
|
+
return {None: 'Insufficient permissions'}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# -------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def audit_deployment_config(glEntity, glObject, **kwargs):
|
|
47
|
+
"""
|
|
48
|
+
id: 5.1.2
|
|
49
|
+
title: Ensure changes in deployment configuration are audited
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
53
|
+
GitlabHttpError, GitlabLicenseError,
|
|
54
|
+
GitlabListError)
|
|
55
|
+
|
|
56
|
+
from gitlabcis.utils import ci
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
|
|
60
|
+
# get the ci config file obj:
|
|
61
|
+
gitlab_ci_yml = ci.getConfig(glEntity, glObject, **kwargs)
|
|
62
|
+
|
|
63
|
+
ciFile, reason = gitlab_ci_yml.popitem()
|
|
64
|
+
|
|
65
|
+
if ciFile in [None, False]:
|
|
66
|
+
return {ciFile: reason}
|
|
67
|
+
|
|
68
|
+
for approval in glEntity.approvalrules.list(get_all=True):
|
|
69
|
+
if approval.approvals_required < 1:
|
|
70
|
+
return {False: 'at least one approval is required '
|
|
71
|
+
'for code changes'}
|
|
72
|
+
|
|
73
|
+
if glObject.get_license().get('plan') not in ['premium', 'ultimate']:
|
|
74
|
+
return {False: 'License does not allow audit'}
|
|
75
|
+
|
|
76
|
+
return {True: 'Changes are audited , reviewed and tracked'}
|
|
77
|
+
|
|
78
|
+
except (GitlabHttpError, GitlabGetError, GitlabLicenseError,
|
|
79
|
+
GitlabAuthenticationError, GitlabListError) as e:
|
|
80
|
+
if e.response_code in [401, 403]:
|
|
81
|
+
return {None: 'Insufficient permissions'}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# -------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def secret_scan_deployment_config(glEntity, glObject, **kwargs):
|
|
88
|
+
"""
|
|
89
|
+
id: 5.1.3
|
|
90
|
+
title: Ensure scanners are in place to identify and prevent
|
|
91
|
+
sensitive data in deployment configuration
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
95
|
+
GitlabHttpError)
|
|
96
|
+
|
|
97
|
+
from gitlabcis.utils import ci
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
return ci.searchConfig(
|
|
101
|
+
glEntity, glObject, 'Secret-Detection')
|
|
102
|
+
|
|
103
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
104
|
+
if e.response_code in [401, 403]:
|
|
105
|
+
return {None: 'Insufficient permissions'}
|
|
106
|
+
|
|
107
|
+
# -------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def limit_deployment_config_access(glEntity, glObject, **kwargs):
|
|
111
|
+
"""
|
|
112
|
+
id: 5.1.4
|
|
113
|
+
title: Limit access to deployment configurations
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
117
|
+
return {None: 'This check requires validation'}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# -------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def scan_iac(glEntity, glObject, **kwargs):
|
|
124
|
+
"""
|
|
125
|
+
id: 5.1.5
|
|
126
|
+
title: Scan Infrastructure as Code (IaC)
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
from gitlab.exceptions import (GitlabAuthenticationError, GitlabGetError,
|
|
130
|
+
GitlabHttpError)
|
|
131
|
+
|
|
132
|
+
from gitlabcis.utils import ci
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
return ci.searchConfig(
|
|
136
|
+
glEntity, glObject, 'SAST-IaC')
|
|
137
|
+
|
|
138
|
+
except (GitlabHttpError, GitlabGetError, GitlabAuthenticationError) as e:
|
|
139
|
+
if e.response_code in [401, 403]:
|
|
140
|
+
return {None: 'Insufficient permissions'}
|
|
141
|
+
|
|
142
|
+
# -------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def verify_deployment_config(glEntity, glObject, **kwargs):
|
|
146
|
+
"""
|
|
147
|
+
id: 5.1.6
|
|
148
|
+
title: Ensure deployment configuration manifests are verified
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
152
|
+
return {None: 'This check requires validation'}
|
|
153
|
+
|
|
154
|
+
# -------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def pin_deployment_config_manifests(glEntity, glObject, **kwargs):
|
|
158
|
+
"""
|
|
159
|
+
id: 5.1.7
|
|
160
|
+
title: Ensure deployment configuration manifests are pinned to a
|
|
161
|
+
specific, verified version
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
# We cannot automatically answer this check, therefore we SKIP:
|
|
165
|
+
return {None: 'This check requires validation'}
|