One Step Ahead

プログラミングやエンジニアリング全般について書いていきます

Github Actions で microsoft/setup-msbuild@v1.0.1が失敗する。

はじめに


開発で使用していたWorkflowが年明けくらいから失敗していました。
(自分が気づいたのが、年明けなので実際にいつから失敗していたのか不明です....お恥ずかしい...)   

今日はその修正方法のまとめです。

環境設定


  • OS : windows-latest
  • プロジェクト : .NET Framework

失敗していたworkflow


失敗していた実際のworkflowを簡素化したものは下記の通りです。

name: Dotnet Framework Build Actions

on:
  push:
    branches:
      - master
      - develop/**

jobs:
  build:
    runs-on: windows-latest
    env:
      BUILD_PATH: src\Example.sln

    steps:
      - uses: actions/checkout@v2

      - name: Setup Nuget
        uses: nuget/setup-nuget@v1

      - name: Restore package
        run: nuget restore $env:BUILD_PATH

      - name: Setup MSBuild
        uses: microsoft/setup-msbuild@v1.0.1

      - name: Run Build
        run: msbuild $env:BUILD_PATH -p:Configuration=Release

      - name: Run Test
        run: vstest.console.exe /Platform:x64 src\Tests\Test_**\bin\Release\Test_**.dll

失敗していたStepはSetup MSBuildで,,,

f:id:EaE:20210203003200p:plain

このようなErrorが出力されていて、Setupの段階でBuildが失敗していました。

Errorログの確認


まずはErrorログの確認です。

[原文]
Unable to process command '::add-path::C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin' successfully.

[和訳]
コマンド ::add-path::C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Binを正常に終了できません。

とりあえず、add-pathコマンドが正常終了していないことが分かりました。

[原文]
The add-path command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the ACTIONS_ALLOW_UNSECURE_COMMANDS environment variable to true. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

[和訳]
add-path コマンドは無効になっています。環境ファイルを使用するようにアップグレードするか、ACTIONS_ALLOW_UNSECURE_COMMANDS 環境変数に true を設定して、アンセーフコマンドを実行するようにしてください。詳細は https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ を参照してください。

なんかすでに答えが出ていますが、ACTIONS_ALLOW_UNSECURE_COMMANDS=TRUEの環境変数を設定すればいけそうです。

修正の経緯


GitHub Actions: Deprecating set-env and add-path commandsの内容を見るに,,,

[原文]
A moderate security vulnerability has been identified in the GitHub Actions runner that can allow environment variable and path injection in workflows that log untrusted data to STDOUT. This can result in environment variables being introduced or modified without the intention of the workflow author.

[和訳]
GitHub Actions ランナーに中程度のセキュリティ脆弱性が確認されており、信頼できないデータを STDOUT に記録するワークフローに環境変数やパスインジェクションを許す可能性があります。これにより、ワークフロー作成者の意図せずに環境変数が導入されたり変更されたりする可能性があります。

set-envadd-pathといったコマンドが該当するようです。

Workflowの修正


修正と言ってもやることは単純です。
エラーに示されている通り、環境変数ACTIONS_ALLOW_UNSECURE_COMMANDS: trueを設定するだけです。

name: Dotnet Framework Build Actions

on:
  push:
    branches:
      - master
      - develop/**

jobs:
  build:
    runs-on: windows-latest
    env:
      BUILD_PATH: src\Example.sln
      ACTIONS_ALLOW_UNSECURE_COMMANDS: true

    steps:
      - uses: actions/checkout@v2

      - name: Setup Nuget
        uses: nuget/setup-nuget@v1

      - name: Restore package
        run: nuget restore $env:BUILD_PATH

      - name: Setup MSBuild
        uses: microsoft/setup-msbuild@v1.0.1

      - name: Run Build
        run: msbuild $env:BUILD_PATH -p:Configuration=Release

      - name: Run Test
        run: vstest.console.exe /Platform:x64 src\Tests\Test_**\bin\Release\Test_**.dll

まとめ


  • ACTIONS_ALLOW_UNSECURE_COMMANDS: trueの環境変数を追加する。
  • 信頼できないデータを STDOUT に記録するワークフローコマンドは、明示的に環境変数に設定を追加しないと利用できない。