{"id":"cfd92662ee77620b","repo":"spring-projects/spring-boot","slug":"invalid-docker-registry-configuration-either-t-cfd926","errorCode":null,"errorMessage":"Invalid Docker {} registry configuration, either token or username/password must be provided","messagePattern":"Invalid Docker (.+?) registry configuration, either token or username/password must be provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java","lineNumber":211,"sourceCode":"\n\tprivate DockerRegistryAuthentication getRegistryAuthentication(String type, @Nullable DockerRegistry registry,\n\t\t\tDockerRegistryAuthentication fallback) {\n\t\tif (registry == null || registry.isEmpty()) {\n\t\t\treturn fallback;\n\t\t}\n\t\tif (registry.hasTokenAuth() && !registry.hasUserAuth()) {\n\t\t\tString token = registry.getToken();\n\t\t\tAssert.state(token != null, \"'token' must not be null\");\n\t\t\treturn DockerRegistryAuthentication.token(token);\n\t\t}\n\t\tif (registry.hasUserAuth() && !registry.hasTokenAuth()) {\n\t\t\tString username = registry.getUsername();\n\t\t\tString password = registry.getPassword();\n\t\t\tAssert.state(username != null, \"'username' must not be null\");\n\t\t\tAssert.state(password != null, \"'password' must not be null\");\n\t\t\treturn DockerRegistryAuthentication.user(username, password, registry.getUrl(), registry.getEmail());\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Invalid Docker \" + type\n\t\t\t\t+ \" registry configuration, either token or username/password must be provided\");\n\t}\n\n\t/**\n\t * Encapsulates Docker registry authentication configuration options.\n\t */\n\tpublic static class DockerRegistry {\n\n\t\tprivate @Nullable String username;\n\n\t\tprivate @Nullable String password;\n\n\t\tprivate @Nullable String url;\n\n\t\tprivate @Nullable String email;\n\n\t\tprivate @Nullable String token;\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Docker.java#L193-L229","documentation":"Thrown by Docker.getRegistryAuthentication as an IllegalArgumentException when a registry (builder or publish) is configured but provides neither pure token auth nor pure username/password auth. The accepted combinations are exactly token-only or username+password-only; supplying both, supplying only a username without a password (or vice-versa), or supplying a token plus a username triggers this. The {} interpolates 'builder' or 'publish'.","triggerScenarios":"Setting <docker><builder><token>... and <docker><builder><username>... at the same time; configuring a registry with <username> but no <password>; configuring publish auth when image.publish is true but providing only partial credentials; migrating from user/pass to token auth and leaving the old fields populated.","commonSituations":"CI previously used username/password, switched to a registry token, but the old fields remained in the POM; a secrets-management plugin injecting only one of username/password; publish=true (which forces publish auth resolution) while publishRegistry holds partial credentials.","solutions":["Use exactly one auth method: <token> alone, or <username>+<password> together.","If using publish, ensure <publishRegistry> has complete credentials (or remove it to use the fallback).","Audit the POM and any properties files for stale username/password or token fields.","If credentials come from ~/.m2/settings.xml or env, verify all required values resolve."],"exampleFix":"// before — partial credentials\n<docker>\n  <publishRegistry>\n    <username>myuser</username>\n  </publishRegistry>\n</docker>\n// after — complete user/pass, or token only\n<docker>\n  <publishRegistry>\n    <username>myuser</username><password>${env.DOCKER_PASS}</password>\n  </publishRegistry>\n</docker>","handlingStrategy":"validation","validationCode":"// Validate registry auth shape before build-image\nimport java.util.Objects;\n\nvoid checkRegistry(String username, String password, String token, String type) {\n    boolean hasUser = username != null && password != null;\n    boolean hasToken = token != null;\n    if (hasUser == hasToken) { // both set, or both unset-but-not-empty-config\n        throw new IllegalArgumentException(\n            \"Invalid Docker \" + type + \" registry: provide token OR username+password\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly one auth mechanism per registry: <token> alone, or <username>+<password> together.","Source credentials from settings.xml or env vars and verify both username AND password resolve.","For publish=true, ensure <publishRegistry> is fully populated or omitted (to use the fallback)."],"tags":["maven","spring-boot","build-image","docker","registry","authentication"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}