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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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 60.93%. Comparing base (2c4c9df) to head (9851466).
Report is 6 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%   60.93%   +0.09%     
==========================================
  Files         354      354              
  Lines       40935    40935              
==========================================
+ Hits        24903    24942      +39     
+ Misses      13772    13714      -58     
- Partials     2260     2279      +19     
Flag Coverage Δ
unittests 60.93% <50.00%> (+0.09%) ⬆️

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
4 participants