项目作者: venura9

项目描述 :
GitHub Action to Manage NSG Rules allowing public running deployment to resources secured by Azure NSGs
高级语言: Shell
项目地址: git://github.com/venura9/manage-nsg.git
创建时间: 2020-03-16T11:27:38Z
项目社区:https://github.com/venura9/manage-nsg

开源协议:MIT License

下载


Manage NSG for Deployments

run_test_master run_test_develop

This GitHub action allows a hosted(public) runner image to access resources secured by an Azure Network Security Group (NSG) by creating an allow rule picking the current IP address of the hosted runner, also the same task can be used to remove existing NSG rules allowing the cleanup of the created rules.

E.g. Web Deploy to a WebApp inside an Azure Application Service Environment (ASE)

Inputs

azure-credentials

  • Required SPN details as secrets.AZURE_CREDENTIALS, Refer Configure Azure Credentials on how to.
  • Default "N/A".

    rule-priority-start:

  • Optional Start value for the priority range to be used.
  • Default "300".

    rule-priority-range:

  • Optional range of the NSG priority values to be used when multiple agents are deploying sharing the same NSG.
  • Default "100".

    rule-inbound-port:

  • Optional Port for the inbound rule’.
  • Default "443".

    rule-id-for-removal:

  • Optional rule id to remove. If this value is defined the action will default to deleteing.
  • Default "".

    rule-nsg-resource-group-name:

  • Required Resource Group of the NSG.
  • Default "N/A".

    rule-nsg-name:

  • Required Name of the NSG.
  • Default "N/A".

Outputs

rule_name

Created or Deleted NSG Rule Name

Example usage

  1. #File: .github/workflows/deploy_action.yml
  2. name: deploy_to_azure_resource_behind_nsg
  3. on:
  4. push:
  5. branches:
  6. - master
  7. jobs:
  8. deploy:
  9. runs-on: ubuntu-latest
  10. name: Deploying to Azure
  11. steps:
  12. - name: dig +short myip.opendns.com @resolver1.opendns.com
  13. run: dig +short myip.opendns.com @resolver1.opendns.com
  14. - name: Add NSG Rule
  15. uses: venura9/manage-nsg@master
  16. id: rule
  17. with:
  18. azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
  19. rule-nsg-resource-group-name: ManageNsg
  20. rule-nsg-name: ManageNsg
  21. - name: Print Created NSG Rule Name
  22. run: echo "Rule Name ${{ steps.rule.outputs.rule_name }}"
  23. - name: Remove NSG Rule
  24. uses: venura9/manage-nsg@master
  25. with:
  26. azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
  27. rule-id-for-removal: ${{ steps.rule.outputs.rule_name }}
  28. rule-nsg-resource-group-name: ManageNsg
  29. rule-nsg-name: ManageNsg

Configure Azure credentials:

To fetch the credentials required to authenticate with Azure, run the following command to generate an Azure Service Principal (SPN) with Contributor permissions:

  1. az ad sp create-for-rbac --name "myApp" --role contributor \
  2. --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
  3. --sdk-auth
  4. # Replace {subscription-id}, {resource-group} with yout subscription, resource group details
  5. # The command should output a JSON object similar to this:
  6. {
  7. "clientId": "<GUID>",
  8. "clientSecret": "<GUID>",
  9. "subscriptionId": "<GUID>",
  10. "tenantId": "<GUID>",
  11. (...)
  12. }
  13. # Note: You can always create the json string manually and add as a secret

Add the json output as a secret (let’s say with the name AZURE_CREDENTIALS) in the GitHub repository.