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

Remove golang.org/x/crypto package Dependency #239

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

razo7
Copy link
Member

@razo7 razo7 commented Oct 31, 2024

Why we need this PR

Remove the golang.org/x/cryptopackage dependency when github.com/Masterminds/sprig is used. It is coming from running the go mod why command.

go mod why -m golang.org/x/crypto
# golang.org/x/crypto
github.com/medik8s/self-node-remediation/pkg/render
github.com/Masterminds/sprig
golang.org/x/crypto/scrypt

Changes made

  1. Remove Sprig functions and golang.org/x/crypto package dependency. No longer add Sprig (200+) universal functions when rendering the template. Add dummy function as it is needed for 1 unit test.
  2. Cleaning up unused modules using go mod ... commands.
  3. Remove deprecated function ReadFile and package io/ioutil and using os.ReadFile

Which issue(s) this PR fixes

Test plan

Copy link
Contributor

openshift-ci bot commented Oct 31, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@razo7
Copy link
Member Author

razo7 commented Nov 4, 2024

The changes in the PR are insufficient.
Before the renderTemplate function, the Sprig package was used to import (230) universal functions when some of the functions were implemented locally by Sprig.
There is no clear (1-1) alternative function, and if that still a requirement to have all the "old" functions then we need to look for more options

razo7 added 3 commits November 5, 2024 11:22
Package github.com/Masterminds/sprig imports a golang.org/x/crypto package that we wish to avoid. We remove all the unviersal functions from sprig as two of them, bcrypt and htpasswd use insecure algorithms from golang.org/x/crypto
Add missing and remove unused modules, make vendored copy of dependencies, and verify dependencies have expected content by go mod verify
As of Go 1.16, this function simply calls os.ReadFile, thus we can remove it and simply call os.ReadFile
@razo7 razo7 force-pushed the avoid-using-sprig branch from a573b7e to 288a8df Compare November 5, 2024 09:48
@razo7
Copy link
Member Author

razo7 commented Nov 5, 2024

The changes in the PR are insufficient.
Before the renderTemplate function, the Sprig package was used to import (230) universal functions when some of the functions were implemented locally by Sprig.
There is no clear (1-1) alternative function, and if that still a requirement to have all the "old" functions then we need to look for more options

The universal functions are redundant, so they are no longer needed.

@razo7
Copy link
Member Author

razo7 commented Nov 5, 2024

/test 4.16-openshift-e2e
/test 4.17-openshift-e2e

@razo7
Copy link
Member Author

razo7 commented Nov 5, 2024

/test 4.16-openshift-e2e

@@ -89,7 +89,8 @@ func TestDir(t *testing.T) {
g := NewGomegaWithT(t)

d := MakeRenderData()
d.Funcs["fname"] = func(s string) string { return s }
d.Funcs["fname"] = func(s string) string { return "test-" + s }
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a significant change to me, can you explain please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why it was changed. I reverted it

No changes are needed in the rendet_test.go file for applying the removal of github.com/Masterminds/sprig package
@razo7 razo7 force-pushed the avoid-using-sprig branch from e80d32c to aff549f Compare November 6, 2024 07:24
@razo7
Copy link
Member Author

razo7 commented Nov 6, 2024

/test 4.16-openshift-e2e
/test 4.17-openshift-e2e

Copy link
Contributor

openshift-ci bot commented Nov 6, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: razo7, slintes

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

@razo7 razo7 marked this pull request as ready for review November 11, 2024 06:13
@openshift-ci openshift-ci bot requested review from beekhof and mshitrit November 11, 2024 06:13
@openshift-merge-bot openshift-merge-bot bot merged commit 644140d into medik8s:main Nov 11, 2024
26 checks passed
@razo7
Copy link
Member Author

razo7 commented Nov 11, 2024

/cherry-pick release-0.9

@openshift-cherrypick-robot

@razo7: new pull request created: #241

In response to this:

/cherry-pick release-0.9

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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.

3 participants