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

[Security Hardened Kubernetes Cluster] Rule 2005 implementation #380

Merged

Conversation

AleksandarSavchev
Copy link
Member

What this PR does / why we need it:

Which issue(s) this PR fixes:
Part of #356

Special notes for your reviewer:

Release note:

Implementation for rule `2005` from the `security-hardened-k8s` ruleset for provider `managedk8s`.

@AleksandarSavchev AleksandarSavchev requested a review from a team as a code owner November 25, 2024 14:09
@gardener-robot gardener-robot added needs/review Needs review size/l Size of pull request is large (see gardener-robot robot/bots/size.py) needs/second-opinion Needs second review by someone else labels Nov 25, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) 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 25, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev left a comment

Choose a reason for hiding this comment

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

Just a few change requests.


type Rule2005 struct {
Client client.Client
Options *Options2005
Copy link
Member

Choose a reason for hiding this comment

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

Please ensure that this implements the required Option interface.

}

type Options2005 struct {
AllowedRepositories []AllowedRepository `json:"allowedRepositories" yaml:"allowedRepositories"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AllowedRepositories []AllowedRepository `json:"allowedRepositories" yaml:"allowedRepositories"`
AllowedRepositories []AllowedRepository `json:"allowedImages" yaml:"allowedImages"`

return rule.Result(r, rule.ErroredCheckResult("rule options are missing, but required", nil)), nil
}

var checkResults []rule.CheckResult
Copy link
Member

Choose a reason for hiding this comment

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

Please move this closer to its use.

checkResults = append(checkResults, rule.ErroredCheckResult(err.Error(), containerTarget.With("imageRef", imageRef)))
continue
}
imageBase := named.Name()
Copy link
Member

Choose a reason for hiding this comment

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

Let's also include the version/hash when comparing to prefixes

}) {
checkResults = append(checkResults, rule.PassedCheckResult("Image comes from allowed repository.", containerTarget.With("imageBase", imageBase)))
} else {
checkResults = append(checkResults, rule.FailedCheckResult("Image comes from not allowed repository.", containerTarget.With("imageBase", imageBase)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
checkResults = append(checkResults, rule.FailedCheckResult("Image comes from not allowed repository.", containerTarget.With("imageBase", imageBase)))
checkResults = append(checkResults, rule.FailedCheckResult("Image has not allowed prefix.", containerTarget.With("imageRef", imageRef)))

@gardener-robot gardener-robot added the needs/changes Needs (more) changes label Nov 25, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 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 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 25, 2024
dimityrmirchev
dimityrmirchev previously approved these changes Nov 26, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev left a comment

Choose a reason for hiding this comment

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

Two really small suggestions


func (r *Rule2005) Run(ctx context.Context) (rule.RuleResult, error) {
if r.Options == nil {
return rule.Result(r, rule.ErroredCheckResult("rule options are missing, but required", nil)), nil
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 that we should rather report such error earlier. And/Or return a failed result when allowed images are not configured since all images are disallowed. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be best if the ruleset can run without requiring any options to be set. The earlier place to report this error would be when we register the rules.

We can change this check result to Failed and change the message to "There are no configured allowed images."

# - ruleID: "2005"
# args:
# allowedImages:
# - prefix: "repository.prefix"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# - prefix: "repository.prefix"
# - prefix: "example.foo.repository/organisation/releases/"

@gardener-robot-ci-1 gardener-robot-ci-1 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 27, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 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 27, 2024
dimityrmirchev
dimityrmirchev previously approved these changes Nov 27, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev 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/changes Needs (more) changes labels Nov 27, 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 27, 2024
@gardener-robot gardener-robot removed needs/review Needs review needs/second-opinion Needs second review by someone else labels Nov 27, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 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 27, 2024
@gardener-robot gardener-robot added needs/changes Needs (more) changes needs/review Needs review and removed needs/review Needs review labels Nov 27, 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 27, 2024
@gardener-robot gardener-robot added needs/second-opinion Needs second review by someone else and removed reviewed/lgtm Has approval for merging labels Nov 27, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 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 27, 2024
Copy link
Member

@dimityrmirchev dimityrmirchev left a comment

Choose a reason for hiding this comment

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

/lgtm

@dimityrmirchev dimityrmirchev merged commit 3f6469e into gardener:main Nov 27, 2024
9 checks passed
@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging status/closed Issue is closed (either delivered or triaged) and removed needs/changes Needs (more) changes needs/second-opinion Needs second review by someone else labels Nov 27, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 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 27, 2024
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 reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) size/l Size of pull request is large (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.

6 participants