This guide walks you through the steps to gather the necessary information and configure your AWS
account for the purpose of creating an integration with Synqly's Network Security connector. AWS
Network Security integrates Amazon VPC Flow Logs and Route 53 Resolver query logs with Synqly.

## Prerequisites

Before you begin, ensure that you have:

- Access to the [AWS Management Console](https://console.aws.amazon.com/)
- VPC Flow Logs publishing to [Amazon CloudWatch
Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-cwl.html) and/or [Amazon
S3](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-s3.html)
- Route 53 Resolver query logs publishing to [Amazon CloudWatch Logs or Amazon
S3](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resolver-query-logs.html)
- Access to an AWS account with permission to create IAM policies, roles, and users


Synqly can discover VPC Flow Log and Route 53 Resolver query log configurations that deliver to
CloudWatch Logs or S3. Event queries are supported for CloudWatch Logs Insights and for S3 objects
in text or gzip format. Kinesis Data Firehose destinations and S3 parquet delivery are not
supported for event queries.

## Required Policy Actions

| Operation | Required Policy Action(s) |
|  --- | --- |
| Query Traffic Log Configurations | `ec2:DescribeFlowLogs` |
| Query DNS Log Configurations | `route53resolver:ListResolverQueryLogConfigs` |
| Resolve account context | `sts:GetCallerIdentity` |
| Query Traffic or DNS Events (CloudWatch Logs destination) | `logs:StartQuery` `logs:GetQueryResults` |
| Query Traffic or DNS Events (S3 destination) | `s3:ListBucket` `s3:GetObject` |


If your logs only publish to CloudWatch Logs, the S3 actions are not required. If your logs only
publish to S3, the CloudWatch Logs actions are not required. `sts:GetCallerIdentity` is required
for all setups — the client uses it at initialization to resolve the account ID (including when
building S3 log prefixes).

## Example IAM Policy

Replace `YOUR_ACCOUNT_ID`, `YOUR_FLOW_LOG_BUCKET`, and any optional custom prefix to match your
environment. Attach this policy (or an equivalent) to the IAM role or user you create in the
credentials section below.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DiscoverVpcFlowLogs",
      "Effect": "Allow",
      "Action": ["ec2:DescribeFlowLogs"],
      "Resource": "*"
    },
    {
      "Sid": "DiscoverResolverQueryLogs",
      "Effect": "Allow",
      "Action": ["route53resolver:ListResolverQueryLogConfigs"],
      "Resource": "*"
    },
    {
      "Sid": "ResolveCallerIdentity",
      "Effect": "Allow",
      "Action": ["sts:GetCallerIdentity"],
      "Resource": "*"
    },
    {
      "Sid": "QueryCloudWatchFlowLogs",
      "Effect": "Allow",
      "Action": [
        "logs:StartQuery",
        "logs:GetQueryResults"
      ],
      "Resource": "*"
    },
    {
      "Sid": "ListS3FlowLogPrefix",
      "Effect": "Allow",
      "Action": ["s3:ListBucket"],
      "Resource": "arn:aws:s3:::YOUR_FLOW_LOG_BUCKET",
      "Condition": {
        "StringLike": {
          "s3:prefix": [
            "AWSLogs/YOUR_ACCOUNT_ID/*",
            "OPTIONAL_CUSTOM_PREFIX/AWSLogs/YOUR_ACCOUNT_ID/*"
          ]
        }
      }
    },
    {
      "Sid": "ReadS3FlowLogObjects",
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": [
        "arn:aws:s3:::YOUR_FLOW_LOG_BUCKET/AWSLogs/YOUR_ACCOUNT_ID/*",
        "arn:aws:s3:::YOUR_FLOW_LOG_BUCKET/OPTIONAL_CUSTOM_PREFIX/AWSLogs/YOUR_ACCOUNT_ID/*"
      ]
    }
  ]
}
```

## Choose which logs to read

Two optional settings decide which logs the integration reads. Most integrations leave both
empty. The integration then reads every flow log and every query logging configuration in
the integration's region.

Flow Log Configuration IDs
This setting is a filter. It does not add logs. It limits the integration to the flow logs
you list. Leave it empty to read every flow log in the integration's region.

Each entry is a VPC Flow Log ID, for example `fl-098a97a109f7d2750`. A flow log can be
created for a VPC, a subnet or a network interface, and its ID is shown on that resource.
The VPC console has no single page that lists every flow log, so to find them you check
each resource, as in the steps below.

#### Find flow log IDs

1. In the AWS console, go to **[VPC](https://console.aws.amazon.com/vpcconsole/home)**.
In the region selector at the top right, choose the region you set in the integration.
2. In the left navigation, choose **Your VPCs**.
3. Choose the **VPC ID** of a VPC to open it, then open its **Flow logs** tab.
4. For each flow log you want, enter its **Flow log ID**.
5. Repeat steps 3 and 4 for each VPC. A VPC whose **Flow logs** tab is empty has no flow
log of its own.


Flow logs can also be created for a single subnet or network interface. If you didn't find
a flow log you expected, check **Subnets** and **Network interfaces** in the left
navigation the same way: open each one and check its **Flow logs** tab.

#### List every flow log at once

To skip checking each resource one-by-one, open **CloudShell** from the console's top bar and run:

aws ec2 describe-flow-logs --region {region} 
--query 'FlowLogs[].[FlowLogId,ResourceId,LogDestinationType,FlowLogStatus]' 
--output table

Each row shows a flow log ID and the VPC, subnet or network interface it belongs to.

#### Check your entries

Enter the flow log ID (`fl-…`), not its ARN. Check each entry: one that is not a valid
flow log ID, or that does not match a flow log in the integration's region and AWS
account, makes flow log queries fail with an error that names it.

Resolver Query Logging Configuration IDs
This setting is a filter. It does not add logs. It limits the integration to the Route 53
query logging configurations you list. Leave it empty to read every query logging
configuration in the integration's region.

Each entry is a query logging configuration ID, for example `rqlc-917320c828f84c70`. A
configuration logs the DNS queries made from the VPCs associated with it.

#### Find query logging configuration IDs

1. In the AWS console, go to **[Route 53](https://console.aws.amazon.com/route53/v2/home)**.
2. In the left navigation, under **VPC Resolver**, choose **Query logging**.
3. In the region selector at the top right, choose the region you set in the integration.
The selector shows **Global** and can't be changed until you open **Query logging**.
This page lists every query logging configuration in the region.
4. Open a configuration by choosing its name.
5. Enter the **ID** shown in the configuration's details.
6. Repeat steps 4 and 5 for each configuration you want.


#### List every configuration at once

To see every ID without opening each configuration, open **CloudShell** from the
console's top bar and run:

aws route53resolver list-resolver-query-log-configs --region {region} 
--query 'ResolverQueryLogConfigs[].[Id,Name,DestinationArn,Status]' 
--output table

Each row shows a configuration's ID, its name and where it sends its logs.

#### Check your entries

Enter the configuration ID (`rqlc-…`), not its ARN. Check each entry: one that does not
match a query logging configuration in the integration's region and AWS account makes DNS
log queries fail with an error that names it.

## AWS Credentials Configuration

Synqly supports two methods for authenticating with AWS: static credentials (IAM user access keys)
and role-based access (IAM role assumption). Role-based access is recommended for production
environments because it uses short-lived credentials and provides better auditability through
CloudTrail.

Role-Based Access
### Role-Based Access

Role-Based access is recommended and is considered an [AWS best
practice](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-workloads-use-roles).

Role-based access uses AWS IAM roles to grant Synqly temporary credentials to access resources in
your AWS account. This eliminates long-lived credentials and provides better security through the
principle of least privilege.

#### 1. Create an IAM Role

Create a role in your AWS account with a name that starts with `SynqlyAccess` (for example,
`SynqlyAccessS3Reader`). This naming convention is required.

1. In the AWS IAM console, go to **Roles** and choose **Create role**.
2. For trusted entity type, choose **Custom trust policy**.
3. Enter the following trust policy:


```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::733459310821:role/SynqlyIntegrationAccess"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "sts:ExternalId": "YOUR_EXTERNAL_ID"
        }
      }
    }
  ]
}
```

Replace `YOUR_EXTERNAL_ID` with a unique identifier you generate (for example, a UUID). You will
provide this External ID when configuring the integration.

1. Name the role with a `SynqlyAccess` prefix (for example, `SynqlyAccessMyIntegration`).
2. Attach the appropriate permissions policy for your use case.
3. Create the role and note its ARN.


For more details, see:

- [Access to AWS accounts owned by third
parties](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_third-party.html)
- [Create a role using custom trust
policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-custom.html)


### External ID Requirements

The External ID is a security mechanism that prevents the [confused deputy
problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html). It ensures that
only authorized requests from Synqly can assume your role.

The External ID must contain only the following characters:

- Alphanumeric characters (a-z, A-Z, 0-9)
- Special characters: `+ = , . @ : / -`
- Must be between 2 and 1224 characters in length


### Configuring the Integration Credentials

When creating an AWS integration in Synqly, provide the following configuration values based on your
chosen authentication method.

| Credential Parameter | Description |
|  --- | --- |
| Role ARN | The ARN of the IAM role you created, for example `arn:aws:iam::123456789012:role/SynqlyAccessMyIntegration`. The role name must start with `SynqlyAccess` |
| External ID | The External ID you specified in the role's trust policy. This value must match exactly |
| Role Session Name | **OPTIONAL:** A name for the role session. If not specified, Synqly generates a default session name |
| Duration | **OPTIONAL:** The duration of the role session in seconds. The value can range from 900 seconds (15 minutes) up to the maximum session duration configured on your role (default is 1 hour) |


Static Credentials (IAM User)
### Static Credentials (IAM User)

AWS static credentials are **NOT RECOMMENDED** for production systems. See the [AWS best
practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-workloads-use-roles)
for more details.

Static credentials consist of an Access Key ID and Secret Access Key associated with an IAM user.
Use this method for simpler setups.

#### 1. Create an IAM User

1. In the AWS IAM console, go to **Users** and choose **Create user**.
2. Enter a user name (for example, `SynqlyIntegration`).
3. Do not enable console access; this user only needs programmatic access.
4. Under permissions, choose **Attach policies directly** and attach the appropriate policy for your
use case.
5. Create the user.


#### 2. Create an Access Key

1. Open the newly created user and choose **Create access key**.
2. For the use case, choose **Third-party service**.
3. Create the key and securely copy the **Access Key ID** and **Secret Access Key**.


For more details, see:

- [Managing access keys for IAM
users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)
- [How an IAM administrator can manage IAM user access
keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-keys-admin-managed.html).


### Configuring the Integration Credentials

When creating an AWS integration in Synqly, provide the following configuration values based on your
chosen authentication method.

| Credential Parameter | Description |
|  --- | --- |
| Access Key ID | The Access Key ID from your IAM user's access key pair |
| Secret Access Key | The Secret Access Key from your IAM user's access key pair |
| Session Token | **OPTIONAL:** A temporary session token. Only required if you are using temporary credentials from AWS STS. |


## Configure the Integration

Create your integration by supplying the following configuration values, in addition to the AWS
credentials from the section above.

| Integration Parameter | Description |
|  --- | --- |
| Region | The [AWS region](https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html) containing the logs to query. Example: `us-east-1` |
| Flow Log Configuration IDs *(optional)* | VPC Flow Log IDs (`fl-...`). Leave empty to read every flow log in the region. See [Choose which logs to read](#choose-which-logs-to-read). |
| Resolver Query Logging Configuration IDs *(optional)* | Route 53 query logging configuration IDs (`rqlc-...`). Leave empty to read every query logging configuration in the region. See [Choose which logs to read](#choose-which-logs-to-read). |