GitLab Duo Principles - ハンズオンラボ: セキュリティ脆弱性への対応
推定所要時間: 15 分
目標
このラボでは、GitLab Duo がセキュリティ脆弱性の説明と解決にどのように役立つかを確認してください。
タスク A. セキュリティ脆弱性を説明する
GitLab Duo Principles プロジェクトに移動してください。
.gitlab-ci.ymlファイルを選択してください。Edit > Edit in pipeline editor を選択してください。
以前の YAML をすべて削除して、以下のコードを追加してください。
.gitlab-ci.ymlは次のようになっているはずです:stages: - test include: - component: $CI_SERVER_FQDN/components/sast/[email protected]任意のコミットメッセージを入力し、ターゲットブランチを main に設定して、Commit changes を選択してください。
左サイドバーで Code > Repository を選択してください。
main.goを選択してください。Edit > Edit single file を選択してください。
すべてのコードを以下のコードに置き換えてください:
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) }任意のコミットメッセージを入力し、ターゲットブランチを main に設定して、Commit changes を選択してください。
左サイドバーで Build > Pipelines を選択し、パイプラインが完了するまで待ってください。
パイプラインが完了したら、左サイドバーで Secure > Vulnerability Report に移動してください。
レポートに
Slowlorisという 1 つの脆弱性が表示されます。脆弱性「Uncontrolled resource consumption…」を選択してください。
脆弱性の概要ページに移動してください。
脆弱性概要の右上にある Explain or Resolve with AI ドロップダウンを選択してください。
Explain with AI を選択してください。
GitLab Duo が生成した応答を確認して脆弱性を理解してください。
タスク B. 脆弱性を解決する
Duo Chat からの提案を
main.goファイルに適用してください。次のようになっているはずです:
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() }パイプラインを再実行して脆弱性が解決されたことを確認してください。
ラボガイド完了
このラボ演習が完了しました。このコースの他のラボガイドを確認できます。
ご提案
ラボへの変更を提案したい場合は、マージリクエスト経由でご提出ください。
