diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ae9dd054..e8e2c963 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,6 +20,16 @@ updates: interval: "daily" time: "04:00" timezone: "America/Los_Angeles" + # Hold public-registry version updates for a few days so a malicious or yanked release is + # likely to be caught upstream before it is auto-merged. Security updates ignore cooldown. + # Our own packages are exempt so book content still ships the next day: ContentFeedNuget (private + # feed) and EssentialCSharp.Shared.Models (nuget.org) share $(ToolingPackagesVersion) and move together. + cooldown: + default-days: 3 + semver-major-days: 7 + exclude: + - "ContentFeedNuget" + - "EssentialCSharp.Shared.Models" groups: tooling-dependencies: applies-to: version-updates @@ -36,6 +46,9 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" + # github-actions supports only default-days (no semver-*-days). + cooldown: + default-days: 3 ignore: # gh-aw action pins are compiler-managed and updated with workflow source updates/recompilation. - dependency-name: "github/gh-aw-actions/*" @@ -44,6 +57,9 @@ updates: directory: "/EssentialCSharp.Web/" schedule: interval: "weekly" + cooldown: + default-days: 3 + semver-major-days: 7 - package-ecosystem: "docker" # Look for a `Dockerfile` in the `root` directory diff --git a/.github/workflows/Automerge-ContentNugetFeed.yml b/.github/workflows/Automerge-ContentNugetFeed.yml index cd2f68fb..db5b731b 100644 --- a/.github/workflows/Automerge-ContentNugetFeed.yml +++ b/.github/workflows/Automerge-ContentNugetFeed.yml @@ -1,33 +1,62 @@ name: Dependabot auto-merge on: pull_request +# Every privileged call below uses BOT_PAT; the workflow token needs nothing beyond read. permissions: - contents: write - pull-requests: write + contents: read jobs: dependabot: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} + # Act only when Dependabot opened the PR, Dependabot's own push started this run, and a re-run + # by anyone else (github.triggering_actor) cannot reuse Dependabot's actor identity. + if: >- + github.event.pull_request.user.login == 'dependabot[bot]' && + github.actor == 'dependabot[bot]' && + github.triggering_actor == 'dependabot[bot]' && + github.event.pull_request.head.repo.full_name == github.repository steps: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v3 + uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 with: github-token: ${{ secrets.BOT_PAT }} + + # Approve and merge only the commit this run was triggered for. If anything was pushed to the + # branch after Dependabot's commit, stop instead of approving someone else's code. + - name: Verify the PR head is still the triggering commit + env: + GH_TOKEN: ${{ secrets.BOT_PAT }} + PR_URL: ${{ github.event.pull_request.html_url }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + live_head="$(gh pr view "$PR_URL" --json headRefOid --jq .headRefOid)" + if [ "$live_head" != "$HEAD_SHA" ]; then + echo "::error::PR head is $live_head, but this run was triggered for $HEAD_SHA. Not approving." + exit 1 + fi + - name: Add a label for content updates - if: ${{contains(steps.metadata.outputs.dependency-names, 'ContentFeedNuget')}} + if: ${{ contains(steps.metadata.outputs.dependency-names, 'ContentFeedNuget') }} run: gh pr edit "$PR_URL" --add-label "content update" env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{ secrets.BOT_PAT }} - - name: Approve a PR - run: gh pr review --approve "$PR_URL" + PR_URL: ${{ github.event.pull_request.html_url }} + GH_TOKEN: ${{ secrets.BOT_PAT }} + + - name: Approve the triggering commit env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.BOT_PAT}} - - name: Enable auto-merge for Dependabot PRs - run: gh pr merge --auto --squash --delete-branch "$PR_URL" + GH_TOKEN: ${{ secrets.BOT_PAT }} + PR_NUMBER: ${{ github.event.pull_request.number }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + gh api --method POST "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews" \ + -f commit_id="$HEAD_SHA" \ + -f event=APPROVE \ + -f body="Auto-approved Dependabot update at ${HEAD_SHA}." + + - name: Enable auto-merge for the triggering commit env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.BOT_PAT}} + GH_TOKEN: ${{ secrets.BOT_PAT }} + PR_URL: ${{ github.event.pull_request.html_url }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: gh pr merge --auto --squash --delete-branch --match-head-commit "$HEAD_SHA" "$PR_URL" diff --git a/.github/workflows/Build-Test-And-Deploy.yml b/.github/workflows/Build-Test-And-Deploy.yml index cc8f514b..a6771b69 100644 --- a/.github/workflows/Build-Test-And-Deploy.yml +++ b/.github/workflows/Build-Test-And-Deploy.yml @@ -29,7 +29,7 @@ jobs: - windows-latest steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Verify Node version matches the Docker build shell: bash @@ -42,7 +42,7 @@ jobs: fi - name: Set up Node.js - uses: actions/setup-node@v7.1.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: EssentialCSharp.Web/.nvmrc cache: npm @@ -59,7 +59,7 @@ jobs: # The .NET jobs build with SkipFrontendBuild; the browser journey tests need the compiled frontend. - name: Upload frontend build if: matrix.runner == 'ubuntu-latest' - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: frontend-dist path: EssentialCSharp.Web/wwwroot/dist @@ -73,35 +73,65 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 environment: "BuildAndUploadImage" + permissions: + contents: read + id-token: write # OIDC sign-in for the private NuGet feed; unused until AZURE_DEVOPS_FEED_CLIENT_ID is set + env: + # Private-feed auth: OIDC when vars.AZURE_DEVOPS_FEED_CLIENT_ID is set, else AZURE_DEVOPS_PAT. + # Remove the PAT fallback once OIDC has worked on main. + FEED_AUTH_MODE: ${{ vars.AZURE_DEVOPS_FEED_CLIENT_ID != '' && 'oidc' || 'pat' }} steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up .NET Core - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json - source-url: https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json - env: - NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }} + # Distinct prefix: this cache holds private-feed packages, so PR jobs (prefix *-nuget-public-) + # must never restore it by prefix fallback. - name: Set up dependency caching for faster builds - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: nuget-cache with: path: | ~/.nuget/packages ${{ github.workspace }}/**/obj/project.assets.json - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + key: ${{ runner.os }}-nuget-feed-${{ hashFiles('**/packages.lock.json') }} restore-keys: | - ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-feed- + + - name: Azure login for the private NuGet feed (restore) + if: env.FEED_AUTH_MODE == 'oidc' + uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0 + with: + client-id: ${{ vars.AZURE_DEVOPS_FEED_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + allow-no-subscriptions: true + + # Credentials-only user-level NuGet.Config; the repo nuget.config supplies the sources. + # It sits outside the Docker build context and is deleted right after restore. + - name: Write NuGet feed credentials + env: + AZURE_DEVOPS_PAT: ${{ env.FEED_AUTH_MODE == 'pat' && secrets.AZURE_DEVOPS_PAT || '' }} + run: | + NUGET_FEED_TOKEN="$(bash scripts/nuget/get-feed-token.sh)" + export NUGET_FEED_TOKEN + mkdir -p ~/.nuget/NuGet + bash scripts/nuget/emit-creds-config.sh > ~/.nuget/NuGet/NuGet.Config + chmod 600 ~/.nuget/NuGet/NuGet.Config + echo "Private feed auth mode: ${FEED_AUTH_MODE}" - name: Restore with dotnet run: dotnet restore + - name: Remove NuGet feed credentials + if: always() + run: rm -f ~/.nuget/NuGet/NuGet.Config + - name: Download frontend build - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: frontend-dist path: EssentialCSharp.Web/wwwroot/dist @@ -113,7 +143,7 @@ jobs: run: pwsh dev/EssentialCSharp.Web.AppHost.Tests/bin/Release/net10.0/playwright.ps1 install --with-deps chromium - name: Expose GitHub Actions Runtime - uses: actions/github-script@v9 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN']); @@ -124,7 +154,7 @@ jobs: - name: Upload Playwright failure captures if: failure() - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: playwright-captures-${{ github.run_attempt }} path: dev/EssentialCSharp.Web.AppHost.Tests/bin/Release/net10.0/playwright-artifacts @@ -132,29 +162,42 @@ jobs: retention-days: 7 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 id: buildx + # Credentialed build: its NuGet cache mount holds private-feed packages, so it uses the + # buildkit-cache-feed- prefix. PR builds use buildkit-cache-public- and never fall back to it. - name: Restore BuildKit cache mounts - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: buildkit-cache with: path: buildkit-cache - key: buildkit-cache-${{ hashFiles('EssentialCSharp.Web/Dockerfile', 'Directory.Packages.props', '**/*.csproj', 'EssentialCSharp.Web/package-lock.json') }} - restore-keys: buildkit-cache- + key: buildkit-cache-feed-${{ hashFiles('EssentialCSharp.Web/Dockerfile', 'Directory.Packages.props', '**/*.csproj', 'EssentialCSharp.Web/package-lock.json') }} + restore-keys: buildkit-cache-feed- - name: Inject BuildKit cache mounts - uses: reproducible-containers/buildkit-cache-dance@v3 + uses: reproducible-containers/buildkit-cache-dance@5422eac04292c961a382e0f584ea0f03ad9da723 # v3.4.0 with: builder: ${{ steps.buildx.outputs.name }} dockerfile: EssentialCSharp.Web/Dockerfile cache-dir: buildkit-cache skip-extraction: false + # Sign in again: the GitHub OIDC assertion from the first login may have expired by now. + - name: Azure login for the private NuGet feed (container build) + if: env.FEED_AUTH_MODE == 'oidc' + uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0 + with: + client-id: ${{ vars.AZURE_DEVOPS_FEED_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + allow-no-subscriptions: true + - name: Generate Docker NuGet credentials config env: - NUGET_FEED_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }} + AZURE_DEVOPS_PAT: ${{ env.FEED_AUTH_MODE == 'pat' && secrets.AZURE_DEVOPS_PAT || '' }} run: | + NUGET_FEED_TOKEN="$(bash scripts/nuget/get-feed-token.sh)" + export NUGET_FEED_TOKEN mkdir -p "${RUNNER_TEMP}/nuget" bash scripts/nuget/emit-creds-config.sh > "${RUNNER_TEMP}/nuget/NuGet.Config" chmod 600 "${RUNNER_TEMP}/nuget/NuGet.Config" @@ -162,7 +205,7 @@ jobs: # Only build for dev registry — prod gets the image via az acr import in deploy-production - name: Build Container Image if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request' - uses: docker/build-push-action@v7 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: tags: ${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb:${{ github.sha }},${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb:latest file: ./EssentialCSharp.Web/Dockerfile @@ -178,8 +221,14 @@ jobs: if: always() run: rm -f "${RUNNER_TEMP}/nuget/NuGet.Config" + - name: Sign out of Azure + if: always() && env.FEED_AUTH_MODE == 'oidc' + run: | + az logout || true + az account clear || true + - name: Upload artifact - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: essentialcsharpwebimage path: ${{ github.workspace }}/essentialcsharpwebimage.tar @@ -202,23 +251,23 @@ jobs: collect_coverage: false steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up .NET - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json - name: Set up NuGet cache - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | ~/.nuget/packages ${{ github.workspace }}/**/obj/project.assets.json - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + # No private-feed packages here; *-nuget-public- never matches the credentialed *-nuget-feed- caches. + key: ${{ runner.os }}-nuget-public-${{ hashFiles('**/packages.lock.json') }} restore-keys: | - ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-public- - name: Restore .NET dependencies run: dotnet restore /p:AccessToNugetFeed=false @@ -226,7 +275,7 @@ jobs: # Browser journey tests need Linux containers, so they only run on the Ubuntu leg (skipped elsewhere). - name: Download frontend build if: matrix.collect_coverage - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: frontend-dist path: EssentialCSharp.Web/wwwroot/dist @@ -250,7 +299,7 @@ jobs: - name: Expose GitHub Actions Runtime if: matrix.collect_coverage - uses: actions/github-script@v9 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN']); @@ -266,7 +315,7 @@ jobs: - name: Upload Playwright failure captures if: ${{ failure() && matrix.collect_coverage }} - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: playwright-captures-${{ github.run_attempt }} path: dev/EssentialCSharp.Web.AppHost.Tests/bin/Release/net10.0/playwright-artifacts @@ -275,7 +324,7 @@ jobs: - name: Convert TRX to VS Playlist if: ${{ failure() && matrix.collect_coverage }} - uses: BenjaminMichaelis/trx-to-vsplaylist@v5 + uses: BenjaminMichaelis/trx-to-vsplaylist@e8d6bf4721d96b95a5de0a4c0b302c09be97abaa # v5 with: trx-file-path: '${{ runner.temp }}/*.trx' output-directory: '${{ runner.temp }}/vsplaylists' @@ -288,22 +337,24 @@ jobs: timeout-minutes: 30 steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 id: buildx + # Uncredentialed build: only ever restore buildkit-cache-public- entries (this PR's own), never + # main's credentialed buildkit-cache-feed- entries or the legacy buildkit-cache- ones. - name: Restore BuildKit cache mounts - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: buildkit-cache with: path: buildkit-cache - key: buildkit-cache-${{ hashFiles('EssentialCSharp.Web/Dockerfile', 'Directory.Packages.props', '**/*.csproj', 'EssentialCSharp.Web/package-lock.json') }} - restore-keys: buildkit-cache- + key: buildkit-cache-public-${{ hashFiles('EssentialCSharp.Web/Dockerfile', 'Directory.Packages.props', '**/*.csproj', 'EssentialCSharp.Web/package-lock.json') }} + restore-keys: buildkit-cache-public- - name: Inject BuildKit cache mounts - uses: reproducible-containers/buildkit-cache-dance@v3 + uses: reproducible-containers/buildkit-cache-dance@5422eac04292c961a382e0f584ea0f03ad9da723 # v3.4.0 with: builder: ${{ steps.buildx.outputs.name }} dockerfile: EssentialCSharp.Web/Dockerfile @@ -311,7 +362,7 @@ jobs: skip-extraction: ${{ steps.buildkit-cache.outputs.cache-hit }} - name: Build container image - uses: docker/build-push-action@v7 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: file: ./EssentialCSharp.Web/Dockerfile context: . @@ -337,19 +388,22 @@ jobs: permissions: id-token: write contents: read + outputs: + # Registry manifest digest of the image this run built and pushed; production promotes exactly this. + image-digest: ${{ steps.push.outputs.digest }} steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Azure Login - uses: azure/login@v3 + uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Download artifact - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: essentialcsharpwebimage path: ${{ github.workspace }} @@ -365,11 +419,35 @@ jobs: az acr login --name "${REGISTRY%.azurecr.io}" - name: Push Image to Dev Container Registry - run: docker push --all-tags ${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb + id: push + env: + DEV_ACR: ${{ vars.DEVCONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }} + run: | + REPO="${DEV_ACR}/essentialcsharpweb" + docker push --all-tags "$REPO" + + # Digest of what this job just pushed, from the local image (not re-read through a mutable tag). + DIGEST="$(docker image inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "${REPO}:${IMAGE_TAG}" \ + | sed -n "s|^${REPO}@||p" | sort -u)" + if ! [[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then + echo "::error::Could not determine a single pushed digest for ${REPO}:${IMAGE_TAG} (got '${DIGEST}')" + exit 1 + fi + + # The registry's tag must point at the same manifest; anything else means it moved underneath us. + REGISTRY_DIGEST="$(az acr repository show --name "${DEV_ACR%.azurecr.io}" \ + --image "essentialcsharpweb:${IMAGE_TAG}" --query digest --output tsv)" + if [ "$REGISTRY_DIGEST" != "$DIGEST" ]; then + echo "::error::Dev ACR tag ${IMAGE_TAG} points to ${REGISTRY_DIGEST}, but this job pushed ${DIGEST}" + exit 1 + fi + echo "Pushed ${REPO}@${DIGEST}" + echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT" - name: Run database migrations env: - MIGRATION_IMAGE: ${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb:${{ github.sha }} + MIGRATION_IMAGE: ${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb@${{ steps.push.outputs.digest }} MIGRATION_JOB_NAME: ${{ vars.MIGRATION_JOB_NAME }} RESOURCEGROUP: ${{ vars.RESOURCEGROUP }} run: bash scripts/run-ef-migration-job.sh @@ -382,13 +460,13 @@ jobs: az containerapp update \ --name "$CONTAINER_APP_NAME" \ --resource-group "$RESOURCEGROUP" \ - --image "${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb:${{ github.sha }}" + --image "${{ vars.DEVCONTAINER_REGISTRY }}/essentialcsharpweb@${{ steps.push.outputs.digest }}" # Smoke tests stay in this job so it holds the deploy-development concurrency group (no image swap mid-test); # deploy-production needs this job, so a failure blocks promotion. # Prep runs before the revision wait so it overlaps with the new revision starting up. - name: Set up .NET - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json @@ -430,7 +508,7 @@ jobs: - name: Upload smoke test results if: failure() - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: smoke-test-results path: | @@ -440,7 +518,7 @@ jobs: - name: Logout of Azure CLI if: always() - uses: azure/CLI@v3 + uses: azure/CLI@9eb25b8360668fb0ecbafa808d40e2197b2f5f52 # v3.0.0 with: inlineScript: | az logout @@ -463,39 +541,48 @@ jobs: actions: write steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Azure Login - uses: azure/login@v3 + uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} # Server-side copy from dev ACR to prod ACR — no artifact download needed. + # Promotes by the digest deploy-development pushed (dev tags are mutable) and fails unless prod + # ends up with that exact manifest. Later steps deploy and verify against this built digest. # PREREQUISITE: prod OIDC identity must have AcrPull on the dev ACR (Terraform RBAC). - name: Import image from dev ACR to prod ACR id: import + env: + DEV_ACR: ${{ vars.DEVCONTAINER_REGISTRY }} + PROD_ACR: ${{ vars.PRODCONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }} + BUILT_DIGEST: ${{ needs.deploy-development.outputs.image-digest }} run: | - DEV_ACR="${{ vars.DEVCONTAINER_REGISTRY }}" - PROD_ACR="${{ vars.PRODCONTAINER_REGISTRY }}" + if ! [[ "$BUILT_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then + echo "::error::deploy-development did not provide a valid image digest (got '${BUILT_DIGEST}')" + exit 1 + fi az acr import \ --name "${PROD_ACR%.azurecr.io}" \ - --source "${DEV_ACR}/essentialcsharpweb:${{ github.sha }}" \ - --image "essentialcsharpweb:${{ github.sha }}" \ + --source "${DEV_ACR}/essentialcsharpweb@${BUILT_DIGEST}" \ + --image "essentialcsharpweb:${IMAGE_TAG}" \ --image "essentialcsharpweb:latest" \ --force - DIGEST=$(az acr repository show \ + PROD_DIGEST=$(az acr repository show \ --name "${PROD_ACR%.azurecr.io}" \ - --image "essentialcsharpweb:${{ github.sha }}" \ + --image "essentialcsharpweb:${IMAGE_TAG}" \ --query "digest" -o tsv) - if [ -z "$DIGEST" ]; then - echo "::error::Failed to capture image digest from prod ACR after import" + if [ "$PROD_DIGEST" != "$BUILT_DIGEST" ]; then + echo "::error::Prod ACR tag ${IMAGE_TAG} points to '${PROD_DIGEST}', expected the built digest ${BUILT_DIGEST}" exit 1 fi - echo "digest=$DIGEST" >> $GITHUB_OUTPUT + echo "digest=${BUILT_DIGEST}" >> "$GITHUB_OUTPUT" - name: Run database migrations env: @@ -543,7 +630,7 @@ jobs: curl --fail --retry 10 --retry-delay 15 --retry-all-errors --max-time 30 "https://$FQDN/health" - name: Cancel pending deployment workflow runs - uses: actions/github-script@v9 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | // Cancel pending workflow runs queued from earlier commits. @@ -609,7 +696,7 @@ jobs: - name: Logout of Azure CLI if: always() - uses: azure/CLI@v3 + uses: azure/CLI@9eb25b8360668fb0ecbafa808d40e2197b2f5f52 # v3.0.0 with: inlineScript: | az logout diff --git a/.github/workflows/Build-Vector-DB.yml b/.github/workflows/Build-Vector-DB.yml index 45c71c31..eb98c6fa 100644 --- a/.github/workflows/Build-Vector-DB.yml +++ b/.github/workflows/Build-Vector-DB.yml @@ -10,9 +10,9 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python 3.8 - uses: actions/setup-python@v7 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.8 - name: Install dependencies diff --git a/.github/workflows/Scheduled-Smoke-Test-Development.yml b/.github/workflows/Scheduled-Smoke-Test-Development.yml index 575d0e54..cddbfd01 100644 --- a/.github/workflows/Scheduled-Smoke-Test-Development.yml +++ b/.github/workflows/Scheduled-Smoke-Test-Development.yml @@ -28,10 +28,10 @@ jobs: actions: read steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up .NET - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json @@ -56,7 +56,7 @@ jobs: - name: Upload smoke test results if: failure() - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: smoke-test-results path: | diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e0a399ff..f624d9bf 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -30,32 +30,32 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v4 + uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: languages: ${{ matrix.language }} build-mode: none queries: security-and-quality - name: Set up .NET Core - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json - name: Set up dependency caching for faster builds - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: nuget-cache with: path: | ~/.nuget/packages ${{ github.workspace }}/**/obj/project.assets.json - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + # No private-feed packages here; *-nuget-public- never matches the credentialed *-nuget-feed- caches. + key: ${{ runner.os }}-nuget-public-${{ hashFiles('**/packages.lock.json') }} restore-keys: | - ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-public- - name: Restore with dotnet run: | @@ -63,7 +63,7 @@ jobs: dotnet build --configuration Release --no-restore --no-incremental /p:AccessToNugetFeed=false /p:SkipFrontendBuild=true - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v4 + uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: category: "/language:${{matrix.language}}" @@ -83,19 +83,19 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v4 + uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: languages: ${{ matrix.language }} queries: security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@v4 + uses: github/codeql-action/autobuild@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v4 + uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index afa4a73a..0a4015c0 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -19,10 +19,10 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up .NET Core - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: global-json-file: global.json source-url: https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json @@ -30,26 +30,26 @@ jobs: NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }} - name: Set up Node.js for frontend development - uses: actions/setup-node@v7.1.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: EssentialCSharp.Web/.nvmrc cache: npm cache-dependency-path: EssentialCSharp.Web/package-lock.json - name: Set up dependency caching for faster builds - uses: actions/cache@v6 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: nuget-cache with: path: | ~/.nuget/packages ${{ github.workspace }}/**/obj/project.assets.json - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + # Restored with private-feed credentials: keep it apart from the *-nuget-public- caches PR jobs use. + key: ${{ runner.os }}-nuget-feed-${{ hashFiles('**/packages.lock.json') }} restore-keys: | - ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - ${{ runner.os }}-nuget- + ${{ runner.os }}-nuget-feed- - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - name: Install additional development tools shell: bash diff --git a/scripts/nuget/get-feed-token.sh b/scripts/nuget/get-feed-token.sh new file mode 100644 index 00000000..a9e713f4 --- /dev/null +++ b/scripts/nuget/get-feed-token.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Prints a token that can read the private Azure Artifacts feed, masked for GitHub Actions logs. +# +# FEED_AUTH_MODE=oidc: an Entra access token for Azure DevOps from the current `az login` +# (azure/login with OIDC must have run in an earlier step of the same job). +# FEED_AUTH_MODE=pat (default): the legacy personal access token in AZURE_DEVOPS_PAT. +set -euo pipefail + +# Azure DevOps resource (application) ID; the same for every organization. +readonly AZURE_DEVOPS_RESOURCE="499b84ac-1321-427f-aa17-267ca6975798" + +mode="${FEED_AUTH_MODE:-pat}" +case "${mode}" in + oidc) + token="$(az account get-access-token --resource "${AZURE_DEVOPS_RESOURCE}" --query accessToken --output tsv)" + ;; + pat) + token="${AZURE_DEVOPS_PAT:-}" + ;; + *) + echo "get-feed-token.sh: unknown FEED_AUTH_MODE '${mode}' (expected oidc or pat)" >&2 + exit 1 + ;; +esac + +if [[ -z "${token}" ]]; then + echo "get-feed-token.sh: no feed token available for FEED_AUTH_MODE=${mode}" >&2 + exit 1 +fi + +if [[ -n "${GITHUB_ACTIONS:-}" ]]; then + # Stderr, so the mask command never ends up in a captured token. + echo "::add-mask::${token}" >&2 +fi +printf '%s' "${token}"