Skip to content
VPNDetection

AWS S3

Have each new build of VPNDetection's databases written to your Amazon S3 bucket through an IAM role you create, or to any S3-compatible storage.

View as Markdown

VPNDetection writes each new build of the databases you choose to a bucket of yours: to Amazon S3 as an IAM role you let it take on, or to any S3-compatible storage with an access key. What lands in the bucket, and when, is on Database Delivery.

For a bucket in your own AWS account, use a role. VPNDetection takes on a role that can write only where you say, so there's no key to create or hand over. Use an access key for any other S3-compatible storage, such as Cloudflare R2, Backblaze B2 or Wasabi, or for Amazon S3 if you'd rather not create a role.

Before you begin

  • The Manage database delivery permission in your organization, which owners and admins have.
  • A license for at least one database. Every organization holds the Open databases from the start.
  • For Amazon S3, the AWS account that owns the bucket, with the AWS CLI and the right to create an IAM role there.
  • For other S3-compatible storage, an access key that can write, list and delete in the bucket, and the storage's https:// endpoint.

Set up Amazon S3 with a role

The steps below use the bucket acme-data and the folder databases. The console fills in your own bucket, folder and External ID in each policy it shows.

1. Add the destination

In the console, under Database > Delivery, click Add destination and pick Amazon S3.

2. Enter the bucket

Under Connection, enter the Bucket, its Region and a Folder, then click Save. The destination then shows both policies below with your bucket, folder and its External ID filled in.

3. Create the role

Create a role with this trust policy. It lets VPNDetection's AWS account take the role on, and only with this destination's External ID, so nobody else's destination can use it:

trust-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::079769603397:user/vpndetection-delivery" },
      "Action": "sts:AssumeRole",
      "Condition": { "StringEquals": { "sts:ExternalId": "vpndetection-1a2b3c4d5e6f7a8b9c0d1e2f" } }
    }
  ]
}

Give it this permissions policy:

policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload"],
      "Resource": "arn:aws:s3:::acme-data/databases/*"
    },
    {
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::acme-data"
    }
  ]
}

With the AWS CLI, creating the role and attaching the policy take two commands:

bash
aws iam create-role --role-name vpndetection-delivery --assume-role-policy-document file://trust-policy.json
aws iam put-role-policy --role-name vpndetection-delivery --policy-name database-delivery \
  --policy-document file://policy.json

s3:DeleteObject and s3:ListBucket are what Every build needs to delete dated folders past their days, and what the test needs to clean up after itself. VPNDetection never reads your objects, so the role needs no s3:GetObject. If the bucket encrypts with a KMS key of yours, give the role kms:GenerateDataKey and kms:Decrypt on that key too.

4. Enter the role's ARN

Paste the role's ARN into Role ARN, then click Save.

5. Choose the databases and files

Under Databases, tick each database in the formats you want, CSV, MMDB or both. Under Files, choose Latest only to keep one copy of each file, or Every build to keep a dated folder per build, then click Save.

6. Test and activate

Click Test connection. It writes vpndetection-connection-test.txt to the folder and deletes it again, and reports each step. Once it passes, click Activate, and the current build goes out first.

Set up S3-compatible storage

Any storage with an S3 API works the same way: give VPNDetection an access key that can write to the bucket, and its endpoint. In the console, add an S3-compatible storage destination, fill in the fields below, and click Save. Then choose the databases and files, click Test connection, and Activate once it passes, as steps 5 and 6 above describe.

FieldValue
Endpointyour storage's https:// endpoint, from the table below
Bucketthe bucket's name, such as acme-data
Regionthe bucket's region, where your provider names one
Folderdatabases, or empty for the top of the bucket
Path-style addressingon, unless your provider says otherwise
Access key ID, Secret access keythe key's

These endpoints and regions fit the common providers:

ProviderEndpointRegion
Cloudflare R2https://<account-id>.r2.cloudflarestorage.comauto
Backblaze B2https://s3.<region>.backblazeb2.comthe bucket's, such as us-west-004
Wasabihttps://s3.<region>.wasabisys.comthe bucket's, such as us-east-1
DigitalOcean Spaceshttps://<region>.digitaloceanspaces.comthe Space's, such as nyc3
MinIO, Ceph and other servers of your ownyour server's https:// URLas configured

Leave Path-style addressing on unless your provider says otherwise; Amazon S3 is the one that doesn't need it. The endpoint has to be https:// on a public address.

Amazon S3 with an access key

If you'd rather not create a role, an IAM user with the same permissions policy and an access key works too. Add an S3-compatible storage destination instead, with these values:

FieldValue
Endpointhttps://s3.<region>.amazonaws.com, for the bucket's region
Bucketacme-data
Regionthe bucket's region, such as us-east-1
Folderdatabases, or empty for the top of the bucket
Path-style addressingoff
Access key ID, Secret access keythe user's

Verify that a build arrived

A small database lands within a pass or two of activating, and a large one takes as long as its transfer. To confirm it, open the destination's History tab: each file sent reads New build under Why and Delivered under Result, and the destination's row shows the time under Last delivered.

In the bucket, each file sits beside its .sha256, and manifest.json lists them all:

bash
aws s3 ls s3://acme-data/databases/

Download a file and its .sha256 together, and sha256sum -c vpn_ip_v1.mmdb.sha256 confirms that it's intact.

When delivery fails

The test result and the Detail column in History say what failed, in words, and a database.delivery_failed event carries the same failure as an error_code. The common ones are these:

error_codeCauseWhat to do
ASSUME_ROLE_FAILEDVPNDetection couldn't take on the role.Check that the trust policy names VPNDetection's AWS account and requires this destination's External ID.
ACCESS_DENIEDThe role or the key can't write to that bucket or folder.Check that the permissions policy's resources match the bucket and folder.
BUCKET_NOT_FOUNDThe bucket doesn't exist.Check the bucket's name.
WRONG_REGIONThe bucket is in a different region from the one given.Enter the bucket's own region.
KMS_DENIEDThe bucket encrypts with a KMS key the role can't use.Give the role kms:GenerateDataKey and kms:Decrypt on that key.
AUTH_FAILEDThe storage turned the access key down.Check the access key ID and the secret.

A key that can write but not delete fails the test at its delete step, since the test cleans up after itself. A failed delivery is tried again on a schedule, and after three days of failures the destination is paused until someone resumes it, as When delivery fails explains.

Next steps

Your bucket now receives each new build of the databases you chose. To act on each delivery as it lands, add a webhook and watch for database.delivered, or point a job at manifest.json, which changes only once a whole pass is in place.