Skip to content

Github action that allows you to open or close a specific port in your DigitalOcean firewall.

License

Notifications You must be signed in to change notification settings

patoroco/doorkeeper

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Doorman

Doorkeeper DigitalOcean Action Tests

This Github action allows you to open or close a specific port in your DigitalOcean firewall. It's really useful for deploying to your instances from Github Actions, as they don't provide a list of IPs to add to your security groups.

Diagram of doorkeeper

Usage

You need to generate a personal access token from your DigitalOcean Applications & API page.

DigitalOcean token

Copy that token, and paste in the secrets of your repo: Github Repo Secrets

Create or update a workflow, adding the file .github/workflows/doorkeeper.yml (more info about how to use Github Actions).

############################
## prepare your artifacts ##
############################

- name: Doorkeeper open
  id: doorkeeper_open
  uses: patoroco/doorkeeper@v0.4.0
  with:
    digitaloceanToken: ${{ secrets.DO_TOKEN }}
    firewallName: "name_of_the_firewall"
    actionToDo: "add"
    dryRun: false

############################
## deploy to DigitalOcean ##
############################

- name: Doorkeeper close
  uses: patoroco/doorkeeper@v0.4.0
  with:
    digitaloceanToken: ${{ secrets.DO_TOKEN }}
    firewallName: "name_of_the_firewall"
    actionToDo: "remove"
    # Use the IP from the open step to ensure we remove the correct one
    IP: ${{ steps.doorkeeper_open.outputs.ip }}
    dryRun: false

To check that everything is working as expected, you have to push these changes to your repo, and a new build in the Actions tab should be starting.

Inputs

Input Required Default Description
digitaloceanToken Yes - Your DigitalOcean API token
firewallName Yes - Name of the firewall attached to your droplet
actionToDo Yes - add or remove the IP from the firewall
protocol No tcp Protocol used by the service (tcp or udp)
port No 22 Port used by the service
IP No Auto-detected IP address to add/remove. If not set, uses the runner's public IP
dryRun No false Set to true to test without applying changes

Outputs

Output Description
ip The IP address that was added/removed from the firewall

This is useful when you want to ensure the same IP is removed in a cleanup step, even if the job runs on a different runner:

- name: Doorkeeper open
  id: doorkeeper
  uses: patoroco/doorkeeper@v0.4.0
  with:
    digitaloceanToken: ${{ secrets.DO_TOKEN }}
    firewallName: "my-firewall"
    actionToDo: "add"

# ... your deployment steps ...

- name: Doorkeeper close
  if: always()  # Run even if previous steps fail
  uses: patoroco/doorkeeper@v0.4.0
  with:
    digitaloceanToken: ${{ secrets.DO_TOKEN }}
    firewallName: "my-firewall"
    actionToDo: "remove"
    IP: ${{ steps.doorkeeper.outputs.ip }}

Development

Requirements: Node.js 20+

First of all, you have to install the dependencies:

npm install

Run the tests:

npm test

I've been using act to test the action locally, and it's really useful because it doesn't require pushing anything to GitHub. After installing it, you can do:

npm run local:action

You can also run the code itself using:

npm run local

Build the distribution bundle:

npm run pack

LICENSE

About

Github action that allows you to open or close a specific port in your DigitalOcean firewall.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5