#!/usr/bin/env bash # Prowler - the handy cloud security tool (copyright 2019) by Toni de la Fuente # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy # of the License at http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. CHECK_ID_extra7174="7.174" CHECK_TITLE_extra7174="[extra7174] CodeBuild Project last invoked greater than 90 days" CHECK_SCORED_extra7174="NOT_SCORED" CHECK_CIS_LEVEL_extra7174="EXTRA" CHECK_SEVERITY_extra7174="High" CHECK_ASFF_TYPE_extra7174="AwsCodebuildProject" CHECK_ALTERNATE_check7174="extra7174" CHECK_SERVICENAME_extra7174="codebuild" CHECK_RISK_extra7174='Older CodeBuild projects can be checked to see if they are currently in use' CHECK_REMEDIATION_extra7174='Check if CodeBuild project are really in use and remove the stale ones' CHECK_DOC_extra7174='https://docs.aws.amazon.com/codebuild/latest/userguide/delete-project.html' CHECK_CAF_EPIC_extra7174='Infrastructure Security' extra7174(){ # "Looking for all build projects with last build invocation greater then 90 days in all regions" for regx in ${REGIONS}; do LIST_OF_PROJECTS=$("${AWSCLI}" codebuild list-projects ${PROFILE_OPT} --region "${regx}" --query 'projects[*]' --output text 2>&1) if grep -q -E 'AccessDenied|UnauthorizedOperation|AuthorizationError' <<< "${LIST_OF_PROJECTS}"; then textInfo "${regx}: Access Denied trying to list Codebuild projects" "${regx}" continue fi if [[ "${LIST_OF_PROJECTS}" ]]; then for project in ${LIST_OF_PROJECTS}; do project_id=$("${AWSCLI}" codebuild list-builds-for-project ${PROFILE_OPT} --project-name "${project}" --query 'ids[0]' --region "${regx}" --output text | head -n 1 2>&1) if grep -q -E 'AccessDenied|UnauthorizedOperation|AuthorizationError' <<< "${project_id}"; then textInfo "${regx}: Access Denied trying to fetch Id for Codebuild project" "${regx}" "${project}" continue elif grep -q -E 'None' <<< "${project_id}"; then textInfo "${regx}: Codebuild project ${project} has been never build" "${regx}" "${project}" continue fi last_invoked_time=$("${AWSCLI}" codebuild batch-get-builds ${PROFILE_OPT} --ids "${project_id}" --region "${regx}" --query 'builds[0].endTime' --output text 2>&1) if grep -q -E 'AccessDenied|UnauthorizedOperation|AuthorizationError' <<< "${last_invoked_time}"; then textInfo "${regx}: Access Denied trying to get build details for Codebuild project ID" "${regx}" "${project}" elif grep -q -E 'None' <<< "${last_invoked_time}"; then textInfo "${regx}: Codebuild project ${project} has been never build" "${regx}" "${project}" else HOWOLDER=$(how_older_from_today "${last_invoked_time}") if [ "${HOWOLDER}" -ge 90 ]; then textFail "${regx}: CodeBuild project ${project} was last invoked greater then 90 days" "${regx}" "${project}" else textPass "${regx}: Codebuild project ${project} was last invoked in the past 90 days" "${regx}" "${project}" fi fi done else textInfo "${regx}: No CodeBuild Projects found" "${regx}" fi done }