GitLab Duo Principles - ハンズオンラボ: セキュリティ脆弱性への対応

このハンズオンガイドでは、GitLab Duo を使ってセキュリティ脆弱性を説明する方法を説明します。

推定所要時間: 15 分

目標

このラボでは、GitLab Duo がセキュリティ脆弱性の説明と解決にどのように役立つかを確認してください。

タスク A. セキュリティ脆弱性を説明する

  1. GitLab Duo Principles プロジェクトに移動してください。

  2. .gitlab-ci.yml ファイルを選択してください。

  3. Edit > Edit in pipeline editor を選択してください。

  4. 以前の YAML をすべて削除して、以下のコードを追加してください。.gitlab-ci.yml は次のようになっているはずです:

    stages:
      - test
    
    include:
      - component: $CI_SERVER_FQDN/components/sast/[email protected]
    
  5. 任意のコミットメッセージを入力し、ターゲットブランチを main に設定して、Commit changes を選択してください。

  6. 左サイドバーで Code > Repository を選択してください。

  7. main.go を選択してください。

  8. Edit > Edit single file を選択してください。

  9. すべてのコードを以下のコードに置き換えてください:

    package main
    
    import (
      "net/http"
      "fmt"
    )
    
    func randomGitlab(w http.ResponseWriter, r *http.Request) {
      words := []string{"git", "lab", "repo", "commit", "branch"}
      word := words[rand.Intn(len(words))]
    
      fmt.Fprintf(w, word)
    }
    
    func main() {
      http.HandleFunc("/random", randomGitlab)
      http.ListenAndServe(":8080", nil)
    }
    
  10. 任意のコミットメッセージを入力し、ターゲットブランチを main に設定して、Commit changes を選択してください。

  11. 左サイドバーで Build > Pipelines を選択し、パイプラインが完了するまで待ってください。

  12. パイプラインが完了したら、左サイドバーで Secure > Vulnerability Report に移動してください。

    レポートに Slowloris という 1 つの脆弱性が表示されます。

  13. 脆弱性「Uncontrolled resource consumption…」を選択してください。

    脆弱性の概要ページに移動してください。

  14. 脆弱性概要の右上にある Explain or Resolve with AI ドロップダウンを選択してください。

  15. Explain with AI を選択してください。

  16. GitLab Duo が生成した応答を確認して脆弱性を理解してください。

タスク B. 脆弱性を解決する

  1. Duo Chat からの提案を main.go ファイルに適用してください。

  2. 次のようになっているはずです:

    package main
    
    import (
      "net/http"
      "fmt"
      "math/rand"
      "time"
    )
    
    func randomGitlab(w http.ResponseWriter, r *http.Request) {
      words := []string{"git", "lab", "repo", "commit", "branch"}
      word := words[rand.Intn(len(words))]
    
      fmt.Fprintf(w, word)
    }
    
    
    func main() {
    
        http.HandleFunc("/random", randomGitlab)
        // Create a new HTTP server with timeout configurations
        server := &http.Server{
            Addr:           ":8080",
            ReadTimeout:    10 * time.Second,
            WriteTimeout:   10 * time.Second,
            MaxHeaderBytes: 1 << 20, // 1 MB
        }
    
        // Start the server
        server.ListenAndServe()
    
    }
    
  3. パイプラインを再実行して脆弱性が解決されたことを確認してください。

ラボガイド完了

このラボ演習が完了しました。このコースの他のラボガイドを確認できます。

ご提案

ラボへの変更を提案したい場合は、マージリクエスト経由でご提出ください。