Skip to content

Commit

Permalink
Check permission when operating on lease
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCao committed Aug 19, 2024
1 parent 298c3ea commit 0c78b47
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/service/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net"
"os"
"strings"
Expand Down Expand Up @@ -440,6 +441,10 @@ func (s *ControllerService) GetLease(
return nil, err
}

if lease.Spec.ClientName != client.Name {
return nil, fmt.Errorf("GetLease permission denied")
}

var matchExpressions []*pb.LabelSelectorRequirement
for _, exp := range lease.Spec.Selector.MatchExpressions {
matchExpressions = append(matchExpressions, &pb.LabelSelectorRequirement{
Expand Down Expand Up @@ -519,6 +524,10 @@ func (s *ControllerService) DeleteLease(
return nil, err
}

if lease.Spec.ClientName != client.Name {
return nil, fmt.Errorf("DeleteLease permission denied")
}

if err := s.Delete(ctx, &lease); err != nil {
return nil, err
}
Expand Down

0 comments on commit 0c78b47

Please sign in to comment.