Skip to content

nicholas-fedor/goGenerateCFToken

Repository files navigation

Cloudflare API Token Generator

A simple CLI tool for generating Cloudflare API tokens.

CircleCI codecov Codacy Badge Go Report Card GoDoc GitHub go.mod Go version latest version AGPLv3 License


Overview

The generated tokens are intended to be service-specific, i.e. Plex, Radarr, etc, for generating SSL certificates by tools, such as Certbot or Lego.

Prerequisites

Cloudflare-managed Domain Name

You will need to own a domain name configured to use Cloudflare's nameservers.
Once that is setup, you will be able to specify the domain's zone (i.e. example.com) that you want linked to the API token.

Cloudflare API Token with API Tokens: Edit Permissions

An API token needs to be manually created via the Cloudflare account dashboard to be used by goGenerateCFToken.

  1. Select the Create Additional Tokens template
  2. Update the Token name, as needed
  3. Add the following permission: Zone - Zone - Read
  4. Zone Resources: Include - Specific Zone - example.com
  5. Client IP Address Filtering: This limits usage of the token to a specified IP address
  6. Save the newly-created API token to a safe location

Installation

go install github.com/nicholas-fedor/gogeneratecftoken@latest

Prebuilt binaries are also available here

Usage

For access to usage instructions:

goGenerateCFToken -h

Configuration

There are several options for providing the api_token and zone to goGenerateCFToken, as it uses Cobra and Viper to enable configuration functionality.

  • YAML Config File:
    Setup a configuration file, as shown in the provided config.yaml.template, in a location, such as the default $HOME/.goGenerateCFToken/config.yaml.
    If using a custom location, then use the --config [path] flag.

  • Environment Variables:
    If no config file is found or specified, then the program falls back to environment variables.

    export CF_API_TOKEN="your-cloudflare-api-token-here"
    export CF_ZONE="example.com"
  • CLI Flags:

    To see the available flags:

    goGenerateCFToken generate -h

    Example Usage:

    goGenearteCFToken generate [service name] -z [example.com] -t [supersecretcftoken]

Recommended Usage

  1. Copy the template to $HOME/.goGenerateCFToken/config.yaml:

    cp ./config.yaml.template $HOME/.goGenerateCFToken/config.yaml
  2. Obtain your master Cloudflare API token for creating additional service-specific tokens

  3. Save the master token and associated zone to the configuration file

  4. Generate a test API token to confirm configuration is successful:

    goGenerateCFToken generate test
  5. If successful, you should see the following output:

    Generating API token: test.example.com
    yoursuperlongandsecretserviceapitoken

Resources

Development

GitHub releases

Using GoReleaser to build the release files.

Quick Start

To run a new build, update the tag, as follows:

git tag -a v0.1.0 -m "First release"
git push origin v0.1.0

About

A simple tool written in Go for generating Cloudflare API tokens

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages