Cloudflare Workers

Setup Onboardbase to manage Cloudflare Workers secrets via the Onboardbase web platform

Via Cloudflare Dashboard

You can also push secrets from Onboardbase into your Cloudflare worker via the Onboardbase UI Integration for Cloudflare.

For this integration to work, we assume you already have a KV store on Cloudflare with at least one namespace in it.

You will have to create an API token on Cloudflare with some minimum permissions. From the Cloudflare dashboard, go to My Profile > API Tokens.

You need to create a custom token with the following permissions (minimum)

After the token has been created, you will need to copy it.

Navigate to the Onboardbase Project you want to integrate with, on the project page, click on the Integrations tab:

Click on Add Integration in the new tab opened.

As we have a lot of Cloud Integrations possible, you can search for Cloudlfare in the search bar on the Add Integration page:

Click Add next to Cloudflare Workers KV. A modal pops up for you to provide the necessary information Onboardbase needs to integrate with your Cloudflare worker.

You first need to select the Onboardbase environment you want to sync with your Cloudflare worker, then you provide the API token. We verify the token and then list the Cloudflare account(s) linked to that token.
After selecting the correct Cloudflare account, you will then be prompted to select a namespace.

After selecting the namespace, click on Proceed to complete the integration. When the integration is complete, we will upload the current secrets on Onboardbase to the KV namespace you provided. We will also sync new secrets added to the environment on Onboardbase to Cloudflare.

Common Issue: I don't see a list of Cloudflare Accounts After Inserting an API Token from Cloudflare

If you provided an API token from Cloudflare while integrating with Onboardbase and you are not shown a list of accounts linked to that Token, it means the token does not have the required minimum permissions.

The minimum permissions we need are:

Via Cloudflare CLI

You can push your secrets from Onboardbase into your Cloudflare worker with the help of Onboardbase CLI secret command and Cloudflare's wrangler secret command.

Ensure that you have installed, logged in, and set up Onboardbase project in your Cloudflare workers project. You can do these from the setup here.

Download your secrets in JSON

Run onboardbase secrets:download --json

This would generate an onboardbase.json file which contains a JSON of key/value for the project and secret that has been set up in the .onboardbase.yamlfile in the root of your project.

Upload your secrets to your workers K/V secrets

Run npx wrangler secrets:bulk ./onboardbase.json

This would take the secrets downloaded above and upload them to your Cloudflare worker key/value secrets.

See Wrangler Bulk Secrets for more information.

Confirm this operation by going into the settings page of your worker on Cloudflare and clicking on the variables tab

Use your secrets in your worker

In your index.ts file, add the secret that you require in the Env interface, then in your code with the env variable access the env using the dot operator and then the key name

export interface Env {
  HI: string;
}

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    return new Response(`Secret value for HI = ${env.HI}`);
  },
};

Run yarn start or npm start to start the development server.

You should have the value for the variable HI referenced in the output HTML