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

Don't run auth check for every log fragment #740

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions pkg/api/server/v1alpha2/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func getLogRecord(txn *gorm.DB, parent, result, name string) (*db.Record, error)

// UpdateLog updates log record content
func (s *Server) UpdateLog(srv pb.Logs_UpdateLogServer) error {
var name string
var name, parent, resultName, recordName string
var bytesWritten int64
var rec *db.Record
var object *v1alpha2.Log
Expand All @@ -114,6 +114,14 @@ func (s *Server) UpdateLog(srv pb.Logs_UpdateLogServer) error {
if name == "" {
name = recv.GetName()
s.logger.Debugf("receiving logs for %s", name)
parent, resultName, recordName, err = log.ParseName(name)
if err != nil {
return s.handleReturn(srv, rec, object, bytesWritten, err)
}

if err := s.auth.Check(srv.Context(), parent, auth.ResourceLogs, auth.PermissionUpdate); err != nil {
return s.handleReturn(srv, rec, object, bytesWritten, err)
}
}
if name != recv.GetName() {
err := fmt.Errorf("cannot put logs for multiple records in the same server")
Expand All @@ -124,21 +132,11 @@ func (s *Server) UpdateLog(srv pb.Logs_UpdateLogServer) error {
err)
}

parent, resultName, recordName, err := log.ParseName(name)
if err != nil {
return s.handleReturn(srv, rec, object, bytesWritten, err)
}

if err := s.auth.Check(srv.Context(), parent, auth.ResourceLogs, auth.PermissionUpdate); err != nil {
return s.handleReturn(srv, rec, object, bytesWritten, err)
}

if rec == nil {
rec, err = getRecord(s.db.WithContext(srv.Context()), parent, resultName, recordName)
if err != nil {
return s.handleReturn(srv, rec, object, bytesWritten, err)
}

}

if stream == nil {
Expand Down