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

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 <mohamedmohey2352@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2024

⚠️ 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 76 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
@mohamedawnallah
Copy link
Contributor Author

Hi @zhzhuang-zju, Could you please take a look at this PR if everything alright?

@zhzhuang-zju
Copy link
Contributor

Hi @zhzhuang-zju, Could you please take a look at this PR if everything alright?

Sorry for the late, I was on vacation recently and will respond shortly.

@zhzhuang-zju
Copy link
Contributor

/lgtm
thanks, this update improves the function's robustness and makes unit testing more convenient.
cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 8, 2024
@mohamedawnallah
Copy link
Contributor Author

Sorry for the late, I was on vacation recently and will respond shortly.

No worries. Hope you had great time in the vacation :)

@mohamedawnallah
Copy link
Contributor Author

Hi @RainbowMango, @XiShanYongYe-Chang, and @zhzhuang-zju,

Could we please get this PR merged? The unit test certificates PR #5559, which depends on this, has been stale for a while. If anything is needed to move it forward, please let me know.

Thanks! 🙏

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~
/approve

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2024
@karmada-bot karmada-bot merged commit c230b14 into karmada-io:master Oct 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. 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.

5 participants