From 1a92413648fb733162be25e306ea53430c8277dc Mon Sep 17 00:00:00 2001 From: Tom Kretschmann Date: Wed, 20 Nov 2024 21:10:16 +0100 Subject: [PATCH] Add curl timeout for cloud metadata lookup at unix systems on Azure (#4895) * add curl timeout for cloud metadata lookup on unix systems * add retries and retry-delay to curl command of metadata lookup * increase timeout of metadata lookup at windows systems * add and increase --max-time to 30 * increase timeout of metadata lookup at windows systems from 5 to 15 seconds * ajust metadata lookup timeouts to 5 seconds * ensure curl connection timeout of 5 seconds --- providers/os/id/azcompute/azcompute.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/os/id/azcompute/azcompute.go b/providers/os/id/azcompute/azcompute.go index d283731a4e..c7fff619ae 100644 --- a/providers/os/id/azcompute/azcompute.go +++ b/providers/os/id/azcompute/azcompute.go @@ -17,7 +17,7 @@ import ( const ( identityUrl = "http://169.254.169.254/metadata/instance?api-version=2021-02-01" - metadataIdentityScriptWindows = `Invoke-RestMethod -TimeoutSec 1 -Headers @{"Metadata"="true"} -Method GET -URI http://169.254.169.254/metadata/instance?api-version=2021-02-01 -UseBasicParsing | ConvertTo-Json` + metadataIdentityScriptWindows = `Invoke-RestMethod -TimeoutSec 5 -Headers @{"Metadata"="true"} -Method GET -URI http://169.254.169.254/metadata/instance?api-version=2021-02-01 -UseBasicParsing | ConvertTo-Json` ) func MondooAzureInstanceID(instanceID string) string { @@ -57,7 +57,7 @@ func (m *commandInstanceMetadata) Identify() (Identity, error) { var instanceDocument string switch { case m.platform.IsFamily(inventory.FAMILY_UNIX): - cmd, err := m.conn.RunCommand("curl --noproxy '*' -H Metadata:true " + identityUrl) + cmd, err := m.conn.RunCommand("curl --retry 5 --retry-delay 1 --connect-timeout 1 --retry-max-time 5 --max-time 10 --noproxy '*' -H Metadata:true " + identityUrl) if err != nil { return Identity{}, err }