Recognize empty provider templates during deployment preflight
Build and verify web migration / verify (push) Has been cancelled
Build and verify web migration / verify (push) Has been cancelled
This commit is contained in:
+8
-1
@@ -49,6 +49,12 @@ def image_id(image):
|
||||
return run(["docker", "image", "inspect", "--format", "{{.Id}}", image]).decode().strip()
|
||||
|
||||
|
||||
def provider_configured(config, target):
|
||||
section = "Pms" if target == "/run/guestops/pms.json" else "Payments"
|
||||
# Only the exact shipped empty template is public; unknown settings fail closed.
|
||||
return config not in ({}, {section: {"Hotels": {}}})
|
||||
|
||||
|
||||
AUTH = 'const c=new Mongo("mongodb://127.0.0.1"); c.getDB("admin").auth(process.env.MONGO_INITDB_ROOT_USERNAME,process.env.MONGO_INITDB_ROOT_PASSWORD);'
|
||||
INVENTORY = 'const d=c.getDB("guestops"); print(JSON.stringify({bytes:d.stats().storageSize+d.stats().indexSize,collections:Object.fromEntries(d.getCollectionNames().filter(n=>!n.startsWith("system.")).sort().map(n=>[n,{count:d.getCollection(n).countDocuments({}),indexes:d.getCollection(n).getIndexes().map(i=>{delete i.ns;return i;}).sort((a,b)=>a.name.localeCompare(b.name))}]))}));'
|
||||
|
||||
@@ -94,7 +100,7 @@ def preflight(args):
|
||||
require(Path(volume["source"]).exists(), f"A required {name} bind mount is missing.")
|
||||
if volume["target"] in ("/run/guestops/pms.json", "/run/guestops/payments.json"):
|
||||
provider = Path(volume["source"])
|
||||
if any(json.loads(provider.read_text()).values()):
|
||||
if provider_configured(json.loads(provider.read_text()), volume["target"]):
|
||||
require(stat.S_IMODE(provider.stat().st_mode) & 0o077 == 0, "Configured provider files must not be accessible to group or other users.")
|
||||
if not args.offline:
|
||||
url = config["services"]["api"]["environment"]["PublicUrl"]
|
||||
@@ -249,3 +255,4 @@ if __name__ == "__main__":
|
||||
# Never include subprocess output, config values or parsed guest data.
|
||||
print(str(error) if isinstance(error, RuntimeError) else "Operation failed (" + type(error).__name__ + "). No sensitive details were logged.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user