Skip to content

Commit

Permalink
Also write README file to /etc/letsencrypt/live (#6377)
Browse files Browse the repository at this point in the history
We want to discourage people from moving things around in `/etc/letsencrypt/live`! So we dropped an extra README in the `/etc/` directory when it's first created.
  • Loading branch information
sydneyli committed Oct 18, 2018
1 parent b9dd40b commit bfaf029
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Certbot adheres to [Semantic Versioning](http://semver.org/).

### Changed

* `--manual` will explicitly warn users that earlier challenges should remain in place when setting up subsequent challenges.
* Write README to the base of (config-dir)/live directory
* `--manual` will explicitly warn users that earlier challenges should remain in place when setting up subsequent challenges.

### Fixed

Expand Down
39 changes: 24 additions & 15 deletions certbot/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ def get_link_target(link):
target = os.path.join(os.path.dirname(link), target)
return os.path.abspath(target)

def _write_live_readme_to(readme_path, is_base_dir=False):
prefix = ""
if is_base_dir:
prefix = "[cert name]/"
with open(readme_path, "w") as f:
logger.debug("Writing README to %s.", readme_path)
f.write("This directory contains your keys and certificates.\n\n"
"`{prefix}privkey.pem` : the private key for your certificate.\n"
"`{prefix}fullchain.pem`: the certificate file used in most server software.\n"
"`{prefix}chain.pem` : used for OCSP stapling in Nginx >=1.3.7.\n"
"`{prefix}cert.pem` : will break many server configurations, and "
"should not be used\n"
" without reading further documentation (see link below).\n\n"
"WARNING: DO NOT MOVE OR RENAME THESE FILES!\n"
" Certbot expects these files to remain in this location in order\n"
" to function properly!\n\n"
"We recommend not moving these files. For more information, see the Certbot\n"
"User Guide at https://certbot.eff.org/docs/using.html#where-are-my-"
"certificates.\n".format(prefix=prefix))


def _relevant(option):
"""
Expand Down Expand Up @@ -1003,6 +1023,9 @@ def new_lineage(cls, lineagename, cert, privkey, chain, cli_config):
logger.debug("Creating directory %s.", i)
config_file, config_filename = util.unique_lineage_name(
cli_config.renewal_configs_dir, lineagename)
base_readme_path = os.path.join(cli_config.live_dir, README)
if not os.path.exists(base_readme_path):
_write_live_readme_to(base_readme_path, is_base_dir=True)

# Determine where on disk everything will go
# lineagename will now potentially be modified based on which
Expand Down Expand Up @@ -1045,21 +1068,7 @@ def new_lineage(cls, lineagename, cert, privkey, chain, cli_config):

# Write a README file to the live directory
readme_path = os.path.join(live_dir, README)
with open(readme_path, "w") as f:
logger.debug("Writing README to %s.", readme_path)
f.write("This directory contains your keys and certificates.\n\n"
"`privkey.pem` : the private key for your certificate.\n"
"`fullchain.pem`: the certificate file used in most server software.\n"
"`chain.pem` : used for OCSP stapling in Nginx >=1.3.7.\n"
"`cert.pem` : will break many server configurations, and "
"should not be used\n"
" without reading further documentation (see link below).\n\n"
"WARNING: DO NOT MOVE THESE FILES!\n"
" Certbot expects these files to remain in this location in order\n"
" to function properly!\n\n"
"We recommend not moving these files. For more information, see the Certbot\n"
"User Guide at https://certbot.eff.org/docs/using.html#where-are-my-"
"certificates.\n")
_write_live_readme_to(readme_path)

# Document what we've done in a new renewal config file
config_file.close()
Expand Down
2 changes: 2 additions & 0 deletions certbot/tests/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ def test_new_lineage(self, mock_rv):
self.assertTrue(result._consistent())
self.assertTrue(os.path.exists(os.path.join(
self.config.renewal_configs_dir, "the-lineage.com.conf")))
self.assertTrue(os.path.exists(os.path.join(
self.config.live_dir, "README")))
self.assertTrue(os.path.exists(os.path.join(
self.config.live_dir, "the-lineage.com", "README")))
with open(result.fullchain, "rb") as f:
Expand Down

0 comments on commit bfaf029

Please sign in to comment.