Cloud Functions Should Have Default Timeout Configured
More Info:
The default timeout for Cloud Functions should be configured
Risk Level
Low
Address
Operational Maturity, Reliability, Security
Compliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- Cloudanix Best Practice
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Sure, I can help you with that. Here are the step-by-step instructions to remediate the misconfiguration "Cloud Functions Should Have Default Timeout Configured" for GCP using GCP console:
- Open the GCP Console and navigate to the Cloud Functions page.
- Find the function that you want to remediate and click on its name.
- In the left-hand menu, click on the "Edit" button.
- Scroll down to the "Runtime, build, and connections settings" section.
- Under the "General" tab, locate the "Timeout" field.
- Set a default timeout value for your function. The recommended timeout value is 60 seconds.
- Click on the "Save" button to save your changes.
That's it! You have now successfully remediated the misconfiguration "Cloud Functions Should Have Default Timeout Configured" for GCP using GCP console.
Using CLI
To remediate the misconfiguration "Cloud Functions Should Have Default Timeout Configured" for GCP using GCP CLI, follow these steps:
-
Open the GCP Cloud Shell or any terminal with GCP CLI installed.
-
Run the following command to set the default timeout for Cloud Functions:
gcloud functions deploy FUNCTION_NAME --timeout TIMEOUTReplace
FUNCTION_NAMEwith the name of the Cloud Function that you want to remediate andTIMEOUTwith the desired timeout value in seconds. For example, to set the default timeout to 60 seconds for a Cloud Function namedmy-function, run the following command:gcloud functions deploy my-function --timeout 60s -
After running the command, the Cloud Function will be redeployed with the default timeout set to the specified value.
-
Verify that the default timeout has been set by checking the Cloud Function's configuration using the following command:
gcloud functions describe FUNCTION_NAMEReplace
FUNCTION_NAMEwith the name of the Cloud Function that you remediated. The output of the command will include thetimeoutfield, which should match the value that you set in step 2.
By following these steps, you have successfully remediated the misconfiguration "Cloud Functions Should Have Default Timeout Configured" for GCP using GCP CLI.
Using Python
To remediate the misconfiguration "Cloud Functions Should Have Default Timeout Configured" for GCP using Python, you can follow these steps:
-
Open the Cloud Functions page in the GCP console.
-
Select the function that you want to configure.
-
In the function details page, click on the "Edit" button.
-
Scroll down to the "Advanced Options" section.
-
In the "Timeout" field, set the default timeout for your function. You can set the timeout value in seconds, up to a maximum of 540 seconds (9 minutes).
-
Click on the "Save" button to save your changes.
-
To automate this process for multiple functions, you can use the GCP Python SDK. Here's an example code snippet to set the default timeout for a Cloud Function using the Python SDK:
from google.cloud import functions_v1
# Replace <function_name> with the name of your Cloud Function
function_name = "<function_name>"
# Replace <timeout_seconds> with the desired timeout value in seconds
timeout_seconds = 60
# Create a Cloud Functions client
client = functions_v1.CloudFunctionsServiceClient()
# Get the current function configuration
function = client.get_function(name=function_name)
# Update the function configuration with the new timeout value
function.timeout_seconds = timeout_seconds
# Update the function with the new configuration
update_mask = {"paths": ["timeout_seconds"]}
response = client.update_function(function=function, update_mask=update_mask)
print("Function timeout updated successfully.")
Note: Before running the above code, make sure that you have installed the google-cloud-functions Python package and authenticated with your GCP account using the gcloud CLI or a service account key file.
Using Terraform
resource "google_cloudfunctions_function" "FUNCTION_NAME" {
name = "FUNCTION_NAME" # replace with your function name
project = "PROJECT_ID" # replace with your project ID
region = "FUNCTION_REGION" # replace with your region
runtime = "RUNTIME_NAME" # e.g. "python311"
entry_point = "ENTRY_POINT" # replace with your function entry point
source_archive_bucket = google_storage_bucket.function_source.name
source_archive_object = google_storage_bucket_object.function_source.name
trigger_http = true
# Configure an explicit timeout instead of relying on the platform default.
# Set this to the desired maximum execution time, up to the product limit.
timeout = "60s" # replace "60s" with your required timeout (e.g. "120s", "540s")
}
Changing timeout on google_cloudfunctions_function is an in-place update and does not force resource replacement.
For verification, terraform plan should show an update to the existing google_cloudfunctions_function with timeout changing from null (or the old value) to your specified value (e.g. "60s").