Skip to content
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

Use utils.command to replace exec.command #3686

Merged

Conversation

cheyang
Copy link
Collaborator

@cheyang cheyang commented Jan 11, 2024

Ⅰ. Describe what this PR does

Ⅱ. Does this pull request fix one issue?

fixes #XXXX

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (453b086) 64.47% compared to head (21ae0ba) 64.46%.
Report is 25 commits behind head on master.

Files Patch % Lines
pkg/utils/home.go 0.00% 14 Missing ⚠️
pkg/utils/helm/utils.go 55.55% 4 Missing and 4 partials ⚠️
pkg/utils/kubectl/configmap.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3686      +/-   ##
==========================================
- Coverage   64.47%   64.46%   -0.01%     
==========================================
  Files         471      472       +1     
  Lines       28140    28180      +40     
==========================================
+ Hits        18142    18165      +23     
- Misses       7844     7856      +12     
- Partials     2154     2159       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cheyang cheyang changed the title Move exec command into helper Use safe command Jan 11, 2024
)

// allowPathlist of safe commands
var allowPathlist = map[string]bool{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming it to allowCommandList?

}

// CheckCommandArgs is check string is valid in args
func checkCommandArgs(arg ...string) (err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this by using strings.ContainsAny()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can indicate which char is illegalChar.

@@ -93,7 +93,10 @@ func GenerateHelmTemplate(name string, namespace string, valueFileName string, c
// return syscall.Exec(cmd, args, env)
// 5. execute the command
log.V(1).Info("Generating template", "args", args)
cmd := exec.Command("bash", "-c", strings.Join(args, " "))
cmd, err := utils.SafeCommand("bash", "-c", strings.Join(args, " "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems in a unused function? How about removing the function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// allowPathlist of safe commands
var allowPathlist = map[string]bool{
// "helm": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding ddc-helm to the white-list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I forgot it.

// allowPathlist of safe commands
var allowPathlist = map[string]bool{
// "helm": true,
"kubectl": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use func init() to find the kubectl and ddc-helm command path, and put them into the white list dynamically

@cheyang cheyang changed the title Use safe command Use utils.command to replace exec.command Jan 18, 2024
Signed-off-by: cheyang <[email protected]>

Remove unused method, To #53506158

Signed-off-by: cheyang <[email protected]>
Copy link

sonarcloud bot commented Jan 18, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

5 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@TrafalgarZZZ TrafalgarZZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Copy link

fluid-e2e-bot bot commented Jan 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: TrafalgarZZZ

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fluid-e2e-bot fluid-e2e-bot bot merged commit 5e13f2c into fluid-cloudnative:master Jan 19, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants