replace error by warning

Signed-off-by: David Wertenteil <dwertent@armosec.io>
This commit is contained in:
David Wertenteil
2023-03-15 17:17:29 +02:00
parent a29fe367dc
commit ec4a098b1c
20 changed files with 62 additions and 62 deletions
+5 -4
View File
@@ -48,7 +48,7 @@ func LoadResourcesFromHelmCharts(ctx context.Context, basePath string) (map[stri
if err == nil {
wls, errs := chart.GetWorkloadsWithDefaultValues()
if len(errs) > 0 {
logger.L().Ctx(ctx).Error(fmt.Sprintf("Rendering of Helm chart template '%s', failed: %v", chart.GetName(), errs))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("Rendering of Helm chart template '%s', failed: %v", chart.GetName(), errs))
continue
}
@@ -88,7 +88,7 @@ func LoadResourcesFromKustomizeDirectory(ctx context.Context, basePath string) (
kustomizeDirectoryName := GetKustomizeDirectoryName(newBasePath)
if len(errs) > 0 {
logger.L().Ctx(ctx).Error(fmt.Sprintf("Rendering yaml from Kustomize failed: %v", errs))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("Rendering yaml from Kustomize failed: %v", errs))
}
for k, v := range wls {
@@ -100,15 +100,16 @@ func LoadResourcesFromKustomizeDirectory(ctx context.Context, basePath string) (
func LoadResourcesFromFiles(ctx context.Context, input, rootPath string) map[string][]workloadinterface.IMetadata {
files, errs := listFiles(input)
if len(errs) > 0 {
logger.L().Ctx(ctx).Error(fmt.Sprintf("%v", errs))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("%v", errs))
}
if len(files) == 0 {
logger.L().Ctx(ctx).Error("no files found to scan", helpers.String("input", input))
return nil
}
workloads, errs := loadFiles(rootPath, files)
if len(errs) > 0 {
logger.L().Ctx(ctx).Error(fmt.Sprintf("%v", errs))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("%v", errs))
}
return workloads
+1 -1
View File
@@ -84,7 +84,7 @@ func downloadArtifacts(ctx context.Context, downloadInfo *metav1.DownloadInfo) e
}
for artifact := range artifacts {
if err := downloadArtifact(ctx, &metav1.DownloadInfo{Target: artifact, Path: downloadInfo.Path, FileName: fmt.Sprintf("%s.json", artifact)}, artifacts); err != nil {
logger.L().Ctx(ctx).Error("error downloading", helpers.String("artifact", artifact), helpers.Error(err))
logger.L().Ctx(ctx).Warning("error downloading", helpers.String("artifact", artifact), helpers.Error(err))
}
}
return nil
+1 -1
View File
@@ -48,7 +48,7 @@ func (ks *Kubescape) Fix(ctx context.Context, fixInfo *metav1.FixInfo) error {
if len(errors) > 0 {
for _, err := range errors {
logger.L().Ctx(ctx).Error(err.Error())
logger.L().Ctx(ctx).Warning(err.Error())
}
return fmt.Errorf("Failed to fix some resources, check the logs for more details")
}
+1 -1
View File
@@ -43,7 +43,7 @@ func (ks *Kubescape) SubmitExceptions(ctx context.Context, credentials *cautils.
// load cached config
tenantConfig := getTenantConfig(credentials, "", "", getKubernetesApi())
if err := tenantConfig.SetTenant(); err != nil {
logger.L().Ctx(ctx).Error("failed setting account ID", helpers.Error(err))
logger.L().Ctx(ctx).Warning("failed setting account ID", helpers.Error(err))
}
// load exceptions from file
+3 -3
View File
@@ -142,13 +142,13 @@ func (h *FixHandler) PrepareResourcesToFix(ctx context.Context) []ResourceFixInf
relativePath, documentIndex, err := h.getFilePathAndIndex(resourcePath)
if err != nil {
logger.L().Ctx(ctx).Error("Skipping invalid resource path: " + resourcePath)
logger.L().Ctx(ctx).Warning("Skipping invalid resource path: " + resourcePath)
continue
}
absolutePath := path.Join(h.localBasePath, relativePath)
if _, err := os.Stat(absolutePath); err != nil {
logger.L().Ctx(ctx).Error("Skipping missing file: " + absolutePath)
logger.L().Ctx(ctx).Warning("Skipping missing file: " + absolutePath)
continue
}
@@ -220,7 +220,7 @@ func (h *FixHandler) ApplyChanges(ctx context.Context, resourcesToFix []Resource
err = writeFixesToFile(filepath, fixedYamlString)
if err != nil {
logger.L().Ctx(ctx).Error(fmt.Sprintf("Failed to write fixes to file %s, %v", filepath, err.Error()))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("Failed to write fixes to file %s, %v", filepath, err.Error()))
errors = append(errors, err)
}
}
+1 -1
View File
@@ -306,7 +306,7 @@ func readDocuments(ctx context.Context, reader io.Reader, decoder yqlib.Decoder)
func safelyCloseFile(ctx context.Context, file *os.File) {
err := file.Close()
if err != nil {
logger.L().Ctx(ctx).Error("Error Closing File")
logger.L().Ctx(ctx).Warning("Error Closing File")
}
}
+3 -2
View File
@@ -87,7 +87,7 @@ func (hsh *HostSensorHandler) Init(ctx context.Context) error {
}
hsh.populatePodNamesToNodeNames(ctx)
if err := hsh.checkPodForEachNode(); err != nil {
logger.L().Ctx(ctx).Error("failed to validate host-sensor pods status", helpers.Error(err))
logger.L().Ctx(ctx).Warning("failed to validate host-sensor pods status", helpers.Error(err))
}
cautils.StopSpinner()
return nil
@@ -237,9 +237,10 @@ func (hsh *HostSensorHandler) populatePodNamesToNodeNames(ctx context.Context) {
LabelSelector: fmt.Sprintf("name=%s", hsh.DaemonSet.Spec.Template.Labels["name"]),
})
if err != nil {
logger.L().Ctx(ctx).Error("failed to watch over daemonset pods - are we missing watch pods permissions?", helpers.Error(err))
logger.L().Ctx(ctx).Warning("failed to watch over DaemonSet pods - are we missing watch pods permissions?", helpers.Error(err))
}
if watchRes == nil {
logger.L().Ctx(ctx).Error("failed to watch over DaemonSet pods, will not be able to get host-sensor data")
return
}
for eve := range watchRes.ResultChan() {
@@ -214,7 +214,7 @@ func (hsh *HostSensorHandler) GetKubeletConfigurations(ctx context.Context) ([]h
for resIdx := range res {
jsonBytes, ery := yaml.YAMLToJSON(res[resIdx].Data)
if ery != nil {
logger.L().Ctx(ctx).Error("failed to convert kubelet configurations from yaml to json", helpers.Error(ery))
logger.L().Ctx(ctx).Warning("failed to convert kubelet configurations from yaml to json", helpers.Error(ery))
continue
}
res[resIdx].SetData(jsonBytes)
@@ -48,10 +48,10 @@ func (wp *workerPool) hostSensorWorker(ctx context.Context, hsh *HostSensorHandl
for job := range wp.jobs {
hostSensorDataEnvelope, err := hsh.getResourcesFromPod(job.podName, job.nodeName, job.requestKind, job.path)
if err != nil {
logger.L().Ctx(ctx).Error("failed to get data", helpers.String("path", job.path), helpers.String("podName", job.podName), helpers.Error(err))
} else {
wp.results <- hostSensorDataEnvelope
logger.L().Ctx(ctx).Warning("failed to get data", helpers.String("path", job.path), helpers.String("podName", job.podName), helpers.Error(err))
continue
}
wp.results <- hostSensorDataEnvelope
}
}
+26 -28
View File
@@ -56,8 +56,7 @@ func (opap *OPAProcessor) ProcessRulesListenner(ctx context.Context, progressLis
// process
if err := opap.Process(ctx, opap.OPASessionObj.AllPolicies, progressListener); err != nil {
logger.L().Ctx(ctx).Error(err.Error())
// Return error?
logger.L().Ctx(ctx).Warning(err.Error())
}
// edit results
@@ -92,7 +91,7 @@ func (opap *OPAProcessor) Process(ctx context.Context, policies *cautils.Policie
resourcesAssociatedControl, err := opap.processControl(ctx, &control)
if err != nil {
logger.L().Ctx(ctx).Error(err.Error())
logger.L().Ctx(ctx).Warning(err.Error())
}
if len(resourcesAssociatedControl) == 0 {
@@ -142,7 +141,7 @@ func (opap *OPAProcessor) processControl(ctx context.Context, control *reporthan
for i := range control.Rules {
resourceAssociatedRule, err := opap.processRule(ctx, &control.Rules[i], control.FixedInput)
if err != nil {
logger.L().Ctx(ctx).Error(err.Error())
logger.L().Ctx(ctx).Warning(err.Error())
continue
}
@@ -212,34 +211,33 @@ func (opap *OPAProcessor) processRule(ctx context.Context, rule *reporthandling.
ruleResponses, err := opap.runOPAOnSingleRule(ctx, rule, inputRawResources, ruleData, RuleRegoDependenciesData)
if err != nil {
// TODO - Handle error
logger.L().Ctx(ctx).Error(err.Error())
} else {
// ruleResponse to ruleResult
for i := range ruleResponses {
failedResources := objectsenvelopes.ListMapToMeta(ruleResponses[i].GetFailedResources())
for j := range failedResources {
ruleResult := &resourcesresults.ResourceAssociatedRule{}
if r, k := resources[failedResources[j].GetID()]; k {
ruleResult = r
}
return resources, err
}
ruleResult.SetStatus(apis.StatusFailed, nil)
for j := range ruleResponses[i].FailedPaths {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FailedPath: ruleResponses[i].FailedPaths[j]})
}
for j := range ruleResponses[i].FixPaths {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FixPath: ruleResponses[i].FixPaths[j]})
}
if ruleResponses[i].FixCommand != "" {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FixCommand: ruleResponses[i].FixCommand})
}
resources[failedResources[j].GetID()] = ruleResult
// ruleResponse to ruleResult
for i := range ruleResponses {
failedResources := objectsenvelopes.ListMapToMeta(ruleResponses[i].GetFailedResources())
for j := range failedResources {
ruleResult := &resourcesresults.ResourceAssociatedRule{}
if r, k := resources[failedResources[j].GetID()]; k {
ruleResult = r
}
ruleResult.SetStatus(apis.StatusFailed, nil)
for j := range ruleResponses[i].FailedPaths {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FailedPath: ruleResponses[i].FailedPaths[j]})
}
for j := range ruleResponses[i].FixPaths {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FixPath: ruleResponses[i].FixPaths[j]})
}
if ruleResponses[i].FixCommand != "" {
ruleResult.Paths = append(ruleResult.Paths, armotypes.PosturePaths{FixCommand: ruleResponses[i].FixCommand})
}
resources[failedResources[j].GetID()] = ruleResult
}
}
return resources, err
return resources, nil
}
func (opap *OPAProcessor) runOPAOnSingleRule(ctx context.Context, rule *reporthandling.PolicyRule, k8sObjects []map[string]interface{}, getRuleData func(*reporthandling.PolicyRule) string, ruleRegoDependenciesData resources.RegoDependenciesData) ([]reporthandling.RuleResponse, error) {
@@ -275,7 +273,7 @@ func (opap *OPAProcessor) runRegoOnK8s(ctx context.Context, rule *reporthandling
// Eval
results, err := opap.regoEval(k8sObjects, compiled, &store)
if err != nil {
logger.L().Ctx(ctx).Error(err.Error())
logger.L().Ctx(ctx).Warning(err.Error())
}
return results, nil
+2 -2
View File
@@ -37,7 +37,7 @@ func (policyHandler *PolicyHandler) getPolicies(ctx context.Context, policyIdent
if err == nil {
policiesAndResources.Exceptions = exceptionPolicies
} else {
logger.L().Ctx(ctx).Error("failed to load exceptions", helpers.Error(err))
logger.L().Ctx(ctx).Warning("failed to load exceptions", helpers.Error(err))
}
// get account configuration
@@ -45,7 +45,7 @@ func (policyHandler *PolicyHandler) getPolicies(ctx context.Context, policyIdent
if err == nil {
policiesAndResources.RegoInputData.PostureControlInputs = controlsInputs
} else {
logger.L().Ctx(ctx).Error(err.Error())
logger.L().Ctx(ctx).Warning(err.Error())
}
cautils.StopSpinner()
+1 -1
View File
@@ -223,7 +223,7 @@ func (k8sHandler *K8sResourceHandler) collectAPIServerInfoResource(allResources
func (k8sHandler *K8sResourceHandler) GetClusterAPIServerInfo(ctx context.Context) *version.Info {
clusterAPIServerInfo, err := k8sHandler.k8s.DiscoveryClient.ServerVersion()
if err != nil {
logger.L().Ctx(ctx).Error("failed to discover API server information", helpers.Error(err))
logger.L().Ctx(ctx).Warning("failed to discover API server information", helpers.Error(err))
return nil
}
return clusterAPIServerInfo
@@ -32,12 +32,12 @@ type IPrinter interface {
func GetWriter(ctx context.Context, outputFile string) *os.File {
if outputFile != "" {
if err := os.MkdirAll(filepath.Dir(outputFile), os.ModePerm); err != nil {
logger.L().Ctx(ctx).Error(fmt.Sprintf("failed to create directory, reason: %s", err.Error()))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("failed to create directory, reason: %s", err.Error()))
return os.Stdout
}
f, err := os.Create(outputFile)
if err != nil {
logger.L().Ctx(ctx).Error(fmt.Sprintf("failed to open file for writing, reason: %s", err.Error()))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("failed to open file for writing, reason: %s", err.Error()))
return os.Stdout
}
return f
@@ -110,9 +110,9 @@ func (hp *HtmlPrinter) ActionPrint(ctx context.Context, opaSessionObj *cautils.O
err := tpl.Execute(hp.writer, reportingCtx)
if err != nil {
logger.L().Ctx(ctx).Error("failed to render template", helpers.Error(err))
} else {
printer.LogOutputFile(hp.writer.Name())
return
}
printer.LogOutputFile(hp.writer.Name())
}
@@ -51,7 +51,7 @@ func (jp *JsonPrinter) ActionPrint(ctx context.Context, opaSessionObj *cautils.O
if _, err := jp.writer.Write(r); err != nil {
logger.L().Ctx(ctx).Error("failed to write results", helpers.Error(err))
} else {
printer.LogOutputFile(jp.writer.Name())
return
}
printer.LogOutputFile(jp.writer.Name())
}
+2 -2
View File
@@ -120,9 +120,9 @@ func (jp *JunitPrinter) ActionPrint(ctx context.Context, opaSessionObj *cautils.
if _, err := jp.writer.Write(postureReportStr); err != nil {
logger.L().Ctx(ctx).Error("failed to write results", helpers.Error(err))
} else {
printer.LogOutputFile(jp.writer.Name())
return
}
printer.LogOutputFile(jp.writer.Name())
}
func testsSuites(results *cautils.OPASessionObj) *JUnitTestSuites {
+2 -2
View File
@@ -98,9 +98,9 @@ func (pp *PdfPrinter) ActionPrint(ctx context.Context, opaSessionObj *cautils.OP
if _, err := pp.writer.Write(outBuff.Bytes()); err != nil {
logger.L().Ctx(ctx).Error("failed to write results", helpers.Error(err))
} else {
printer.LogOutputFile(pp.writer.Name())
return
}
printer.LogOutputFile(pp.writer.Name())
}
// printHeader prints the Kubescape logo and report date
@@ -53,7 +53,7 @@ func (pp *PrometheusPrinter) ActionPrint(ctx context.Context, opaSessionObj *cau
if _, err := pp.writer.Write([]byte(metrics.String())); err != nil {
logger.L().Ctx(ctx).Error("failed to write results", helpers.Error(err))
} else {
printer.LogOutputFile(pp.writer.Name())
return
}
printer.LogOutputFile(pp.writer.Name())
}
+1 -1
View File
@@ -116,7 +116,7 @@ func NewPrinter(ctx context.Context, printFormat, formatVersion string, verboseM
return printerv2.NewSARIFPrinter()
default:
if printFormat != printer.PrettyFormat {
logger.L().Ctx(ctx).Error(fmt.Sprintf("Invalid format \"%s\", default format \"pretty-printer\" is applied", printFormat))
logger.L().Ctx(ctx).Warning(fmt.Sprintf("Invalid format \"%s\", default format \"pretty-printer\" is applied", printFormat))
}
return printerv2.NewPrettyPrinter(verboseMode, formatVersion, attackTree, viewType)
}
@@ -38,7 +38,7 @@ func (handler *HTTPHandler) executeScan() {
response.Response = err.Error()
}
} else {
logger.L().Success("done scanning", helpers.String("ID", scanReq.scanID))
logger.L().Ctx(scanReq.ctx).Success("done scanning", helpers.String("ID", scanReq.scanID))
if scanReq.scanQueryParams.ReturnResults {
response.Type = utilsapisv1.ResultsV1ScanResponseType
response.Response = results