Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2dc2ac2
Add version and hostname indexes to cache
nicholasmarais1158 Sep 16, 2025
5af5151
Add `ListBotInstancesV2` rpc and use request options
nicholasmarais1158 Sep 17, 2025
b295941
Add v2 bot instance list endpoint
nicholasmarais1158 Sep 17, 2025
144c659
Use v2 endpoint in web UI
nicholasmarais1158 Sep 17, 2025
ce44caf
Pass signal through to support aborting requests
nicholasmarais1158 Sep 17, 2025
877813f
Fix comment typo
nicholasmarais1158 Sep 18, 2025
3562bf5
Rename util func
nicholasmarais1158 Sep 18, 2025
77faebc
Deprecate `ListBotInstances` rpc
nicholasmarais1158 Sep 22, 2025
3cde394
Encode hostname in cache key
nicholasmarais1158 Sep 22, 2025
ba5d656
Address pre-release sorting in version numbers
nicholasmarais1158 Sep 22, 2025
55d2cca
Rename bot instance cache utils
nicholasmarais1158 Sep 22, 2025
09a48d4
Merge branch 'master' into nicholasmarais1158/feat/mwi-bot-instances-v2
nicholasmarais1158 Sep 22, 2025
044bef3
Fix lint deprecation warnings
nicholasmarais1158 Sep 22, 2025
04d30a4
Extract filter fields to message
nicholasmarais1158 Sep 24, 2025
2fbd797
Replace `fmt.Sprintf("%06d", ...)`
nicholasmarais1158 Sep 24, 2025
019340f
Update invalid sort field error
nicholasmarais1158 Sep 24, 2025
d1fb2f4
Fallback to v1 endpoint if possible
nicholasmarais1158 Sep 24, 2025
129a4a5
Use `strcase` for case-insensitive compare
nicholasmarais1158 Sep 24, 2025
e153fa9
Backend results are filtered by bot name so no need to re-filter in `…
nicholasmarais1158 Sep 24, 2025
4717dba
Merge branch 'master' into nicholasmarais1158/feat/mwi-bot-instances-v2
nicholasmarais1158 Sep 24, 2025
30392ba
Revert "Replace `fmt.Sprintf("%06d", ...)`"
nicholasmarais1158 Sep 25, 2025
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
252 changes: 208 additions & 44 deletions api/gen/proto/go/teleport/machineid/v1/bot_instance_service.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 37 additions & 1 deletion api/proto/teleport/machineid/v1/bot_instance_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@ message ListBotInstancesRequest {
types.SortBy sort = 5;
}

// Request for ListBotInstancesV2.
//
// Follows the pagination semantics of
// https://cloud.google.com/apis/design/standard_methods#list
message ListBotInstancesV2Request {
// The maximum number of items to return.
// The server may impose a different page size at its discretion.
int32 page_size = 1;
// The page_token value returned from a previous ListBotInstancesV2 request,
// if any.
string page_token = 2;
// The sort field to use for the results. If empty, the default sort field is
// used.
string sort_field = 3;
// The sort order to use for the results. If empty, the default sort order is
// used.
bool sort_desc = 4;
// Fields used to filter the results
Filters filter = 5;

// Filters contains fields to be used to filter the results.
message Filters {
// The name of the Bot to list BotInstances for. If non-empty, only
// BotInstances for that bot will be listed.
string bot_name = 1;
// A search term used to filter the results. If non-empty, it's used to
// match against supported fields.
string search_term = 2;
}
}

// Response for ListBotInstances.
message ListBotInstancesResponse {
// BotInstance that matched the search.
Expand Down Expand Up @@ -83,7 +114,12 @@ service BotInstanceService {
// GetBotInstance returns the specified BotInstance resource.
rpc GetBotInstance(GetBotInstanceRequest) returns (BotInstance);
// ListBotInstances returns a page of BotInstance resources.
rpc ListBotInstances(ListBotInstancesRequest) returns (ListBotInstancesResponse);
// Deprecated: Use ListBotInstancesV2 instead
rpc ListBotInstances(ListBotInstancesRequest) returns (ListBotInstancesResponse) {
option deprecated = true;
}
// ListBotInstancesV2 returns a page of BotInstance resources.
rpc ListBotInstancesV2(ListBotInstancesV2Request) returns (ListBotInstancesResponse);
// DeleteBotInstance hard deletes the specified BotInstance resource.
rpc DeleteBotInstance(DeleteBotInstanceRequest) returns (google.protobuf.Empty);
// SubmitHeartbeat submits a heartbeat for a BotInstance.
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/authclient/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ type Cache interface {
GetBotInstance(ctx context.Context, botName, instanceID string) (*machineidv1.BotInstance, error)

// ListBotInstances returns a page of BotInstance resources.
ListBotInstances(ctx context.Context, botName string, pageSize int, lastToken string, search string, sort *types.SortBy) ([]*machineidv1.BotInstance, string, error)
ListBotInstances(ctx context.Context, pageSize int, lastToken string, options *services.ListBotInstancesRequestOptions) ([]*machineidv1.BotInstance, string, error)
Comment thread
nicholasmarais1158 marked this conversation as resolved.

// ListProvisionTokens returns a paginated list of provision tokens.
ListProvisionTokens(ctx context.Context, pageSize int, pageToken string, anyRoles types.SystemRoles, botName string) ([]types.ProvisionToken, string, error)
Expand Down
29 changes: 27 additions & 2 deletions lib/auth/machineid/machineidv1/bot_instance_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type BotInstancesCache interface {
GetBotInstance(ctx context.Context, botName, instanceID string) (*pb.BotInstance, error)

// ListBotInstances returns a page of BotInstance resources.
ListBotInstances(ctx context.Context, botName string, pageSize int, lastToken string, search string, sort *types.SortBy) ([]*pb.BotInstance, string, error)
ListBotInstances(ctx context.Context, pageSize int, lastToken string, options *services.ListBotInstancesRequestOptions) ([]*pb.BotInstance, string, error)
}

// BotInstanceServiceConfig holds configuration options for the BotInstance gRPC
Expand Down Expand Up @@ -148,6 +148,26 @@ func (b *BotInstanceService) GetBotInstance(ctx context.Context, req *pb.GetBotI

// ListBotInstances returns a list of bot instances matching the criteria in the request
func (b *BotInstanceService) ListBotInstances(ctx context.Context, req *pb.ListBotInstancesRequest) (*pb.ListBotInstancesResponse, error) {
var sortField string
var sortDesc bool
if req.GetSort() != nil {
sortField = req.GetSort().Field
sortDesc = req.GetSort().IsDesc
}
return b.ListBotInstancesV2(ctx, &pb.ListBotInstancesV2Request{
PageSize: req.GetPageSize(),
PageToken: req.GetPageToken(),
SortField: sortField,
SortDesc: sortDesc,
Filter: &pb.ListBotInstancesV2Request_Filters{
BotName: req.GetFilterBotName(),
SearchTerm: req.GetFilterSearchTerm(),
},
})
}

// ListBotInstancesV2 returns a list of bot instances matching the criteria in the request
func (b *BotInstanceService) ListBotInstancesV2(ctx context.Context, req *pb.ListBotInstancesV2Request) (*pb.ListBotInstancesResponse, error) {
authCtx, err := b.authorizer.Authorize(ctx)
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -157,7 +177,12 @@ func (b *BotInstanceService) ListBotInstances(ctx context.Context, req *pb.ListB
return nil, trace.Wrap(err)
}

res, nextToken, err := b.cache.ListBotInstances(ctx, req.FilterBotName, int(req.PageSize), req.PageToken, req.FilterSearchTerm, req.Sort)
res, nextToken, err := b.cache.ListBotInstances(ctx, int(req.PageSize), req.PageToken, &services.ListBotInstancesRequestOptions{
SortField: req.GetSortField(),
SortDesc: req.GetSortDesc(),
FilterBotName: req.GetFilter().GetBotName(),
FilterSearchTerm: req.GetFilter().GetSearchTerm(),
})
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
8 changes: 8 additions & 0 deletions lib/auth/machineid/machineidv1/bot_instance_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func TestBotInstanceServiceAccess(t *testing.T) {
},
allowedVerbs: []string{types.VerbRead, types.VerbList},
},
{
name: "ListBotInstancesV2",
allowedStates: []authz.AdminActionAuthState{
authz.AdminActionAuthUnauthorized, authz.AdminActionAuthNotRequired,
authz.AdminActionAuthMFAVerified, authz.AdminActionAuthMFAVerifiedWithReuse,
},
allowedVerbs: []string{types.VerbRead, types.VerbList},
},
{
name: "DeleteBotInstance",
allowedStates: []authz.AdminActionAuthState{
Expand Down
Loading
Loading