Skip to content

Commit 0eec124

Browse files
committed
Add PulpException for ssl CA verification error in replication
1 parent 0d3fa50 commit 0eec124

File tree

3 files changed

+70
-37
lines changed

3 files changed

+70
-37
lines changed

pulpcore/app/tasks/replica.py

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from pulpcore.app.apps import pulp_plugin_configs, PulpAppConfig
1010
from pulpcore.app.models import UpstreamPulp, Task, TaskGroup
1111
from pulpcore.app.replica import ReplicaContext
12+
from pulpcore.exceptions.base import (
13+
SSLCertificateVerificationError,
14+
)
1215
from pulpcore.tasking.tasks import dispatch
1316

1417
from pulp_glue.common import __version__ as pulp_glue_version
@@ -68,43 +71,51 @@ def replicate_distributions(server_pk):
6871

6972
task_group = TaskGroup.current()
7073
supported_replicators = []
71-
# Load all the available replicators
72-
for config in pulp_plugin_configs():
73-
if config.replicator_classes:
74-
for replicator_class in config.replicator_classes:
75-
req = PluginRequirement(config.label, specifier=replicator_class.required_version)
76-
if ctx.has_plugin(req):
77-
replicator = replicator_class(ctx, task_group, tls_settings, server)
78-
supported_replicators.append(replicator)
79-
80-
for replicator in supported_replicators:
81-
distros = replicator.upstream_distributions(q=server.q_select)
82-
distro_names = []
83-
for distro in distros:
84-
# Create remote
85-
remote = replicator.create_or_update_remote(upstream_distribution=distro)
86-
if not remote:
87-
# The upstream distribution is not serving any content,
88-
# let if fall through the cracks and be cleanup below.
89-
continue
90-
# Check if there is already a repository
91-
repository = replicator.create_or_update_repository(remote=remote)
92-
if not repository:
93-
# No update occured because server.policy==LABELED and there was
94-
# an already existing local repository with the same name
95-
continue
96-
97-
# Dispatch a sync task if needed
98-
if replicator.requires_syncing(distro):
99-
replicator.sync(repository, remote)
100-
101-
# Get or create a distribution
102-
replicator.create_or_update_distribution(repository, distro)
103-
104-
# Add name to the list of known distribution names
105-
distro_names.append(distro["name"])
106-
107-
replicator.remove_missing(distro_names)
74+
try:
75+
# Load all the available replicators
76+
for config in pulp_plugin_configs():
77+
if config.replicator_classes:
78+
for replicator_class in config.replicator_classes:
79+
req = PluginRequirement(
80+
config.label, specifier=replicator_class.required_version
81+
)
82+
if ctx.has_plugin(req):
83+
replicator = replicator_class(ctx, task_group, tls_settings, server)
84+
supported_replicators.append(replicator)
85+
86+
for replicator in supported_replicators:
87+
distros = replicator.upstream_distributions(q=server.q_select)
88+
distro_names = []
89+
for distro in distros:
90+
# Create remote
91+
remote = replicator.create_or_update_remote(upstream_distribution=distro)
92+
if not remote:
93+
# The upstream distribution is not serving any content,
94+
# let if fall through the cracks and be cleanup below.
95+
continue
96+
# Check if there is already a repository
97+
repository = replicator.create_or_update_repository(remote=remote)
98+
if not repository:
99+
# No update occured because server.policy==LABELED and there was
100+
# an already existing local repository with the same name
101+
continue
102+
103+
# Dispatch a sync task if needed
104+
if replicator.requires_syncing(distro):
105+
replicator.sync(repository, remote)
106+
107+
# Get or create a distribution
108+
replicator.create_or_update_distribution(repository, distro)
109+
110+
# Add name to the list of known distribution names
111+
distro_names.append(distro["name"])
112+
113+
replicator.remove_missing(distro_names)
114+
except Exception as e:
115+
# DEBUG: Strip "SSLError" from message so test fails in CI but shows exception details
116+
exc_type = f"{type(e).__module__}.{type(e).__name__}"
117+
exc_msg = str(e).replace("SSLError", "TLS_CERT_ERROR").replace("SSL", "TLS")
118+
raise SSLCertificateVerificationError(exc_msg)
108119

109120
dispatch(
110121
finalize_replication,

pulpcore/exceptions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
UrlSchemeNotSupportedError,
99
ProxyAuthenticationRequiredError,
1010
RepositoryVersionDeleteError,
11+
SSLCertificateVerificationError,
1112
)
1213
from .validation import (
1314
DigestValidationError,

pulpcore/exceptions/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,24 @@ def __str__(self):
166166
"Cannot delete repository version. Repositories must have at least one "
167167
"repository version."
168168
)
169+
170+
171+
class SSLCertificateVerificationError(PulpException):
172+
"""
173+
Exception raised when SSL certificate verification fails due to incorrect
174+
CA certificate configuration by the user.
175+
"""
176+
177+
def __init__(self, url):
178+
"""
179+
:param url: The URL where certificate verification failed.
180+
:type url: str
181+
"""
182+
super().__init__("PLP0012")
183+
self.url = url
184+
185+
def __str__(self):
186+
return _(
187+
"SSL certificate verification failed for {url}. "
188+
"The configured CA certificate does not match the server's certificate. "
189+
).format(url=self.url)

0 commit comments

Comments
 (0)