Skip to content

Instantly share code, notes, and snippets.

@martin-c
Created June 18, 2019 01:08
Show Gist options
  • Save martin-c/984447adcaa99d079d39a2e2ff80adcd to your computer and use it in GitHub Desktop.
Save martin-c/984447adcaa99d079d39a2e2ff80adcd to your computer and use it in GitHub Desktop.
Patch certbot/plugins/webroot.py to fix [Errno 30] Read-only file system error
def _create_challenge_dirs(self):
path_map = self.conf("map")
if not path_map:
raise errors.PluginError(
"Missing parts of webroot configuration; please set either "
"--webroot-path and --domains, or --webroot-map. Run with "
" --help webroot for examples.")
for name, path in path_map.items():
self.full_roots[name] = os.path.join(path, challenges.HTTP01.URI_ROOT_PATH)
print(name, self.full_roots[name])
logger.debug("Creating root challenges validation dir at %s",
self.full_roots[name])
# Change the permissions to be writable (GH #1389)
# Umask is used instead of chmod to ensure the client can also
# run as non-root (GH #1795)
old_umask = os.umask(0o022)
try:
stat_path = os.stat(path)
# We ignore the last prefix in the next iteration,
# as it does not correspond to a folder path ('/' or 'C:')
print('get_refixes:', util.get_prefixes(self.full_roots[name]))
print('get_refixes[-1]:', util.get_prefixes(self.full_roots[name])[:-1])
print('sorted:', sorted(util.get_prefixes(self.full_roots[name])[:-1], key=len))
for prefix in sorted(util.get_prefixes(self.full_roots[name])[:-1], key=len):
try:
# This is coupled with the "umask" call above because
# os.mkdir's "mode" parameter may not always work:
# https://docs.python.org/3/library/os.html#os.mkdir
print(prefix)
try:
res = os.stat(prefix)
continue
except:
os.mkdir(prefix, 0o0755)
self._created_dirs.append(prefix)
# Set owner as parent directory if possible
try:
os.chown(prefix, stat_path.st_uid, stat_path.st_gid)
except (OSError, AttributeError) as exception:
logger.info("Unable to change owner and uid of webroot directory")
logger.debug("Error was: %s", exception)
except OSError as exception:
if exception.errno not in (errno.EEXIST, errno.EISDIR):
raise errors.PluginError(
"Couldn't create root for {0} http-01 "
"challenge responses: {1}".format(name, exception))
finally:
os.umask(old_umask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment