Skip to content

Commit

Permalink
fix: only expire machines from tailnet of the auth filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Jun 1, 2022
1 parent b9b42d8 commit 687fcd1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/domain/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ func (r *repository) SetMachineLastSeen(ctx context.Context, machineID uint64) e
return nil
}

func (r *repository) ExpireMachineByAuthMethod(ctx context.Context, authMethodID uint64) (int64, error) {
func (r *repository) ExpireMachineByAuthMethod(ctx context.Context, tailnetID, authMethodID uint64) (int64, error) {
now := time.Now().UTC()

subQuery := r.withContext(ctx).
Select("machines.id").
Table("machines").
Joins("JOIN users u on u.id = machines.user_id JOIN accounts a on a.id = u.account_id").
Where("a.auth_method_id = ?", authMethodID)
Where("machines.tailnet_id = ? AND a.auth_method_id = ?", tailnetID, authMethodID)

tx := r.withContext(ctx).
Table("machines").
Expand Down
2 changes: 1 addition & 1 deletion internal/domain/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Repository interface {
ListMachinePeers(ctx context.Context, tailnetID uint64, key string) (Machines, error)
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
SetMachineLastSeen(ctx context.Context, machineID uint64) error
ExpireMachineByAuthMethod(ctx context.Context, authMethodID uint64) (int64, error)
ExpireMachineByAuthMethod(ctx context.Context, tailnetID, authMethodID uint64) (int64, error)

SaveRegistrationRequest(ctx context.Context, request *RegistrationRequest) error
GetRegistrationRequestByKey(ctx context.Context, key string) (*RegistrationRequest, error)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/auth_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Service) DeleteAuthFilter(ctx context.Context, req *api.DeleteAuthFilte
return status.Error(codes.NotFound, "auth filter not found")
}

c, err := rp.ExpireMachineByAuthMethod(ctx, filter.AuthMethodID)
c, err := rp.ExpireMachineByAuthMethod(ctx, *filter.TailnetID, filter.AuthMethodID)
if err != nil {
return err
}
Expand Down

0 comments on commit 687fcd1

Please sign in to comment.