docker_login: fix permissions for ~/.docker/config.json (#67353)

* Fix permissions for ~/.docker/config.json.

* Add changelog, remove debug output.

(cherry picked from commit 55cb8c5388)
pull/67619/head
Felix Fontein 5 years ago committed by Matt Clay
parent 6fc2ae7476
commit a24dcf232c

@ -0,0 +1,2 @@
bugfixes:
- "docker_login - make sure that ``~/.docker/config.json`` is created with permissions ``0600``."

@ -257,8 +257,13 @@ class LoginManager(DockerBaseClass):
def write_config(self, path, config):
try:
with open(path, "w") as file:
json.dump(config, file, indent=5, sort_keys=True)
# Write config; make sure it has permissions 0x600
content = json.dumps(config, indent=5, sort_keys=True).encode('utf-8')
f = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
try:
os.write(f, content)
finally:
os.close(f)
except Exception as exc:
self.fail("Error: failed to write config to %s - %s" % (path, str(exc)))

Loading…
Cancel
Save