diff --git a/api/gen/proto/go/usageevents/v1/usageevents.pb.go b/api/gen/proto/go/usageevents/v1/usageevents.pb.go index 7b699e131e695..2248de7f39086 100644 --- a/api/gen/proto/go/usageevents/v1/usageevents.pb.go +++ b/api/gen/proto/go/usageevents/v1/usageevents.pb.go @@ -3203,11 +3203,12 @@ func (m *UIIntegrationEnrollCompleteEvent) GetMetadata() *IntegrationEnrollMetad // ResourceCreateEvent is emitted when a resource is created. type ResourceCreateEvent struct { - // resource_type is the type of resource ("node", "node.openssh", "db", "k8s"). + // resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app"). ResourceType string `protobuf:"bytes,1,opt,name=resource_type,json=resourceType,proto3" json:"resource_type,omitempty"` - // resource_origin is the origin of the resource ("cloud"). + // resource_origin is the origin of the resource ("cloud", "kubernetes"). ResourceOrigin string `protobuf:"bytes,2,opt,name=resource_origin,json=resourceOrigin,proto3" json:"resource_origin,omitempty"` - // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP"). + // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP") + // if resource_origin == "cloud". CloudProvider string `protobuf:"bytes,3,opt,name=cloud_provider,json=cloudProvider,proto3" json:"cloud_provider,omitempty"` // database contains additional database information if resource_type == "db". Database *DiscoveredDatabaseMetadata `protobuf:"bytes,4,opt,name=database,proto3" json:"database,omitempty"` diff --git a/api/proto/teleport/usageevents/v1/usageevents.proto b/api/proto/teleport/usageevents/v1/usageevents.proto index 99d1dcdd325d1..452add9c85f9d 100644 --- a/api/proto/teleport/usageevents/v1/usageevents.proto +++ b/api/proto/teleport/usageevents/v1/usageevents.proto @@ -499,11 +499,12 @@ message UIIntegrationEnrollCompleteEvent { // ResourceCreateEvent is emitted when a resource is created. message ResourceCreateEvent { - // resource_type is the type of resource ("node", "node.openssh", "db", "k8s"). + // resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app"). string resource_type = 1; - // resource_origin is the origin of the resource ("cloud"). + // resource_origin is the origin of the resource ("cloud", "kubernetes"). string resource_origin = 2; - // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP"). + // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP") + // if resource_origin == "cloud". string cloud_provider = 3; // database contains additional database information if resource_type == "db". DiscoveredDatabaseMetadata database = 4; diff --git a/api/types/constants.go b/api/types/constants.go index b65de4ab93d15..ddf07591d23ac 100644 --- a/api/types/constants.go +++ b/api/types/constants.go @@ -677,6 +677,8 @@ const ( DiscoveredResourceKubernetes = "k8s" // DiscoveredResourceAgentlessNode identifies a discovered agentless SSH node. DiscoveredResourceAgentlessNode = "node.openssh" + // DiscoveredResourceApp identifies a discovered Kubernetes App. + DiscoveredResourceApp = "app" // TeleportAzureMSIEndpoint is a special URL intercepted by TSH local proxy, serving Azure credentials. TeleportAzureMSIEndpoint = "azure-msi." + TeleportNamespace diff --git a/gen/proto/go/prehog/v1alpha/teleport.pb.go b/gen/proto/go/prehog/v1alpha/teleport.pb.go index f1ba7b26bd2d9..e9eb9e0e7447d 100644 --- a/gen/proto/go/prehog/v1alpha/teleport.pb.go +++ b/gen/proto/go/prehog/v1alpha/teleport.pb.go @@ -943,11 +943,12 @@ type ResourceCreateEvent struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // resource_type is the type of resource ("node", "node.openssh", "db", "k8s"). + // resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app"). ResourceType string `protobuf:"bytes,1,opt,name=resource_type,json=resourceType,proto3" json:"resource_type,omitempty"` - // resource_origin is the origin of the resource ("cloud"). + // resource_origin is the origin of the resource ("cloud", "kubernetes"). ResourceOrigin string `protobuf:"bytes,2,opt,name=resource_origin,json=resourceOrigin,proto3" json:"resource_origin,omitempty"` - // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP"). + // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP") + // if resource_origin == "cloud". CloudProvider string `protobuf:"bytes,3,opt,name=cloud_provider,json=cloudProvider,proto3" json:"cloud_provider,omitempty"` // database contains additional database information if resource_type == "db". Database *DiscoveredDatabaseMetadata `protobuf:"bytes,4,opt,name=database,proto3" json:"database,omitempty"` diff --git a/lib/srv/discovery/kube_services_watcher.go b/lib/srv/discovery/kube_services_watcher.go index 1731e858e1cf5..814796ade6227 100644 --- a/lib/srv/discovery/kube_services_watcher.go +++ b/lib/srv/discovery/kube_services_watcher.go @@ -23,11 +23,14 @@ import ( "github.com/gravitational/trace" + usageeventsv1 "github.com/gravitational/teleport/api/gen/proto/go/usageevents/v1" "github.com/gravitational/teleport/api/types" "github.com/gravitational/teleport/lib/services" "github.com/gravitational/teleport/lib/srv/discovery/common" ) +const appEventPrefix = "app/" + func (s *Server) startKubeAppsWatchers() error { if len(s.kubeAppsFetchers) == 0 { return nil @@ -113,7 +116,20 @@ func (s *Server) onAppCreate(ctx context.Context, rwl types.ResourceWithLabels) if trace.IsAlreadyExists(err) { return trace.Wrap(s.onAppUpdate(ctx, rwl)) } - return trace.Wrap(err) + if err != nil { + return trace.Wrap(err) + } + err = s.emitUsageEvents(map[string]*usageeventsv1.ResourceCreateEvent{ + appEventPrefix + app.GetName(): { + ResourceType: types.DiscoveredResourceApp, + ResourceOrigin: types.OriginKubernetes, + // CloudProvider is not set for apps created from Kubernetes services + }, + }) + if err != nil { + s.Log.WithError(err).Debug("Error emitting usage event.") + } + return nil } func (s *Server) onAppUpdate(ctx context.Context, rwl types.ResourceWithLabels) error { diff --git a/proto/prehog/v1alpha/teleport.proto b/proto/prehog/v1alpha/teleport.proto index b6b3aac25153a..9aab3883b5a93 100644 --- a/proto/prehog/v1alpha/teleport.proto +++ b/proto/prehog/v1alpha/teleport.proto @@ -50,11 +50,12 @@ message SSOCreateEvent { // ResourceCreateEvent is emitted when a resource is created. message ResourceCreateEvent { - // resource_type is the type of resource ("node", "node.openssh", "db", "k8s"). + // resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app"). string resource_type = 1; - // resource_origin is the origin of the resource ("cloud"). + // resource_origin is the origin of the resource ("cloud", "kubernetes"). string resource_origin = 2; - // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP"). + // cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP") + // if resource_origin == "cloud". string cloud_provider = 3; // database contains additional database information if resource_type == "db". DiscoveredDatabaseMetadata database = 4;