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

fix: check data field for user provided tls #8200

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Conversation

loomts
Copy link
Contributor

@loomts loomts commented Sep 24, 2024

resolve #8199

@loomts loomts requested a review from a team as a code owner September 24, 2024 16:13
@github-actions github-actions bot added the size/S Denotes a PR that changes 10-29 lines. label Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 63.75%. Comparing base (2c4c9df) to head (9851466).
Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controller/plan/tls_utils.go 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8200      +/-   ##
==========================================
+ Coverage   60.83%   63.75%   +2.91%     
==========================================
  Files         354      361       +7     
  Lines       40935    45045    +4110     
==========================================
+ Hits        24903    28718    +3815     
- Misses      13772    13973     +201     
- Partials     2260     2354      +94     
Flag Coverage Δ
unittests 63.75% <50.00%> (+2.91%) ⬆️

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.

return errors.New("tls secret's data field shouldn't be nil")
}
keys := []string{secretRef.CA, secretRef.Cert, secretRef.Key}
for _, key := range keys {
if _, ok := secret.StringData[key]; !ok {
if (secret.StringData != nil && secret.StringData[key] == "") || (secret.Data != nil && secret.Data[key] == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check len(secret.Data[key]) == 0 instead, the value can be an empty string.

kubectl create secret generic test-empty-value \
    --from-literal=key=''

kubectl get secret test-empty-value -o yaml
>
apiVersion: v1
data:
  key: ""
kind: Secret
metadata:
  creationTimestamp: "2024-09-25T03:34:43Z"
  name: test-empty-value
  namespace: default
  resourceVersion: "2309582"
  uid: ff72e8d8-cbb2-4f7b-aac8-f5b6fd97b0b1
type: Opaque

@github-actions github-actions bot added size/M Denotes a PR that changes 30-99 lines. and removed size/S Denotes a PR that changes 10-29 lines. labels Sep 25, 2024
@apecloud-bot apecloud-bot added the approved PR Approved Test label Sep 25, 2024
@@ -109,12 +109,12 @@ func CheckTLSSecretRef(ctx context.Context, cli client.Reader, namespace string,
if err := cli.Get(ctx, types.NamespacedName{Namespace: namespace, Name: secretRef.Name}, secret); err != nil {
return err
}
if secret.StringData == nil {
if secret.StringData == nil && secret.Data == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It only needs to check the data field.

Copy link
Contributor Author

@loomts loomts Sep 26, 2024

Choose a reason for hiding this comment

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

fixed

@apecloud-bot apecloud-bot removed the approved PR Approved Test label Sep 26, 2024
@loomts loomts requested a review from free6om October 25, 2024 12:33
@apecloud-bot apecloud-bot added the approved PR Approved Test label Oct 30, 2024
@loomts loomts merged commit b171ec8 into main Oct 30, 2024
36 checks passed
@loomts loomts deleted the bugfix/user-provided-tls branch October 30, 2024 04:35
@github-actions github-actions bot added this to the Release 0.9.2 milestone Oct 30, 2024
@loomts
Copy link
Contributor Author

loomts commented Oct 31, 2024

/cherry-pick release-0.9

Copy link

🤖 says: ‼️ cherry pick action failed.
See: https://github.com/apecloud/kubeblocks/actions/runs/11608222001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved PR Approved Test size/M Denotes a PR that changes 30-99 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] user provided tls secret doesn't check data field
5 participants