
AIエージェントの行動境界に対するポータブルなセキュリティルール
AIエージェントセキュリティルールのためのポータブルなオープン仕様
仕様 · ドキュメント · ルールセット · JSON Schema
HushSpecは、AIエージェントセキュリティルールのためのオープンポリシーフォーマットです。ファイルシステムアクセス、ネットワークエグレス、ツール利用、シークレット検出など、エージェントが実行時に何をしてよいかを定義します。これらの制御をどのように強制するかは規定しません。この分離により、ポリシーはランタイム、フレームワーク、言語を問わず移植可能になります。
v0.1.1-alpha — コア仕様、4つのSDK(Rust、TypeScript、Python、Go)、およびh2h CLIが公開され、機能しています。パース、検証、評価、マージ、解決、検出、署名、監査の各機能を10のルールタイプと3の拡張モジュールで実行できます。APIサーフェスは安定化しつつありますが、まだ凍結されていません。v1.0までに改良が予定されています。
hushspec: "0.1.0"
name: production-agent
rules:
forbidden_paths:
patterns:
- "**/.ssh/**"
- "**/.aws/**"
- "/etc/shadow"
egress:
allow:
- "api.openai.com"
- "*.anthropic.com"
- "api.github.com"
default: block
tool_access:
block: [shell_exec, run_command]
require_confirmation: [file_write, git_push]
default: allow
secret_patterns:
patterns:
- name: aws_key
pattern: "AKIA[0-9A-Z]{16}"
severity: critical
skip_paths: ["**/test/**"]
shell_commands:
forbidden_patterns:
- "rm\\s+-rf\\s+/"
- "curl.*\\|.*bash"
4つのSDKはすべて、パースと検証から解決と評価に至るHushSpecパイプライン全体を実装しています。
Homebrew、npm、ビルド済みバイナリは、リリースパイプラインが最初の
v0.xタグでビルドされ、アーティファクト、tap formula、npmパッケージが公開された時点から利用可能になります。それまではCargo経由でインストールしてください。
すべての方法でh2hコマンドがインストールされます。下のCLIツールを参照してください。
[dependencies]
hushspec = "0.1"
npm install @hushspec/core
pip install hushspec
go get github.com/backbay-labs/hush/packages/go@main
use hushspec::HushSpec;
let yaml_str = "hushspec: \"0.1.0\"\nname: example\n";
let spec = HushSpec::parse(yaml_str)?;
let result = hushspec::validate(&spec);
assert!(result.is_valid());
import { parseOrThrow, validate } from '@hushspec/core';
const yamlString = 'hushspec: "0.1.0"\nname: example\n';
const spec = parseOrThrow(yamlString);
const result = validate(spec);
console.log(result.valid); // true
from hushspec import parse_or_raise, validate
yaml_string = 'hushspec: "0.1.0"\nname: example\n'
spec = parse_or_raise(yaml_string)
result = validate(spec)
assert result.is_valid
import (
"fmt"
"github.com/backbay-labs/hush/packages/go/hushspec"
)
yamlString := "hushspec: \"0.1.0\"\nname: example\n"
spec, err := hushspec.Parse(yamlString)
if err != nil {
panic(err)
}
result := hushspec.Validate(spec)
fmt.Println(result.IsValid())
各SDKは、パース済みのスペックとアクションを受け取り、決定(allow、warn、deny)と一致したルールの詳細を返すevaluate()関数を公開しています。
import { parseOrThrow, evaluate } from '@hushspec/core';
const spec = parseOrThrow(policyYaml);
const result = evaluate(spec, { type: 'egress', target: 'api.openai.com' });
// result.decision === 'allow' | 'warn' | 'deny'
// result.matched_rule === 'egress'
from hushspec import parse_or_raise, evaluate
spec = parse_or_raise(policy_yaml)
result = evaluate(spec, {"type": "egress", "target": "api.openai.com"})
assert result.decision in ("allow", "warn", "deny")
HushGuardは、ポリシーの読み込みと評価を、アプリケーションコード向けのシンプルなevaluate、check、enforceインターフェースの背後にラップします。
import { HushGuard } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
guard.enforce({ type: 'tool_call', target: 'bash' }); // 拒否された場合はHushSpecDeniedをスロー
from hushspec import HushGuard
guard = HushGuard.from_file("./policy.yaml")
guard.enforce({"type": "tool_call", "target": "bash"}) # 拒否された場合はHushSpecDeniedを送出
h2h CLIは、一般的なポリシーワークフロー(検証、テスト、単一アクションの評価と説明、lint、差分、フォーマット、初期化、署名、検証、パニックモードのトリガー)をカバーしています。
# HushSpecスキーマに対してポリシーを検証
h2h validate policy.yaml
# 評価テストスイートを実行
h2h test --fixtures ./tests/
# 1つのアクションを評価し、決定を説明
h2h eval policy.yaml --type egress --target api.example.com
h2h explain policy.yaml --type egress --target api.example.com
# 静的解析とlint
h2h lint policy.yaml
# lintと決定に影響しない問題の自動修正
h2h lint policy.yaml --fix
# 2つのポリシーを比較し、実効的な決定の変更を表示
h2h diff old.yaml new.yaml
# ポリシーファイルを標準形式にフォーマット
h2h fmt policy.yaml
# 新しいポリシープロジェクトをスキャフォールド
h2h init --preset default
# Ed25519でポリシーに署名
h2h sign policy.yaml --key h2h.key
# ポリシーの署名を検証
h2h verify policy.yaml --key h2h.pub
# 新しいEd25519鍵ペアを生成
h2h keygen
# 緊急オーバーライド(全拒否のキルスイッチ)
h2h panic activate --sentinel /tmp/hushspec.panic
h2h panic deactivate --sentinel /tmp/hushspec.panic
インストールオプションについては、上のインストールを参照してください(Homebrew、npm、Cargo、ビルド済みバイナリ)。
evaluate_audited()は、ルールトレース、ポリシーサマリー、オプションのコンテンツ秘匿を含む構造化された決定レシートを生成します。レシートはhushspec-receipt.v0.schema.jsonに準拠し、SOC 2、HIPAA、PCI-DSS、FedRAMPなどの監査重視の環境をサポートするように設計されています。
import { parseOrThrow, evaluateAudited } from '@hushspec/core';
const spec = parseOrThrow(policyYaml);
const receipt = evaluateAudited(spec, action, {
enabled: true,
include_rule_trace: true,
redact_content: false,
});
// receipt.decision, receipt.rule_evaluations, receipt.policy_summary
レシートシンク(FileReceiptSink、ConsoleReceiptSink、FilteredSink、MultiSink、CallbackSink)は4つのSDKすべてで利用可能で、レシートをストレージ、ログ、またはOTLPエンドポイントにルーティングできます。
検出パイプラインは、プロンプトインジェクション、脱獄、データ流出チェックを評価フローに組み込みます。すべてのSDKには正規表現ベースの参照検出器が付属しており、DetectorRegistryを通じてカスタム検出器を登録できます。
import { parseOrThrow, evaluateWithDetection, DetectorRegistry } from '@hushspec/core';
const registry = DetectorRegistry.withDefaults();
const result = evaluateWithDetection(spec, action, registry, {
enabled: true,
prompt_injection_threshold: 0.5,
});
// result.detection_results contains matched patterns and confidence scores
ビルド済みのアダプターが、フレームワーク固有のツール呼び出しをHushSpec評価アクションに変換します。
EvaluationObserverインターフェースとObservableEvaluatorラッパーは、すべての評価、ポリシー読み込み、ポリシー再読み込みに対して構造化イベントを発行します。組み込みのオブザーバーにはJsonLineObserver、ConsoleObserver、MetricsCollectorがあります。
import { ObservableEvaluator, JsonLineObserver, MetricsCollector } from '@hushspec/core';
const evaluator = new ObservableEvaluator();
evaluator.addObserver(new JsonLineObserver(process.stderr));
evaluator.addObserver(new MetricsCollector());
const result = evaluator.evaluate(spec, action);
ポリシーはEd25519鍵で署名でき、読み込み時に検証できます。CLIはsign、verify、keygenコマンドを提供します。署名形式はhushspec-signature.v0.schema.jsonに準拠しています。
# 鍵ペアを生成
h2h keygen --output-dir mykeys
# ポリシーに署名(policy.yaml.sigを作成)
h2h sign policy.yaml --key mykeys/h2h.key
# 署名を検証
h2h verify policy.yaml --key mykeys/h2h.pub
パニックモードは全面拒否のキルスイッチで、ポリシーを再デプロイすることなく即座に有効化できます。センチネルファイル、CLI、API呼び出しでトリガーできます。パニックモードがアクティブな間、すべての評価はdenyを返します。
# パニックモードを有効化
h2h panic activate --sentinel /tmp/hushspec.panic
# 無効化
h2h panic deactivate --sentinel /tmp/hushspec.panic
import { activatePanic, deactivatePanic, isPanicActive } from '@hushspec/core';
activatePanic();
// これ以降の evaluate() 呼び出しはすべて deny を返す
deactivatePanic();
ポリシーはローカルファイル、HTTPS URL(ETagキャッシュとSSRF保護付き)、または組み込みルールセットから読み込めます。PolicyWatcherとPolicyPollerはプロセス再起動なしのホットリロードをサポートします。
import { PolicyWatcher, HushGuard } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
const watcher = new PolicyWatcher('./policy.yaml', {
onChange: (newSpec) => guard.swapPolicy(newSpec),
});
watcher.start();
HushSpecは、より高度なポリシー動作のためのオプションの拡張モジュールをサポートしています。
| 拡張 | 目的 |
|---|---|
| Posture | 機能と予算のための宣言型ステートマシン |
| Origins | 発信元を認識したポリシープロジェクション(Slack、GitHub、メールなど) |
| Detection | プロンプトインジェクション、脱獄、脅威インテリジェンスのしきい値設定 |
extensions:
posture:
initial: standard
states:
standard: { capabilities: [file_access, egress] }
restricted: { capabilities: [file_access] }
transitions:
- { from: "*", to: restricted, on: critical_violation }
detection:
prompt_injection:
block_at_or_above: high
すぐに使えるポリシーがrulesets/にあります。
HushSpecドキュメントはClawdstrikeでネイティブに読み込めます。
// HushSpecかClawdstrikeネイティブ形式かを自動検出
let policy = clawdstrike::Policy::from_yaml_auto(yaml)?;
# 形式間の変換
hush policy migrate policy.yaml --to hushspec
spec/ 規範的な仕様書(コアおよび拡張ドキュメント)
schemas/ JSON Schema定義
crates/ Rustクレート
hushspec/ コアライブラリ: パース、検証、マージ、解決、評価、検出、署名
hushspec-cli/ CLIツール
hushspec-testkit/ 適合性テストランナー
packages/ TypeScript、Python、Goの言語SDK
rulesets/ 組み込みセキュリティルールセット
fixtures/ 適合性および評価フィクスチャ
docs/ mdBookドキュメントサイト
generated/ 生成された共有SDKコントラクトアーティファクト
scripts/ コード生成およびCIツール
規範的な仕様はspec/にあります。プログラムによる検証のためのJSON Schema定義はschemas/にあります。完全なドキュメントはdocs/にあります。
Apache-2.0。詳細はLICENSEを参照してください。
| 機能 | Rust | TypeScript | Python | Go |
|---|
| パース + 検証(レベル1) | 対応 | 対応 | 対応 | 対応 |
| マージ(レベル2) | 対応 | 対応 | 対応 | 対応 |
| 解決(レベル2+) | 対応 | 対応 | 対応 | 対応 |
| 評価(レベル3) | 対応 | 対応 | 対応 | 対応 |
| 監査証跡(レベル4) | 対応 | 対応 | 対応 | 対応 |
| 検出 | 対応 | 対応 | 対応 | 対応 |
| 可観測性 | 対応 | 対応 | 対応 | 対応 |
| レシートシンク | 対応 | 対応 | 対応 | 対応 |
| 方法 | コマンド |
|---|
| Homebrew(macOS/Linux) | brew install backbay-labs/tap/h2h |
| npm | npm install -g @hushspec/cli(または npx @hushspec/cli validate policy.yaml) |
| Cargo(ソースから) | cargo install hushspec-cli |
| ビルド済みバイナリ | GitHub Releases — h2h-<tag>-<target>.tar.gz + SHA256SUMS、出所証明付き |
| フレームワーク | アダプター | SDK |
|---|
| Claude / Anthropic | mapClaudeToolToAction, createSecureToolHandler | TypeScript |
| OpenAI | mapOpenAIToolCall, createOpenAIGuard | TypeScript |
| MCP(Model Context Protocol) | mapMCPToolCall, createMCPGuard | TypeScript |
import { HushGuard, mapClaudeToolToAction } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
const action = mapClaudeToolToAction(toolUseBlock);
guard.enforce(action);
| ルール | 目的 |
|---|
forbidden_paths | 機密ファイルシステムパスへのアクセスをブロック |
path_allowlist | ホワイトリストベースの読み取り/書き込み/パッチアクセス |
egress | ドメイン単位でのネットワークエグレス制御 |
secret_patterns | ファイルコンテンツ内のシークレットを検出 |
patch_integrity | diffの安全性を検証(サイズ制限、禁止パターン) |
shell_commands | 危険なシェルコマンドをブロック |
tool_access | ツール/MCP呼び出しを制御 |
computer_use | CUAアクションを制御 |
remote_desktop_channels | リモートデスクトップのサイドチャネルを制御 |
input_injection | 入力インジェクション機能を制御 |
| ルールセット | 説明 |
|---|
default | AIエージェント実行のためのバランスのとれたセキュリティ |
strict | 最大セキュリティ、最小権限 |
permissive | 開発向け、緩やかな制限 |
ai-agent | AIコーディングアシスタントに最適化 |
cicd | CI/CDパイプラインセキュリティ |
remote-desktop | コンピュータ使用エージェントセッション |
panic | 全面拒否の緊急オーバーライド |