-
Notifications
You must be signed in to change notification settings - Fork 14
feat: password sanitization #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ash-exp
wants to merge
29
commits into
main
Choose a base branch
from
feat-password-sanitization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
77bede9
feat: password sanitization
Ash-exp 12d497c
updated docker login
Ash-exp 3f7b9e8
fixed: format
Ash-exp 7988261
fixed: updated gitcli
Ash-exp 275e6c9
fixed: git cli issue
Ash-exp f298e8f
sanitised buildx commands
Ash-exp 21f3cfa
added comments and fixed build pack cmds
Ash-exp 4c7ca25
fixed: buildx k8s driver cmd
Ash-exp 49472de
sanitized
Ash-exp eda3833
Merge branch 'main' into feat-password-sanitization
Ash-exp db9823f
fixed: docker push command
Ash-exp 893b747
fixed: docker command
Ash-exp 544476c
Refactored: cli commands
Ash-exp 0e559e2
fixed: docker daemon command
Ash-exp c0da9c8
added empty arg check to cmd
Ash-exp 384c372
fixed: docker stop command
Ash-exp efe62ed
added logs for debugging
Ash-exp c2fc9de
added: todo
Ash-exp 2d753af
err log added
Ash-exp c69e8ea
added: log
Ash-exp 5051979
fixed: docker daemon command
Ash-exp 41c9945
reverted: docker daemon command
Ash-exp f62fa4a
debug: docker daemon command
e2d8c9b
removed: debug logs
8060139
debug: git merge logs
478119e
reverted: debug commits
Ash-exp 4762af6
updated: LOCAL_BUILDX_LOCATION value
Ash-exp a15cb45
feat: updated checkAndCreateDirectory
Ash-exp fdff04f
feat: updated checkAndCreateDirectory
Ash-exp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,13 @@ func NewGitUtil() *GitUtil { | |
|
|
||
| const GIT_AKS_PASS = "/git-ask-pass.sh" | ||
|
|
||
| // Fetch uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) Fetch(gitContext GitContext, rootDir string) (response, errMsg string, err error) { | ||
| log.Println(util.DEVTRON, "git fetch ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "fetch", "origin", "--tags", "--force") | ||
|
|
@@ -28,6 +35,13 @@ func (impl *GitUtil) Fetch(gitContext GitContext, rootDir string) (response, err | |
| return output, "", nil | ||
| } | ||
|
|
||
| // Checkout uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) Checkout(rootDir string, checkout string) (response, errMsg string, err error) { | ||
| log.Println(util.DEVTRON, "git checkout ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "checkout", checkout, "--force") | ||
|
|
@@ -36,11 +50,18 @@ func (impl *GitUtil) Checkout(rootDir string, checkout string) (response, errMsg | |
| return output, "", nil | ||
| } | ||
|
|
||
| // runCommandWithCred uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) runCommandWithCred(cmd *exec.Cmd, userName, password string) (response, errMsg string, err error) { | ||
| cmd.Env = append(os.Environ(), | ||
| fmt.Sprintf("GIT_ASKPASS=%s", GIT_AKS_PASS), | ||
| fmt.Sprintf("GIT_USERNAME=%s", userName), // ignored | ||
| fmt.Sprintf("GIT_PASSWORD=%s", password), // this value is used | ||
| fmt.Sprintf("GIT_USERNAME=%q", userName), // ignored; %q is used intentionally to sanitise the username | ||
| fmt.Sprintf("GIT_PASSWORD=%q", password), // this value is used; %q is used intentionally to sanitise the password | ||
| ) | ||
| return impl.runCommand(cmd) | ||
| } | ||
|
|
@@ -99,16 +120,30 @@ func (impl *GitUtil) Clone(gitContext GitContext, rootDir string, remoteUrl stri | |
| return response, errMsg, err | ||
| } | ||
|
|
||
| // setting user.name and user.email as for non-fast-forward merge, git ask for user.name and email | ||
| // Merge sets user.name and user.email as for non-fast-forward merge, git ask for user.name and email | | ||
| // Merge uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) Merge(rootDir string, commit string) (response, errMsg string, err error) { | ||
| log.Println(util.DEVTRON, "git merge ", "location", rootDir) | ||
| command := "cd " + rootDir + " && git config user.email [email protected] && git config user.name Devtron && git merge " + commit + " --no-commit" | ||
| command := fmt.Sprintf("cd %q && git config user.email [email protected] && git config user.name Devtron && git merge %q --no-commit", rootDir, commit) | ||
| cmd := exec.Command("/bin/sh", "-c", command) | ||
| output, errMsg, err := impl.runCommand(cmd) | ||
| log.Println(util.DEVTRON, "merge output", "root", rootDir, "opt", output, "errMsg", errMsg, "error", err) | ||
| return output, errMsg, err | ||
| } | ||
|
|
||
| // RecursiveFetchSubmodules uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) RecursiveFetchSubmodules(rootDir string) (response, errMsg string, error error) { | ||
| log.Println(util.DEVTRON, "git recursive fetch submodules ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "submodule", "update", "--init", "--recursive") | ||
|
|
@@ -117,6 +152,13 @@ func (impl *GitUtil) RecursiveFetchSubmodules(rootDir string) (response, errMsg | |
| return output, eMsg, err | ||
| } | ||
|
|
||
| // UpdateCredentialHelper uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) UpdateCredentialHelper(rootDir string) (response, errMsg string, error error) { | ||
| log.Println(util.DEVTRON, "git credential helper store ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "config", "--global", "credential.helper", "store") | ||
|
|
@@ -125,6 +167,13 @@ func (impl *GitUtil) UpdateCredentialHelper(rootDir string) (response, errMsg st | |
| return output, eMsg, err | ||
| } | ||
|
|
||
| // UnsetCredentialHelper uses CLI to run git command and it is prone to script injection | | ||
| // Don'ts: | ||
| // 1- Never concatenate the whole cmd args into a single string and pass it as exec.Command(name, fmt.Sprintf("--flag1 %s --flag2 %s --flag3 %s", value1, value2, value3)) | | ||
| // DOs: | ||
| // 1- Break the command to name and []args as exec.Command(name, []arg...) | ||
| // 2- Use strings.TrimSpace() to build an user defined flags; e.g: fmt.Sprintf("--%s", strings.TrimSpace(userDefinedFlag)) | ||
| // 3- In case a single arg contains multiple user defined inputs, then use fmt.Sprintf() with %q to sanitize user defined inputs; exec.Command(name, "--flag=", fmt.Sprintf("key1=%q,key2=%q,key3=%q", userDefinedArg-1, userDefinedArg-2, userDefinedArg-2)) | ||
| func (impl *GitUtil) UnsetCredentialHelper(rootDir string) (response, errMsg string, error error) { | ||
| log.Println(util.DEVTRON, "git credential helper unset ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "config", "--global", "--unset", "credential.helper") | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.