feat(Docker, encryption): add mandatory ENCRYPTION_KEY environment variable for IPSec password encryption; update documentation and Docker configurations to reflect changes
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m18s

This commit is contained in:
2026-01-22 20:07:29 +07:00
parent 86e8b5fece
commit 82c9ff8a04
3 changed files with 64 additions and 10 deletions
+23 -6
View File
@@ -5,21 +5,38 @@
const crypto = require('crypto');
// Ключ шифрования из переменной окружения
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY || crypto.randomBytes(32).toString('hex');
// Ключ шифрования из переменной окружения (обязателен для работы с IPSec паролями)
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY;
if (!ENCRYPTION_KEY) {
console.warn('WARNING: ENCRYPTION_KEY is not set. IPSec password encryption/decryption will fail.');
console.warn('Please set ENCRYPTION_KEY environment variable (64 hex characters for AES-256).');
console.warn('You can generate a key with: node -e "console.log(require(\'crypto\').randomBytes(32).toString(\'hex\'))"');
}
const ALGORITHM = 'aes-256-gcm';
/**
* Получить ключ шифрования (32 байта)
*/
function getEncryptionKey() {
// Если ENCRYPTION_KEY - hex строка, конвертируем в Buffer
if (ENCRYPTION_KEY.length === 64) {
return Buffer.from(ENCRYPTION_KEY, 'hex');
if (!ENCRYPTION_KEY) {
throw new Error('ENCRYPTION_KEY environment variable is not set. Cannot encrypt/decrypt IPSec passwords.');
}
// Иначе используем как есть и дополняем/обрезаем до 32 байт
// Если ENCRYPTION_KEY - hex строка (64 символа для 32 байт), конвертируем в Buffer
if (ENCRYPTION_KEY.length === 64) {
try {
return Buffer.from(ENCRYPTION_KEY, 'hex');
} catch (error) {
throw new Error(`Invalid ENCRYPTION_KEY format: not a valid hex string. ${error.message}`);
}
}
// Иначе используем как UTF-8 строку и дополняем/обрезаем до 32 байт
const key = Buffer.from(ENCRYPTION_KEY, 'utf8');
if (key.length === 32) return key;
// Дополняем или обрезаем до 32 байт
const result = Buffer.alloc(32);
key.copy(result, 0, 0, Math.min(key.length, 32));