Skip to content
Merged
Show file tree
Hide file tree
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
151 changes: 117 additions & 34 deletions api/gen/proto/go/teleport/machineid/v1/bot_instance.pb.go

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

23 changes: 23 additions & 0 deletions api/proto/teleport/machineid/v1/bot_instance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,34 @@ message BotInstanceStatusHeartbeat {
// and updater status.
types.UpdaterV2Info updater_info = 12;

// Identifies whether the bot is running in the tbot binary or embedded in
// another component.
BotKind kind = 13;

// In future iterations, additional information can be submitted here.
// For example, the configuration of `tbot` or the health of individual
// outputs.
}

// BotKind identifies whether the bot is the tbot binary or embedded in another
// component.
enum BotKind {
// The enum zero-value, it means no kind was included.
BOT_KIND_UNSPECIFIED = 0;

// Means the bot is running the tbot binary.
BOT_KIND_TBOT = 1;

// Means the bot is running inside one of our Terraform providers.
BOT_KIND_TERRAFORM_PROVIDER = 2;

// Means the bot is running inside the Teleport Kubernetes operator.
BOT_KIND_KUBERNETES_OPERATOR = 3;

// Means the bot is running inside tctl (e.g. `tctl terraform env`)
BOT_KIND_TCTL = 4;
}

