LoginSignup
0
0

More than 1 year has passed since last update.

AzureDevOpsパイプラインで、npmライブラリの脆弱性チェックを定期的に実施する

Last updated at Posted at 2022-05-20

背景

使用しているnpmライブラリにいつの間にか脆弱性が含まれてしまい、それを知らないうちに放置していた。

定期的に脆弱性チェックを行うことで、脆弱性が含まれたことを検知したい。

対応

パイプラインからnpm auditを行う

下記のcommand: 'custom'で指定したディレクトリに対してnpm auditを実施する

    steps:

    # Nodeインストール
    - task: NodeTool@0
      inputs:
        versionSpec: '14.16.0'
      displayName: 'Install Node.js'

    # npm ci
    - script: |
        npm ci
      displayName: 'npm ci'
      workingDirectory:  '$(System.DefaultWorkingDirectory)'

    # 脆弱性high以上が含まれるかチェック
    - task: Npm@1
      inputs:
        command: 'custom'
        workingDir: '$(System.DefaultWorkingDirectory)'
        customCommand: 'audit --registry=https://registry.npmjs.org/ --audit-level=high'
      displayName: 'npm audit'

--registry=https://registry.npmjs.org/このオプションについては、Azure公式Docで必要と記載があるのでつけてます。(registryを明示してあげないといけないっぽい?/デフォルトのregistry指定では動作しない?)

パイプラインを定期的に実行する

下記記載により、パイプラインの定期実行を構成する。

schedules:
- cron: '0 10 * * *'
  displayName: '毎日19:00起動'
  branches:
    include:
    - develop

上記設定後、AzureDevOps > Pipelinesの該当パイプラインの設定から「Scheduled runs」を押下すると、設定を確認することができます。

image.png

npm auditでhigh以上のものを検知すると、パイプライン自体が失敗するようになっています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0