AppSync APIs Should Have Authorization Configuration
More Info:
This rule evaluates the authorization configuration of AWS AppSync APIs to ensure that appropriate access controls are in place. It verifies whether authentication modes such as API key, IAM, or Cognito user pools are properly configured and whether authorization mechanisms such as fine-grained resolver permissions or GraphQL field-level security are implemented to restrict access to sensitive data.
Risk Level
Medium
Address
Security
Compliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- 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
- StateRAMP
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Cause
- Remediation
Check Cause
Using Console
- Sign in to the AWS Management Console.
- Navigate to the AWS AppSync service by typing 'AppSync' into the search bar and selecting it from the dropdown menu.
- Once in the AppSync dashboard, you will see a list of your APIs. Click on the name of the API you want to check.
- In the settings of the selected API, look for the 'Authorization' section. Here, you should see the authorization type and additional authorization providers if any have been configured. If there is no authorization configuration, it indicates a misconfiguration.
Using CLI
- First, you need to list all the available AppSync APIs. You can do this by using the AWS CLI command
list-graphql-apis. The command is as follows:
aws appsync list-graphql-apis --region <region-name>
Replace <region-name> with the name of the AWS region where the APIs are hosted.
-
The output of the above command will give you a list of all the AppSync APIs in the specified region. Each API will have an 'arn' and 'name'. You can use the 'arn' to get more details about each API.
-
Now, for each API, you need to check the authorization configuration. You can do this by using the AWS CLI command
get-graphql-api. The command is as follows:
aws appsync get-graphql-api --api-id <api-id> --region <region-name>
Replace <api-id> with the 'arn' of the API you want to check and <region-name> with the name of the AWS region where the API is hosted.
- The output of the above command will give you details about the specified API. Look for the 'authorizationConfig' field in the output. If this field is missing or not properly configured, then the API does not have proper authorization configuration.
Using Python
-
Install and configure AWS SDK for Python (Boto3): Before you can start writing Python scripts to check AppSync APIs, you need to install and configure Boto3. You can install it using pip:
pip install boto3Then, configure your AWS credentials either by setting the following environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN (optional), or by using the AWS CLI command
aws configure. -
Import the necessary modules and create an AppSync client: In your Python script, you need to import Boto3 and create an AppSync client. Here's how you can do it:
import boto3client = boto3.client('appsync') -
List all AppSync APIs and check their authorization configuration: You can use the
list_graphql_apismethod to get a list of all AppSync APIs. Then, for each API, you can use theget_graphql_apimethod to get its details and check its authorization configuration. Here's a sample script:import boto3client = boto3.client('appsync')# List all AppSync APIsresponse = client.list_graphql_apis()for api in response['graphqlApis']:# Get the details of each APIapi_response = client.get_graphql_api(apiId=api['apiId'])# Check the authorization configurationif 'authorizationConfig' not in api_response['graphqlApi']:print(f"AppSync API {api['name']} does not have an authorization configuration.") -
Handle pagination: The
list_graphql_apismethod returns a maximum of 25 APIs at a time. If you have more APIs, you need to handle pagination by using thenextTokenparameter. Here's how you can modify the above script to handle pagination:import boto3client = boto3.client('appsync')# Initialize the next tokennext_token = Nonewhile True:# List all AppSync APIsif next_token:response = client.list_graphql_apis(nextToken=next_token)else:response = client.list_graphql_apis()for api in response['graphqlApis']:# Get the details of each APIapi_response = client.get_graphql_api(apiId=api['apiId'])# Check the authorization configurationif 'authorizationConfig' not in api_response['graphqlApi']:print(f"AppSync API {api['name']} does not have an authorization configuration.")# If there are more APIs, get the next token, otherwise break the loopif 'nextToken' in response:next_token = response['nextToken']else:break
This script will print the names of all AppSync APIs that do not have an authorization configuration.
Remediation
Using Console
To remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS, you can follow these steps using the AWS Management Console:
-
Login to AWS Console: Go to the AWS Management Console (https://aws.amazon.com/console/) and log in to your AWS account.
-
Navigate to AWS AppSync: Go to the AWS AppSync service by typing "AppSync" in the search bar and selecting it from the options that appear.
-
Select your API: In the AWS AppSync console, select the API that you want to configure authorization for from the list of APIs.
-
Configure Authorization: In the API details page, click on the "Settings" tab to configure the authorization settings for your API.
-
Edit Authorization Settings: Under the "Authorization mode" section, click on the "Edit" button to modify the authorization settings.
-
Choose Authorization Type: In the Edit Authorization dialog box, select the appropriate authorization type based on your requirements. You can choose from API Key, IAM, Cognito User Pool, or OpenID Connect.
-
Configure Authorization: Depending on the authorization type you selected, configure the settings accordingly. For example, if you choose Cognito User Pool, you will need to select the User Pool ID and App Client ID.
-
Save Changes: After configuring the authorization settings, click on the "Save" button to apply the changes.
-
Test Authorization: It is recommended to test the authorization settings to ensure that they are working as expected. You can do this by making a test request to your API using the configured authorization method.
By following these steps, you can remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS AppSync using the AWS Management Console.
Using CLI
To remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS using AWS CLI, follow these steps:
-
List all the APIs in AppSync: Run the following AWS CLI command to list all the APIs in AppSync:
aws appsync list-graphql-apis -
Identify the API without authorization configuration: Check the output of the above command and identify the API that does not have authorization configuration set up.
-
Update the API with authorization configuration: Run the following AWS CLI command to update the API with the required authorization configuration. Replace
<api-id>with the actual API ID and<authorization-type>with the desired authorization type (e.g., API_KEY, AWS_IAM, AMAZON_COGNITO_USER_POOLS, OPENID_CONNECT).aws appsync update-graphql-api --api-id <api-id> --authenticationType <authorization-type> -
Verify the authorization configuration: Run the following AWS CLI command to verify that the authorization configuration has been successfully updated for the API:
aws appsync get-graphql-api --api-id <api-id> --query "graphqlApi.authenticationType" -
Test the API with the new authorization configuration: Test the API to ensure that the authorization configuration is working as expected. You may need to update your client applications to provide the required authorization credentials based on the chosen authentication type.
By following these steps, you can successfully remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS using AWS CLI.
Using Python
To remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS, you can follow these steps using Python:
- Import the necessary libraries:
import boto3
- Initialize the AppSync client:
client = boto3.client('appsync')
- List all the existing APIs in your AppSync service:
response = client.list_graph_ql_apis()
- Iterate through the list of APIs and update the authorization configuration for each one:
for api in response['graphQlApis']:
api_id = api['apiId']
# Update the authorization configuration for the API
client.update_graph_ql_api(
apiId=api_id,
authenticationType='API_KEY', # You can choose the appropriate authentication type here
userPoolConfig={
'userPoolId': 'YOUR_USER_POOL_ID',
'awsRegion': 'YOUR_AWS_REGION'
}
)
-
Replace
'YOUR_USER_POOL_ID'and'YOUR_AWS_REGION'with the appropriate values for your setup. You can also choose the appropriateauthenticationTypebased on your requirements. -
Run the Python script to update the authorization configuration for all the APIs in your AppSync service.
By following these steps, you can remediate the misconfiguration of AppSync APIs not having authorization configuration in AWS using Python.
Using Terraform
# Primary AppSync API with AWS_IAM authorization (recommended for strong auth)
resource "aws_appsync_graphql_api" "THIS_API" {
name = "APPsync API Name" # replace with your API name
authentication_type = "AWS_IAM"
schema = file("PATH_TO_SCHEMA.graphql") # replace with your schema path
# add any existing settings you already manage (log_config, xray_enabled, tags, etc.)
}
# Alternative: AppSync API using API_KEY authorization
resource "aws_appsync_graphql_api" "THIS_API" {
name = "APPsync API Name" # replace with your API name
authentication_type = "API_KEY"
schema = file("PATH_TO_SCHEMA.graphql") # replace with your schema path
}
# Creates an API key for the AppSync API, matching `aws appsync create-api-key`
resource "aws_appsync_api_key" "PRIMARY_KEY" {
api_id = aws_appsync_graphql_api.THIS_API.id
description = "Primary API Key"
# Optionally control expiration:
# expires = TIMESTAMP_EPOCH_SECONDS
}
# Alternative: AppSync API using Cognito User Pool authorization
resource "aws_cognito_user_pool" "USER_POOL" {
name = "USER_POOL_NAME" # replace with your existing or desired pool name
# … configure pool as needed …
}
resource "aws_appsync_graphql_api" "THIS_API" {
name = "APPsync API Name" # replace with your API name
authentication_type = "AMAZON_COGNITO_USER_POOLS"
schema = file("PATH_TO_SCHEMA.graphql") # replace with your schema path
user_pool_config {
aws_region = "COGNITO_POOL_REGION" # e.g., "us-east-1" (must match the pool’s region)
default_action = "ALLOW"
user_pool_id = aws_cognito_user_pool.USER_POOL.id
}
}
Replace:
THIS_APIwith the Terraform name you already use for the GraphQL API (if it exists).APPsync API Namewith your actual API name.PATH_TO_SCHEMA.graphqlwith the path to your GraphQL schema file.USER_POOL_NAMEandCOGNITO_POOL_REGIONwith your actual Cognito details, or wire to existing resources/data sources instead of creating a new pool if one already exists.
Changing authentication_type on an existing aws_appsync_graphql_api typically forces resource replacement (ForceNew behavior), which means the GraphQL API will be recreated; plan for potential downtime and re-association of data sources/resolvers.
To verify, terraform plan should show:
- For the IAM option: a change on
aws_appsync_graphql_api.THIS_API.authentication_typeto"AWS_IAM"(with a replacement of the API). - For the API key option: the same change to
"API_KEY"plus+ createforaws_appsync_api_key.PRIMARY_KEY. - For the Cognito option: the change to
"AMAZON_COGNITO_USER_POOLS"and a populateduser_pool_config(and user pool creation if you included that resource).