Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1cbbe8c
Start sketching out BotService handler impl
strideynet Dec 6, 2023
4e448ed
Allow bots to be created without roles
strideynet Dec 12, 2023
f217d94
Fix up tests
strideynet Dec 12, 2023
d2e4c95
Add warning about adding a role to the bot
strideynet Dec 12, 2023
effb495
Improve resource type handling
strideynet Dec 13, 2023
f4cf615
Update tool/tctl/common/bots_command.go
strideynet Dec 14, 2023
238b811
Fix godoc for client
strideynet Dec 14, 2023
07a20d9
Explain ordering for bot resource application
strideynet Dec 14, 2023
0c5a9ae
Record CreatedBy for bot users
strideynet Dec 14, 2023
c2fc752
Don't display traits with zero length values
strideynet Dec 14, 2023
d552a14
Preserve json style output for `tctl bots add`
strideynet Dec 14, 2023
d439892
Unbreak tests broken by CreatedBy changes
strideynet Dec 14, 2023
e23ccce
Merge remote-tracking branch 'origin/master' into strideynet/machinei…
strideynet Dec 15, 2023
e472f48
Clarify deprecation/deletion
strideynet Dec 19, 2023
3b27833
Improve error message when no proxies
strideynet Dec 19, 2023
9c9a2f0
Merge remote-tracking branch 'origin/master' into strideynet/machinei…
strideynet Dec 19, 2023
00233f2
Merge branch 'master' into strideynet/machineid-service
strideynet Dec 19, 2023
7217691
Merge remote-tracking branch 'origin/master' into strideynet/machinei…
strideynet Dec 21, 2023
bd4abe9
An -> a
strideynet Dec 21, 2023
6da3b2a
Further clarify GoDoc
strideynet Dec 21, 2023
83272c9
Remove redundant case statements
strideynet Dec 21, 2023
88abec0
Remove unused import
strideynet Dec 21, 2023
191930b
Use `slices`
strideynet Dec 21, 2023
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
18 changes: 18 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
integrationpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/integration/v1"
kubeproto "github.com/gravitational/teleport/api/gen/proto/go/teleport/kube/v1"
loginrulepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/loginrule/v1"
machineidv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
oktapb "github.com/gravitational/teleport/api/gen/proto/go/teleport/okta/v1"
pluginspb "github.com/gravitational/teleport/api/gen/proto/go/teleport/plugins/v1"
resourceusagepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/resourceusage/v1"
Expand Down Expand Up @@ -849,6 +850,11 @@ func (c *Client) EmbeddingClient() assist.AssistEmbeddingServiceClient {
return assist.NewAssistEmbeddingServiceClient(c.conn)
}

// BotServiceClient returns an unadorned client for the bot service.
func (c *Client) BotServiceClient() machineidv1pb.BotServiceClient {
return machineidv1pb.NewBotServiceClient(c.conn)
}

