Compare commits

..

1 Commits

Author SHA1 Message Date
T.J. Corrigan
05337708db
Introduce insecure NSG 2022-11-01 10:51:53 -05:00
5 changed files with 37 additions and 23 deletions

View File

@ -30,11 +30,11 @@ jobs:
steps: steps:
# Checkout the repository to the GitHub Actions runner # Checkout the repository to the GitHub Actions runner
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
# Install the latest version of the Terraform CLI # Install the latest version of the Terraform CLI
- name: Setup Terraform - name: Setup Terraform
uses: hashicorp/setup-terraform@v3 uses: hashicorp/setup-terraform@v2
with: with:
terraform_wrapper: false terraform_wrapper: false
@ -61,7 +61,7 @@ jobs:
# Save plan to artifacts # Save plan to artifacts
- name: Publish Terraform Plan - name: Publish Terraform Plan
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v3
with: with:
name: tfplan name: tfplan
path: tfplan path: tfplan
@ -93,7 +93,7 @@ jobs:
# If changes are detected, create a new issue # If changes are detected, create a new issue
- name: Publish Drift Report - name: Publish Drift Report
if: steps.tf-plan.outputs.exitcode == 2 if: steps.tf-plan.outputs.exitcode == 2
uses: actions/github-script@v7 uses: actions/github-script@v6
env: env:
SUMMARY: "${{ steps.tf-plan-string.outputs.summary }}" SUMMARY: "${{ steps.tf-plan-string.outputs.summary }}"
with: with:
@ -141,7 +141,7 @@ jobs:
# If changes aren't detected, close any open drift issues # If changes aren't detected, close any open drift issues
- name: Publish Drift Report - name: Publish Drift Report
if: steps.tf-plan.outputs.exitcode == 0 if: steps.tf-plan.outputs.exitcode == 0
uses: actions/github-script@v7 uses: actions/github-script@v6
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |

View File

@ -33,11 +33,11 @@ jobs:
steps: steps:
# Checkout the repository to the GitHub Actions runner # Checkout the repository to the GitHub Actions runner
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
# Install the latest version of the Terraform CLI # Install the latest version of the Terraform CLI
- name: Setup Terraform - name: Setup Terraform
uses: hashicorp/setup-terraform@v3 uses: hashicorp/setup-terraform@v2
with: with:
terraform_wrapper: false terraform_wrapper: false
@ -69,7 +69,7 @@ jobs:
# Save plan to artifacts # Save plan to artifacts
- name: Publish Terraform Plan - name: Publish Terraform Plan
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v3
with: with:
name: tfplan name: tfplan
path: tfplan path: tfplan
@ -101,7 +101,7 @@ jobs:
# If this is a PR post the changes # If this is a PR post the changes
- name: Push Terraform Output to PR - name: Push Terraform Output to PR
if: github.ref != 'refs/heads/main' if: github.ref != 'refs/heads/main'
uses: actions/github-script@v7 uses: actions/github-script@v6
env: env:
SUMMARY: "${{ steps.tf-plan-string.outputs.summary }}" SUMMARY: "${{ steps.tf-plan-string.outputs.summary }}"
with: with:
@ -125,11 +125,11 @@ jobs:
steps: steps:
# Checkout the repository to the GitHub Actions runner # Checkout the repository to the GitHub Actions runner
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform - name: Setup Terraform
uses: hashicorp/setup-terraform@v3 uses: hashicorp/setup-terraform@v2
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init - name: Terraform Init
@ -137,7 +137,7 @@ jobs:
# Download saved plan from artifacts # Download saved plan from artifacts
- name: Download Terraform Plan - name: Download Terraform Plan
uses: actions/download-artifact@v4 uses: actions/download-artifact@v3
with: with:
name: tfplan name: tfplan

View File

