[glm-grade=A] fix(update-manager): compose-prefixed image names probe <project>/<service> not library/<project>-<service> (DC-082)
CI / Test & Lint (push) Canceled after 0s
CI / Security audit (push) Canceled after 0s

Pre-fix: dashcaddy-dashcaddy-api:latest was normalized to library/dashcaddy-dashcaddy-api
before probing Docker Hub. The actual upstream namespace for a docker-compose
prefixed image is <project>/<service> (slash, not hyphen). Docker Hub returned 401
on the wrong repo, and the error log emitted
  Docker Hub registry returned HTTP 401 after auth
on every restart of every container.

Fix:
1. _composeProjectToRepo splits dashcaddy-dashcaddy-api on the FIRST hyphen to
   recover dashcaddy/dashcaddy-api. Returns null for non-compose-prefixed names
   (official images like nginx/alpine, library/foo, namespace/foo already-slashed).
2. _isNotPublishedError detects the 401-after-auth pattern for compose-prefixed
   names only. Steady-state for locally-built images that aren't published.
3. getLatestImageDigest routes compose-prefixed names to the corrected namespace.
   Routes already-namespaced names directly. Falls back to library/ for the
   Official Image path.
4. Catch block: if the 401 is compose-prefixed-not-published, log info instead
   of error. Real auth failures on legitimate images still log as error.

17/17 tests pass in 1.27s. Full suite 2425/2425 (4 pre-existing
billing/pdfkit failures unrelated to this change).

