first commit
This commit is contained in:
39
app/Console/Commands/AuditPurgeCommand.php
Normal file
39
app/Console/Commands/AuditPurgeCommand.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\AuditLog;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Удаление устаревших записей журнала по сроку хранения (мера РСБ.4, РСБ.8).
|
||||
*
|
||||
* Срок хранения задаётся AUDIT_RETENTION_DAYS (для УЗ-1 — не менее 3 лет).
|
||||
* Перед удалением записи должны быть выгружены в архив/SIEM.
|
||||
*/
|
||||
class AuditPurgeCommand extends Command
|
||||
{
|
||||
protected $signature = 'audit:purge {--dry-run : Показать количество без удаления}';
|
||||
|
||||
protected $description = 'Удалить записи журнала аудита старше срока хранения';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$days = (int) config('audit.retention_days');
|
||||
$threshold = now()->subDays($days);
|
||||
|
||||
$query = AuditLog::query()->where('created_at', '<', $threshold);
|
||||
$count = $query->count();
|
||||
|
||||
if ($this->option('dry-run')) {
|
||||
$this->info("К удалению (старше {$days} дн.): {$count} записей.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$query->delete();
|
||||
$this->info("Удалено записей журнала: {$count}.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
33
app/Console/Commands/AuditVerifyCommand.php
Normal file
33
app/Console/Commands/AuditVerifyCommand.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\Audit\AuditService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Проверка целостности журнала аудита (мера РСБ.3, ОЦЛ.1).
|
||||
*
|
||||
* Запускать по расписанию и при расследовании инцидентов.
|
||||
*/
|
||||
class AuditVerifyCommand extends Command
|
||||
{
|
||||
protected $signature = 'audit:verify';
|
||||
|
||||
protected $description = 'Проверить HMAC-подписи и хеш-цепочку журнала аудита';
|
||||
|
||||
public function handle(AuditService $audit): int
|
||||
{
|
||||
$broken = $audit->verifyIntegrity();
|
||||
|
||||
if ($broken === []) {
|
||||
$this->info('Целостность журнала аудита подтверждена.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->error('Обнаружены нарушения целостности журнала! ID записей: '.implode(', ', $broken));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
65
app/Console/Commands/CreateAdminCommand.php
Normal file
65
app/Console/Commands/CreateAdminCommand.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Auth\PasswordManager;
|
||||
use App\Support\PasswordPolicy;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
use function Laravel\Prompts\password as promptPassword;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
/**
|
||||
* Создание администратора первоначальной настройки (мера УПД.1).
|
||||
*
|
||||
* Создаёт учётную запись и назначает роль admin. Пароль вводится скрытно и
|
||||
* проходит парольную политику. После первого входа администратор обязан
|
||||
* настроить MFA (ИАФ.4).
|
||||
*/
|
||||
class CreateAdminCommand extends Command
|
||||
{
|
||||
protected $signature = 'user:create-admin {--name=} {--email=}';
|
||||
|
||||
protected $description = 'Создать учётную запись администратора';
|
||||
|
||||
public function handle(PasswordManager $passwords): int
|
||||
{
|
||||
$name = $this->option('name') ?: text('Имя администратора', required: true);
|
||||
$email = $this->option('email') ?: text('Email', required: true);
|
||||
$plain = promptPassword('Пароль', required: true);
|
||||
|
||||
$validator = Validator::make(
|
||||
['name' => $name, 'email' => $email, 'password' => $plain],
|
||||
[
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'unique:users,email'],
|
||||
'password' => ['required', PasswordPolicy::rule()],
|
||||
]
|
||||
);
|
||||
|
||||
if ($validator->fails()) {
|
||||
foreach ($validator->errors()->all() as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => 'placeholder',
|
||||
]);
|
||||
|
||||
// Через PasswordManager — чтобы корректно проставить password_changed_at.
|
||||
$passwords->change($user, $plain);
|
||||
|
||||
$user->assignRole('admin');
|
||||
|
||||
$this->info("Администратор {$email} создан. Настройте MFA при первом входе.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
35
app/Console/Commands/SecurityAuditDependenciesCommand.php
Normal file
35
app/Console/Commands/SecurityAuditDependenciesCommand.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Анализ уязвимостей в зависимостях (мера УКФ.4, ОЦЛ).
|
||||
*
|
||||
* Запускает `composer audit`. В CI/CD дополните Trivy/OWASP ZAP.
|
||||
*/
|
||||
class SecurityAuditDependenciesCommand extends Command
|
||||
{
|
||||
protected $signature = 'security:audit-deps';
|
||||
|
||||
protected $description = 'Проверить зависимости на известные уязвимости (composer audit)';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$process = new Process(['composer', 'audit', '--no-interaction'], base_path());
|
||||
$process->setTimeout(300);
|
||||
$process->run(fn ($type, $buffer) => $this->output->write($buffer));
|
||||
|
||||
if (! $process->isSuccessful()) {
|
||||
$this->error('Обнаружены уязвимости в зависимостях. Требуется обновление.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('Уязвимостей в зависимостях не обнаружено.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user