Skip to content

Commit

Permalink
chore(gcp): add script to enable APIs in GCP projects (#4117)
Browse files Browse the repository at this point in the history
Co-authored-by: Pepe Fagoaga <[email protected]>
  • Loading branch information
MrCloudSec and jfagoagas authored May 28, 2024
1 parent 98b7df6 commit a5378b5
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ cd ~ || exit
python3.9 -m pip install prowler-cloud
prowler -v
# Run Prowler
prowler
prowler aws
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions contrib/gcp/enable_apis_in_projects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# List of project IDs
PROJECT_IDS=(
"project-id-1"
"project-id-2"
"project-id-3"
# Add more project IDs as needed
)

# List of Prowler APIs to enable
APIS=(
"apikeys.googleapis.com"
"artifactregistry.googleapis.com"
"bigquery.googleapis.com"
"sqladmin.googleapis.com" # Cloud SQL
"storage.googleapis.com" # Cloud Storage
"compute.googleapis.com"
"dataproc.googleapis.com"
"dns.googleapis.com"
"containerregistry.googleapis.com" # GCR (Google Container Registry)
"container.googleapis.com" # GKE (Google Kubernetes Engine)
"iam.googleapis.com"
"cloudkms.googleapis.com" # KMS (Key Management Service)
"logging.googleapis.com"
)

# Function to enable APIs for a given project
enable_apis_for_project() {
local PROJECT_ID=$1

echo "Enabling APIs for project: ${PROJECT_ID}"

for API in "${APIS[@]}"; do
echo "Enabling API: $API for project: ${PROJECT_ID}"
if gcloud services enable "${API}" --project="${PROJECT_ID}"; then
echo "Successfully enabled API $API for project ${PROJECT_ID}."
else
echo "Failed to enable API $API for project ${PROJECT_ID}."
fi
done
}

# Loop over each project and enable the APIs
for PROJECT_ID in "${PROJECT_IDS[@]}"; do
enable_apis_for_project "${PROJECT_ID}"
done
20 changes: 20 additions & 0 deletions docs/tutorials/gcp/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ Prowler will follow the same credentials search as [Google authentication librar
3. [The attached service account, returned by the metadata server](https://cloud.google.com/docs/authentication/application-default-credentials#attached-sa)

Those credentials must be associated to a user or service account with proper permissions to do all checks. To make sure, add the `Viewer` role to the member associated with the credentials.

# GCP Service APIs

Prowler will use the Google Cloud APIs to get the information needed to perform the checks. Make sure that the following APIs are enabled in the project:

- apikeys.googleapis.com
- artifactregistry.googleapis.com
- bigquery.googleapis.com
- sqladmin.googleapis.com
- storage.googleapis.com
- compute.googleapis.com
- dataproc.googleapis.com
- dns.googleapis.com
- containerregistry.googleapis.com
- container.googleapis.com
- iam.googleapis.com
- cloudkms.googleapis.com
- logging.googleapis.com

You can enable them automatically using our script [enable_apis_in_projects.sh](https://github.com/prowler-cloud/prowler/blob/master/contrib/gcp/enable_apis_in_projects.sh)

0 comments on commit a5378b5

Please sign in to comment.