Skip to content

Commit

Permalink
Add curl timeout for cloud metadata lookup at unix systems on Azure (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tomtrix authored Nov 20, 2024
1 parent c10e069 commit 1a92413
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions providers/os/id/azcompute/azcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1a92413

Please sign in to comment.