-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Reed
committed
Feb 19, 2021
1 parent
7647c03
commit 87b4c12
Showing
10 changed files
with
581 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: troubleshoot.sh/v1beta2 | ||
kind: HostPreflight | ||
metadata: | ||
name: certificate | ||
spec: | ||
collectors: | ||
- certificate: | ||
certificatePath: /etc/ssl/corp.crt | ||
keyPath: /etc/ssl/corp.key | ||
analyzers: | ||
- certificate: | ||
outcomes: | ||
- fail: | ||
when: "key-pair-missing" | ||
message: Certificate key pair not found in /etc/ssl | ||
- fail: | ||
when: "key-pair-switched" | ||
message: Cert and key pair are switched | ||
- fail: | ||
when: "key-pair-encrypted" | ||
message: Private key is encrypted | ||
- fail: | ||
when: "key-pair-mismatch" | ||
message: Cert and key do not match | ||
- fail: | ||
when: "key-pair-invalid" | ||
message: Certificate key pair is invalid | ||
- pass: | ||
when: "key-pair-valid" | ||
message: Certificate key pair is valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package analyzer | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" | ||
) | ||
|
||
func analyzeHostCertificate(hostAnalyzer *troubleshootv1beta2.CertificateAnalyze, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) { | ||
collectorName := hostAnalyzer.CollectorName | ||
if collectorName == "" { | ||
collectorName = "certificate" | ||
} | ||
name := filepath.Join("certificate", collectorName+".json") | ||
contents, err := getCollectedFileContents(name) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get collected file") | ||
} | ||
status := string(contents) | ||
|
||
result := AnalyzeResult{} | ||
|
||
title := hostAnalyzer.CheckName | ||
if title == "" { | ||
title = "Certificate Key Pair" | ||
} | ||
result.Title = title | ||
|
||
for _, outcome := range hostAnalyzer.Outcomes { | ||
if outcome.Fail != nil { | ||
if outcome.Fail.When == "" || outcome.Fail.When == status { | ||
result.IsFail = true | ||
result.Message = outcome.Fail.Message | ||
result.URI = outcome.Fail.URI | ||
|
||
return &result, nil | ||
} | ||
} else if outcome.Warn != nil { | ||
if outcome.Warn.When == "" || outcome.Warn.When == status { | ||
result.IsWarn = true | ||
result.Message = outcome.Warn.Message | ||
result.URI = outcome.Warn.URI | ||
|
||
return &result, nil | ||
} | ||
} else if outcome.Pass != nil { | ||
if outcome.Pass.When == "" || outcome.Pass.When == status { | ||
result.IsPass = true | ||
result.Message = outcome.Pass.Message | ||
result.URI = outcome.Pass.URI | ||
|
||
return &result, nil | ||
} | ||
} | ||
} | ||
|
||
return &result, nil | ||
} |
Oops, something went wrong.