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
2 changes: 1 addition & 1 deletion cmd/fleet/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func cronVulnerabilities(
return nil
}

vulnPath := configureVulnPath(*config, appConfig, logger)
vulnPath := configureVulnPath(ctx, *config, appConfig, logger)
if vulnPath != "" {
logger.InfoContext(ctx, "scanning vulnerabilities")
if err := scanVulnerabilities(ctx, ds, logger, config, appConfig, vulnPath); err != nil {
Expand Down
14 changes: 6 additions & 8 deletions cmd/fleet/vuln_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/fleetdm/fleet/v4/server/datastore/mysql"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/go-kit/log/level"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -103,21 +102,21 @@ by an exit code of zero.`,
return err
}
vulnConfig := cfg.Vulnerabilities
vulnPath := configureVulnPath(vulnConfig, appConfig, logger)
vulnPath := configureVulnPath(ctx, vulnConfig, appConfig, logger)
// this really shouldn't ever be empty string since it's defaulted, but could be due to some misconfiguration
// we'll throw an error here since the entire point of this command is to process vulnerabilities
if vulnPath == "" {
return errors.New("vuln path empty, check environment variables or app config yml")
}
level.Info(logger).Log("msg", "scanning vulnerabilities")
logger.InfoContext(ctx, "scanning vulnerabilities")
start := time.Now()
vulnFuncs := getVulnFuncs(ds, logger, &vulnConfig)
for _, vulnFunc := range vulnFuncs {
if err := vulnFunc.VulnFunc(ctx); err != nil {
return err
}
}
level.Info(logger).Log("msg", "vulnerability processing finished", "took", time.Since(start))
logger.InfoContext(ctx, "vulnerability processing finished", "took", time.Since(start))

return
},
Expand All @@ -135,20 +134,19 @@ by an exit code of zero.`,
return vulnProcessingCmd
}

func configureVulnPath(vulnConfig config.VulnerabilitiesConfig, appConfig *fleet.AppConfig, logger *logging.Logger) (vulnPath string) {
func configureVulnPath(ctx context.Context, vulnConfig config.VulnerabilitiesConfig, appConfig *fleet.AppConfig, logger *logging.Logger) (vulnPath string) {
switch {
case vulnConfig.DatabasesPath != "" && appConfig != nil && appConfig.VulnerabilitySettings.DatabasesPath != "":
vulnPath = vulnConfig.DatabasesPath
level.Info(logger).Log(
"msg", "fleet config takes precedence over app config when both are configured",
logger.InfoContext(ctx, "fleet config takes precedence over app config when both are configured",
"databases_path", vulnPath,
)
case vulnConfig.DatabasesPath != "":
vulnPath = vulnConfig.DatabasesPath
case appConfig != nil && appConfig.VulnerabilitySettings.DatabasesPath != "":
vulnPath = appConfig.VulnerabilitySettings.DatabasesPath
default:
level.Info(logger).Log("msg", "vulnerability scanning not configured, vulnerabilities databases path is empty")
logger.InfoContext(ctx, "vulnerability scanning not configured, vulnerabilities databases path is empty")
}
return vulnPath
}
Expand Down
41 changes: 20 additions & 21 deletions ee/server/service/certificate_authorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/ptr"
"github.com/fleetdm/fleet/v4/server/variables"
"github.com/go-kit/log/level"
)

func (svc *Service) GetCertificateAuthority(ctx context.Context, id uint) (*fleet.CertificateAuthority, error) {
Expand Down Expand Up @@ -231,7 +230,7 @@ func (svc *Service) validateDigicert(ctx context.Context, digicertCA *fleet.Digi
}

if err := svc.digiCertService.VerifyProfileID(ctx, *digicertCA); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate DigiCert profile GUID", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate DigiCert profile GUID", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sCould not verify DigiCert profile ID: %s. Please correct and try again.", errPrefix, err.Error())}
}
return nil
Expand Down Expand Up @@ -375,11 +374,11 @@ func (svc *Service) validateNDESSCEPProxy(ctx context.Context, ndesSCEP *fleet.N
return err
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, ndesSCEP.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate NDES SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate NDES SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
if err := svc.scepConfigService.ValidateNDESSCEPAdminURL(ctx, *ndesSCEP); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate NDES SCEP admin URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate NDES SCEP admin URL", "err", err)
switch {
case errors.As(err, &NDESPasswordCacheFullError{}):
return &fleet.BadRequestError{Message: fmt.Sprintf("%sThe NDES password cache is full. Please increase the number of cached passwords in NDES and try again.", errPrefix)}
Expand All @@ -403,7 +402,7 @@ func (svc *Service) validateCustomSCEPProxy(ctx context.Context, customSCEP *fle
return fleet.NewInvalidArgumentError("challenge", fmt.Sprintf("%sCustom SCEP Proxy challenge cannot be empty", errPrefix))
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, customSCEP.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate custom SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate custom SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
return nil
Expand All @@ -423,11 +422,11 @@ func (svc *Service) validateSmallstepSCEPProxy(ctx context.Context, smallstepSCE
return fleet.NewInvalidArgumentError("password", fmt.Sprintf("%sSmallstep password cannot be empty", errPrefix))
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, smallstepSCEP.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate Smallstep SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate Smallstep SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
if err := svc.scepConfigService.ValidateSmallstepChallengeURL(ctx, *smallstepSCEP); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate Smallstep SCEP admin URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate Smallstep SCEP admin URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid challenge URL or credentials. Please correct and try again.", errPrefix)}
}
return nil
Expand Down Expand Up @@ -499,12 +498,12 @@ func (svc *Service) BatchApplyCertificateAuthorities(ctx context.Context, incomi
}

if ops == nil {
level.Debug(svc.logger).Log("msg", "batch apply certificate authorities: no certificate authority changes to apply")
svc.logger.DebugContext(ctx, "batch apply certificate authorities: no certificate authority changes to apply")
return nil
}

if dryRun {
level.Debug(svc.logger).Log("msg", "batch apply certificate authorities: no certificate authority changes to apply")
svc.logger.DebugContext(ctx, "batch apply certificate authorities: no certificate authority changes to apply")
return nil
Comment thread
getvictor marked this conversation as resolved.
}

Expand Down Expand Up @@ -629,19 +628,19 @@ func (svc *Service) processNDESSCEP(ctx context.Context, batchOps *fleet.Certifi

if existing == nil && incoming == nil {
// do nothing
level.Debug(svc.logger).Log("msg", "no existing or incoming NDES SCEP CA, skipping")
svc.logger.DebugContext(ctx, "no existing or incoming NDES SCEP CA, skipping")
return nil
}

if existing != nil && incoming != nil && incoming.URL == existing.URL && incoming.AdminURL == existing.AdminURL && incoming.Username == existing.Username && incoming.Password == existing.Password {
// all fields are identical so we can skip further validation and processing
level.Debug(svc.logger).Log("msg", "existing and incoming NDES SCEP CA are identical, skipping")
svc.logger.DebugContext(ctx, "existing and incoming NDES SCEP CA are identical, skipping")
return nil
}

if existing != nil && (incoming == nil || (incoming.URL == "" && incoming.AdminURL == "" && incoming.Username == "" && incoming.Password == "")) {
// delete current
level.Debug(svc.logger).Log("msg", "deleting existing NDES SCEP CA as incoming is empty")
svc.logger.DebugContext(ctx, "deleting existing NDES SCEP CA as incoming is empty")
batchOps.Delete = append(batchOps.Delete, &fleet.CertificateAuthority{
Type: string(fleet.CATypeNDESSCEPProxy),
Name: &ndesName,
Expand All @@ -662,7 +661,7 @@ func (svc *Service) processNDESSCEP(ctx context.Context, batchOps *fleet.Certifi

// add if there is no existing
if existing == nil || (existing.URL == "" && existing.AdminURL == "" && existing.Username == "" && existing.Password == "") {
level.Debug(svc.logger).Log("msg", "adding new NDES SCEP CA as none exists")
svc.logger.DebugContext(ctx, "adding new NDES SCEP CA as none exists")
batchOps.Add = append(batchOps.Add, &fleet.CertificateAuthority{
Type: string(fleet.CATypeNDESSCEPProxy),
Name: &ndesName,
Expand All @@ -675,7 +674,7 @@ func (svc *Service) processNDESSCEP(ctx context.Context, batchOps *fleet.Certifi
}

// otherwise update with existing id
level.Debug(svc.logger).Log("msg", "updating existing NDES SCEP CA")
svc.logger.DebugContext(ctx, "updating existing NDES SCEP CA")
incoming.ID = existing.ID
batchOps.Update = append(batchOps.Update, &fleet.CertificateAuthority{
Type: string(fleet.CATypeNDESSCEPProxy),
Expand Down Expand Up @@ -1277,7 +1276,7 @@ func (svc *Service) validateDigicertUpdate(ctx context.Context, digicert *fleet.
digicertCA.APIToken = *oldCA.APIToken
}
if err := svc.digiCertService.VerifyProfileID(ctx, digicertCA); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate DigiCert URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate DigiCert URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sCould not verify DigiCert URL: %s. Please correct and try again.", errPrefix, err.Error())}
}
}
Expand Down Expand Up @@ -1309,7 +1308,7 @@ func (svc *Service) validateDigicertUpdate(ctx context.Context, digicert *fleet.
digicertCA.APIToken = *oldCA.APIToken
}
if err := svc.digiCertService.VerifyProfileID(ctx, digicertCA); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate DigiCert profile GUID", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate DigiCert profile GUID", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sCould not verify DigiCert profile ID: %s. Please correct and try again.", errPrefix, err.Error())}
}
}
Expand Down Expand Up @@ -1403,7 +1402,7 @@ func (svc *Service) validateNDESSCEPProxyUpdate(ctx context.Context, ndesSCEP *f
return err
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, *ndesSCEP.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate NDES SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate NDES SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
}
Expand Down Expand Up @@ -1436,7 +1435,7 @@ func (svc *Service) validateNDESSCEPProxyUpdate(ctx context.Context, ndesSCEP *f
}

if err := svc.scepConfigService.ValidateNDESSCEPAdminURL(ctx, NDESProxy); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate NDES SCEP admin URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate NDES SCEP admin URL", "err", err)
switch {
case errors.As(err, &NDESPasswordCacheFullError{}):
return &fleet.BadRequestError{Message: fmt.Sprintf("%sThe NDES password cache is full. Please increase the number of cached passwords in NDES and try again.", errPrefix)}
Expand All @@ -1461,7 +1460,7 @@ func (svc *Service) validateCustomSCEPProxyUpdate(ctx context.Context, customSCE
return err
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, *customSCEP.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate custom SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate custom SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
}
Expand All @@ -1485,7 +1484,7 @@ func (svc *Service) validateSmallstepSCEPProxyUpdate(ctx context.Context, smalls
return err
}
if err := svc.scepConfigService.ValidateSCEPURL(ctx, *smallstep.URL); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate Smallstep SCEP URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate Smallstep SCEP URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid SCEP URL. Please correct and try again.", errPrefix)}
}
}
Expand Down Expand Up @@ -1531,7 +1530,7 @@ func (svc *Service) validateSmallstepSCEPProxyUpdate(ctx context.Context, smalls
}

if err := svc.scepConfigService.ValidateSmallstepChallengeURL(ctx, smallstepSCEPProxy); err != nil {
level.Error(svc.logger).Log("msg", "Failed to validate Smallstep challenge URL", "err", err)
svc.logger.ErrorContext(ctx, "Failed to validate Smallstep challenge URL", "err", err)
return &fleet.BadRequestError{Message: fmt.Sprintf("%sInvalid challenge URL or credentials. Please correct and try again.", errPrefix)}
}
}
Expand Down
3 changes: 1 addition & 2 deletions ee/server/service/condaccess/idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ func (s *idpService) buildIdentityProvider(ctx context.Context, serverURL string
}
ssoURL = ssoURL.JoinPath(idpSSOPath)

// Create kitlog adapter for SAML library
samlLogger := &kitlogAdapter{logger: s.logger.With("component", "saml-idp")}
samlLogger := &slogAdapter{ctx: ctx, logger: s.logger.SlogLogger().With("component", "saml-idp")}

// Build IdentityProvider
// Note: SessionProvider is set dynamically in serveSSO based on the authenticated device
Expand Down
48 changes: 24 additions & 24 deletions ee/server/service/condaccess/log_adapter.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package condaccess

import (
"context"
"fmt"

"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/go-kit/log/level"
"log/slog"
)

// kitlogAdapter adapts to saml logger.Interface
type kitlogAdapter struct {
logger *logging.Logger
// slogAdapter adapts *slog.Logger to saml logger.Interface
type slogAdapter struct {
ctx context.Context
logger *slog.Logger
}

func (k *kitlogAdapter) Printf(format string, v ...interface{}) {
level.Info(k.logger).Log("msg", fmt.Sprintf(format, v...))
func (k *slogAdapter) Printf(format string, v ...any) {
k.logger.InfoContext(k.ctx, fmt.Sprintf(format, v...))
}

func (k *kitlogAdapter) Print(v ...interface{}) {
level.Info(k.logger).Log("msg", fmt.Sprint(v...))
func (k *slogAdapter) Print(v ...any) {
k.logger.InfoContext(k.ctx, fmt.Sprint(v...))
}

func (k *kitlogAdapter) Println(v ...interface{}) {
level.Info(k.logger).Log("msg", fmt.Sprint(v...))
func (k *slogAdapter) Println(v ...any) {
k.logger.InfoContext(k.ctx, fmt.Sprint(v...))
}

func (k *kitlogAdapter) Fatal(v ...interface{}) {
level.Error(k.logger).Log("msg", fmt.Sprint(v...))
func (k *slogAdapter) Fatal(v ...any) {
k.logger.ErrorContext(k.ctx, fmt.Sprint(v...))
}

func (k *kitlogAdapter) Fatalf(format string, v ...interface{}) {
level.Error(k.logger).Log("msg", fmt.Sprintf(format, v...))
func (k *slogAdapter) Fatalf(format string, v ...any) {
k.logger.ErrorContext(k.ctx, fmt.Sprintf(format, v...))
}

func (k *kitlogAdapter) Fatalln(v ...interface{}) {
level.Error(k.logger).Log("msg", fmt.Sprint(v...))
func (k *slogAdapter) Fatalln(v ...any) {
k.logger.ErrorContext(k.ctx, fmt.Sprint(v...))
}

func (k *kitlogAdapter) Panic(v ...interface{}) {
func (k *slogAdapter) Panic(v ...any) {
msg := fmt.Sprint(v...)
level.Error(k.logger).Log("msg", msg)
k.logger.ErrorContext(k.ctx, msg)
panic(msg)
}

func (k *kitlogAdapter) Panicf(format string, v ...interface{}) {
func (k *slogAdapter) Panicf(format string, v ...any) {
msg := fmt.Sprintf(format, v...)
level.Error(k.logger).Log("msg", msg)
k.logger.ErrorContext(k.ctx, msg)
panic(msg)
}

func (k *kitlogAdapter) Panicln(v ...interface{}) {
func (k *slogAdapter) Panicln(v ...any) {
msg := fmt.Sprint(v...)
level.Error(k.logger).Log("msg", msg)
k.logger.ErrorContext(k.ctx, msg)
panic(msg)
}
5 changes: 2 additions & 3 deletions ee/server/service/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
hostctx "github.com/fleetdm/fleet/v4/server/contexts/host"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/go-kit/log/level"
)

func (svc *Service) ListDevicePolicies(ctx context.Context, host *fleet.Host) ([]*fleet.HostPolicy, error) {
Expand All @@ -24,7 +23,7 @@ func (svc *Service) ListDevicePolicies(ctx context.Context, host *fleet.Host) ([
// the server/webhooks one because it is a Fleet Premium only feature and for
// licensing reasons this needs to live under this package.
func (svc *Service) TriggerMigrateMDMDevice(ctx context.Context, host *fleet.Host) error {
level.Debug(svc.logger).Log("msg", "trigger migration webhook", "host_id", host.ID,
svc.logger.DebugContext(ctx, "trigger migration webhook", "host_id", host.ID,
"refetch_critical_queries_until", host.RefetchCriticalQueriesUntil)

ac, err := svc.ds.AppConfig(ctx)
Expand All @@ -39,7 +38,7 @@ func (svc *Service) TriggerMigrateMDMDevice(ctx context.Context, host *fleet.Hos
// the webhook has already been triggered successfully recently (within the
// refetch critical queries delay), so return as if it did send it successfully
// but do not re-send.
level.Debug(svc.logger).Log("msg", "waiting for critical queries refetch, skip sending webhook",
svc.logger.DebugContext(ctx, "waiting for critical queries refetch, skip sending webhook",
"host_id", host.ID)
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions ee/server/service/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/go-kit/log/level"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -499,7 +498,7 @@ func (svc *Service) enqueueWipeHostRequest(
wipeType := fleet.MDMWindowsWipeTypeDoWipeProtected
if metadata != nil && metadata.Windows != nil {
wipeType = metadata.Windows.WipeType
level.Debug(svc.logger).Log("msg", "Windows host wipe request", "wipe_type", wipeType.String())
svc.logger.DebugContext(ctx, "Windows host wipe request", "wipe_type", wipeType.String())
}
wipeCmdUUID := uuid.NewString()
wipeCmd := &fleet.MDMWindowsCommand{
Expand Down
3 changes: 1 addition & 2 deletions ee/server/service/in_house_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/mdm/apple/mobileconfig"
"github.com/fleetdm/fleet/v4/server/ptr"
"github.com/go-kit/log/level"
)

func (svc *Service) updateInHouseAppInstaller(ctx context.Context, payload *fleet.UpdateSoftwareInstallerPayload, vc viewer.Viewer, teamName *string, software *fleet.SoftwareTitle) (*fleet.SoftwareInstaller, error) {
Expand Down Expand Up @@ -178,7 +177,7 @@ func (svc *Service) GetInHouseAppManifest(ctx context.Context, titleID uint, tea
signedURL, err := svc.softwareInstallStore.Sign(ctx, meta.StorageID, fleet.InHouseAppSignedURLExpiry)
if err != nil {
// We log the error and continue to send the Fleet server URL for the in-house app
level.Error(svc.logger).Log("msg", "error signing in-house app URL; check CloudFront configuration", "err", err)
svc.logger.ErrorContext(ctx, "error signing in-house app URL; check CloudFront configuration", "err", err)
} else {
downloadURL = signedURL
}
Expand Down
Loading
Loading