From 7e173d1a149e25731edf6857f7e506328c7c1d05 Mon Sep 17 00:00:00 2001 From: Justin Hutchings Date: Tue, 22 Sep 2020 01:03:27 -0700 Subject: [PATCH 1/4] Add CodeQL security scanning (#35) --- .github/workflows/codeql.yml | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..9771ca0f --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,52 @@ +name: "Code scanning - action" + +on: + push: + pull_request: + schedule: + - cron: '0 19 * * 0' + +jobs: + CodeQL-Build: + + # CodeQL runs on ubuntu-latest and windows-latest + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # If this run was triggered by a pull request event, then checkout + # the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + # Override language selection by uncommenting this and choosing your languages + # with: + # languages: go, javascript, csharp, python, cpp, java + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From 5dbba71255e6f1ec32d91a1621a144d8b24f41a9 Mon Sep 17 00:00:00 2001 From: Max Held Date: Tue, 29 Sep 2020 14:17:06 +0200 Subject: [PATCH 2/4] fix typo (#58) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9109e730..ec249d54 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Follow the steps to configure the secret: } ``` - * You can also further scope down the Azure Credentials to a specific Azure resource, for example - a Web App by specifying the path to the specic resource in the *--scopes* attribute. Below script is for scoping the credentials to a web app of name *{app-name}* + * You can also further scope down the Azure Credentials to a specific Azure resource, for example - a Web App by specifying the path to the specific resource in the *--scopes* attribute. Below script is for scoping the credentials to a web app of name *{app-name}* ```bash az ad sp create-for-rbac --name "myApp" --role contributor \ --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} \ From 6fc8a38800cd4d22846e21a50282c361ff00552c Mon Sep 17 00:00:00 2001 From: Kraig Brockschmidt Date: Wed, 30 Sep 2020 03:55:49 +0000 Subject: [PATCH 3/4] Add explanation of az ad sp create-for-rbac (#57) * Add explanation of az ad sp create-for-rbac Fulfills an internal Microsoft request to explain what the command is doing. Also cleans up the readmd a little and add a note about forking a sample repository when applicable. * Add note on managing service principals * Update secrets link --- README.md | 274 +++++++++++++++++++++++++++--------------------------- 1 file changed, 139 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index ec249d54..012bb12f 100644 --- a/README.md +++ b/README.md @@ -1,135 +1,139 @@ -# GitHub Actions for deploying to Azure - -## Automate your GitHub workflows using Azure Actions - -[GitHub Actions](https://help.github.com/en/articles/about-github-actions) gives you the flexibility to build an automated software development lifecycle workflow. - -With [GitHub Actions for Azure](https://github.com/Azure/actions/) you can create workflows that you can set up in your repository to build, test, package, release and **deploy** to Azure. - -# GitHub Action for Azure Login -With the Azure login Action, you can automate your workflow to do an Azure login using [Azure service principal](https://docs.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals) and run Az CLI and Azure PowerShell scripts. - -By default, only az cli login will be done. In addition to az cli, you can login using Az module to run Azure PowerShell scripts by setting enable-AzPSSession to true. - -Get started today with a [free Azure account](https://azure.com/free/open-source)! - -This repository contains GitHub Action for [Azure Login](https://github.com/Azure/login/blob/master/action.yml). - -## Sample workflow that uses Azure login action to run az cli - -```yaml - -# File: .github/workflows/workflow.yml - -on: [push] - -name: AzureLoginSample - -jobs: - - build-and-deploy: - runs-on: ubuntu-latest - steps: - - - uses: azure/login@v1.1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - run: | - az webapp list --query "[?state=='Running']" - -``` - -## Sample workflow that uses Azure login action to run Azure PowerShell - -```yaml - -# File: .github/workflows/workflow.yml - -on: [push] - -name: AzurePowerShellSample - -jobs: - - build-and-deploy: - runs-on: ubuntu-latest - steps: - - - name: Login via Az module - uses: azure/login@v1.1 - with: - creds: ${{secrets.AZURE_CREDENTIALS}} - enable-AzPSSession: true - - - name: Run Az CLI script - run: | - az webapp list --query "[?state=='Running']" - - - name: Run Azure PowerShell script - uses: azure/powershell@v1 - with: - azPSVersion: '3.1.0' - inlineScript: | - Get-AzVM -ResourceGroupName "ActionsDemo" - - - -``` - -Refer [Azure PowerShell](https://github.com/azure/powershell) Github action to run your Azure PowerShell scripts. - -## Configure deployment credentials: - -For any credentials like Azure Service Principal, Publish Profile etc add them as [secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) in the GitHub repository and then use them in the workflow. - -The above example uses user-level credentials i.e., Azure Service Principal for deployment. - -Follow the steps to configure the secret: - * Define a new secret variable under your repository **Settings** -> **Secrets** -> **New secret**. Provide a secret variable **Name**, for example 'AZURE_CREDENTIALS'. - * Run the below [az cli](https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest) command and Store the output as the **Value** of the secret variable - * Below *az ad* command scopes the service principal to a specific resource group *{resource-group}* within a specific Azure subscription *{subscription-id}* -```bash - - az ad sp create-for-rbac --name "myApp" --role contributor \ - --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \ - --sdk-auth - - # Replace {subscription-id}, {resource-group} with the subscription, resource group details - - # The command should output a JSON object similar to this: - - { - "clientId": "", - "clientSecret": "", - "subscriptionId": "", - "tenantId": "", - (...) - } - -``` - * You can also further scope down the Azure Credentials to a specific Azure resource, for example - a Web App by specifying the path to the specific resource in the *--scopes* attribute. Below script is for scoping the credentials to a web app of name *{app-name}* -```bash - az ad sp create-for-rbac --name "myApp" --role contributor \ - --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} \ - --sdk-auth - - # Replace {subscription-id}, {resource-group}, and {app-name} with the names of your subscription, resource group, and Azure Web App. -``` - * Now in the workflow file in your branch: `.github/workflows/workflow.yml` replace the secret in Azure login action with your secret (Refer to the example above) - - - -# Contributing - -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. - -When you submit a pull request, a CLA bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +# GitHub Actions for deploying to Azure + +## Automate your GitHub workflows using Azure Actions + +[GitHub Actions](https://help.github.com/en/articles/about-github-actions) gives you the flexibility to build an automated software development lifecycle workflow. + +With [GitHub Actions for Azure](https://github.com/Azure/actions/) you can create workflows that you can set up in your repository to build, test, package, release and **deploy** to Azure. + +NOTE: you must have write permissions to the repository in question. If you're using a sample repository from Microsoft, be sure to first fork the repository to your own GitHub account. + +Get started today with a [free Azure account](https://azure.com/free/open-source). + +# GitHub Action for Azure Login + +With the Azure login Action, you can automate your workflow to do an Azure login using [Azure service principal](https://docs.microsoft.com/azure/active-directory/develop/app-objects-and-service-principals) and run Azure CLI and Azure PowerShell scripts. + +By default, the action only logs in with the Azure CLI (using the `az login` command). To log in with the Az PowerShell module, set `enable-AzPSSession` to true. + +This repository contains GitHub Action for [Azure Login](https://github.com/Azure/login/blob/master/action.yml). + +## Sample workflow that uses Azure login action to run az cli + +```yaml +# File: .github/workflows/workflow.yml + +on: [push] + +name: AzureLoginSample + +jobs: + + build-and-deploy: + runs-on: ubuntu-latest + steps: + + - uses: azure/login@v1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - run: | + az webapp list --query "[?state=='Running']" +``` + +## Sample workflow that uses Azure login action to run Azure PowerShell + +```yaml +# File: .github/workflows/workflow.yml + +on: [push] + +name: AzurePowerShellSample + +jobs: + + build-and-deploy: + runs-on: ubuntu-latest + steps: + + - name: Login via Az module + uses: azure/login@v1.1 + with: + creds: ${{secrets.AZURE_CREDENTIALS}} + enable-AzPSSession: true + + - name: Run Az CLI script + run: | + az webapp list --query "[?state=='Running']" + + - name: Run Azure PowerShell script + uses: azure/powershell@v1 + with: + azPSVersion: '3.1.0' + inlineScript: | + Get-AzVM -ResourceGroupName "ActionsDemo" +``` + +Refer to the [Azure PowerShell](https://github.com/azure/powershell) Github action to run your Azure PowerShell scripts. + +## Configure deployment credentials: + +The previous sample workflows depend on a [secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) named `AZURE_CREDENTIALS` in your repository. The value of this secret is expected to be a JSON object that represents a service principal (an identifer for an application or process) that authenticates the workflow with Azure. + +To function correctly, this service principal must be assigned the [Contributor]((https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#contributor)) role for the web app or the resource group that contains the web app. + +The following steps describe how to create the service principal, assign the role, and create a secret in your repository with the resulting credentials. + +1. Open the Azure Cloud Shell at [https://shell.azure.com](https://shell.azure.com). You can alternately use the [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) if you've installed it locally. (For more information on Cloud Shell, see the [Cloud Shell Overview](https://docs.microsoft.com/azure/cloud-shell/overview).) + +2. Use the [az ad dp create-for-rbac](https://docs.microsoft.com/cli/azure/ad/sp?view=azure-cli-latest#az_ad_sp_create_for_rbac) command to create a service principal and assign a Contributor role: + + ```azurecli + az ad sp create-for-rbac --name "{sp-name}" --sdk-auth --role contributor \ + --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} + ``` + + Replace the following: + * `{sp-name}` with a suitable name for your service principal, such as the name of the app itself. The name must be unique within your organization. + * `{subscription-id}` with the subscription you want to use + * `{resource-group}` the resource group containing the web app. + * `{app-name}` with the name of the web app. + + This command invokes Azure Active Directory (via the `ad` part of the command) to create a service principal (via `sp`) specifically for [Role-Based Access Control (RBAC)](https://docs.microsoft.com/azure/role-based-access-control/overview) (via `create-for-rbac`). + + The `--role` argument specifies the permissions to grant to the service principal at the specified `--scope`. In this case, you grant the built-in [Contributor](https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#contributor) role at the scope of the web app in the specified resource group in the specified subscription. + + If desired, you can omit the part of the scope starting with `/providers/...` to grant the service principal the Contributor role for the entire resource group: + + ```azurecli + az ad sp create-for-rbac --name "{sp-name}" --sdk-auth --role contributor \ + --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} + ``` + + For security purposes, however, it's always preferable to grant permissions at the most restrictive scope possible. + +3. When complete, the `az ad sp create-for-rbac` command displays JSON output in the following form (which is specified by the `--sdk-auth` argument): + + ```json + { + "clientId": "", + "clientSecret": "", + "subscriptionId": "", + "tenantId": "", + (...) + } + ``` + +4. In your repository, use **Add secret** to create a new secret named `AZURE_CREDENTIALS` (as shown in the example workflow), or using whatever name is in your workflow file. + +5. Paste the entire JSON object produced by the `az ad sp create-for-rbac` command as the secret value and save the secret. + +NOTE: to manage service principals created with `az ad sp create-for-rbac`, visit the [Azure portal](https://portal.azure.com), navigate to your Azure Active Directory, then select **Manage** > **App registrations** on the left-hand menu. Your service principal should appear in the list. Select a principal to navigate to its properties. You can also manage role assignments using the [az role assignment](https://docs.microsoft.com/cli/azure/role/assignment?view=azure-cli-latest) command. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. + +When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. From 756a6f0316b9e80247485ab760c30852157c5f84 Mon Sep 17 00:00:00 2001 From: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com> Date: Tue, 6 Oct 2020 10:30:41 +0530 Subject: [PATCH 4/4] Create issue-label-bot.yaml --- .github/issue-label-bot.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/issue-label-bot.yaml diff --git a/.github/issue-label-bot.yaml b/.github/issue-label-bot.yaml new file mode 100644 index 00000000..b6422262 --- /dev/null +++ b/.github/issue-label-bot.yaml @@ -0,0 +1,4 @@ +label-alias: + bug: 'bug' + feature_request: 'enhancement' + question: 'question'