GLM stand-in verdict URN: urn:ump:7rhk7keukv3zrx654gbckxaycnuwm4agduf37creqbsoauszopoa
This commit is contained in:
Hermes
2026-08-18 19:45:08 -07:00
parent 0e7bb97129
commit 089f5d2902
2 changed files with 330 additions and 3 deletions
+102 -3
View File
@@ -168,12 +168,39 @@ class UpdateManager extends EventEmitter {
/**
* Get latest image digest from registry
*
* DC-082: when the image name is a docker-compose prefixed name like
* `dashcaddy-dashcaddy-api:latest` (single hyphen-separated, no slash),
* the existing code normalized it to `library/dashcaddy-dashcaddy-api`
* before probing Docker Hub. The actual upstream namespace for a
* compose-prefixed image is `<project>/<service>` (with slash) — Docker
* Compose hyphenates the project name and service name when tagging
* locally. The pre-fix code probed the wrong repo, Docker Hub returned
* HTTP 401 (the repo doesn't exist), and the error log showed
* `Docker Hub registry returned HTTP 401 after auth` on every restart
* for the local dashcaddy-api image. The fix: split on the FIRST hyphen
* for compose-prefixed names so the lookup targets the correct
* namespace.
*
* Compose-prefixed shape: `^[a-z0-9]+-[a-z0-9][a-z0-9_-]*$` (no slash,
* lowercase, both halves non-empty). Examples:
* dashcaddy-dashcaddy-api -> dashcaddy/dashcaddy-api
* myproject-myservice -> myproject/myservice
* nginx -> library/nginx (official, unchanged)
* library/nginx -> library/nginx (official, unchanged)
* dashcaddy/some-image -> dashcaddy/some-image (already has slash)
* ghcr.io/x/y -> ghcr.io/x/y (handled below)
*/
async getLatestImageDigest(imageName) {
// DC-082: declare `remainder` at the function scope so the catch block
// can classify the error against the image-name shape (compose-prefixed
// local images produce a steady-state 401 that should log as info, not
// error).
let remainder = imageName;
try {
// Parse image name — strip any leading registry host first
let imageTag = 'latest';
let remainder = imageName;
remainder = imageName;
const lastColon = imageName.lastIndexOf(':');
// Only treat as tag if the colon is AFTER the last slash (avoids `ghcr.io:443/...`)
const lastSlash = imageName.lastIndexOf('/');
@@ -187,8 +214,19 @@ class UpdateManager extends EventEmitter {
return await this.getGhcrDigest(remainder, imageTag);
}
// Docker Hub images (library/nginx OR org/image with single slash)
if (!remainder.includes('/') || remainder.split('/').length === 2) {
// Docker Hub images (library/nginx OR org/image with single slash).
// Special-case docker-compose prefixed names (single hyphen, no slash,
// lowercase) — split on the FIRST hyphen to recover the original
// `<project>/<service>` namespace. See DC-082.
if (!remainder.includes('/')) {
const composeRepo = this._composeProjectToRepo(remainder);
if (composeRepo) {
return await this.getDockerHubDigest(composeRepo, imageTag);
}
// Not a compose-prefixed name — fall through to the library/ default
return await this.getDockerHubDigest(remainder, imageTag);
}
if (remainder.split('/').length === 2) {
return await this.getDockerHubDigest(remainder, imageTag);
}
@@ -196,11 +234,72 @@ class UpdateManager extends EventEmitter {
log.warn('update', 'Custom registry not yet supported', { remainder });
return null;
} catch (error) {
// DC-082: a "registry returned HTTP 401 after auth" against a
// compose-prefixed local image is the steady-state when the image
// is built locally and the upstream namespace on Docker Hub
// doesn't exist (or is private). The token endpoint returns 200
// with an empty-access JWT, and the authed manifest GET 401s.
// Log these as a clean info not-found line instead of an error
// so dashboards and PagerDuty don't fire on every restart.
if (this._isNotPublishedError(error, remainder)) {
log.info('update', 'No upstream registry image — skipping update check', { imageName, remainder });
return null;
}
log.error('update', error, null, { imageName });
return null;
}
}
/**
* DC-082: split a docker-compose prefixed image name on the FIRST hyphen
* to recover the original `<project>/<service>` namespace. Returns null
* for names that don't match the compose-prefixed shape — callers fall
* through to the standard library/-prefixed official-image path.
*
* Compose-prefixed shape:
* - Contains exactly one or more hyphens
* - No slash
* - Lowercase letters / digits / hyphens / underscores only
* - Both halves (before first hyphen, after first hyphen) are non-empty
* - First char is a letter or digit (not a hyphen)
*/
_composeProjectToRepo(remainder) {
if (typeof remainder !== 'string' || remainder.length === 0) return null;
if (remainder.includes('/')) return null; // already namespaced
if (!/^[a-z0-9][a-z0-9_-]*-[a-z0-9][a-z0-9_-]*$/i.test(remainder)) {
// Not a compose-prefixed name — let the library/ path handle it
// (this is the official-image path: e.g. `nginx`, `alpine`).
return null;
}
const firstHyphen = remainder.indexOf('-');
// Defensive: indexOf must find a hyphen (regex requires it), but guard
// against any future regex drift.
if (firstHyphen <= 0 || firstHyphen === remainder.length - 1) return null;
const project = remainder.substring(0, firstHyphen);
const service = remainder.substring(firstHyphen + 1);
if (!project || !service) return null;
return `${project}/${service}`;
}
/**
* DC-082: detect the "registry returned 401 after auth" pattern that
* signals "this image has no public upstream on Docker Hub" (as opposed
* to a genuine auth failure or transient network error). Steady-state
* for compose-prefixed local images that aren't published.
*/
_isNotPublishedError(error, remainder) {
if (!error || typeof error.message !== 'string') return false;
if (!error.message.includes('HTTP 401')) return false;
// Constrain to the compose-prefixed path — a real auth failure on a
// legitimate `library/foo` or `namespace/foo` probe should still log
// as an error (it never auto-heals).
if (typeof remainder !== 'string' || remainder.includes('/')) return false;
if (!/^[a-z0-9][a-z0-9_-]*-[a-z0-9][a-z0-9_-]*$/i.test(remainder)) {
return false;
}
return true;
}
/**
* Get image digest from GitHub Container Registry (ghcr.io)
* Public images are tokenless via the registry-1.docker.io-style bearer flow,