?この GitHub アクションを使用して、脅威モデリングとセキュリティ レビュー用の AI 特集コンテンツを生成できます。その下で xvnpw/ai-threat-modeling を使用します。
️ これは実験的なプロジェクトです
サポートされている機能:
特徴 | 説明 |
---|---|
高レベルのセキュリティとプライバシーの要件 | アクションではプロジェクトの説明が取得され、LLM を使用してセキュリティとプライバシーに関する高レベルの要件が生成されます。 |
アーキテクチャの脅威モデル | アクションはアーキテクチャの説明を取得し、LLM を使用してその脅威モデルを生成します。 |
ユーザーストーリーのセキュリティ許容基準 | アクションは特定のユーザー ストーリーを取得し、セキュリティ関連の受け入れ基準を生成します |
入力ファイルのレビュー | アクションは入力ファイル (アーキテクチャ記述など) を受け取り、LLM を使用してレビューします。 |
特定のモデルには以下のバージョンを使用してください。
モデル | バージョン | 注記 |
---|---|---|
OpenAI GPT-3.5、人間クロード 2 | v1.2.6.1 | |
OpenAI GPT-4 | 最新 | |
クロード3 | 最新 |
モデル | 入力 | 出力 |
---|---|---|
OpenAI GPT-3.5 | プロジェクト.md | PROJECT_SECURITY.md またはプル リクエストとして |
人間性クロード 2 | プロジェクト.md | PROJECT_SECURITY.md またはプル リクエストとして |
OpenAI GPT-4 | プロジェクト.md | PROJECT_SECURITY.md またはプル リクエストとして |
人間性クロード 3 作品集 | プロジェクト.md | PROJECT_SECURITY.md またはプル リクエストとして |
モデル | 入力 | 出力 |
---|---|---|
OpenAI GPT-3.5 | アーキテクチャ.md | アーキテクチャ_セキュリティ.md |
人間性クロード 2 | アーキテクチャ.md | アーキテクチャ_セキュリティ.md |
OpenAI GPT-4 | アーキテクチャ.md | アーキテクチャ_セキュリティ.md |
人間性クロード 3 作品集 | アーキテクチャ.md | アーキテクチャ_セキュリティ.md |
モデル | 入力 | 出力 |
---|---|---|
OpenAI GPT-3.5 | 0001_STORE_DIET_INTRODUCTIONS.md または問題 | 0001_STORE_DIET_INTRODUCTIONS_SECURITY.md または問題のコメントとして |
人間性クロード 2 | 0001_STORE_DIET_INTRODUCTIONS.md または問題 | 0001_STORE_DIET_INTRODUCTIONS_SECURITY.md または問題のコメントとして |
OpenAI GPT-4 | 0001_STORE_DIET_INTRODUCTIONS.md または問題 | 0001_STORE_DIET_INTRODUCTIONS_SECURITY.md または問題のコメントとして |
人間性クロード 3 作品集 | 0001_STORE_DIET_INTRODUCTIONS.md または問題 | 0001_STORE_DIET_INTRODUCTIONS_SECURITY.md または問題のコメントとして |
モデル | 入力 | 出力 |
---|---|---|
OpenAI GPT-4 | アーキテクチャ.md | アーキテクチャ_レビュー.md |
人間性クロード 3 作品集 | アーキテクチャ.md | アーキテクチャ_レビュー.md |
次のようなステップをワークフローに追加します。
- uses : xvnpw/[email protected] # You can change this to use a specific version.
with :
# Type of feature, one of: project, architecture, user-story
# Default: ''
# Required
type : ' project '
# Provider name, one of: openai, openrouter
# Default: 'openai'
provider : ' openai '
# Paths to input files formatted as json array
# Default: ''
input_files : ' ["PROJECT.md"] '
# Path to output file
# Default: ''
output_file : ' PROJECT_SECURITY.md '
# For USER STORY only! paths to architecture files formatted as json array
# Default: ''
input_architecture_files : ' ["ARCHITECTURE.md"] '
# For USER STORY only! path to architecture threat model
# Default: ''
input_architecture_threat_model_file : ' ARCHITECTURE_SECURITY.md '
# For USER STORY only! suffix that will be added to input file name to create output file
# Default: '_SECURITY'
user_story_output_suffix : ' _SECURITY '
# Type of OpenAI GPT model
# Default: gpt-4
# For openai models check: https://platform.openai.com/account/rate-limits
# For openrouter models check: https://openrouter.ai/docs#models
model : ' gpt-3.5-turbo-16k '
# Sampling temperature for a model
# Default: 0
temperature : ' 0.3 '
# Review input files using LLM
# Default: false
review : true
# Verbose log messages
# Default: false
verbose : true
# Debug log messages
# Default: false
debug : true
# Prompt templates directory
# Default: '/app/templates'
# By default action will use prompt templates build-in docker image. You can specify your own without forking action.
templates_dir : ' ./templates '
env :
# OpenAI API key
# Optional. Only if want to use openai provider
# Get a key from https://platform.openai.com/account/api-keys
# Add it to secrets in your repository settings
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
# Open Router API key
# Optional. Only if want to use openrouter provider
# Get a key from https://openrouter.ai/keys
# Add it to secrets in your repository settings
OPENROUTER_API_KEY : ${{ secrets.OPENROUTER_API_KEY }}
現在サポートしているもの:
アクションは入力に基づいてoutput_file
を生成します。他のアクションを使用すると、次のことが可能になります。
入力ファイルが非常に大きい場合は、 model
より大きなコンテキストを持つモデル ( gpt-3.5-turbo-16k
など) に変更する必要があります。
入力ファイルを変更する場合は、必ずトリガーを変更してください。
on :
push :
branches :
- main
paths :
- ' project-desc-1.md '
- ' project-desc-2.md '
例 (プルリクエストアプローチ):
on :
push :
branches :
- main
paths :
- ' PROJECT.md '
jobs :
project_ai_devsecops_job :
runs-on : ubuntu-latest
permissions :
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository. Also permission to create/update
# pull requests.
contents : write
pull-requests : write
name : Run ai threat modeling action for project analysis
steps :
- name : Checkout repo
uses : actions/checkout@v3
- name : Generate project security requirements
uses : xvnpw/[email protected]
with :
type : ' project '
input_files : ' ["PROJECT.md"] '
output_file : ' PROJECT_SECURITY.md '
temperature : 0
verbose : true
env :
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
# Will use peter-evans/create-pull-request to create or update pull request
- name : Create Pull Request
uses : peter-evans/create-pull-request@v5
with :
branch : create-pull-request/project
title : (AI Generated) High Level Security and Privacy Requirements
body : Automated pull request based on your changes to project. Please review it carefully.
labels : ' security, ai '
トリガーとモデルの詳細については、高レベルのセキュリティとプライバシーの要件を確認してください。
例 (リポジトリへの直接プッシュ):
on :
push :
branches :
- main
paths :
- ' ARCHITECTURE.md '
jobs :
architecture_ai_tm_job :
runs-on : ubuntu-latest
permissions :
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents : write
name : Will run ai threat modeling action for architecture analysis
steps :
- name : Checkout repo
uses : actions/checkout@v3
- name : Generate architecture threat model
uses : xvnpw/[email protected]
with :
type : ' architecture '
input_files : ' ["ARCHITECTURE.md"] '
output_file : ' ARCHITECTURE_SECURITY.md '
temperature : 0
verbose : true
env :
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
# Will use add-and-commit action to push output_file directly into repository
- name : Commit changes
uses : EndBug/add-and-commit@v9
with :
message : ' Project architecture threat model '
add : ' ARCHITECTURE_SECURITY.md '
最も有用な使用法は、github の問題を使用した場合です。ただし、特定のディレクトリへの変更に基づいて出力を生成することもできます (私は研究でそれを行いました)。
ユーザー ストーリー機能には 2 つの新しいパラメーターが必要です。
input_architecture_files
- 入力アーキテクチャ ファイルのパスの json 配列 例: ["arch-1.md","arch-2.md"]
input_architecture_threat_model_file
- アーキテクチャ脅威モデルへのパス (例: ARCHITECTURE_SECURITY.md
そして 1 つはオプションです:
user_story_output_suffix
- 出力ファイルを作成するために入力ファイル名に追加されるサフィックス (例: _SECURITY
ユーザー ストーリーの場合、特定のディレクトリへの変更時にビルドがトリガーされます。まず、どのファイルが変更されたかを把握し、個別に処理する必要があります。
ご覧のとおり、 input_files
パラメーターは使用しません。今回は、ディレクトリ全体の変更を監視します。
on :
push :
branches :
- main
paths :
- ' user-stories/*.md '
- ' !user-stories/*_SECURITY.md '
独自のディレクトリの場合は、 paths
構成を調整する必要があります。同じことがadd: 'user-stories/'
を使用して変更をコミットする場合にも当てはまります。
例 (リポジトリへの直接プッシュ):
on :
push :
branches :
- main
paths :
- ' user-stories/*.md '
- ' !user-stories/*_SECURITY.md '
jobs :
user_story_ai_tm_job :
runs-on : ubuntu-latest
permissions :
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents : write
name : Will run ai threat modeling action for user story analysis
steps :
- name : Checkout repo
uses : actions/checkout@v3
- name : Check which files were changed
id : files_check
uses : lots0logs/[email protected]
with :
token : ${{ secrets.GITHUB_TOKEN }}
- name : Printing
run : |
echo "${{ steps.files_check.outputs.all }}"
- name : Generate user story security acceptance criteria
uses : xvnpw/[email protected]
with :
type : ' user-story '
input_files : " ${{ steps.files_check.outputs.all }} "
input_architecture_files : ' ["ARCHITECTURE.md"] '
input_architecture_threat_model_file : " ARCHITECTURE_SECURITY.md "
user_story_output_suffix : " _SECURITY "
temperature : 0
verbose : true
model : " gpt-3.5-turbo-16k "
env :
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
- name : Commit changes
uses : EndBug/add-and-commit@v9
with :
message : ' User stories: security acceptance criteria '
add : ' user-stories/ '
この場合、特定のラベルが付いたストーリーのみを考慮します。
if : contains(github.event.issue.labels.*.name, 'ai-threat-modeling')
コメントは、peter-evans/find-comment および Peter-evans/create-or-update-comment アクションを使用して追加 (または更新) されます。
例 (問題に関するコメント):
name : Run ai threat modeling action for user story in issue analysis
on :
issues :
types :
- labeled
- edited
jobs :
user_story_issue_ai_devsecops :
name : Run ai threat modeling action for user story in issue analysis
if : contains(github.event.issue.labels.*.name, 'ai-threat-modeling')
runs-on : ubuntu-latest
permissions :
issues : write
contents : write
steps :
- name : Checkout repo
uses : actions/checkout@v3
- uses : actions/github-script@v6
id : set-result
with :
result-encoding : string
retries : 3
script : |
const issue = await github.rest.issues.get({
issue_number: ${{ github.event.issue.number }},
owner: "${{ github.repository_owner }}",
repo: "${{ github.event.repository.name }}",
});
const body = issue.data.body;
const fs = require('fs');
fs.writeFile('${{ github.workspace }}/issue_body.md', body, (err) => {
if (err) throw err;
console.log('Data written to file');
});
return JSON.stringify(body);
- name : Generate user story security acceptance criteria
uses : xvnpw/[email protected]
with :
type : ' user-story '
input_files : ' ["issue_body.md"] '
input_architecture_files : ' ["ARCHITECTURE.md"] '
input_architecture_threat_model_file : " ARCHITECTURE_SECURITY.md "
temperature : 0
verbose : true
model : " gpt-3.5-turbo-16k "
env :
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
- name : Find Comment
uses : peter-evans/find-comment@v2
id : fc
with :
issue-number : ${{ github.event.issue.number }}
comment-author : ' github-actions[bot] '
body-includes : (AI Generated) Security Related Acceptance Criteria
- name : Add comment
uses : peter-evans/create-or-update-comment@v3
with :
comment-id : ${{ steps.fc.outputs.comment-id }}
issue-number : ${{ github.event.issue.number }}
body-path : ${{ github.workspace }}/issue_body_SECURITY.md
edit-mode : replace
例 (リポジトリへの直接プッシュ):
on :
push :
branches :
- main
paths :
- ' ARCHITECTURE.md '
workflow_dispatch :
jobs :
architecture_ai_review_job :
runs-on : ubuntu-latest
permissions :
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents : write
name : Run ai threat modeling action for architecture review
steps :
- name : Checkout repo
uses : actions/checkout@v3
- name : Generate architecture review
uses : xvnpw/[email protected]
with :
type : ' architecture ' # will create threat model
input_files : ' ARCHITECTURE.md '
output_file : ' ARCHITECTURE_REVIEW.md '
review : true
temperature : 0.2
verbose : true
model : ' gpt-4 '
env :
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
- name : Commit changes
uses : EndBug/add-and-commit@v9
with :
message : ' Project architecture review '
add : ' ARCHITECTURE_REVIEW.md '
pull : ' --rebase --autostash '
Add & Commit を使用すると、 output_file
リポジトリに簡単にコミットできます。
- name : Commit changes
uses : EndBug/add-and-commit@v9
with :
message : ' Project architecture threat model '
add : ' ARCHITECTURE_SECURITY.md '
出力ファイルを変更する場合は、必ずコミット ファイルを変更してください。
- name : Commit changes
uses : EndBug/add-and-commit@v9
with :
message : ' Project security requirements '
add : ' project-sec-reqs.md '
Create Pull Request を使用すると、 output_file
を使用して新しいプル リクエストを作成できます。
- name : Create Pull Request
uses : peter-evans/create-pull-request@v5
with :
branch : create-pull-request/project
title : (AI Generated) High Level Security and Privacy Requirements
body : Automated pull request based on your changes to project. Please review it carefully.
labels : ' security, ai '
このモードでは、ワークフローの権限を調整する必要もあります。
permissions :
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
# It has also permission to pull requests
contents : write
pull-requests : write
アクションの設定も変更します。
プロンプトを調整することもできます。これを行うには、アクションをフォークする必要はありませんが、ターゲット リポジトリにテンプレート ディレクトリを指定します。
cd $HOME / < projects > # your directory with repositories
git clone [email protected]:xvnpw/ai-threat-modeling-action.git
cp -r ai-threat-modeling-action/templates < target-repo > /
cd < target-repo > /templates
# edit templates
ワークフロー ファイルに次を追加します。
uses : xvnpw/[email protected]
with :
...
templates_dir : ' ./templates '
./templates
- <target-repo>
ルートに相対的なディレクトリです。
このプロジェクトは LLM の機能の研究として始まりましたが、時間の経過とともに単純な PoC を超えて改善されました。バージョン 1 では、ダイレクト プッシュ、pr、または Issue を使用して github 内のドキュメントをレビューするために使用できます。今後の開発や修正は保証されません。社内で使用する予定がある場合は、フォークしてニーズに合わせて調整するのが最善です。
このプロジェクトをフォークします。ファイルを編集してアクションをリリースします。
git add .
git commit -m "My first action is ready"
git tag -a -m "My first action release" v1
git push --follow-tags
このプロジェクトはOpenAI APIを使用しています。デフォルトでは、API データ使用ポリシーに従って、データは学習に使用されません。
OpenAI は、お客様がこの目的でデータを当社と共有することを明示的に決定しない限り、当社の API を介して顧客から送信されたデータを使用してモデルをトレーニングまたは改善することはありません。データの共有をオプトインできます。
OpenRouter では、各モデルの設定でプライバシーとフィルタリングについて説明します。