Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git_hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

npx commitlint --edit $1
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Users referenced in this file will automatically be requested as reviewers for PRs that modify the given paths.
# See https://help.github.com/articles/about-code-owners/

* @Orkuncakilkaya
11 changes: 11 additions & 0 deletions .github/workflows/analyze-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Analyze Commit Messages
on:
pull_request:

permissions:
pull-requests: write
contents: write
jobs:
analyze-commits:
name: Generate docs and coverage report
uses: fingerprintjs/dx-team-toolkit/.github/workflows/analyze-commits.yml@v1
15 changes: 15 additions & 0 deletions .github/workflows/create-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Create PR (for main and rc)

on:
release:
types:
- published

jobs:
create-pr:
name: Create PR
uses: fingerprintjs/dx-team-toolkit/.github/workflows/create-pr.yml@v1
with:
target_branch: ${{ github.event.release.prerelease && 'main' || 'rc' }}
tag_name: ${{ github.event.release.tag_name }}
prerelease: ${{ github.event.release.prerelease }}
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: release
on:
push:
branches:
- main
- rc

jobs:
build-and-release:
name: 'Build project, run CI checks and publish new release'
uses: fingerprintjs/dx-team-toolkit/.github/workflows/release-server-sdk.yml@v1
with:
language: terraform
language-version: 1.9.4
appId: ${{ vars.APP_ID }}
secrets:
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ override.tf.json
.terraformrc
terraform.rc
.idea

assets

examples/**/*.lock.hcl
.DS_Store
50 changes: 50 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"branches": [
"main",
{
"name": "rc",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"config": "@fingerprintjs/conventional-changelog-dx-team",
"releaseRules": "@fingerprintjs/conventional-changelog-dx-team/release-rules"
}
],
[
"@semantic-release/release-notes-generator",
{
"config": "@fingerprintjs/conventional-changelog-dx-team"
}
],
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "./scripts/preparePackage.sh"
}
],
[
"@semantic-release/git",
{
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
"assets": [
"CHANGELOG.md"
]
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "package.zip"
}
]
}
]
]
}
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Contributing to Fingerprint Fastly Compute Integration Terraform Module

## Working with code


For proposing changes, use the standard [pull request approach](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). It's recommended to discuss fixes or new functionality in the Issues, first.

* The `main` and `rc` branches are locked for the push action.
* Releases are created from the `main` branch. If you have Fastly Compute Integration set up, it is running code from the `main` branch. Pull requests into the `main` branch are not accepted.
* The `rc` branch functions as a candidate for the next release. Create your pull requests into this branch. The code in `rc` must always pass the tests.

### Code style

Consistent code formatting is enforced by [TFLint](https://github.com/terraform-linters/tflint) and [Prettier](https://prettier.io/).

### Security scans

We are using [Trivy](https://aquasecurity.github.io/trivy/v0.47/tutorials/misconfiguration/terraform/) to do security scans for us.

### Commit style

You are required to follow [conventional commits](https://www.conventionalcommits.org) rules.

### How to test

We manually test the implementation.

### How to release a new version

Every PR should target `rc` branch first. Upon merge, if there are relevant changes a new release candidate is created.
When that happens, an automated PR is created to `main` branch, and E2E tests run against it. If the tests pass, the PR can be merged and the release is created.

The integration is automatically released on every push to the main branch if there are relevant changes. The workflow must be approved by one of the maintainers, first.

## How to test without DNS and TLS Setup

To test terraform module on your Fastly Compute service, you can use Fastly subdomain `.edgecompute.app`. See example below:

```terraform
module "fingerprint_fastly_compute_integration" {
# ...
integration_domain = "my-test-subdomain.edgecompute.app" # <- Use subdomain here
}
```

## How test using Fingerprint Staging Environment

To test terraform module using Fingerprint's staging environment, you can alter origins like this:

```terraform
module "fingerprint_fastly_compute_integration" {
# ...
fpjs_backend_url = "api.stage.fpjs.sh" # <- Update Ingress origin here
fpjs_cdn_url = "procdn.fpjs.sh" # <- Update CDN origin here
}
```
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Fingerprint

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
153 changes: 107 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,79 @@
# Prerequisites
* Create an empty compute service on Fastly and copy its ID.
* Copy your Fastly API token
* Create your own terraform folder and create main.tf file
* Fill the file like this:
<p align="center">
<a href="https://fingerprint.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://fingerprintjs.github.io/home/resources/logo_light.svg" />
<source media="(prefers-color-scheme: light)" srcset="https://fingerprintjs.github.io/home/resources/logo_dark.svg" />
<img src="https://fingerprintjs.github.io/home/resources/logo_dark.svg" alt="Fingerprint logo" width="312px" />
</picture>
</a>
</p>

<p align="center">
<a href="https://registry.terraform.io/modules/fingerprintjs/compute-fingerprint-proxy-integration/fastly/latest"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fregistry.terraform.io%2Fv2%2Fmodules%2Ffingerprintjs%2Fcompute-fingerprint-proxy-integration%2Ffastly%3Finclude%3Dlatest-version&query=%24.included%5B0%5D.attributes.version&prefix=v&label=Terraform" alt="Current version"></a>
<a href="https://github.com/fingerprintjs/terraform-fastly-compute-fingerprint-proxy-integration"><img src="https://img.shields.io/github/v/release/fingerprintjs/terraform-fastly-compute-fingerprint-proxy-integration" alt="Current version"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/:license-mit-blue.svg" alt="MIT license"></a>
<a href="https://discord.gg/39EpE2neBg"><img src="https://img.shields.io/discord/852099967190433792?style=logo&label=Discord&logo=Discord&logoColor=white" alt="Discord server"></a>
</p>

# Fingerprint Fastly Compute Integration (Terraform module)

[Fingerprint](https://fingerprint.com/) is a device intelligence platform offering industry-leading accuracy.

Fingerprint Fastly Compute Integration is responsible for

- Proxying download requests of the latest Fingerprint JS Agent between your site and Fingerprint CDN.
- Proxying identification requests and responses between your site and Fingerprint's APIs.

This [improves](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration#the-benefits-of-using-the-fastly-compute-proxy-integration) both accuracy and reliability of visitor identification and bot detection on your site.

You can install the Fastly Compute proxy integration [manually](https://dev.fingerprint.com/docs/deploy-fastly-compute-manually) or as [a Terraform module](https://registry.terraform.io/modules/fingerprintjs/compute-fingerprint-proxy-integration/fastly/latest) included in this repository. For more details, see the [full documentation](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration).

## Requirements

- [Fastly](https://www.fastly.com/signup) Account
- [Terraform CLI](https://developer.hashicorp.com/terraform/install).
- [Fastly API Token](https://manage.fastly.com/account/tokens)

> [!IMPORTANT]
> The Fastly Compute Proxy Integration is exclusively supported for customers on the Enterprise Plan. Other customers are encouraged to use [Custom subdomain setup](https://dev.fingerprint.com/docs/custom-subdomain-setup) or [Cloudflare Proxy Integration](https://dev.fingerprint.com/docs/cloudflare-integration).

> [!WARNING]
> The underlying data contract in the identification logic can change to keep up with browser updates. Using the Fastly Compute Proxy Integration might require occasional manual updates on your side. Ignoring these updates will lead to lower accuracy or service disruption.

## How to install

### 1. Create an empty Fastly Compute Service

Create and empty Fastly Compute service, for example, using the [Fastly web interface](https://manage.fastly.com/compute/new). Note down the service ID.

### 2. Install the Terraform module

Add the module to your Terraform file (for example, `main.tf`) and configure it with your Fastly API token, [Fingerprint proxy secret](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration#step-1-create-a-fingerprint-proxy-secret), integration domain, and other required values:

```terraform
terraform {
required_version = ">=1.5"
}

module "fingerprint_fastly_compute_integration" {
source = "github.com/fingerprintjs/temp-fastly-compute-terraform"
fastly_api_token = "<your fastly api token>"
integration_domain = "<your domain to serve fingerprint integration>"
service_id = "<your empty fastly compute service id>"
agent_script_download_path = "<random path like this: qwe123>"
get_result_path = "<random path like this: asd987>"
fastly_api_token = "FASTLY_API_TOKEN"
service_id = "EMPTY_FASTLY_COMPUTE_SERVICE_ID"
agent_script_download_path = "AGENT_SCRIPT_DOWNLOAD_PATH"
get_result_path = "GET_RESULT_PATH"
integration_domain = "metrics.yourwebsite.com"
}
```
* Run `terraform init`

The properties you see here come from the Fingerprint module's variables, you can see the full list of properties below:
You can see the full list of the Terraform module's variables below:

| Variable | Description | Required | Example |
|--------------------------------|---------------------------------------------------------|----------|---------------------------------------------------------|
| `fastly_api_token` | Your Fastly API token | Required | `"ABC123...xyz"` |
| `integration_domain` | Domain used for your proxy integration | Required | `"metrics.yourdomain.com"` |
| `service_id` | ID of your empty Fastly Compute service | Required | `"SU1Z0isxPaozGVKXdv0eY"` |
| `agent_script_download_path` | Path to serve agent script from your domain | Required | `"4fs80xgx"` |
| `get_result_path` | Path to serve identification and browser cache requests | Required | `"vpyr9bev"` |
| `integration_domain` | Domain used for your proxy integration | Required | `"metrics.yourdomain.com"` |
| `integration_name` | Name of Fastly service | Optional | `"fingerprint-fastly-compute-proxy-integration"` |
| `download_asset` | Whether to auto-download latest release | Optional | `true` |
| `compute_asset_name` | Custom filename if not downloading | Optional | `"fingerprint-fastly-compute-proxy-integration.tar.gz"` |
Expand All @@ -36,45 +82,60 @@ The properties you see here come from the Fingerprint module's variables, you ca
| `kv_store_save_plugin_enabled` | Enables plugin to save to KV store | Optional | `"false"` |
| `fpjs_backend_url` | Domain for Ingress endpoint & browser cache endpoint | Optional | `"api.fpjs.io"` |
| `fpjs_cdn_url` | Domain for Agent Script | Optional | `"fpcdn.io"` |

# Deploy

Run these commands in order
```shell
terraform apply -target=module.fingerprint_fastly_compute_integration.module.compute_asset
terraform import module.fingerprint_fastly_compute_integration.fastly_service_compute.fingerprint_integration "<your empty fastly compute service id>"
terraform apply
```

# Custom Package
### 2. Deploy your Terraform changes

If you want to use your own asset instead of downloading latest follow these steps:
1. Initialize the Terraform module

Place your custom asset in `<your_module_root>/assets/custom-asset.tar.gz` and then edit your `main.tf` file, and add these 2 variables inside "compute" module block:
```terraform
download_asset = false
compute_asset_name = "custom-asset.tar.gz"
```
```shell
terraform init
```

Run these commands:
```shell
terraform init
terraform import module.fingerprint_fastly_compute_integration.fastly_service_compute.fingerprint_integration "<your empty fastly compute service id>"
terraform apply
```
2. Apply the Compute Asset

> After you deployed your service via terraform, you need to add Secret Store item with key PROXY_SECRET
> to Secret Store created via Terraform and fill your value. This approach is suggested by Fastly. For details please see [this link](https://registry.terraform.io/providers/fastly/fastly/latest/docs/resources/secretstore) and check Note section.
```shell
terraform apply -target=module.fingerprint_fastly_compute_integration.module.compute_asset
```

# Destroy
3. Import the Fastly service

To destroy, run this:
```shell
terraform destroy
```
```shell
terraform import \
module.fingerprint_fastly_compute_integration.fastly_service_compute.fingerprint_integration \
"<your empty fastly compute service id>"
```

4. Apply the changes

```shell
terraform apply
```
### 3. Add the proxy secret to your Fastly Secret Store

1. Using the [Fastly web interface](https://manage.fastly.com/compute), open the Secret Store created for your service by Terraform. It will be named `Fingerprint_Compute_Secret_Store_<SERVICE_ID>`.
2. Add a `PROXY_SECRET` item with your Fingerprint proxy secret as the value.

## Using a Custom package

To use your own `.tar.gz` package instead of downloading the official release, please see [Using a custom build](https://dev.fingerprint.com/docs/deploy-fastly-compute-using-terraform#using-a-custom-build-optional) in the full integration guide.

This is only necessary if you're using [Open Client Response](https://dev.fingerprint.com/docs/open-client-response).

## Examples

This repository also includes an example Terraform project. Use this example only as a reference, and make sure to follow best practices when provisioning Fastly services:

- [Minimal example](./examples/minimal/)

## How to update

The Terraform module does include any mechanism for automatic updates. To keep your integration up to date, please run `terraform apply` regularly.

## More resources

- [Documentation](https://dev.fingerprint.com/docs/fastly-compute-proxy-integration)

## License

# Limitations & Known Issues
This project is licensed under the MIT license. See the [LICENSE](/LICENSE) file for more info.

* In our implementation for Fastly Compute, we support multiple proxy integrations in one account, in order to do this, we bind store names with compute service id.
To apply this on terraform, we run in to cyclical dependency problem. In order to fix this, we rely on already created empty service and its ID.
* If you use your own custom asset, then you need to maintain your asset's version on your own!
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@fingerprintjs/commit-lint-dx-team'] };
Loading
Loading