AWS

Tutorials

Limiting CloudQuery access to AWS accounts

When using CloudQuery to sync data from AWS, a common practice is to use a read-only IAM role. This approach gives CloudQuery access to your resources without posing a security risk of unwanted writes. However, sometimes, you will want more granular control, limiting CloudQuery's access to only the specific resources defined in their sync configurations. Previously, obtaining the necessary permissions for this level of control was a manual, cumbersome process. That’s why we now provide an API endpoint that simplifies this process, allowing you to automate the collection of required permissions based on your chosen tables.

How to limit access to selected tables only

When the only tables you want to sync are from the EC2 and EKS services, you could use a role with permissions limited to those services, not broad read access across the entire AWS account. You can go through the integration documentation and see the permissions for each table, or you could use CloudQuery API to do that automatically.

The API endpoint that provides the required information is the GetPluginVersionTable. All you need to know is the plugin name, plugin version, and the table name. Here’s an example request to get permissions for the aws_ec2_instances table and extract the permissions using jq:

curl -s https://api.cloudquery.io/plugins/cloudquery/source/aws/versions/v34.9.0/tables/aws_ec2_instances | jq -r '.permissions_needed.[]'

Output:

ec2:DescribeInstances

The only thing remaining is to list the tables from your AWS sync config,call the API endpoint for each table, and then extract the permissions_needed field from the JSON response.

Suppose you want to sync the following AWS tables using the CloudQuery AWS integration version v34.9.0:

  • aws_ec2_instances
  • aws_eks_clusters
  • aws_ec2_hosts

Using the API endpoint mentioned above, you can retrieve the permissions for each table with an API call similar to the following (replace TABLE_NAME_GOES_HERE with the actual table name):

curl  -s https://api.cloudquery.io/plugins/cloudquery/source/aws/versions/v34.9.0/tables/TABLE_NAME_GOES_HERE | jq -r '.permissions_needed.[]'

Calling the above API calls will return the following permissions needed for each table:

  • ec2:DescribeInstances
  • eks:DescribeCluster
  • eks:ListClusters
  • ec2:DescribeHosts

Based on the results, a minimal IAM policy can be created to grant access to the tables from the example above only with the following permissions:

{
"Version": "2012-10-17",
"Statement": [
{
"Action": ["ec2:DescribeInstances", "ec2:DescribeHosts"],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": ["eks:DescribeCluster", "eks:ListClusters"],
"Effect": "Allow",
"Resource": "*"
}
]
}

Putting it all together

Here's a full shell script that generates a JSON IAM policy based on the defined tables:


# Define the tables to check
tables="aws_ec2_instances aws_eks_clusters aws_ec2_hosts"

# Get the latest version of the aws plugin
latest_version=$(curl -s https://api.cloudquery.io/plugins/cloudquery/source/aws | jq -r ".latest_version")


# Get the permissions needed for each table
permissions=$(echo $tables | xargs -n 1 -I {} curl -s https://api.cloudquery.io/plugins/cloudquery/source/aws/versions/$latest_version/tables/{} | jq '.permissions_needed.[]' | sort -u)

# Print the sorted permissions as JSON IAM policy
echo "{
\"Version\": \"2012-10-17\",
\"Statement\": [
{
\"Action\": [$(echo $permissions | tr ' ' ',')],
\"Effect\": \"Allow\",
\"Resource\": \"*\"
}
]
}"

The output of the above:

{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:DescribeHosts",
"ec2:DescribeInstances",
"eks:DescribeCluster",
"eks:ListClusters"
],
"Effect": "Allow",
"Resource": "*"
}
]
}

Wrap Up

By using CloudQuery’s new API endpoint, you can easily automate the creation of the least privileged IAM roles, eliminate manual errors in mapping tables to their required permissions, and streamline the setup of secure and granular CloudQuery syncs.

CloudQuery simplifies cloud asset discovery and governance, making it easy to audit, monitor, and manage cloud environments at scale. If you haven’t already, get started with CloudQuery today to enhance your cloud visibility.

Have questions or need help? Join the CloudQuery Developer Community to connect with other users, share insights, and get support. Let us know how your team is tackling cloud security by engaging with us on LinkedIn or X.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

AWS

Security

Tutorials

Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond

Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Security

Tutorials

AWS IAM Identity Center with Google Workspace as an IdP: 2026 Step-by-Step Guide

Set up AWS IAM Identity Center with Google Workspace: SAML authentication, SCIM user provisioning, and group sync with CLI or ssosync. Updated for 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Cloud Infrastructure

Security

Tutorials

Integrate AbuseIPDB Threat Intelligence with CloudQuery

Enrich your cloud asset inventory with AbuseIPDB threat intelligence to identify public cloud IPs with known abuse reports.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Cloud Infrastructure

Tutorials

How to Query ipinfo.io Data with CloudQuery

Learn how to enrich your cloud asset inventory with ipinfo.io IP geolocation and threat intelligence data using CloudQuery.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Security

Tutorials

AWS IAM Identity Center (Formerly AWS SSO): The Complete 2026 Guide

AWS IAM Identity Center replaced AWS SSO in 2022. Learn how to set it up, configure permission sets, use the AWS CLI, and audit access with CloudQuery.

Joe Karlsson

Joe Karlsson

April 6, 2026

AWS

Tutorials

AWS Pinpoint Is Being Deprecated: How to Assess Your Migration Scope

AWS Pinpoint reaches end of support October 2026. Query your Pinpoint usage across all accounts to find what needs migrating before the deadline.

Joe Karlsson

Joe Karlsson

March 24, 2026

AWS

Best Practices

Tutorials

CloudQuery Sync Performance: A Practical Troubleshooting Guide

Diagnose why CloudQuery syncs slow down after plugin upgrades, identify expensive tables, and use the CLI command that replaces the tables wildcard.

Joe Karlsson

Joe Karlsson

March 6, 2026

AWS

Security

Tutorials

Set Up AWS CLI with SSO (IAM Identity Center) — Step by Step

Set up AWS CLI v2 with IAM Identity Center in 5 minutes. Covers SSO registration scopes, sso-session config, token refresh, and multi-account profiles.

Yevgeny Pats

Yevgeny Pats

February 25, 2026

AWS

Cloud Infrastructure

Tutorials

AWS Lambda Python 3.9 End-of-Support: Find and Upgrade Every Affected Function

AWS Lambda Python 3.9 security patches stopped Dec 15, 2025. Find every affected function across all accounts with SQL queries and upgrade to 3.12 or 3.13.

Joe Karlsson

Joe Karlsson

February 10, 2026

Own your pipeline.
Own your data.