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

operator/pkg/certs: mitigate potential null pointer dereference in AltNames Mutators for both the APIServer and EtcdServer #5560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mohamedawnallah
Copy link
Contributor

@mohamedawnallah mohamedawnallah commented Sep 16, 2024

Description

In this commit, we fix the null pointer dereference issue that happens in altnames mutators for both Karmada APIServer and EtcdServer when accessing the Components field on AltNamesMutatorConfig struct.

Motivation and Context

In testing the Certificate Manager and Karmada Store (#5559), empty Components in AltNamesMutatorConfig struct triggered a null pointer dereference in both APIServer and EtcdServer AltNames mutators. This PR resolves that issue.

What type of PR is this?

/kind bug

Does this PR introduce a user-facing change?:

NONE

In this commit, we fix th null pointer dereference issue
that happens in altnames mutators for both Karmada APIServer
and EtcdServer when accessing the `Components` field on
`AltNamesMutatorConfig` struct.

Signed-off-by: Mohamed Awnallah <[email protected]>
@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 16, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign calvin0327 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 34.14%. Comparing base (671372a) to head (89794f1).
Report is 22 commits behind head on master.

Files with missing lines Patch % Lines
operator/pkg/certs/certs.go 0.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5560      +/-   ##
==========================================
+ Coverage   33.71%   34.14%   +0.43%     
==========================================
  Files         643      643              
  Lines       44500    44524      +24     
==========================================
+ Hits        15001    15204     +203     
+ Misses      28357    28163     -194     
- Partials     1142     1157      +15     
Flag Coverage Δ
unittests 34.14% <0.00%> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@zhzhuang-zju
Copy link
Contributor

@mohamedawnallah

func setDefaultsKarmadaComponents(obj *Karmada) {
if obj.Spec.Components == nil {
obj.Spec.Components = &KarmadaComponents{}
}
setDefaultsEtcd(obj.Spec.Components)
setDefaultsKarmadaAPIServer(obj.Spec.Components)
setDefaultsKarmadaAggregatedAPIServer(obj.Spec.Components)
setDefaultsKubeControllerManager(obj.Spec.Components)
setDefaultsKarmadaControllerManager(obj.Spec.Components)
setDefaultsKarmadaScheduler(obj.Spec.Components)
setDefaultsKarmadaWebhook(obj.Spec.Components)
setDefaultsKarmadaMetricsAdapter(obj.Spec.Components)
setDefaultsKarmadaSearch(obj.Spec.Components)
// set addon defaults
setDefaultsKarmadaDescheduler(obj.Spec.Components)
}

The karmada-operator initializes Components.Etcd and Components.KarmadaAPIServer by default, so in actual runtime, a null pointer exception will not occur.

/remove-kind bug
/kind cleanup

@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed kind/bug Categorizes issue or PR as related to a bug. labels Sep 18, 2024
@mohamedawnallah
Copy link
Contributor Author

mohamedawnallah commented Sep 18, 2024

@zhzhuang-zju The PR title might be a bit unclear. While it’s true that this issue wouldn't cause a null pointer dereference at runtime in Karmada as you said, testing etcdServerAltNamesMutator and apiServerAltNamesMutator as isolated units in the unit tests would lead to a null pointer dereference in case of empty Components in AltNamesMutatorConfig struct. What do you think?

@zhzhuang-zju
Copy link
Contributor

How about operator/pkg/certs: mitigate potential null pointer dereference in AltNames Mutators for both the APIServer and EtcdServer

@mohamedawnallah mohamedawnallah changed the title operator/pkg/certs: fix null pointer dereference in AltNames Mutators for both the APIServer and EtcdServer operator/pkg/certs: mitigate potential null pointer dereference in AltNames Mutators for both the APIServer and EtcdServer Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants