fix: migrate legacy Docker volume ownership before dropping privileges
build-image / build-push (push) Successful in 2m58s
build-image / build-push (push) Successful in 2m58s
This commit is contained in:
1 parent
c58953b736
commit
bba6dcd37e
7 files changed
+96
-4
No files matched your search
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import config from './config.js';
|
||||
|
||||
// Earlier images wrote this volume as root. Repair only the database directory
|
||||
// and its two known files, then permanently drop privileges before starting HTTP.
|
||||
if (process.getuid?.() === 0) {
|
||||
const dir = path.resolve(config.dataDir);
|
||||
if (['/', '/app', '/app/src', '/app/public'].includes(dir)) throw new Error('DATA_DIR deve ser um diretório exclusivo para dados');
|
||||
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
const directory = fs.openSync(dir, fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW);
|
||||
try {
|
||||
fs.fchownSync(directory, 1000, 1000);
|
||||
fs.fchmodSync(directory, fs.fstatSync(directory).mode | 0o700);
|
||||
} finally { fs.closeSync(directory); }
|
||||
for (const name of ['db.json', 'db.json.tmp']) {
|
||||
let fd;
|
||||
try {
|
||||
fd = fs.openSync(path.join(dir, name), fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
||||
if (!fs.fstatSync(fd).isFile()) throw new Error(`${name} deve ser um arquivo regular`);
|
||||
fs.fchownSync(fd, 1000, 1000);
|
||||
fs.fchmodSync(fd, 0o600);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') throw e;
|
||||
} finally { if (fd !== undefined) fs.closeSync(fd); }
|
||||
}
|
||||
process.setgroups([]);
|
||||
process.setgid(1000);
|
||||
process.setuid(1000);
|
||||
}
|
||||
|
||||
await import('./index.js');
|
||||
@@ -32,6 +32,8 @@ app.get('/admin', (req, res) => res.sendFile(path.join(__dirname, '../public/adm
|
||||
app.use(express.static(path.join(__dirname, '../public')));
|
||||
|
||||
initDb();
|
||||
// Check volume write access before accepting checkouts or creating PIX orders.
|
||||
saveDb();
|
||||
initMp();
|
||||
|
||||
const { checkPayment, checks } = paymentService({ getDb, saveDb, getPaymentStatus, rosCommand, createHotspotUser });
|
||||
|
||||
Reference in new issue
Block a user