@ -3,11 +3,6 @@ name: 'Terraform Unit Tests'
on: on:
push: push:
permissions:
security-events: write # Needed to upload-sarif
contents: read # Needed to clone repo
actions: read # Potentially needed for private repositories (see https://github.com/github/codeql-action/issues/2117)
jobs: jobs:
terraform-unit-tests: terraform-unit-tests:
name: 'Terraform Unit Tests' name: 'Terraform Unit Tests'
@ -16,11 +11,11 @@ jobs:
steps: steps:
# Checkout the repository to the GitHub Actions runner # Checkout the repository to the GitHub Actions runner
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform - name: Setup Terraform
uses: hashicorp/setup-terraform@v3 uses: hashicorp/setup-terraform@v2
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init - name: Terraform Init
@ -44,7 +39,7 @@ jobs:
# Upload results to GitHub Advanced Security # Upload results to GitHub Advanced Security
- name: Upload SARIF file - name: Upload SARIF file
if: success() || failure() if: success() || failure()
uses: github/codeql-action/upload-sarif@v3 uses: github/codeql-action/upload-sarif@v2
with: with:
sarif_file: results.sarif sarif_file: results.sarif
category: checkov category: checkov

View File

@ -19,7 +19,7 @@ This is a sample repository that shows how to use GitHub Actions workflows to ma
1. [**Terraform Unit Tests**](.github/workflows/tf-unit-tests.yml) 1. [**Terraform Unit Tests**](.github/workflows/tf-unit-tests.yml)
This workflow runs on every commit and is composed of a set of unit tests on the infrastructure code. It runs [terraform fmt]( https://www.terraform.io/cli/commands/fmt) to ensure the code is properly linted and follows terraform best practices. Next it performs [terraform validate](https://www.terraform.io/cli/commands/validate) to check that the code is syntactically correct and internally consistent. Lastly, [checkov](https://github.com/bridgecrewio/checkov), an open source static code analysis tool for IaC, will run to detect security and compliance issues. If the repository is utilizing GitHub Advanced Security (GHAS), the results will be uploaded to GitHub. This workflow runs on every commit and is composed of a set of unit tests on the infrastructure code. It runs [terraform fmt]( https://www.terraform.io/cli/commands/fmt) to ensure the code is properly linted and follows terraform best practices. Next it performs [terraform validate](https://www.terraform.io/cli/commands/validate) to check that the code is syntactically correct and internally consistent. Lastly, [checkov](https://github.com/bridgecrewio/checkov), an open source static code analysis tool for IaC, will run to detect security and complaince issues. If the repository is utilizing GitHub Advanced Security (GHAS), the results will be uploaded to GitHub.
2. [**Terraform Plan / Apply**](.github/workflows/tf-plan-apply.yml) 2. [**Terraform Plan / Apply**](.github/workflows/tf-plan-apply.yml)
@ -39,7 +39,7 @@ To use these workflows in your environment several prerequisite steps are requir
2. **Create GitHub Environment** 2. **Create GitHub Environment**
The workflows utilizes GitHub Environments and Secrets to store the azure identity information and setup an approval process for deployments. Create an environment named `production` by following these [instructions](https://docs.github.com/actions/deployment/targeting-different-environments/using-environments-for-deployment#creating-an-environment). On the `production` environment setup a protection rule and add any required approvers you want that need to sign off on production deployments. You can also limit the environment to your main branch. Detailed instructions can be found [here](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#environment-protection-rules). The workflows utilizes GitHub Environments and Secrets to store the azure identity information and setup an approval process for deployments. Create an environment named `production` by following these [insturctions](https://docs.github.com/actions/deployment/targeting-different-environments/using-environments-for-deployment#creating-an-environment). On the `production` environment setup a protection rule and add any required approvers you want that need to sign off on production deployments. You can also limit the environment to your main branch. Detailed instructions can be found [here](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#environment-protection-rules).
3. **Setup Azure Identity**: 3. **Setup Azure Identity**:
@ -72,4 +72,4 @@ To use these workflows in your environment several prerequisite steps are requir
## Additional Resources ## Additional Resources
A companion article detailing how to use GitHub Actions to deploy to Azure using IaC can be found at the [DevOps Resource Center](https://learn.microsoft.com/devops/deliver/iac-github-actions). A companion article detailing how to use GitHub Actions to deploy to Azure using IaC can be found at the [DevOps Resource Center](). `TODO: add link`

19
main.tf
View File

@ -26,3 +26,22 @@ resource "azurerm_resource_group" "rg-aks" {
name = var.resource_group_name name = var.resource_group_name
location = var.location location = var.location
} }
# Sample NSG designed to raise a security alert. Delete for any real deployment.
resource "azurerm_network_security_group" "nsg-fail" {
name = "insecureNSG"
location = azurerm_resource_group.rg-aks.location
resource_group_name = azurerm_resource_group.rg-aks.name
security_rule {
name = "badrule"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}