starpost: rotate secrets and close data leaks
This commit is contained in:
1 parent
4f70df55dd
commit
22c1906a67
11 files changed
+725
-61
No files matched your search
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import secrets
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
target = Path(__file__).resolve().with_name(".env")
|
||||
values = {
|
||||
"STARPOST_DB_PASSWORD": secrets.token_urlsafe(48),
|
||||
"STARPOST_SECRET_KEY": secrets.token_urlsafe(48),
|
||||
"STARPOST_WAREHOUSE_CALLBACK_TOKEN": secrets.token_urlsafe(48),
|
||||
}
|
||||
try:
|
||||
descriptor = os.open(target, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||
except FileExistsError:
|
||||
print(f"refusing to overwrite existing {target}", file=sys.stderr)
|
||||
return 1
|
||||
with os.fdopen(descriptor, "w", encoding="utf-8") as output:
|
||||
for key, value in values.items():
|
||||
output.write(f"{key}={value}\n")
|
||||
os.chmod(target, 0o600)
|
||||
print(f"created {target} with mode 0600")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user