PIXI CRSは雲に行きます-パート3:マイクロソフトAzureデップ


私がピクシーCRSを動かした第2の雲プロバイダーは、マイクロソフトAzureデップです:https://dev.azure.com/.
これは、“Pixi CRSの雲に行く”シリーズの3番目のブログ記事です.
これはPixi - CRSがマイクロソフトAzure devopsパイプラインをどう見るかです.

上記のイメージで、私たちはAzure devopsのPixi CRS CIパイプラインがAzure devops > Pixi CRS >パイプラインとして構成されるのを見ます.

ピクシーCRSパイプラインコード


パイプラインの後ろのコードはhereである.
azure devopsパイプラインコードはazureパイプラインで書かれています.リポジトリのルートディレクトリにあるYMLファイル.Azure devopsに新しいパイプラインプロジェクトを作るのはとても簡単です.
このazureパイプラインをより詳しく見ましょう.YMLファイル.
以下の異なるステップを説明します.しかし、私はまた、提供されたYAMLファイルのコメントに説明をします.
# Azure DevOps azure-pipelines.yml

trigger:
# Branch to trigger
- master

stages:

# Start the OWASP ModSecurity Core Rule Set and Pixi with its DB with docker-compose
# OWASP ModSecurity Core Rule Set Container (Apache Reverse Proxy)
# owasp/modsecurity-crs
# See https://coreruleset.org/
# ModSecurity Tuning:
# See https://www.netnea.com/cms/apache-tutorial-8_handling-false-positives-modsecurity-core-rule-set/
- stage: StartContainersAndTests
  jobs:
  - job: BuildJob
    steps:
      # Debugging
      # - script: pwd
      # - script: ls
      - task: DockerCompose@0
        displayName: Start Pixi and CRS
        inputs:
          containerregistrytype: 'Container Registry'
          dockerComposeFile: '**/docker-compose.yaml'
          action: 'Run a Docker Compose command'
          dockerComposeFileArgs: |
            CRSPORTHTTP=8080
            PROXYLOCATION=http://app:8000/
          dockerComposeCommand: 'up -d'

      # Application Tests with Testcafe
      # skip-js-errors because of: Uncaught Error: Bootstrap tooltips require Tether
      # Another way: https://devexpress.github.io/testcafe/documentation/continuous-integration/azure-devops.html
      # Debugging
      #- script: docker ps
      - script: docker run --volume /home/vsts/work/1/s/testcafe/tests_container_ip/:/tests testcafe/testcafe --skip-js-errors 'chromium:headless --no-sandbox'
        displayName: Run Testcafe Tests without and with CRS

      # Show Full error.log
      - script: docker exec crs cat /var/log/apache2/error.log
        displayName: Show ModSecurity logs

      # ModSecurity Log Analysis:
      # Fail if ModSecurity log is not empty
      # Show ModSecurity logs of Testcafe Tests
      # If not empty -> Repair your application OR
      #              -> ModSecurity Tuning:
      # See https://www.netnea.com/cms/apache-tutorial-8_handling-false-positives-modsecurity-core-rule-set/ OR
      #              -> GitHub issue: https://github.com/SpiderLabs/owasp-modsecurity-crs
      - script: if docker exec crs cat /var/log/apache2/error.log | grep ModSecurity | grep -vi MyEvilWAFTest | grep -v 949110 | grep -v 980130 | grep msg; then echo "False Positive Found! Aborting!" && exit 1 ; else echo "ModSecurity Logs empty. This is good!"; fi
        displayName: Fail if ModSecurity logs are not empty

      # Fail if ModSecurity log does not contain WAF Test String "MyEvilWAFTest"
      # That means CRS is not working properly or test was aborted.
      - script: if docker exec crs cat /var/log/apache2/error.log | grep ModSecurity | grep MyEvilWAFTest; then echo "WAF Test String Found. This is good!"; else echo "WAF Test String not Found! Aborting!" && exit 1; fi
        displayName: Fail if WAF Test String is missing in ModSecurity logs

パイプラインステップ


PIXIとCRSを起動する


私たちはPIXIとCRSを起動します.DockerやDockerをインストールする必要はありません.しかし、例えばDockerComposeFileArgsのようないくつかの設定をする必要があります.
それから、PIXIとCRSをDockerComposeCommandと"CUP - D "で起動します.

テストカフェ


CRSとPIXIが走っているので、テストカフェのテストを行います.今回はTestCafe/TestCafe Dockerコンテナでテストを実行できます.テストは、この容器に簡単に取り付けられることができます.
繰り返しますが、まず、PIXIを直接テストし、PIXをCRSでテストします.また、悪意のある文字列でcrs自体をテストします.WAFがそれをブロックするのを確実にしたいです.
我々のテストのために、我々はTestCafe Docker Containerの中から彼らを呼ぶので、我々はhttp://172.17.0.1:8000とCRSをhttp://172.17.0.1:8080を経てPIXIと呼びます.
そして、これは、TestCafaのテスト出力がどのように見えるかです.

チェック結果


最後に、結果をチェックします.CRS Dockerコンテナ内のmodsecurityログを見てみましょう.
これは、我々が我々の正当なテストでどんな偽陽性でもないことを確実とする重要なステップです.さらに、私たちは、悪意のあるテストが記録されていることを確認します.

トリガー


Pixi CRSはCIパイプラインであり、リポジトリへのすべてのプッシュ後にAzure Devopsパイプラインプロジェクトを実行したいので、プッシュイベントにトリガーを設定する必要があります.
私は、Azureパイプラインの「トリガー:マスター」エントリを通してこれを加えました.YMLファイル.

言及すべき事柄


Pixi CRSはCIパイプラインで、CD部分を構成しませんでした.
このブログの記事では、CI部を見たかっただけです.そして、私はまた、はるかに多くのazure devopsオプションが利用可能であることに気づいています.しかし、このブログ記事のために、私はそれを単純にして、Pixi CRS CI部分に集中したかったです.

ブログ投稿


次のブログ記事では、GoogleクラウドプラットフォームでPixi CRSパイプラインを学びます.