feat: implement macOS Keychain integration for SSH password management

Overview

現在fnbは.envファイルに平文でSSHパスワードを保存していますが、macOSユーザー向けにキーチェーン統合を実装してセキュリティを向上させる必要があります。標準ライブラリを使用した段階的な実装アプローチを採用します。

Implementation Tasks

Phase 1: Core Keychain Integration

  • env.pyget_keychain_password()関数を追加
  • macOSプラットフォーム検出機能を実装
  • securityコマンドを使用したキーチェーンアクセス
  • get_ssh_password()の検索順序を拡張(env変数 → keychain → default)
  • エラーハンドリングと適切なフォールバック機能

Phase 2: Testing and Validation

  • キーチェーン統合のユニットテストを追加
  • macOS環境での統合テストを実装
  • 非macOS環境での動作確認テスト
  • エラーケースのテストカバレッジ追加

Phase 3: Documentation and UX

  • キーチェーン使用方法をセキュリティガイドに追加
  • CLI使用例とトラブルシューティングガイド更新
  • 移行手順(.env → keychain)の詳細化
  • パスワード設定用のヘルパーコマンド検討

Phase 4: Future Enhancements (Optional)

  • keyringライブラリ統合の検討
  • Windows Credential Manager対応
  • Linux Secret Service対応
  • 設定ファイルでの認証方法優先順位指定

Technical Design

Current Architecture

def get_ssh_password(host: str) -> str | None:
    # 1. FNB_PASSWORD_{NORMALIZED_HOST}
    # 2. FNB_PASSWORD_DEFAULT

Proposed Architecture

def get_ssh_password(host: str) -> str | None:
    # 1. Environment variables (existing)
    # 2. macOS Keychain (new)
    # 3. Default environment variable (existing fallback)

Implementation Strategy

  • Standard library only - No additional dependencies
  • Platform-specific - macOS security command integration
  • Backward compatible - Existing .env functionality preserved
  • Graceful degradation - Falls back to .env on errors or non-macOS

Acceptance Criteria

  • macOSでキーチェーンからパスワードを取得できる
  • 既存の.env機能が完全に保持されている
  • 非macOS環境で既存動作が維持されている
  • キーチェーンエラー時に適切にフォールバックする
  • テストカバレッジが83%以上を維持している
  • セキュリティガイドが更新されている

Priority

Medium - セキュリティ改善だが既存機能に影響しない

Related

セキュリティ強化 - パスワード管理改善フェーズ