Browse code

fix: propagate registry auth error in swarm image pull

When a worker pull fails with unauthorized, the error was being
swallowed and replaced with misleading 'No such image' message.
Fix error propagation so the actual cause is reported.

Signed-off-by: Md_Mushfiqur Rahim <20mahin20201@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Md_Mushfiqur Rahim authored on 2026/05/25 20:29:19
Showing 2 changed files
... ...
@@ -174,6 +174,14 @@ func (r *controller) Prepare(ctx context.Context) error {
174 174
 				// If you don't want this behavior, lock down your image to an
175 175
 				// immutable tag or digest.
176 176
 				log.G(ctx).WithError(r.pullErr).Error("pulling image failed")
177
+
178
+				// If the pull failed with an authentication error, return it
179
+				// so the actual cause is propagated instead of the misleading
180
+				// "No such image" error that would otherwise result from the
181
+				// container create below.
182
+				if cerrdefs.IsUnauthorized(r.pullErr) {
183
+					return r.pullErr
184
+				}
177 185
 			}
178 186
 		}
179 187
 	}
... ...
@@ -106,6 +106,8 @@ func translatePullError(err error, ref reference.Named) error {
106 106
 		switch v.Code {
107 107
 		case errcode.ErrorCodeDenied, v2.ErrorCodeManifestUnknown, v2.ErrorCodeNameUnknown:
108 108
 			return notFoundError{v, ref}
109
+		case errcode.ErrorCodeUnauthorized:
110
+			return errdefs.Unauthorized(v)
109 111
 		}
110 112
 	case xfer.DoNotRetry:
111 113
 		return translatePullError(v.Err, ref)