Read Testrig backend credentials from managed files
tests / ci (pull_request) Failing after 2m47s

This commit is contained in:
Mark Gregory
2026-12-01 08:40:59 +00:00
parent 47963715d1
commit 27ddba98e1
4 changed files with 93 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Support;
use RuntimeException;
final class ManagedCredentialFiles
{
public static function databasePassword(): string
{
return self::read('absdev-db-password');
}
public static function redisPassword(): string
{
return self::read('absdev-redis-password');
}
private static function read(string $filename): string
{
$path = '/run/secrets/'.$filename;
clearstatcache(true, $path);
if (is_link($path) || ! is_file($path) || (fileperms($path) & 0777) !== 0600) {
throw new RuntimeException('Managed credential file is missing or unsafe.');
}
$password = @file_get_contents($path, false, null, 0, 4097);
if ($password === false || strlen($password) > 4096) {
throw new RuntimeException('Managed credential file could not be read.');
}
$password = rtrim($password, "\r\n");
if ($password === '' || strpbrk($password, "\r\n\0") !== false) {
throw new RuntimeException('Managed credential file is invalid.');
}
return $password;
}
}