fix: Docker login fails with GAR JSON key authentication#3936
Open
sdkakcy wants to merge 1 commit intoDokploy:canaryfrom
Open
fix: Docker login fails with GAR JSON key authentication#3936sdkakcy wants to merge 1 commit intoDokploy:canaryfrom
sdkakcy wants to merge 1 commit intoDokploy:canaryfrom
Conversation
- Use safeDockerLoginCommand in buildRemoteDocker - Replace "DockerHub Failed" with "Registry Login Failed" - Centralize Docker login logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
This PR fixes Docker registry authentication failures when using Google Artifact Registry (GAR) with JSON key credentials. The issue was caused by improper handling of special characters in JSON keys during docker login commands. The fix introduces a safeDockerLoginCommand helper function that properly escapes shell special characters and uses printf %s instead of echo to safely pass passwords containing newlines, quotes, and other special characters to docker login --password-stdin.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #3935
Screenshots (if applicable)
Greptile Summary
This PR fixes Docker registry login failures when using Google Artifact Registry (GAR) JSON key credentials by replacing the unsafe
echo "${password}" | docker login ...pattern with a newsafeDockerLoginCommandhelper that properly single-quote-escapes all inputs and usesprintf %sto pass the password to stdin — correctly handling special characters (newlines, double-quotes,$, backticks, etc.) that a JSON service account key typically contains.shEscapeinregistry.tsuses POSIX single-quote escaping ('\''for embedded single quotes), which prevents all shell interpretation inside the quoted string — this is the correct approach.printf %savoids the trailing-newline and escape-sequence interpretation issues ofecho, and since the password is always passed as a single-quoted argument,%characters in the password are not treated asprintfformat specifiers.upload.tsanddocker.ts) are updated consistently.printfformat string%sshould be quoted as'%s'per best practice, though it is functionally equivalent here.Confidence Score: 4/5
shEscape+ single-quoting) is correct and handles all edge cases in a GAR JSON key (actual newlines, double-quotes,$, backticks).printf %sis a well-known improvement overechofor piping passwords. The only finding is the cosmeticprintf %svsprintf '%s'style point — no functional bugs were identified.printfformat-string quoting suggestion inpackages/server/src/services/registry.ts.Comments Outside Diff (1)
packages/server/src/services/registry.ts, line 27 (link)Quote the
printfformat stringThe format string
%sis unquoted. While this is functionally safe here since%scontains no shell metacharacters, quoting it as'%s'is considered best practice — it also makes the intent clearer and guards against any future refactoring where the format string might become a variable.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Last reviewed commit: 484ceec
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!