Document staging publication and test Apache rollback
This commit is contained in:
1 parent
0f9f0adc5c
commit
528fa73286
2 files changed
+113
No files matched your search
@@ -1491,6 +1491,46 @@ its dedicated candidate database.
|
|||||||
sudo /opt/coulobre/bin/coulobre-web-node discard-wordpress-staging staging.json
|
sudo /opt/coulobre/bin/coulobre-web-node discard-wordpress-staging staging.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Publish a verified WordPress staging revision over HTTPS
|
||||||
|
|
||||||
|
Choose a separate hostname for staging and point its DNS to the web node.
|
||||||
|
Obtain a Certbot certificate for the staging hostname. Use the certificate
|
||||||
|
name `coulobre-wp-staging-NODE_KEY`, with the live website's node key.
|
||||||
|
Configure the Core Certbot HTTP-01 webroot and Apache reload hook before
|
||||||
|
using HTTP-01. The staging route keeps that challenge available on port 80
|
||||||
|
and redirects other HTTP requests to HTTPS. Enable Apache's `ssl`,
|
||||||
|
`headers`, `proxy_fcgi` and file-based Basic Authentication modules.
|
||||||
|
|
||||||
|
Create a separate Basic Authentication password for the staging site.
|
||||||
|
Name the file after the live website's node key, which is the account ID
|
||||||
|
for a primary site and `s` followed by the site ID for an independent site.
|
||||||
|
For the primary site of account 17, use these commands.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo install -d -m 0755 /etc/apache2/coulobre-wordpress-staging
|
||||||
|
sudo htpasswd -B -c /etc/apache2/coulobre-wordpress-staging/17.htpasswd staging
|
||||||
|
sudo chown root:www-data /etc/apache2/coulobre-wordpress-staging/17.htpasswd
|
||||||
|
sudo chmod 0640 /etc/apache2/coulobre-wordpress-staging/17.htpasswd
|
||||||
|
sudo /opt/coulobre/bin/coulobre-web-node publish-wordpress-staging staging.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Omit `-c` when adding or changing users in an existing password file.
|
||||||
|
The staging site requires authentication for static assets as well as
|
||||||
|
PHP requests and sends `X-Robots-Tag: noindex, nofollow`. Its separate
|
||||||
|
PHP-FPM service uses the candidate Unix identity and database. Outbound
|
||||||
|
IP networking and PHP mail are disabled.
|
||||||
|
|
||||||
|
To refresh, prepare a new revision with the same hostname and publish
|
||||||
|
its manifest. The same password file stays in use. Coulobre keeps the
|
||||||
|
previous revision and restores its Apache configuration if the switch
|
||||||
|
fails. You can also publish the previous manifest to switch back.
|
||||||
|
Discard unused revisions to remove their databases and PHP-FPM services.
|
||||||
|
|
||||||
|
To withdraw the staging route, run `unpublish-wordpress-staging` with
|
||||||
|
the manifest of the currently published revision. Remove its DNS record
|
||||||
|
if you are retiring the hostname. After withdrawing the route, you can
|
||||||
|
discard the remaining revision through the web-node CLI.
|
||||||
|
|
||||||
## Enable the website file manager
|
## Enable the website file manager
|
||||||
|
|
||||||
The installer enables the file manager, scheduled website jobs and local
|
The installer enables the file manager, scheduled website jobs and local
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import CompletedProcess
|
from subprocess import CompletedProcess
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ from django.test import SimpleTestCase
|
|||||||
|
|
||||||
from coulobre.database_node import DatabaseSpec
|
from coulobre.database_node import DatabaseSpec
|
||||||
from coulobre.database_node_backup import check_wordpress_schema
|
from coulobre.database_node_backup import check_wordpress_schema
|
||||||
|
from coulobre.php_runtime import PhpRuntime
|
||||||
from coulobre.web_node import WebSite
|
from coulobre.web_node import WebSite
|
||||||
from coulobre.wordpress_staging import WordPressStagingRevision
|
from coulobre.wordpress_staging import WordPressStagingRevision
|
||||||
from coulobre.wordpress_staging_node import (
|
from coulobre.wordpress_staging_node import (
|
||||||
@@ -14,6 +16,12 @@ from coulobre.wordpress_staging_node import (
|
|||||||
read_source_config,
|
read_source_config,
|
||||||
verify_stage,
|
verify_stage,
|
||||||
)
|
)
|
||||||
|
from coulobre.wordpress_staging_publication import (
|
||||||
|
apply_vhost,
|
||||||
|
render_pool,
|
||||||
|
render_runtime,
|
||||||
|
render_vhost,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StagingRevisionTests(SimpleTestCase):
|
class StagingRevisionTests(SimpleTestCase):
|
||||||
@@ -119,3 +127,68 @@ class WordPressSchemaTests(SimpleTestCase):
|
|||||||
check_wordpress_schema(cursor, "test_db", "wp_")
|
check_wordpress_schema(cursor, "test_db", "wp_")
|
||||||
else:
|
else:
|
||||||
check_wordpress_schema(cursor, "test_db", "wp_")
|
check_wordpress_schema(cursor, "test_db", "wp_")
|
||||||
|
|
||||||
|
|
||||||
|
class StagingPublicationTests(SimpleTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.revision = WordPressStagingRevision(
|
||||||
|
WebSite(7, "wordpress.example.test"),
|
||||||
|
DatabaseSpec(7, "wordpress"),
|
||||||
|
"preview.example.test",
|
||||||
|
uuid4(),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_https_requires_access_for_static_files_and_php(self):
|
||||||
|
directory = Path("/srv/coulobre/wordpress-staging") / self.revision.key
|
||||||
|
config = render_vhost(
|
||||||
|
self.revision,
|
||||||
|
directory,
|
||||||
|
Path("/etc/wordpress.htpasswd"),
|
||||||
|
(Path("/etc/fullchain.pem"), Path("/etc/privkey.pem")),
|
||||||
|
)
|
||||||
|
self.assertIn("ServerName preview.example.test", config)
|
||||||
|
self.assertIn('RedirectMatch permanent "', config)
|
||||||
|
self.assertIn("https://preview.example.test/$1", config)
|
||||||
|
self.assertIn('Alias "/.well-known/acme-challenge/"', config)
|
||||||
|
self.assertIn('<Location "/">', config)
|
||||||
|
self.assertIn("Require valid-user", config)
|
||||||
|
self.assertIn("RequestHeader unset Authorization", config)
|
||||||
|
self.assertIn(
|
||||||
|
'Header always set X-Robots-Tag "noindex, nofollow"', config
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
'Header always set Cache-Control "private, no-store"', config
|
||||||
|
)
|
||||||
|
self.assertNotIn("wordpress.example.test", config.partition("\n")[2])
|
||||||
|
|
||||||
|
def test_the_web_runtime_uses_the_staging_identity_and_blocks_egress(self):
|
||||||
|
directory = Path("/srv/coulobre/wordpress-staging") / self.revision.key
|
||||||
|
unit = render_runtime(self.revision, directory, PhpRuntime("8.5"))
|
||||||
|
pool = render_pool(self.revision, directory)
|
||||||
|
self.assertIn("PrivateNetwork=yes", unit)
|
||||||
|
self.assertIn("RestrictAddressFamilies=AF_UNIX", unit)
|
||||||
|
self.assertIn("TemporaryFileSystem=/run:ro", unit)
|
||||||
|
self.assertIn("BindReadOnlyPaths=/run/mysqld", unit)
|
||||||
|
self.assertIn(f"user = {self.revision.key}", pool)
|
||||||
|
self.assertIn("php_admin_value[sendmail_path] = /usr/bin/false", pool)
|
||||||
|
|
||||||
|
@patch("coulobre.wordpress_staging_publication.read_root_file")
|
||||||
|
@patch("coulobre.wordpress_staging_publication.web.run")
|
||||||
|
def test_failed_reload_restores_the_previous_route(self, run, read):
|
||||||
|
read.side_effect = Path.read_text
|
||||||
|
run.side_effect = (None, ValueError("Apache reload failed"), None)
|
||||||
|
with TemporaryDirectory() as work:
|
||||||
|
root = Path(work)
|
||||||
|
available = root / "sites-available"
|
||||||
|
enabled = root / "sites-enabled"
|
||||||
|
available.mkdir()
|
||||||
|
enabled.mkdir()
|
||||||
|
config = available / "staging.conf"
|
||||||
|
link = enabled / config.name
|
||||||
|
link.symlink_to(Path("../sites-available") / config.name)
|
||||||
|
config.write_text("previous verified revision")
|
||||||
|
with self.assertRaisesRegex(ValueError, "Apache reload failed"):
|
||||||
|
apply_vhost(config, link, "new verified revision")
|
||||||
|
self.assertEqual(config.read_text(), "previous verified revision")
|
||||||
|
self.assertTrue(link.exists())
|
||||||
|
self.assertEqual(run.call_count, 3)
|
||||||
Reference in new issue
Block a user