Skip to content

[Security Hardened Shoot Cluster] Rule 1003 implementation#454

Merged
AleksandarSavchev merged 5 commits intogardener:mainfrom
AleksandarSavchev:add-rule-1003-shs
Mar 25, 2025
Merged

[Security Hardened Shoot Cluster] Rule 1003 implementation#454
AleksandarSavchev merged 5 commits intogardener:mainfrom
AleksandarSavchev:add-rule-1003-shs

Conversation

@AleksandarSavchev
Copy link
Member

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #431

Special notes for your reviewer:

Release note:

Implementation for rule `1003` from the `security-hardened-shoot-cluster` ruleset for provider `garden`.

@AleksandarSavchev AleksandarSavchev requested a review from a team as a code owner March 20, 2025 14:08
@gardener-robot gardener-robot added needs/review size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 20, 2025
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.

Thanks. I have some suggestions

version: <supported-version>
```

The supported versions can be found in the used `CloudProfile`.
Copy link
Member

Choose a reason for hiding this comment

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

Why is this line removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Must have written on top of it 😅 my bad

```

The supported versions can be found in the used `CloudProfile`.
### 1003 - Shoot clusters should have Lakom extension configured correctly. <a id="1003"></a>
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
### 1003 - Shoot clusters should have Lakom extension configured correctly. <a id="1003"></a>
### 1003 - Shoot clusters should have the Lakom extension configured. <a id="1003"></a>

Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use must instead of should when severity is ranked HIGH?

### 1003 - Shoot clusters should have Lakom extension configured correctly. <a id="1003"></a>

#### Description
Shoot clusters should have Lakom extension configured correctly. Trusted public keys should be configured for the Lakom extension.
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
Shoot clusters should have Lakom extension configured correctly. Trusted public keys should be configured for the Lakom extension.
Lakom is an admission controller which implements image signature verification. Shoot clusters should have the Lakom extension configured with trusted public keys so that only trusted images are allowed in the cluster.

Shoot clusters should have Lakom extension configured correctly. Trusted public keys should be configured for the Lakom extension.

#### Fix
Follow the Lakom extension documentation on how to configure [TrustedKeysResourceName](https://github.com/gardener/gardener-extension-shoot-lakom-service/blob/v0.18.1/docs/usage/shoot-extension.md#trustedkeysresourcename)
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
Follow the Lakom extension documentation on how to configure [TrustedKeysResourceName](https://github.com/gardener/gardener-extension-shoot-lakom-service/blob/v0.18.1/docs/usage/shoot-extension.md#trustedkeysresourcename)
Follow the Lakom extension documentation on how to configure [TrustedKeysResourceName](https://github.com/gardener/gardener-extension-shoot-lakom-service/blob/v0.18.1/docs/usage/shoot-extension.md#trustedkeysresourcename).

}

func (r *Rule1003) Severity() rule.SeverityLevel {
return rule.SeverityMedium
Copy link
Member

Choose a reason for hiding this comment

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

You set this to MEDIUM, but the documentation says HIGH?

}

if lakomConfig.TrustedKeysResourceName == nil || len(*lakomConfig.TrustedKeysResourceName) == 0 {
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have TrustedKeysResourceName configured.", lakomExtensionType), rule.NewTarget())), nil
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
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have TrustedKeysResourceName configured.", lakomExtensionType), rule.NewTarget())), nil
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not configure trusted keys.", lakomExtensionType), rule.NewTarget())), nil


if lakomConfig.TrustedKeysResourceName == nil || len(*lakomConfig.TrustedKeysResourceName) == 0 {
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have TrustedKeysResourceName configured.", lakomExtensionType), rule.NewTarget())), nil
} else {
Copy link
Member

Choose a reason for hiding this comment

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

No need for the else. It causes not needed nesting

return rule.Result(r, rule.PassedCheckResult(fmt.Sprintf("Extension %s is correctly configured for the shoot cluster.", lakomExtensionType), rule.NewTarget())), nil
}
case extensionLabelValue == "true" && !extensionDisabled:
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have extension config configured for the shoot cluster.", lakomExtensionType), rule.NewTarget())), nil
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
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have extension config configured for the shoot cluster.", lakomExtensionType), rule.NewTarget())), nil
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s is not configured for the shoot cluster.", lakomExtensionType), rule.NewTarget())), nil

case extensionLabelValue == "true" && !extensionDisabled:
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s does not have extension config configured for the shoot cluster.", lakomExtensionType), rule.NewTarget())), nil
case extensionLabelValue == "true" && extensionDisabled:
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s is disabled in the shoot spec and enabled in labels.", lakomExtensionType), rule.NewTarget())), nil
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a warning? What can cause this behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does make sense for this to not be marked as failed as we should never enter this case.

case extensionLabelValue == "true" && extensionDisabled:
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s is disabled in the shoot spec and enabled in labels.", lakomExtensionType), rule.NewTarget())), nil
default:
return rule.Result(r, rule.FailedCheckResult(fmt.Sprintf("Extension %s has unexpected label value: %s.", lakomExtensionType, extensionLabelValue), rule.NewTarget())), nil
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a warning?

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 have changed this one to warning now and added the changes to rule 1000 as well.

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

@AleksandarSavchev AleksandarSavchev merged commit 5a5b919 into gardener:main Mar 25, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security Hardened Shoot Cluster] Add rule 1003 to check Lakom extension configuration

5 participants