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

Introduce gosec for Static Application Security Testing (SAST) #954

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

thiyyakat
Copy link
Contributor

@thiyyakat thiyyakat commented Nov 13, 2024

What this PR does / why we need it:

This PR introduces two make targets: sast and sast-report to run gosec for Static Application Security Testing. Additionally, it also addresses the security vulnerabilities in the MCM repository. It uses the default ruleset of gosec from gardener/gardener as introduced in gardener/gardener#9959.

sast-report target has also been added as a dependency for the check target.

Which issue(s) this PR fixes:
Partially fixes #948

Special notes for your reviewer:
Tested manually to check if gosec is downloaded and installed to hack/tools/bin, if not already present, on running make sast and make sast-report.
Integration tests passed with provider-aws.

Release note:

Adding `gosec` for Static Application Security Testing (SAST).

@thiyyakat thiyyakat requested a review from a team as a code owner November 13, 2024 09:07
@gardener-robot gardener-robot added needs/review Needs review size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Nov 13, 2024
@gardener-robot-ci-1
Copy link
Contributor

Thank you @thiyyakat for your contribution. Before I can start building your PR, a member of the organization must set the required label(s) {'reviewed/ok-to-test'}. Once started, you can check the build status in the PR checks section below.

@rishabh-11 rishabh-11 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 13, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 13, 2024
@gardener-robot gardener-robot added the needs/rebase Needs git rebase label Nov 14, 2024
@gardener-robot
Copy link

@thiyyakat You need rebase this pull request with latest master branch. Please check.

@rishabh-11 rishabh-11 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed needs/rebase Needs git rebase needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 15, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 15, 2024
Copy link
Contributor

@rishabh-11 rishabh-11 left a comment

Choose a reason for hiding this comment

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

/lgtm

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/review Needs review labels Nov 15, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 15, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 15, 2024
@rishabh-11 rishabh-11 merged commit f17b00e into gardener:master Nov 15, 2024
8 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Nov 15, 2024

.PHONY: sast
sast: $(GOSEC)
@chmod +xw hack/sast.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required? When you introduce a new script you already give it execute permissions and then onwards those permissions are preserved and therefore there is no real need to add this as part of the make target.


.PHONY: sast-report
sast-report:$(GOSEC)
@chmod +xw hack/sast.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

same as the comment for sast target.


if spec.Replicas < 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("replicas"), "Replicas has to be a whole number"))
func canConvertIntOrStringToInt32(val *intstr.IntOrString, replicas int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very generic function, can we move elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's used here only. If we feel like it is required elsewhere, then we'll put it in separate location

if spec.Strategy.Type != "RollingUpdate" && spec.Strategy.Type != "Recreate" {
allErrs = append(allErrs, field.Required(fldPath.Child("strategy.type"), "Type can either be RollingUpdate or Recreate"))
}
if spec.Strategy.Type == "RollingUpdate" {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use:

if spec.Strategy.Type == v1alpha1.MachineDeploymentStrategyType

instead

if spec.Strategy.Type != "RollingUpdate" && spec.Strategy.Type != "Recreate" {
allErrs = append(allErrs, field.Required(fldPath.Child("strategy.type"), "Type can either be RollingUpdate or Recreate"))
}
if spec.Strategy.Type == "RollingUpdate" {
if spec.Strategy.RollingUpdate == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this check done?
As per the doc string if MaxUnavailable is not specified then By default, a fixed value of 1 is used.
Similarly for MaxSurge its mentioned that By default, a value of 1 is used.
So either the doc string needs correction or this check needs to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The doc string is incorrect. If both are zero then we use maxUnavailable as 1.

thiyyakat added a commit to thiyyakat/machine-controller-manager that referenced this pull request Nov 22, 2024
thiyyakat added a commit to thiyyakat/machine-controller-manager that referenced this pull request Nov 22, 2024
rishabh-11 pushed a commit that referenced this pull request Nov 22, 2024
…update (#956)

* Fix edge-case where scale-from-zero is mistaken for rolling update

* Address review comments

* Address review comments of PR #954

* Address review comments

* Fix unit test
acumino pushed a commit to acumino/machine-controller-manager that referenced this pull request Nov 25, 2024
…dener#954)

* Introduce make targets for sast and address security issues.

* Address review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) status/closed Issue is closed (either delivered or triaged)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce gosec for Static Application Security Testing (SAST)
7 participants