Brian Luger
10/23/2023, 9:15 PMgetInstanceIDAndRegion function (here) is called by this table (here) when it's generated but there are no checks to determine if it's running on an ec2 instance. As a result, it fails and logs a warning related to being unable to find the imds service on non-ec2 systems. The docs for getInstanceIDAndRegion mention this:
> One has to ensure that the instance is an EC2 one before calling this method, using isEc2Instance.
But I can't seem to find a isEc2Instance function, and the ec2_instance_metadata table doesn't appear to have any similar checking.
My question: Is there, or should there be, logic already in osquery for checking whether it's running on an ec2 instance?Brian Luger
10/23/2023, 9:24 PMaws_imdsv2_request_attempts to 0.
will try thatBrian Luger
10/23/2023, 9:26 PMseph
John Speno
10/24/2023, 2:00 PMsharvil
10/24/2023, 2:09 PMsharvil
10/24/2023, 2:10 PMsharvil
10/24/2023, 2:12 PMfile and curl tables â read /sys/hypervisor/uuid and make sure that starts with ec2 and then curl to 169.254.169.254 .Stefano Bonicatti
10/24/2023, 2:26 PMStefano Bonicatti
10/24/2023, 2:34 PMFLAGS_aws_imdsv2_request_interval flag to 0, but obviously that is then problematic for the case where you do want for the retry to wait.Brian Luger
10/24/2023, 4:27 PMpack_refresh_interval . This can't be applied on a per-pack basis, which results in further attempts at the metadata service, and more logged warnings/errors.
The original check that was removed would cache the result, preventing continued attempts.
I agree that this is a difficult issue to solve. I think something that checks the metadata service and caches the result would work well. But I also recognize that it may not always be that simple, and even if it was added back, accounting for everything in the identifying ec2 docs for linux / windows, it may not work for all use cases / deployments.
That being said, it's completely reasonable to say that this isn't a problem that OSQuery needs to be solving. Instead, system owners should make that determination through other means, as you mention.
This is what we're doing now, we just happen to be exploring solutions because we recently upgraded from 5.4.0, which had the checks, to 5.9.1, and have had system owners begin to ask about the logs.seph
Brian Luger
10/24/2023, 4:33 PMsharvil
10/24/2023, 4:35 PMLOG(WARNING) or LOG(ERROR) ; not unreasonable to move those to a verbose log I think to quiet it down a bitBrian Luger
10/24/2023, 4:35 PMseph
Brian Luger
10/24/2023, 4:36 PMsharvil
10/24/2023, 4:37 PMBrian Luger
10/24/2023, 4:37 PMBrian Luger
10/24/2023, 4:38 PMseph
Brian Luger
10/24/2023, 4:39 PMStefano Bonicatti
10/24/2023, 4:43 PMseph
Stefano Bonicatti
10/24/2023, 4:45 PMStefano Bonicatti
10/24/2023, 4:48 PMseph
seph
Brian Luger
10/24/2023, 4:49 PMBrian Luger
10/24/2023, 4:50 PMBrian Luger
10/24/2023, 4:55 PMsharvil
10/24/2023, 4:56 PMseph
Brian Luger
10/24/2023, 4:58 PMseph
John Speno
11/21/2023, 1:59 PMec2_instance_metadata table on non-EC2 nodes. This query works, but am I missing a more obvious way to do something like this?
WITH checks AS (
SELECT 1 ec2 FROM platform_info WHERE vendor = 'Amazon EC2' or (vendor = 'Xen' and version like '%.amazon')
)
SELECT osquery_info.version,
osquery_info.uuid,
osquery_info.build_distro,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT instance_id FROM ec2_instance_metadata) ELSE NULL END instance_id,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT local_hostname FROM ec2_instance_metadata) ELSE NULL END local_hostname,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT local_ipv4 FROM ec2_instance_metadata) ELSE NULL END local_ipv4,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT account_id FROM ec2_instance_metadata) ELSE NULL END account_id,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT instance_type FROM ec2_instance_metadata) ELSE NULL END instance_type,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT architecture FROM ec2_instance_metadata) ELSE NULL END architecture,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT region FROM ec2_instance_metadata) ELSE NULL END region,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT mac FROM ec2_instance_metadata) ELSE NULL END mac,
CASE when (
SELECT ec2 FROM checks
) THEN (SELECT ami_id FROM ec2_instance_metadata) ELSE NULL END ami_id
FROM osquery_info;
This query runs very fast, e.g. Run Time: real 0.003 user 0.000878 sys 0.002050 compared to the naive query that doesn't check if it is running on an EC2 node, which takes much longer, e.g. Run Time: real 273.072 user 0.024563 sys 0.041598