diff --git a/lib/cloud/aws/aws.go b/lib/cloud/aws/aws.go index 50a27d991cca2..b1923a9bb9c3f 100644 --- a/lib/cloud/aws/aws.go +++ b/lib/cloud/aws/aws.go @@ -17,6 +17,8 @@ package aws import ( + "context" + "log/slog" "slices" "strings" @@ -27,9 +29,9 @@ import ( "github.com/aws/aws-sdk-go/service/rds" "github.com/aws/aws-sdk-go/service/redshift" "github.com/coreos/go-semver/semver" - log "github.com/sirupsen/logrus" "github.com/gravitational/teleport/lib/services" + logutils "github.com/gravitational/teleport/lib/utils/log" ) // IsResourceAvailable checks if the input status indicates the resource is @@ -38,7 +40,7 @@ import ( // Note that this function checks some common values but not necessarily covers // everything. For types that have other known status values, separate // functions (e.g. IsDBClusterAvailable) can be implemented. -func IsResourceAvailable(r interface{}, status *string) bool { +func IsResourceAvailable(r any, status *string) bool { switch strings.ToLower(aws.StringValue(status)) { case "available", "modifying", "snapshotting", "active": return true @@ -47,7 +49,10 @@ func IsResourceAvailable(r interface{}, status *string) bool { return false default: - log.WithField("aws_resource", r).Warnf("Unknown status type: %q. Assuming the AWS resource %T is available.", aws.StringValue(status), r) + slog.WarnContext(context.Background(), "Assuming that AWS resource with an unknown status is available", + "status", aws.StringValue(status), + "resource", logutils.TypeAttr(r), + ) return true } } @@ -89,7 +94,7 @@ func IsRDSInstanceSupported(instance *rds.DBInstance) bool { // MariaDB follows semver schema: https://mariadb.org/about/ ver, err := semver.NewVersion(aws.StringValue(instance.EngineVersion)) if err != nil { - log.Errorf("Failed to parse RDS MariaDB version: %s", aws.StringValue(instance.EngineVersion)) + slog.ErrorContext(context.Background(), "Failed to parse RDS MariaDB version", "version", aws.StringValue(instance.EngineVersion)) return false } @@ -152,7 +157,7 @@ func AuroraMySQLVersion(cluster *rds.DBCluster) string { func IsDocumentDBClusterSupported(cluster *rds.DBCluster) bool { ver, err := semver.NewVersion(aws.StringValue(cluster.EngineVersion)) if err != nil { - log.Errorf("Failed to parse DocumentDB engine version: %s", aws.StringValue(cluster.EngineVersion)) + slog.ErrorContext(context.Background(), "Failed to parse DocumentDB engine version", "version", aws.StringValue(cluster.EngineVersion)) return false } @@ -201,9 +206,9 @@ func IsRDSInstanceAvailable(instanceStatus, instanceIdentifier *string) bool { return false default: - log.Warnf("Unknown status type: %q. Assuming RDS instance %q is available.", - aws.StringValue(instanceStatus), - aws.StringValue(instanceIdentifier), + slog.WarnContext(context.Background(), "Assuming RDS instance with unknown status is available", + "status", aws.StringValue(instanceStatus), + "instance", aws.StringValue(instanceIdentifier), ) return true } @@ -230,9 +235,9 @@ func IsDBClusterAvailable(clusterStatus, clusterIndetifier *string) bool { return false default: - log.Warnf("Unknown status type: %q. Assuming Aurora cluster %q is available.", - aws.StringValue(clusterStatus), - aws.StringValue(clusterIndetifier), + slog.WarnContext(context.Background(), "Assuming Aurora cluster with unknown status is available", + "status", aws.StringValue(clusterStatus), + "cluster", aws.StringValue(clusterIndetifier), ) return true } @@ -264,9 +269,9 @@ func IsRedshiftClusterAvailable(cluster *redshift.Cluster) bool { return false default: - log.Warnf("Unknown status type: %q. Assuming Redshift cluster %q is available.", - aws.StringValue(cluster.ClusterStatus), - aws.StringValue(cluster.ClusterIdentifier), + slog.WarnContext(context.Background(), "Assuming Redshift cluster with unknown status is available", + "status", aws.StringValue(cluster.ClusterStatus), + "cluster", aws.StringValue(cluster.ClusterIdentifier), ) return true } diff --git a/lib/cloud/aws/policy.go b/lib/cloud/aws/policy.go index 0208dd8ae6bba..e69810af685df 100644 --- a/lib/cloud/aws/policy.go +++ b/lib/cloud/aws/policy.go @@ -21,6 +21,7 @@ package aws import ( "context" "encoding/json" + "log/slog" "net/url" "slices" "sort" @@ -29,7 +30,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/iam" iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types" "github.com/gravitational/trace" - log "github.com/sirupsen/logrus" awsutils "github.com/gravitational/teleport/lib/utils/aws" ) @@ -517,7 +517,10 @@ func (p *policies) Upsert(ctx context.Context, policy *Policy) (string, error) { return "", trace.Wrap(err) } - log.Debugf("Created new policy %q with ARN %q", policy.Name, policyARN) + slog.DebugContext(ctx, "Created new policy", + "policy_name", policy.Name, + "policy_arn", policyARN, + ) return policyARN, nil } @@ -543,7 +546,10 @@ func (p *policies) Upsert(ctx context.Context, policy *Policy) (string, error) { return "", trace.Wrap(err) } - log.Debugf("Max policy versions reached for policy %q, deleted policy version %q", policyARN, policyVersionID) + slog.DebugContext(ctx, "Max policy versions reached for policy, deleted non-default policy version", + "policy_arn", policyARN, + "policy_version", policyVersionID, + ) } // Create new policy version. @@ -552,7 +558,10 @@ func (p *policies) Upsert(ctx context.Context, policy *Policy) (string, error) { return "", trace.Wrap(err) } - log.Debugf("Created new policy version %q for %q", versionID, policyARN) + slog.DebugContext(ctx, "Created new policy version", + "policy_version", versionID, + "policy_arn", policyARN, + ) return policyARN, nil } diff --git a/lib/cloud/aws/tags_helpers.go b/lib/cloud/aws/tags_helpers.go index a6f9f26fdc1ab..27dbe8238f178 100644 --- a/lib/cloud/aws/tags_helpers.go +++ b/lib/cloud/aws/tags_helpers.go @@ -19,6 +19,8 @@ package aws import ( + "context" + "log/slog" "slices" ec2TypesV2 "github.com/aws/aws-sdk-go-v2/service/ec2/types" @@ -32,7 +34,6 @@ import ( "github.com/aws/aws-sdk-go/service/redshift" "github.com/aws/aws-sdk-go/service/redshiftserverless" "github.com/aws/aws-sdk-go/service/secretsmanager" - "github.com/sirupsen/logrus" "golang.org/x/exp/maps" "github.com/gravitational/teleport/api/types" @@ -67,7 +68,7 @@ func TagsToLabels[Tag ResourceTag](tags []Tag) map[string]string { if types.IsValidLabelKey(key) { labels[key] = value } else { - logrus.Debugf("Skipping AWS resource tag %q, not a valid label key.", key) + slog.DebugContext(context.Background(), "Skipping AWS resource tag with invalid label key", "key", key) } } return labels diff --git a/lib/cloud/azure/db_server.go b/lib/cloud/azure/db_server.go index 3efd2a65a7339..855274dfcd096 100644 --- a/lib/cloud/azure/db_server.go +++ b/lib/cloud/azure/db_server.go @@ -19,9 +19,11 @@ package azure import ( + "context" + "log/slog" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysql" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql" - log "github.com/sirupsen/logrus" "github.com/gravitational/teleport/lib/defaults" ) @@ -120,9 +122,9 @@ func (s *DBServer) IsAvailable() bool { case "Inaccessible", "Dropping", "Disabled": return false default: - log.Warnf("Unknown server state: %q. Assuming Azure DB server %q is available.", - s.Properties.UserVisibleState, - s.Name, + slog.WarnContext(context.Background(), "Assuming Azure DB server with unknown server state is available", + "state", s.Properties.UserVisibleState, + "server", s.Name, ) return true } diff --git a/lib/cloud/azure/kubernetes.go b/lib/cloud/azure/kubernetes.go index 1f2e0009daa59..ff78307b102f1 100644 --- a/lib/cloud/azure/kubernetes.go +++ b/lib/cloud/azure/kubernetes.go @@ -21,6 +21,7 @@ package azure import ( "context" "fmt" + "log/slog" "strings" "time" @@ -33,7 +34,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v6" "github.com/golang-jwt/jwt/v4" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" v1 "k8s.io/api/rbac/v1" kubeerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -195,7 +195,10 @@ func (c *aksClient) ListAll(ctx context.Context) ([]*AKSCluster, error) { for _, s := range page.Value { cluster, err := AKSClusterFromManagedCluster(s) if err != nil { - logrus.WithError(err).Debugf("Failed to convert discovered AKS cluster %q to Teleport internal representation.", StringVal(s.Name)) + slog.DebugContext(ctx, "Failed to convert discovered AKS cluster to Teleport internal representation", + "cluster", StringVal(s.Name), + "error", err, + ) continue } servers = append(servers, cluster) @@ -217,7 +220,10 @@ func (c *aksClient) ListWithinGroup(ctx context.Context, group string) ([]*AKSCl for _, s := range page.Value { cluster, err := AKSClusterFromManagedCluster(s) if err != nil { - logrus.WithError(err).Debugf("Failed to convert discovered AKS cluster %q to Teleport internal representation.", StringVal(s.Name)) + slog.DebugContext(ctx, "Failed to convert discovered AKS cluster to Teleport internal representation", + "cluster", StringVal(s.Name), + "error", err, + ) continue } servers = append(servers, cluster) diff --git a/lib/cloud/azure/mysql.go b/lib/cloud/azure/mysql.go index 605e255e0a150..5fbd5e3b68042 100644 --- a/lib/cloud/azure/mysql.go +++ b/lib/cloud/azure/mysql.go @@ -20,10 +20,10 @@ package azure import ( "context" + "log/slog" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysql" "github.com/gravitational/trace" - log "github.com/sirupsen/logrus" ) var _ DBServersClient = (*mySQLClient)(nil) @@ -87,9 +87,9 @@ func isMySQLVersionSupported(s *DBServer) bool { case armmysql.ServerVersionFive6: return false default: - log.Warnf("Unknown server version: %q. Assuming Azure DB server %q is supported.", - s.Properties.Version, - s.Name, + slog.WarnContext(context.Background(), "Assuming Azure DB server with unknown server version is supported", + "version", s.Properties.Version, + "server", s.Name, ) return true } diff --git a/lib/cloud/azure/mysql_flex.go b/lib/cloud/azure/mysql_flex.go index acc7ef6c99ad8..f2d3b00ca860f 100644 --- a/lib/cloud/azure/mysql_flex.go +++ b/lib/cloud/azure/mysql_flex.go @@ -26,7 +26,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysqlflexibleservers" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" ) // armMySQLFlexServersClient is an interface that defines a subset of functions of armmysqlflexibleservers.ServersClient. @@ -44,7 +43,6 @@ var _ MySQLFlexServersClient = (*mySQLFlexServersClient)(nil) // NewMySQLFlexServersClient creates a new Azure MySQL Flexible server client by subscription and credentials. func NewMySQLFlexServersClient(subID string, cred azcore.TokenCredential, opts *arm.ClientOptions) (MySQLFlexServersClient, error) { - logrus.Debug("Initializing Azure MySQL Flexible servers client.") api, err := armmysqlflexibleservers.NewServersClient(subID, cred, opts) if err != nil { return nil, trace.Wrap(err) diff --git a/lib/cloud/azure/postgres_flex.go b/lib/cloud/azure/postgres_flex.go index 8c894ed1ece10..8b05b3b1c7715 100644 --- a/lib/cloud/azure/postgres_flex.go +++ b/lib/cloud/azure/postgres_flex.go @@ -26,7 +26,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresqlflexibleservers" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" ) type armPostgresFlexServersClient interface { @@ -44,7 +43,6 @@ var _ PostgresFlexServersClient = (*postgresFlexServersClient)(nil) // NewPostgresFlexServersClient creates a new Azure PostgreSQL Flexible server client by subscription and credentials. func NewPostgresFlexServersClient(subID string, cred azcore.TokenCredential, opts *arm.ClientOptions) (PostgresFlexServersClient, error) { - logrus.Debug("Initializing Azure PostgreSQL Flexible servers client.") api, err := armpostgresqlflexibleservers.NewServersClient(subID, cred, opts) if err != nil { return nil, trace.Wrap(err) diff --git a/lib/cloud/azure/redis.go b/lib/cloud/azure/redis.go index 318fe42772331..665be2d4fe7e3 100644 --- a/lib/cloud/azure/redis.go +++ b/lib/cloud/azure/redis.go @@ -26,7 +26,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/redis/armredis/v3" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" ) // armRedisClient is an interface defines a subset of functions of armredis.Client. @@ -43,7 +42,6 @@ type redisClient struct { // NewRedisClient creates a new Azure Redis client by subscription and credentials. func NewRedisClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (RedisClient, error) { - logrus.Debug("Initializing Azure Redis client.") api, err := armredis.NewClient(subscription, cred, options) if err != nil { return nil, trace.Wrap(err) diff --git a/lib/cloud/azure/redis_enterprise.go b/lib/cloud/azure/redis_enterprise.go index ec52da777f363..feaf94a5687ba 100644 --- a/lib/cloud/azure/redis_enterprise.go +++ b/lib/cloud/azure/redis_enterprise.go @@ -21,13 +21,13 @@ package azure import ( "context" "fmt" + "log/slog" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/redisenterprise/armredisenterprise" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" ) // armRedisEnterpriseDatabaseClient is an interface defines a subset of @@ -53,7 +53,6 @@ type redisEnterpriseClient struct { // NewRedisEnterpriseClient creates a new Azure Redis Enterprise client by // subscription and credentials. func NewRedisEnterpriseClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (RedisEnterpriseClient, error) { - logrus.Debug("Initializing Azure Redis Enterprise client.") clusterAPI, err := armredisenterprise.NewClient(subscription, cred, options) if err != nil { return nil, trace.Wrap(err) @@ -160,9 +159,14 @@ func (c *redisEnterpriseClient) listDatabasesByClusters(ctx context.Context, clu databases, err := c.listDatabasesByCluster(ctx, cluster) if err != nil { if trace.IsAccessDenied(err) || trace.IsNotFound(err) { - logrus.Debugf("Failed to listDatabasesByCluster on Redis Enterprise cluster %v: %v.", StringVal(cluster.Name), err.Error()) + slog.DebugContext(ctx, "Failed to listDatabasesByCluster on Redis Enterprise cluster", + "cluster", StringVal(cluster.Name), + "error", err) } else { - logrus.Warnf("Failed to listDatabasesByCluster on Redis Enterprise cluster %v: %v.", StringVal(cluster.Name), err.Error()) + slog.WarnContext(ctx, "Failed to listDatabasesByCluster on Redis Enterprise cluster", + "cluster", StringVal(cluster.Name), + "error", err, + ) } continue } diff --git a/lib/cloud/clients.go b/lib/cloud/clients.go index 93bb27f90b246..54b02d84dc400 100644 --- a/lib/cloud/clients.go +++ b/lib/cloud/clients.go @@ -21,6 +21,7 @@ package cloud import ( "context" "io" + "log/slog" "sync" "time" @@ -63,7 +64,6 @@ import ( "github.com/aws/aws-sdk-go/service/sts" "github.com/aws/aws-sdk-go/service/sts/stsiface" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" "google.golang.org/api/option" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -788,12 +788,17 @@ func (c *cloudClients) getAWSSessionForRegion(ctx context.Context, region string return nil, trace.BadParameter("missing aws integration session provider") } - logrus.Debugf("Initializing AWS session for region %v with integration %q.", region, opts.integration) + slog.DebugContext(ctx, "Initializing AWS session", + "region", region, + "integration", opts.integration, + ) session, err := c.awsIntegrationSessionProviderFn(ctx, region, opts.integration) return session, trace.Wrap(err) } - logrus.Debugf("Initializing AWS session for region %v using environment credentials.", region) + slog.DebugContext(ctx, "Initializing AWS session using environment credentials", + "region", region, + ) session, err := awsAmbientSessionProvider(ctx, region) return session, trace.Wrap(err) } @@ -867,7 +872,6 @@ func (c *cloudClients) initGCPIAMClient(ctx context.Context) (*gcpcredentials.Ia if c.gcpIAM != nil { // If some other thread already got here first. return c.gcpIAM, nil } - logrus.Debug("Initializing GCP IAM client.") gcpIAM, err := gcpcredentials.NewIamCredentialsClient(ctx) if err != nil { return nil, trace.Wrap(err) @@ -882,7 +886,6 @@ func (c *cloudClients) initAzureCredential() (azcore.TokenCredential, error) { if c.azureCredential != nil { // If some other thread already got here first. return c.azureCredential, nil } - logrus.Debug("Initializing Azure default credential chain.") // TODO(gavin): if/when we support AzureChina/AzureGovernment, we will need to specify the cloud in these options options := &azidentity.DefaultAzureCredentialOptions{} cred, err := azidentity.NewDefaultAzureCredential(options) @@ -905,7 +908,6 @@ func (c *cloudClients) initAzureMySQLClient(subscription string) (azure.DBServer return client, nil } - logrus.Debug("Initializing Azure MySQL servers client.") // TODO(gavin): if/when we support AzureChina/AzureGovernment, we will need to specify the cloud in these options options := &arm.ClientOptions{} api, err := armmysql.NewServersClient(subscription, cred, options) @@ -928,7 +930,6 @@ func (c *cloudClients) initAzurePostgresClient(subscription string) (azure.DBSer if client, ok := c.azurePostgresClients[subscription]; ok { // If some other thread already got here first. return client, nil } - logrus.Debug("Initializing Azure Postgres servers client.") // TODO(gavin): if/when we support AzureChina/AzureGovernment, we will need to specify the cloud in these options options := &arm.ClientOptions{} api, err := armpostgresql.NewServersClient(subscription, cred, options) @@ -951,7 +952,6 @@ func (c *cloudClients) initAzureSubscriptionsClient() (*azure.SubscriptionClient if c.azureSubscriptionsClient != nil { // If some other thread already got here first. return c.azureSubscriptionsClient, nil } - logrus.Debug("Initializing Azure subscriptions client.") // TODO(gavin): if/when we support AzureChina/AzureGovernment, // we will need to specify the cloud in these options opts := &arm.ClientOptions{} @@ -971,7 +971,6 @@ func (c *cloudClients) initInstanceMetadata(ctx context.Context) (imds.Client, e if c.instanceMetadata != nil { // If some other thread already got here first. return c.instanceMetadata, nil } - logrus.Debug("Initializing instance metadata client.") providers := []func(ctx context.Context) (imds.Client, error){ func(ctx context.Context) (imds.Client, error) { @@ -1012,7 +1011,6 @@ func (c *cloudClients) initAzureKubernetesClient(subscription string) (azure.AKS if client, ok := c.azureKubernetesClient[subscription]; ok { // If some other thread already got here first. return client, nil } - logrus.Debug("Initializing Azure AKS client.") // TODO(tigrato): if/when we support AzureChina/AzureGovernment, we will need to specify the cloud in these options options := &arm.ClientOptions{} api, err := armcontainerservice.NewManagedClustersClient(subscription, cred, options) @@ -1332,7 +1330,10 @@ func (c *TestCloudClients) Close() error { // newSessionWithRole assumes a given AWS IAM Role, passing an external ID if given, // and returns a new AWS session with the assumed role in the given region. func newSessionWithRole(ctx context.Context, svc stscreds.AssumeRoler, region, roleARN, externalID string) (*awssession.Session, error) { - logrus.Debugf("Initializing AWS session for assumed role %q for region %v.", roleARN, region) + slog.DebugContext(ctx, "Initializing AWS session for assumed role", + "assumed_role", roleARN, + "region", region, + ) // Make a credentials with AssumeRoleProvider and test it out. cred := stscreds.NewCredentialsWithClient(svc, roleARN, func(p *stscreds.AssumeRoleProvider) { if externalID != "" { diff --git a/lib/cloud/gcp/vm.go b/lib/cloud/gcp/vm.go index 514d0d3465988..9ebc40b7d88cc 100644 --- a/lib/cloud/gcp/vm.go +++ b/lib/cloud/gcp/vm.go @@ -25,6 +25,7 @@ import ( "errors" "fmt" "io" + "log/slog" "net" "slices" "strings" @@ -37,7 +38,6 @@ import ( "github.com/googleapis/gax-go/v2/apierror" "github.com/gravitational/trace" "github.com/gravitational/trace/trail" - "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" "google.golang.org/api/googleapi" "google.golang.org/api/iterator" @@ -553,11 +553,11 @@ https://cloud.google.com/solutions/connecting-securely#storing_host_keys_by_enab var err error // Fetch the instance first to get the most up-to-date metadata hash. if keyReq.Instance, err = req.Client.GetInstance(ctx, &req.InstanceRequest); err != nil { - logrus.WithError(err).Warn("Error fetching instance.") + slog.WarnContext(ctx, "Error fetching instance", "error", err) return } if err := req.Client.RemoveSSHKey(ctx, keyReq); err != nil { - logrus.WithError(err).Warn("Error deleting SSH Key.") + slog.WarnContext(ctx, "Error deleting SSH Key", "error", err) } }() @@ -578,8 +578,10 @@ https://cloud.google.com/solutions/connecting-securely#storing_host_keys_by_enab for _, ip := range ipAddrs { addr := net.JoinHostPort(ip, req.SSHPort) stdout, stderr, err := sshutils.RunSSH(ctx, addr, req.Script, config, sshutils.WithDialer(req.dialContext)) - logrus.Debug(string(stdout)) - logrus.Debug(string(stderr)) + slog.DebugContext(ctx, "Command completed", + "stdoout", string(stdout), + "stderr", string(stderr), + ) if err == nil { return nil } @@ -592,6 +594,6 @@ https://cloud.google.com/solutions/connecting-securely#storing_host_keys_by_enab } err = trace.NewAggregate(errs...) - logrus.WithError(err).Debug("Command exited with error.") + slog.DebugContext(ctx, "Command exited with error", "error", err) return err }