We’ve made being secure easier with scoped API keys

Posted by:

You can now give every agent, integration, and CI pipeline its own scoped API key with only the access it needs and have it expire on its own.

One key to rule them all?

Until now, every call to the bunny.net API used your account API key, which has full access to your account. While that is very convenient and simple, it has meant that your CI pipeline which only needed to purge a cache could also delete pull zones, edit DNS, or change account settings. If that key leaks, let’s just say you won’t be having a great day.

Scoped API keys fix this. Each one works like your account API key, but it can only do what you allowed when you created it:

  • Only the access it needs: Pick the products and permissions each key can use, such as PullZone.Purge or DnsZone.Read.
  • Locked to specific resources and IPs: Limit a key to specific resources such as a single pull zone, and to specific IPv4 or IPv6 addresses or CIDR blocks.
  • Expires on its own: Every key has an expiry date by default, but if you want to live dangerously, we’ve added a never option for your convenience so your key doesn’t accidentally expire on 30-12-9999.

Your account API key isn’t going anywhere. Scoped keys sit alongside it, so you can give everything its own key and make sure the one key that rules them all is secret and safe.

How to scope your keys

Go to Account > Scoped API keys in the dashboard:

  1. Click Create API Key and give it a descriptive name, such as begone-foul-cache.
  2. Set an expiry date (30 days, 90 days, 1 year, or a custom date) and, if you like, the IPs allowed to use it.
  3. Under Permissions, add each product the key needs and pick its actions. Choose All resources or Selected to lock it to specific ones. Presets fill in common combinations for you.
  4. Create the key and copy it. It’s shown only once, so store it in a secret store or environment variable.

Calling the API works exactly as it does today. Send the scoped key in the same AccessKey header:

# Using curl
curl --request GET \
  --url 'https://api.bunny.net/compute/script?page=1&perPage=1000' \
  --header 'AccessKey: YOUR_SCOPED_API_KEY'

# Using the Bunny CLI
bunny scripts list --api-key=YOUR_SCOPED_API_KEY

Scoped keys start with bnyscpd_ and work with all of our products. If a key tries something it isn’t allowed to do, the API returns a 403. Keys can’t be edited, so to change what one can do, clone it or create a new one and delete the old key.

Each account can have up to 50 scoped API keys by default. We’ll email you when a key is created, when it’s about to expire, and when it has expired.

Read the full guides on creating scoped API keys and authenticating with them.

What you can do with them

Anything you can do with your account API key, you can do with a scoped API key. However, the best practice is to have one key per job, with only the access needed for that job.

There is a lot you can do, but you probably want to do these first:

  • Read-only keys for your AI agents: Give your agent a key with read-only permissions so that your agent can look but not touch. It’s never fun when the agent fixes the problem by deleting the problem.
  • Cache purges from CI: Give your pipeline PullZone.Purge on just the pull zones it deploys to.
  • Static site deploys: Use one of our presets to grant what a deploy needs, limited to the resources for that one site.
  • Third-party integrations and contractors: Hand out a key with a short expiry and the exact access required, because zero-trust is sometimes good for humans as well.
  • Service workers and background jobs: A worker that pulls stats or checks config doesn’t need write access. Scope it to the products it reads and lock it to your server’s IPs.

If a scoped key ever leaks, the damage is limited to what that key could do, and revoking it safely leaves every other key working fine.

Create your first scoped API key

Scoped API keys are available now for every bunny.net account, and team members can create them too, within their own team permissions. Take a few minutes to swap the account API key your agents, scripts, and pipelines use for keys that only do what they need. Your future self will thank you for it, especially if you’ve been a willing or unwilling participant in this October’s security awareness month.

Create a scoped API key here

Comments require cookies. to view and post.