Skip to content

Commit 83b07b6

Browse files
tls: Simplify cockpit-certificate-ensure
Drop support for merged certificate/key files. We deprecated this in 2021 with 76fc4cb ("tls: largely rewrite cockpit-certificate-ensure") and have been warning about it ever since. Turn the --for-cockpit-tls option into a no-op (with deprecation warning): we can't use this tool with cockpit-ws anymore, so the only other mode that makes sense is `--check`. Assisted-by: Claude <noreply@anthropic.com>
1 parent e54fd2e commit 83b07b6

File tree

4 files changed

+25
-43
lines changed

4 files changed

+25
-43
lines changed

containers/ws/label-run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ with tcp_listener:
119119

120120
else:
121121
subprocess.run(
122-
['/usr/libexec/cockpit-certificate-ensure', '--for-cockpit-tls'], env=env, cwd='/', check=True
122+
['/usr/libexec/cockpit-certificate-ensure'], env=env, cwd='/', check=True
123123
)
124124

125125
os.mkdir(wsinstance_dir := "/run/cockpit/wsinstance")

src/systemd/cockpit.service.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ After=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket
88

99
[Service]
1010
RuntimeDirectory=cockpit/tls
11-
ExecStartPre=+@libexecdir@/cockpit-certificate-ensure --for-cockpit-tls
11+
ExecStartPre=+@libexecdir@/cockpit-certificate-ensure
1212
ExecStart=@libexecdir@/cockpit-tls
1313
DynamicUser=yes
1414
# otherwise systemd uses 'cockpit' even if it exists as a normal user account

src/tls/cockpit-certificate-ensure.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
// of more than ~5 years from now was surely generated by the old code.
5353
#define MAX_EXPIRY (5 * 365 * 24 * 60 * 60)
5454

55-
// We tolerate the deprecated merged cert/key files only for cockpit-tls.
56-
static bool tolerate_merged_cert_key;
5755

5856
typedef struct
5957
{
@@ -284,26 +282,13 @@ certificate_and_key_read (CertificateKeyPair *self,
284282
read_file (self->certificate_filename, &self->certificate);
285283

286284
if (certificate_and_key_split (self))
287-
{
288-
self->key_filename = strdupx (self->certificate_filename);
289-
warnx ("%s: merged certificate and key files are %s. "
290-
"Please use a separate .cert and .key file.\n",
291-
certificate_filename,
292-
tolerate_merged_cert_key ? "deprecated" : "unsupported");
293-
294-
if (!tolerate_merged_cert_key)
295-
exit (EXIT_FAILURE);
296-
}
297-
else
298-
{
299-
self->key_filename = cockpit_certificate_key_path (self->certificate_filename);
300-
read_file (self->key_filename, &self->key);
301-
}
285+
errx (EXIT_FAILURE, "%s: merged certificate and key files are no longer supported. "
286+
"Please use a separate .cert and .key file.", certificate_filename);
302287

303-
if (self->key_filename)
304-
asprintfx (&self->filename_for_errors, "%s/.key", self->certificate_filename);
305-
else
306-
self->filename_for_errors = strdupx (self->certificate_filename);
288+
self->key_filename = cockpit_certificate_key_path (self->certificate_filename);
289+
read_file (self->key_filename, &self->key);
290+
291+
asprintfx (&self->filename_for_errors, "%s + %s", self->certificate_filename, self->key_filename);
307292
}
308293

309294
static gnutls_certificate_credentials_t
@@ -398,20 +383,16 @@ main (int argc, char **argv)
398383
{
399384
CertificateKeyPair result = { };
400385
bool check = false;
401-
bool for_cockpit_tls = false;
402386

403387
if (argc == 1)
404388
;
405389
else if (argc == 2 && strcmp (argv[1], "--check") == 0)
406390
check = true;
407391
else if (argc == 2 && strcmp (argv[1], "--for-cockpit-tls") == 0)
408-
for_cockpit_tls = true;
392+
warnx ("--for-cockpit-tls is deprecated and now a no-op");
409393
else
410394
errx (EXIT_FAILURE, "usage: %s [--check]", argv[0]);
411395

412-
if (for_cockpit_tls)
413-
tolerate_merged_cert_key = true;
414-
415396
if (!cockpit_certificate_find (&result, check))
416397
{
417398
if (check)
@@ -424,13 +405,14 @@ main (int argc, char **argv)
424405
}
425406

426407
if (check)
427-
printf ("Would use certificate %s\n", result.certificate_filename);
428-
429-
if (for_cockpit_tls)
408+
{
409+
printf ("Would use certificate %s\n", result.certificate_filename);
410+
}
411+
else
430412
{
431413
const char *runtime_directory = getenv ("RUNTIME_DIRECTORY");
432414
if (runtime_directory == NULL)
433-
errx (EXIT_FAILURE, "--for-cockpit-tls cannot be used unless RUNTIME_DIRECTORY is set");
415+
errx (EXIT_FAILURE, "RUNTIME_DIRECTORY must be set");
434416

435417
certificate_and_key_write (&result, runtime_directory);
436418
}

src/tls/test-cockpit-certificate-ensure.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test_copy (Fixture *fixture,
208208
g_autoptr(GError) error = NULL;
209209

210210
g_autoptr(GSubprocess) helper = g_subprocess_launcher_spawn (fixture->launcher, &error,
211-
CERTIFICATE_HELPER, "--for-cockpit-tls", NULL);
211+
CERTIFICATE_HELPER, NULL);
212212
g_assert_no_error (error);
213213

214214
g_autofree gchar *stdout_str = NULL;
@@ -408,14 +408,14 @@ static const TestCase expired_combined = {
408408
.files = (const gchar *[]) { SRCDIR "/test/data/expired/combined.cert",
409409
NULL },
410410
.check_stdout = "",
411-
.check_stderr = "*merged certificate and key files are unsupported*",
411+
.check_stderr = "*merged certificate and key files are no longer supported*",
412412
.check_exit = EXIT_FAILURE,
413413

414414
.copy_stdout = "",
415-
.copy_stderr = "*merged certificate and key files are deprecated*",
416-
.copy_exit = EXIT_SUCCESS,
417-
.key_source = "*/cockpit/ws-certs.d/combined.cert",
418-
.cert_source = "*/cockpit/ws-certs.d/combined.cert"
415+
.copy_stderr = "*merged certificate and key files are no longer supported*",
416+
.copy_exit = EXIT_FAILURE,
417+
.cert_source = "",
418+
.key_source = "",
419419
};
420420

421421
static const TestCase many_files = {
@@ -426,14 +426,14 @@ static const TestCase many_files = {
426426
SRCDIR "/test/data/expired/combined.cert",
427427
NULL },
428428
.check_stdout = "",
429-
.check_stderr = "*merged certificate and key files are unsupported*",
429+
.check_stderr = "*merged certificate and key files are no longer supported*",
430430
.check_exit = EXIT_FAILURE,
431431

432432
.copy_stdout = "",
433-
.copy_stderr = "*merged certificate and key files are deprecated*",
434-
.copy_exit = EXIT_SUCCESS,
435-
.key_source = "*/cockpit/ws-certs.d/combined.cert",
436-
.cert_source = "*/cockpit/ws-certs.d/combined.cert"
433+
.copy_stderr = "*merged certificate and key files are no longer supported*",
434+
.copy_exit = EXIT_FAILURE,
435+
.cert_source = "",
436+
.key_source = "",
437437
};
438438

439439
int

0 commit comments

Comments
 (0)