// BotInstanceStatusAuthentication contains information about a join or renewal.
// Ths information is entirely sourced by the Auth Server and can be trusted.
message BotInstanceStatusAuthentication {
Expand Down
1 change: 1 addition & 0 deletions integrations/lib/embeddedtbot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func New(botConfig *BotConfig, log *slog.Logger) (*EmbeddedBot, error) {
credential := &clientcredentials.UnstableConfig{}

cfg := bot.Config{
Kind: botConfig.Kind,
Connection: connection.Config{
Address: botConfig.AuthServer,
AddressKind: connection.AddressKindAuth,
Expand Down
1 change: 1 addition & 0 deletions integrations/lib/embeddedtbot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
// of the `lib/tbot/config.BotConfig` struct with CLI flags and operator-specific
// defaults.
type BotConfig struct {
Kind bot.Kind
AuthServer string
Onboarding onboarding.Config
CredentialLifetime bot.CredentialLifetime
Expand Down
3 changes: 2 additions & 1 deletion integrations/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/gravitational/teleport/integrations/lib/embeddedtbot"
"github.com/gravitational/teleport/integrations/operator/controllers"
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
"github.com/gravitational/teleport/lib/tbot/bot"
logutils "github.com/gravitational/teleport/lib/utils/log"
)

Expand Down Expand Up @@ -69,7 +70,7 @@ func main() {

config := &operatorConfig{}
config.BindFlags(flag.CommandLine)
botConfig := &embeddedtbot.BotConfig{}
botConfig := &embeddedtbot.BotConfig{Kind: bot.KindKubernetesOperator}
botConfig.BindFlags(flag.CommandLine)
flag.Parse()

Expand Down
1 change: 1 addition & 0 deletions integrations/terraform-mwi/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
botInternalStore := destination.NewMemory()
newBotConfig := func() bot.Config {
return bot.Config{
Kind: bot.KindTerraformProvider,
Connection: connection.Config{
Address: data.ProxyServer.ValueString(),
AddressKind: connection.AddressKindProxy,
Expand Down
1 change: 1 addition & 0 deletions integrations/terraform/provider/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ See https://goteleport.com/docs/reference/join-methods for more details.`)
return nil, trace.Wrap(err, "Invalid Join Method")
}
botConfig := &embeddedtbot.BotConfig{
Kind: bot.KindTerraformProvider,
AuthServer: addr,
Onboarding: onboarding.Config{
TokenValue: joinToken,
Expand Down
1 change: 1 addition & 0 deletions lib/tbot/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func (b *Bot) buildHeartbeatService(
statusRegistry *readyz.Registry,
) (*heartbeat.Service, error) {
return heartbeat.NewService(heartbeat.Config{
BotKind: machineidv1.BotKind(b.cfg.Kind),
Interval: 30 * time.Minute,
RetryLimit: 5,
Client: machineidv1.NewBotInstanceServiceClient(identityService.GetClient().GetConnection()),
Expand Down
28 changes: 28 additions & 0 deletions lib/tbot/bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gravitational/trace"
"github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"

machineidv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
"github.com/gravitational/teleport/lib/tbot/bot/connection"
"github.com/gravitational/teleport/lib/tbot/bot/destination"
"github.com/gravitational/teleport/lib/tbot/bot/onboarding"
Expand All @@ -33,6 +34,10 @@ import (
// Config contains the core bot's configuration. The tbot binary's configuration
// file format is handled by the lib/tbot/config package.
type Config struct {
// Kind identifies whether the bot is running in the tbot binary or embedded
// in another component.
Kind Kind

// Connection controls how the bot connects to the cluster.
Connection connection.Config

Expand Down Expand Up @@ -87,3 +92,26 @@ func (c *Config) CheckAndSetDefaults() error {
// dynamically registered (like the Kubernetes Secret Destination, which is only
// available if you import the k8s package) without maintaining a global registry.
type UnmarshalConfigContext = internal.UnmarshalConfigContext

// Kind identifies whether the bot is running in the tbot binary or embedded
// in another component
type Kind machineidv1.BotKind

const (
// KindUnspecified means no bot kind was given.
KindUnspecified = Kind(machineidv1.BotKind_BOT_KIND_UNSPECIFIED)

// KindTbot means the bot is running in the tbot binary.
KindTbot = Kind(machineidv1.BotKind_BOT_KIND_TBOT)

// KindTerraformProvider means the bot is embedded in one of our Terraform
// providers.
KindTerraformProvider = Kind(machineidv1.BotKind_BOT_KIND_TERRAFORM_PROVIDER)

// KindKubernetesOperator means the bot is embedded in our Kubernetes
// operator.
KindKubernetesOperator = Kind(machineidv1.BotKind_BOT_KIND_KUBERNETES_OPERATOR)

// KindTctl means the bot is embedded in tctl.
KindTctl = Kind(machineidv1.BotKind_BOT_KIND_TCTL)
)
5 changes: 5 additions & 0 deletions lib/tbot/internal/heartbeat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Client interface {

// Config for the heartbeat service.
type Config struct {
// BotKind identifies whether the bot is running in the tbot binary or
// embedded in another component
BotKind machineidv1pb.BotKind

// Interval controls how frequently heartbeats are submitted.
Interval time.Duration

Expand Down Expand Up @@ -173,6 +177,7 @@ func (s *Service) heartbeat(ctx context.Context, isOneShot, isStartup bool) erro
Version: teleport.Version,
Architecture: runtime.GOARCH,
Os: runtime.GOOS,
Kind: s.cfg.BotKind,
}

_, err = s.cfg.Client.SubmitHeartbeat(ctx, &machineidv1pb.SubmitHeartbeatRequest{
Expand Down
2 changes: 2 additions & 0 deletions lib/tbot/internal/heartbeat/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestHeartbeatService(t *testing.T) {
StartedAt: time.Date(2024, time.April, 1, 11, 0, 0, 0, time.UTC),
Logger: log,
JoinMethod: types.JoinMethodGitHub,
BotKind: machineidv1pb.BotKind_BOT_KIND_TBOT,
})
require.NoError(t, err)

Expand All @@ -99,6 +100,7 @@ func TestHeartbeatService(t *testing.T) {
Architecture: runtime.GOARCH,
Os: runtime.GOOS,
JoinMethod: string(types.JoinMethodGitHub),
Kind: machineidv1pb.BotKind_BOT_KIND_TBOT,
},
}
assert.Empty(t, cmp.Diff(want, got, protocmp.Transform()))
Expand Down
1 change: 1 addition & 0 deletions lib/tbot/tbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (b *Bot) Run(ctx context.Context) (err error) {
}

bt, err := bot.New(bot.Config{
Kind: bot.KindTbot,
Connection: b.cfg.ConnectionConfig(),
Onboarding: b.cfg.Onboarding,
InternalStorage: b.cfg.Storage.Destination,
Expand Down
Loading
Loading