Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/actionlint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sha256=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8

dir="$(mktemp -d)"
trap 'rm -rf "$dir"' EXIT
curl -fsSL --retry 3 -o "$dir/actionlint.tar.gz" \
curl -fsSL --retry 6 --retry-all-errors --retry-max-time 120 -o "$dir/actionlint.tar.gz" \
"https://github.com/rhysd/actionlint/releases/download/v${version}/actionlint_${version}_linux_amd64.tar.gz"
echo "${sha256} $dir/actionlint.tar.gz" | sha256sum --check --strict -
tar -xzf "$dir/actionlint.tar.gz" -C "$dir" actionlint
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/gitleaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sha256=551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb

dir="$(mktemp -d)"
trap 'rm -rf "$dir"' EXIT
curl -fsSL --retry 3 -o "$dir/gitleaks.tar.gz" \
curl -fsSL --retry 6 --retry-all-errors --retry-max-time 120 -o "$dir/gitleaks.tar.gz" \
"https://github.com/gitleaks/gitleaks/releases/download/v${version}/gitleaks_${version}_linux_x64.tar.gz"
echo "${sha256} $dir/gitleaks.tar.gz" | sha256sum --check --strict -
tar -xzf "$dir/gitleaks.tar.gz" -C "$dir" gitleaks
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/install-helm-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ check() { if command -v sha256sum > /dev/null; then sha256sum --check --strict -
dir="$(mktemp -d)"
trap 'rm -rf "$dir"' EXIT

curl -fsSL --retry 3 -o "$dir/helm.tar.gz" "https://get.helm.sh/helm-v${helm_version}-${platform}.tar.gz"
curl -fsSL --retry 6 --retry-all-errors --retry-max-time 120 -o "$dir/helm.tar.gz" "https://get.helm.sh/helm-v${helm_version}-${platform}.tar.gz"
echo "${helm_sha256} $dir/helm.tar.gz" | check
tar -xzf "$dir/helm.tar.gz" -C "$dir" "${platform}/helm"
install -m 755 "$dir/${platform}/helm" "$bin/helm"

curl -fsSL --retry 3 -o "$dir/kind" "https://github.com/kubernetes-sigs/kind/releases/download/v${kind_version}/kind-${platform}"
curl -fsSL --retry 6 --retry-all-errors --retry-max-time 120 -o "$dir/kind" "https://github.com/kubernetes-sigs/kind/releases/download/v${kind_version}/kind-${platform}"
echo "${kind_sha256} $dir/kind" | check
install -m 755 "$dir/kind" "$bin/kind"

Expand Down
36 changes: 36 additions & 0 deletions .github/scripts/install-iac-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Install the pinned tools the platform templates are checked with into a folder, each checked by sha256 before it is used: the versions
# and checksums are pinned here, never read from the download site at run time. Today that is bicep (deploy/azure-container-apps).
# Usage: install-iac-tools.sh <folder> (Linux x86-64, or macOS on Apple silicon for a local run; then put the folder on PATH)
set -euo pipefail

bicep_version=0.49.2

case "$(uname -s)-$(uname -m)" in
Linux-x86_64)
bicep_asset=bicep-linux-x64
bicep_sha256=0ab9de90c2493f206f8281bae74f9ee2d5ed3605548dab1adf41fef185e1f7c5
;;
Darwin-arm64)
bicep_asset=bicep-osx-arm64
bicep_sha256=8ae74a6cf9cbba0cb220c40cf0e955f98d59df950afab07c21b7bcb78c9c5d68
;;
*) echo "install-iac-tools.sh: no pinned checksums for $(uname -s)-$(uname -m)" >&2; exit 1 ;;
esac

if [[ $# -ne 1 ]]; then echo "Usage: install-iac-tools.sh <folder>" >&2; exit 2; fi
bin="$1"
mkdir -p "$bin"

# sha256sum on Linux, shasum on macOS.
check() { if command -v sha256sum > /dev/null; then sha256sum --check --strict -; else shasum -a 256 --check --strict -; fi; }

dir="$(mktemp -d)"
trap 'rm -rf "$dir"' EXIT

# bicep is one self-contained binary, published on the project's GitHub releases.
curl -fsSL --retry 6 --retry-all-errors --retry-max-time 120 -o "$dir/bicep" "https://github.com/Azure/bicep/releases/download/v${bicep_version}/${bicep_asset}"
echo "${bicep_sha256} $dir/bicep" | check
install -m 755 "$dir/bicep" "$bin/bicep"

"$bin/bicep" --version
39 changes: 39 additions & 0 deletions .github/workflows/templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# The platform templates, checked offline: no cloud account, no sign-in, nothing deployed. Today the Azure Container Apps template
# (deploy/azure-container-apps): bicep lint and build, then its tests (jq on the compiled template and on the resources bicep snapshot
# predicts, and what it refuses), then each test's mutation, which it must catch. bicep is a pinned release, checked by sha256
# (.github/scripts/install-iac-tools.sh); jq is the runner's own. No secrets, a read-only token. Actions are pinned to full commit SHAs.
# Every path here is relative to this repository's root.
name: templates

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: templates-${{ github.ref }}
cancel-in-progress: true

jobs:
templates:
name: templates
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install the pinned bicep (checked by sha256)
run: |
.github/scripts/install-iac-tools.sh "$RUNNER_TEMP/bin"
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
- name: Azure Container Apps template tests (bicep lint and build; what it makes and what it refuses)
run: deploy/azure-container-apps/test-template.sh
- name: Each Azure Container Apps template test catches its mutation
env:
MUTATION_JOBS: "4"
run: deploy/azure-container-apps/test-template.sh --mutations
40 changes: 40 additions & 0 deletions deploy/azure-container-apps/bicepconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"analyzers": {
"core": {
"enabled": true,
"rules": {
"secure-parameter-default": { "level": "error" },
"secure-params-in-nested-deploy": { "level": "error" },
"outputs-should-not-contain-secrets": { "level": "error" },
"use-secure-value-for-secure-inputs": { "level": "error" },
"protect-commandtoexecute-secrets": { "level": "error" },
"no-hardcoded-env-urls": { "level": "error" },
"no-unused-params": { "level": "error" },
"no-unused-vars": { "level": "error" },
"no-unused-existing-resources": { "level": "error" },
"no-unnecessary-dependson": { "level": "error" },
"use-resource-id-functions": { "level": "error" },
"use-stable-resource-identifiers": { "level": "error" },
"use-stable-vm-image": { "level": "error" },
"simplify-interpolation": { "level": "error" },
"prefer-interpolation": { "level": "error" },
"secure-secrets-in-params": { "level": "error" },
"use-recent-api-versions": { "level": "warning" },
"use-resource-symbol-reference": { "level": "error" },
"no-deployments-resources": { "level": "error" },
"no-loc-expr-outside-params": { "level": "error" },
"explicit-values-for-loc-params": { "level": "error" },
"max-outputs": { "level": "error" },
"max-params": { "level": "error" },
"max-resources": { "level": "error" },
"max-variables": { "level": "error" },
"adminusername-should-not-be-literal": { "level": "error" },
"artifacts-parameters": { "level": "error" },
"decompiler-cleanup": { "level": "error" },
"nested-deployment-template-scoping": { "level": "error" },
"use-parent-property": { "level": "error" },
"what-if-short-circuiting": { "level": "error" }
}
}
}
}
37 changes: 37 additions & 0 deletions deploy/azure-container-apps/key-vault-access.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Key Vault Secrets User on named secrets of one existing vault, for one identity: it may read those secrets' values, and no other secret
// in the vault. Deployed to the vault's own resource group by main.bicep. The vault must use Azure role-based access control, and each
// secret must exist before the deploy.

@description('The existing Key Vault.')
param keyVaultName string

@description('The identity\'s resource id, known before the deploy, which names the role assignments.')
param identityId string

@description('The identity\'s principal (object) id.')
param principalId string

@description('The names of the secrets the identity may read.')
param secretNames array

// Key Vault Secrets User, a built-in role: read secrets' values. Not Key Vault Administrator, not Secrets Officer.
var builtInRoleGuid = '4633458b-17de-408a-b874-0445c86b69e6'

resource vault 'Microsoft.KeyVault/vaults@2025-05-01' existing = {
name: keyVaultName
}

resource secrets 'Microsoft.KeyVault/vaults/secrets@2025-05-01' existing = [for s in secretNames: {
parent: vault
name: s
}]

resource secretsUser 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for (s, i) in secretNames: {
name: guid(secrets[i].id, identityId, builtInRoleGuid)
scope: secrets[i]
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', builtInRoleGuid)
principalId: principalId
principalType: 'ServicePrincipal'
}
}]
Loading