// Ping gets basic info about the auth server.
func (c *Client) Ping(ctx context.Context) (proto.PingResponse, error) {
rsp, err := c.grpc.Ping(ctx, &proto.PingRequest{})
Expand Down Expand Up @@ -1135,7 +1141,11 @@ func (c *Client) CreateResetPasswordToken(ctx context.Context, req *proto.Create
}

// CreateBot creates a new bot from the specified descriptor.
//
// TODO(noah): DELETE IN 16.0.0
// Deprecated: use [machineidv1pb.BotServiceClient.CreateBot] instead.
func (c *Client) CreateBot(ctx context.Context, req *proto.CreateBotRequest) (*proto.CreateBotResponse, error) {
//nolint:staticcheck // SA1019. Kept for backward compatibility.
response, err := c.grpc.CreateBot(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -1145,15 +1155,23 @@ func (c *Client) CreateBot(ctx context.Context, req *proto.CreateBotRequest) (*p
}

// DeleteBot deletes a bot and associated resources.
//
// TODO(noah): DELETE IN 16.0.0
// Deprecated: use [machineidv1pb.BotServiceClient.DeleteBot] instead.
func (c *Client) DeleteBot(ctx context.Context, botName string) error {
//nolint:staticcheck // SA1019. Kept for backward compatibility.
_, err := c.grpc.DeleteBot(ctx, &proto.DeleteBotRequest{
Name: botName,
})
return trace.Wrap(err)
}

// GetBotUsers fetches all bot users.
//
// TODO(noah): DELETE IN 16.0.0
// Deprecated: use [machineidv1pb.BotServiceClient.ListBots] instead.
func (c *Client) GetBotUsers(ctx context.Context) ([]types.User, error) {
//nolint:staticcheck // SA1019. Kept for backward compatibility.
stream, err := c.grpc.GetBotUsers(ctx, &proto.GetBotUsersRequest{})
if err != nil {
return nil, trace.Wrap(err)
Expand Down
999 changes: 507 additions & 492 deletions api/client/proto/authservice.pb.go

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions api/gen/proto/go/teleport/machineid/v1/bot.pb.go

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

18 changes: 15 additions & 3 deletions api/proto/teleport/legacy/client/proto/authservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2650,11 +2650,23 @@ service AuthService {
rpc CreateResetPasswordToken(CreateResetPasswordTokenRequest) returns (types.UserTokenV3);

// CreateBot creates a new bot user.
rpc CreateBot(CreateBotRequest) returns (CreateBotResponse);
//
// Deprecated: Use [teleport.machineid.v1.BotService] instead.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I ensure that a doc link like this is valid?

This comment ends up in api/client/proto/authservice.pb.go. I was under the impression that if machineid.v1 is not directly imported in that file, then a doc link must use the full import path, which I assume would be github.com/gravitational/teleport/…. Isaiah pointed it out in one of my PRs but I've never tried to actually verify if my doc links are correct.

https://tip.golang.org/doc/comment#doclinks

I know it doesn't matter much as most of the time those "doc links" will not end up in any docs and are just for internal reference. Still, it's been bugging me since it was pointed out to me so I figured maybe you know the answer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I suppose it's a little odd here since my intention was to "comment on the proto" and therefore here I've referred to the proto service rather than the generated code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can:

$ go install golang.org/x/pkgsite/cmd/pkgsite@latest
$ pkgsite .

And then navigate to http://localhost:8080/github.com/gravitational/teleport#section-directories to see the docs rendered locally.

rpc CreateBot(CreateBotRequest) returns (CreateBotResponse) {
option deprecated = true;
}
// DeleteBot deletes a bot user.
rpc DeleteBot(DeleteBotRequest) returns (google.protobuf.Empty);
//
// Deprecated: Use [teleport.machineid.v1.BotService] instead.
rpc DeleteBot(DeleteBotRequest) returns (google.protobuf.Empty) {
option deprecated = true;
}
// GetBotUsers gets all users with bot labels.
rpc GetBotUsers(GetBotUsersRequest) returns (stream types.UserV2);
//
// Deprecated: Use [teleport.machineid.v1.BotService] instead.
rpc GetBotUsers(GetBotUsersRequest) returns (stream types.UserV2) {
option deprecated = true;
}

// GetUser gets a user resource by name.
//
Expand Down
75 changes: 75 additions & 0 deletions api/proto/teleport/legacy/types/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,78 @@ message RoleDelete {
];
}

// BotCreate is emitted when a bot is created/upserted.
message BotCreate {
// Metadata is a common event metadata
Metadata Metadata = 1 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// ResourceMetadata is a common resource event metadata
ResourceMetadata Resource = 2 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// User is a common user event metadata
UserMetadata User = 3 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];
}

// BotCreate is emitted when a bot is created/updated.
message BotUpdate {
// Metadata is a common event metadata
Metadata Metadata = 1 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// ResourceMetadata is a common resource event metadata
ResourceMetadata Resource = 2 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// User is a common user event metadata
UserMetadata User = 3 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];
}

// BotDelete is emitted when a bot is deleted.
message BotDelete {
// Metadata is a common event metadata
Metadata Metadata = 1 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// ResourceMetadata is a common resource event metadata
ResourceMetadata Resource = 2 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];

// User is a common user event metadata
UserMetadata User = 3 [
(gogoproto.nullable) = false,
(gogoproto.embed) = true,
(gogoproto.jsontag) = ""
];
}

// TrustedClusterCreate is the event for creating a trusted cluster.
message TrustedClusterCreate {
// Metadata is a common event metadata
Expand Down Expand Up @@ -3671,6 +3743,9 @@ message OneOf {
events.UserUpdate UserUpdate = 140;
events.ExternalAuditStorageEnable ExternalAuditStorageEnable = 141;
events.ExternalAuditStorageDisable ExternalAuditStorageDisable = 142;
events.BotCreate BotCreate = 143;
events.BotDelete BotDelete = 144;
events.BotUpdate BotUpdate = 145;
}
}

Expand Down
5 changes: 4 additions & 1 deletion api/proto/teleport/machineid/v1/bot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ message BotSpec {
// Fields that are set by the server as results of operations. These should not
// be modified by users.
message BotStatus {
reserved 2;
reserved "role_role";
Comment thread
timothyb89 marked this conversation as resolved.

// The name of the user associated with the bot.
string user_name = 1;
// The name of the role associated with the bot.
string role_role = 2;
string role_name = 3;
}
3 changes: 3 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const (
// KindUser is a user resource
KindUser = "user"

// KindBot is a Machine ID bot resource
KindBot = "bot"

// KindHostCert is a host certificate
KindHostCert = "host_cert"

Expand Down
Loading