Giter VIP home page Giter VIP logo

ziti-webhook-action's Introduction

Ziti Webhook Action

This GitHub workflow action uses Ziti NodeJS SDK to post an event's payload in JSON format over a Ziti connection.

MacOS Compatibility

If you have a MacOS job you may wish to use @v1 ref which works with the macos-latest hosted runner.

Usage

name: ziti-webhook-action
on: [ push ]

jobs:
  ziti-action:
    runs-on: ubuntu-latest
    name: Ziti Webhook Action
    steps:
    - uses: openziti/ziti-webhook-action@v2
      with:
        # Identity JSON containing key to access a Ziti network
        ziti-id: ${{ secrets.ZITI_WEBHOOK_ACTION_ID }}

        # URL to post event payload.  Note that the Ziti service
        # name must match the hostname of the URL (e.g.
        # "someapp.ziti")
        webhook-url: https://someapp.ziti/plugins/github/webhook

        # Used to create a hash signature of the payload
        # to be set in the X-Hub-Signature HTTP header
        webhook-secret: ${{ secrets.ZITI_WEBHOOK_SECRET }}

Ziti Identity

The ziti-id input is the JSON formatted string of an identity enrolled in a Ziti network.

The identity JSON is created by running the ziti edge enroll ./ziti-id.jwt command. The one-time token file e.g. "ziti-id.jwt" is typically downloaded from the web console or output when the identity is created.

# example of saving the token file when the identity is created
ziti edge create identity device my-ziti-identity --jwt-output-file ./ziti-id.jwt

The ziti executable can be obtained here.

Alternatively, you may run the ziti executable with Docker.

docker run --rm --volume ${PWD}:/mnt openziti/quickstart /openziti/ziti-bin/ziti edge enroll /mnt/ziti-id.jwt

WebHook Secret

This is a random secret string that is used to provide a data integrity hash the receiver may validate. Validation logic that works with GitHub webhooks also works with ziti-webhook-action. From that reference:

ruby -rsecurerandom -e 'puts SecureRandom.hex(20)'

Or, generate the random string with Python.

python -c "import os, binascii; print(binascii.hexlify(os.urandom(20)).decode('utf-8'))"

Extra Data Input

There are two ways to pass arbitrary data to be included in the webhook.

  1. Call the Action in a separate workflow with a raw-field. This causes the GitHub context payload to have a top-level dict named inputs with a key for each workflow input. This is useful if this Action is always called from another workflow.
on:
  workflow_dispatch:  # triggered by a step in the main workflow
    inputs:
      my_release_version:
        description: 'Semantic Version from Builder Bot'
        required: true

This example results in a top-level dict in the webhook payload.

# One way to pass a raw field is to use the GitHub CLI which is pre-installed in all hosted runner VMs
gh workflow --repo myorg/myrepo run --ref $(git rev-parse --abbrev-ref HEAD) --raw-field my_release_version=1.2.3 send-ziti-webhook.yml
{
  "inputs": {"my_release_version": "1.2.3"}
}
  1. A multi-line string with key=value pair / line may be passed to the data input field of the Action. This is useful if the Action is called in-line as part of a workflow that contains other steps.
        with:
          ziti-id: ${{ secrets.ZITI_WEBHOOK_IDENTITY }}
          webhook-url: https://someapp.ziti/plugins/github/webhook
          webhook-secret: ${{ secrets.ZITI_WEBHOOK_SECRET }}
          data: |
            my_release_version=1.2.3

Results in:

{
  "data": {"my_release_version": "1.2.3"}
}

ziti-webhook-action's People

Contributors

github-actions[bot] avatar qrkourier avatar smilindave26 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ziti-webhook-action's Issues

retry webhook if fails

Sometimes the CI step fails but the log shows the response was a success. It's not clear what failed, but a retry of the job has succeeded in every spot check.

Some debug logging may be necessary to diagnose the cause of the failure, and a retry behavior may be necessary if the cause is external to this node app.

exploring Linux compatibility

I assume that adding the flexibility to use either of the Darwin or Linux runners would entail:

  1. additionally including the Linux counterpart of dist/build/Release/node-v83-darwin-x64/ziti_sdk_nodejs.node
  2. switching logic in dist/index.js to detect the platform and load the appropriate SDK

Is that an accurate summary?

The reason I'm asking is that I may be able to adapt this action slightly to accept additional inputs, and those values would originate from a job that isn't using a MacOS runner. I'm also assuming the function that generates the HMAC is somewhere in this action, not offloaded to a GitHub API, and therefore it will be feasible to modify the webhook payload before generating the hash.

Add deprecation warning in v1

We need to add a deprecation warning in main and v1 (MacOS only) to prompt consumers to adopt v2 (Linux only) to free up main for continued development.

Main is currently blocked because v2 is incompatible and many NF and OZ workflow templates are pinned for the purpose of surfacing issues with the magic zero alpha release that became v1, and therefore we can't merge v2 to main right away because it would immediately break those actions (again ๐Ÿ˜…).

Alternatively, we could create a new trunk branch and orphan "main" as an alias of v1. I've created development branch "linux-runner" as a workaround and temporary trunk.

After a period of deprecation it will be fine to merge the breaking changes to main.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.