fix(identity): restrict Windows local admin credential ACL
This commit is contained in:
parent
d4aa7d5c79
commit
cc3fb9d62a
|
|
@ -11,3 +11,4 @@ pnpm admin:seed-local
|
|||
```
|
||||
|
||||
`admin:prepare-local` creates an ignored `.env.local-admin` file with `OWNER_EMAIL=admin@manicandles.local`, organization/name settings and a random password. The command refuses to overwrite it. Read the password from that local file; do not commit or share it. `admin:seed-local` passes those values to the existing bootstrap command and prints only the resulting organization and user IDs. The seed accepts only a development environment with a loopback PostgreSQL URL. A second seed fails if an owner already exists; it does not reset the existing password. Use the normal identity workflow to change credentials. Create production administrators separately using fresh credentials and a controlled deployment procedure.
|
||||
On Windows, preparation removes inherited file permissions and grants access only to the running user, SYSTEM and Administrators; it fails and removes the file if that restriction cannot be applied.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'dotenv/config';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import { readFile, unlink, writeFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { parse } from 'dotenv';
|
||||
import {
|
||||
|
|
@ -22,6 +22,25 @@ async function main() {
|
|||
.join('\n') + '\n',
|
||||
{ flag: 'wx', mode: 0o600 },
|
||||
);
|
||||
if (process.platform === 'win32') {
|
||||
const account = `${process.env.USERDOMAIN}\\${process.env.USERNAME}`;
|
||||
const protectedFile = spawnSync(
|
||||
'icacls.exe',
|
||||
[
|
||||
credentialFile,
|
||||
'/inheritance:r',
|
||||
'/grant:r',
|
||||
`${account}:(F)`,
|
||||
'SYSTEM:(F)',
|
||||
'Administrators:(F)',
|
||||
],
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
if (protectedFile.status !== 0) {
|
||||
await unlink(credentialFile);
|
||||
throw new Error('Could not restrict local credential file access');
|
||||
}
|
||||
}
|
||||
console.log('Local admin credentials prepared in .env.local-admin');
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue