Case Study DigitalRoute Case Study: Success Story

Automating License Validity Checks with KrakenD

by Albert Garcia

post image

KrakenD’s Enterprise Edition offers a feature for automated license validity checks. While we at KrakenD always take a proactive role in renewals and interim replacements, we understand the importance of automated systems in avoiding oversights, especially in critical components like your API gateway.

Why Monitor License Validity?

Monitoring license validity is a crucial step in maintaining operational stability, particularly as your business scales. An expired license could lead to unexpected disruptions in your API gateway, a key component in your infrastructure. By implementing automated checks, you ensure continuous service delivery, even in the face of potential human oversight during manual license renewals or replacements.

How It Works

KrakenD offers a krakend license command with various options. Using krakend license validates the current license’s validity, while krakend license days-left reveals the remaining days until the license expires. However, for this article’s purposes, we’re concentrating on krakend license valid-for. This command can predict if the current license will stay valid for a specified number of days. If the license is set to expire within that timeframe, the command will return a non-zero exit status. This makes it particularly suitable for automation in CI/CD pipelines.

Examples

  1. Basic Check:

    Check if the license is valid for the next 90 days 

    $krakend license valid-for 90d
    KO: License will be invalid in 71 days, 5 hours, and 49 minutes

    This command checks if the license is valid for the next 90 days and returns an exit code 1 or 0 accordingly.

  2. One-liner Alert to Slack:

    Check if the license is valid for the next 90 days, and send an alert to Slack otherwise 

    $krakend license valid-for 90d || \
    curl -X POST -H 'Content-type: application/json' \
    --data '{"text":"Warning: KrakenD license expires in less than 90 days."}' \
    https://hooks.slack.com/services/YOUR/SLACK/HOOK

    In this case, if the license expires before 90 days, it will send an alert message to Slack.

  3. Automate in your CI / CD deployment pipeline with Github Actions: You can integrate this check into your DevOps pipelines. For example, you could abort a deployment if the license check fails, ensuring you don’t deploy a version that might soon be disrupted by licensing issues, or configure a scheduled job that verifies the validity of the license periodically.

    name: Schedule KrakenD Enterprise License Check
    
    on:
      schedule:
        - cron: '0 10 * * 1'
    
    jobs:
      license_check:
        runs-on: ubuntu-latest
        steps:
          - name: Check KrakenD License
            run: |
              if ! krakend license valid-for 90d; then
                curl -X POST -H 'Content-type: application/json' --data '{"text":"Warning: KrakenD license expires in less than 90 days."}' ${{ secrets.SLACK_WEBHOOK_URL }}
                exit 1
              fi          
    

    This scheduled job checks the license status every Monday and alerts via Slack if there’s an issue.

Automating license validity checks is a simple yet effective way to ensure your KrakenD deployment runs smoothly without interruptions. By leveraging KrakenD’s built-in commands and integrating them into your existing DevOps tools, you can maintain operational efficiency and compliance with ease.

For more detailed instructions and configurations, visit the KrakenD documentation on managing the LICENSE file.

Scarf

Stay up to date with KrakenD releases and important updates