ArtisanPack-UI/security-analytics

GitHub: ArtisanPack-UI/security-analytics

这是一个为 Laravel 应用提供安全监控和分析的集成包,涵盖事件记录、异常检测和自动化响应。

Stars: 0 | Forks: 0

# ArtisanPack UI — 安全分析 适用于 Laravel 的安全分析功能:结构化安全事件日志记录、可插拔的异常检测、威胁情报聚合、SIEM 导出(Datadog / Elasticsearch / Splunk / Syslog / Webhook)、基于预案的事件响应自动化、多渠道告警、报告以及一个 Livewire 仪表盘。 此包是 **ArtisanPack UI Security 2.0** 拆分的一部分 — 此前集成在 `artisanpack-ui/security`(1.x)中的分析、监控和事件响应功能,在 2.0 及更高版本中独立至此。 ## 特性 - **事件日志记录** — `SecurityEventLogger` 加上一个 `LogAuthenticationEvents` 监听器,可自动捕获 Laravel 认证事件并记录到结构化的 `security_events` 表中。 - **异常检测** — 8 个可插拔检测器(`BruteForce`、`CredentialStuffing`、`GeoVelocity`、`PrivilegeEscalation`、`AccessPattern`、`Behavioral`、`Statistical`、`RuleBased`),由 `AnomalyDetectionService` 编排,并通过 `BaselineManager` 建立用户行为基线。 - **威胁情报** — 5 个可插拔数据源(`AbuseIPDB`、`GoogleSafeBrowsing`、`IpQualityScore`、`VirusTotal`、`CustomFeed`),由 `ThreatIntelligenceService` 聚合。 - **SIEM 导出** — 5 个可插拔导出器(`Datadog`、`Elasticsearch`、`Splunk`、`Syslog`、`Webhook`),由 `SiemExportService` 支持。 - **事件响应自动化** — 10 个可插拔操作(阻止 IP / 用户、锁定账户、撤销会话、强制重置密码、要求 2FA、终止会话、通知管理员、限制 IP 速率、启用增强日志、记录事件),由 `IncidentResponder` 协调,并由 `ResponsePlaybook` 定义驱动。 - **告警** — 8 个渠道(`Database`、`Email`、`OpsGenie`、`PagerDuty`、`Slack`、`Sms`、`Teams`、`Webhook`),通过 `AlertManager` 路由,支持 `AlertRule` 定义和 `AlertHistory` 审计。 - **报告** — 6 种报告类型(`ExecutiveSummary`、`Incident`、`Compliance`、`Threat`、`Trend`、`UserActivity`),可按需或通过 `ScheduledReport` 定时生成。 - **仪表盘** — 内置 `SecurityDashboardController`(10 个 JSON 端点)及 4 个 Livewire 组件(`SecurityDashboard`、`SecurityEventList`、`SecurityStats`、`SuspiciousActivityList`),附带预置的 Blade 视图。 - **Eloquent 模型**(11 个)、迁移(10 个)和工厂(9 个),构成完整的数据架构。 - **控制台命令**(11 个),用于处理、清理、导出、生成报告、同步威胁源和更新行为基线。 - **后台任务**(5 个),用于请求外分析、SIEM 导出、定时报告、指标处理和告警投递。 - **事件**(3 个)— `SecurityEventOccurred`、`AnomalyDetected`、`SuspiciousActivityDetected` — 订阅它们以集成下游系统。 - `SecurityAnalytics` Facade + `security_analytics()` 辅助函数。 ## 安装 ``` composer require artisanpack-ui/security-analytics php artisan migrate ``` (可选)发布配置文件: ``` php artisan vendor:publish --tag=security-analytics-config ``` ## 快速入门 记录一个安全事件: ``` use ArtisanPackUI\SecurityAnalytics\Facades\SecurityAnalytics; security_analytics()->logger()->log( type: 'authentication', name: 'login.failed', severity: 'warning', context: ['username' => $request->input('email')], ); ``` 或者对 Laravel 触发的认证事件做出响应: ``` // The package's LogAuthenticationEvents listener wires this up automatically. // To opt out, set config('artisanpack.security-analytics.auto_log_auth_events') to false. ``` 挂载仪表盘: ``` // The dashboard routes auto-register under the configured prefix (default: /security). // Visit /security/dashboard to see the Livewire UI. ``` ## 仪表盘 Blade 视图 仪表盘视图以纯 HTML + Tailwind 形式提供 — 此包不依赖 `artisanpack-ui/livewire-ui-components`。要自定义它们,请将您自己的文件放在 `resources/views/vendor/security-analytics/livewire/*.blade.php` 以覆盖包视图 — Laravel 会优先使用覆盖文件。 ## 文档 - [文档首页](docs/home.md) - [快速入门](docs/getting-started.md) - [安装](docs/installation.md) - [用法](docs/usage.md) - [高级用法](docs/advanced.md) - [常见问题](docs/faq.md) - [故障排除](docs/troubleshooting.md) - [更新日志](CHANGELOG.md) ## 系统要求 - PHP 8.2+ - Laravel 10 / 11 / 12 - `livewire/livewire` ^3.6 或 ^4.0(仅仪表盘 UI 需要;包的其余功能在没有 Livewire 的情况下也能工作) ## 关联包 | 包 | 范围 | |---|---| | [`artisanpack-ui/security-full`](https://github.com/ArtisanPack-UI/security-full) | 元包 — 通过单一依赖引入完整安全套件(以下全部六个包) | | [`artisanpack-ui/security`](https://github.com/ArtisanPack-UI/security) | 核心:输入净化、转义、CSP、安全头 | | [`artisanpack-ui/security-auth`](https://github.com/ArtisanPack-UI/security-auth) | 2FA、密码复杂度、账户锁定、会话管理 | | [`artisanpack-ui/security-advanced-auth`](https://github.com/ArtisanPack-UI/security-advanced-auth) | WebAuthn、SSO、社交登录 | | [`artisanpack-ui/rbac`](https://github.com/ArtisanPack-UI/rbac) | 角色、权限、Gate 集成 | | [`artisanpack-ui/secure-uploads`](https://github.com/ArtisanPack-UI/secure-uploads) | 文件验证、恶意软件扫描、签名 URL 服务 | | [`artisanpack-ui/compliance`](https://github.com/ArtisanPack-UI/compliance) | GDPR / CCPA / LGPD 合规工具 | ## 许可证 MIT — 详见 [LICENSE](LICENSE)。 ## 贡献 请在提交 issue 或 PR 前阅读 [贡献指南](CONTRIBUTING.md)。
标签:ffuf