Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analyzer): add certificate analyzer #1128

Merged
merged 5 commits into from
May 29, 2023
Merged

Conversation

DexterYan
Copy link
Member

@DexterYan DexterYan commented Apr 18, 2023

Description, Motivation and Context

issue: #762

Support Bundle Yaml

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  name: default
spec:
  collectors:
    - certificates: 
        secrets:
            - name: envoycert
              namespaces:
                - kube-system
                - projectcontour
        configMaps:
            - name: kube-root-ca.crt
              namespaces:
                - curlie
                - kurl
  analyzers:
    - certificates: # Iterate through list of certificates
        outcomes:
          - pass:
              message: "certificate is valid"
          - warn:
              when: "notAfter < Today + 365 days"
              message: "certificate is about to expire"
          - fail:
              when: "notAfter < Today"
              message: "certificate has expired"

Result Json

[
    {
        "name": "cerfiticates.verification",
        "labels": {
            "desiredPosition": "1",
            "iconKey": "",
            "iconUri": ""
        },
        "insight": {
            "name": "cerfiticates.verification",
            "labels": {
                "iconKey": "",
                "iconUri": ""
            },
            "primary": "Cerfiticates Verification",
            "detail": "ca.crt certificate is about to expire in 365 days, obtained from envoycert secret within projectcontour namespace",
            "severity": "warn"
        },
        "severity": "warn",
        "analyzerSpec": ""
    },
    {
        "name": "cerfiticates.verification",
        "labels": {
            "desiredPosition": "1",
            "iconKey": "",
            "iconUri": ""
        },
        "insight": {
            "name": "cerfiticates.verification",
            "labels": {
                "iconKey": "",
                "iconUri": ""
            },
            "primary": "Cerfiticates Verification",
            "detail": "tls.crt certificate is about to expire in 365 days, obtained from envoycert secret within projectcontour namespace",
            "severity": "warn"
        },
        "severity": "warn",
        "analyzerSpec": ""
    },
    {
        "name": "cerfiticates.verification",
        "labels": {
            "desiredPosition": "1",
            "iconKey": "",
            "iconUri": ""
        },
        "insight": {
            "name": "cerfiticates.verification",
            "labels": {
                "iconKey": "",
                "iconUri": ""
            },
            "primary": "Cerfiticates Verification",
            "detail": "ca.crt certificate is valid, obtained from kube-root-ca.crt configmap within kurl namespace",
            "severity": "debug"
        },
        "severity": "debug",
        "analyzerSpec": ""
    }
]

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@DexterYan DexterYan requested a review from a team as a code owner April 18, 2023 06:06
@DexterYan DexterYan marked this pull request as draft April 18, 2023 06:06
@DexterYan DexterYan force-pushed the dx/certificate-analyzer branch 2 times, most recently from f471774 to 7729702 Compare April 19, 2023 05:24
@DexterYan DexterYan added the type::feature New feature or request label Apr 19, 2023
@DexterYan DexterYan marked this pull request as ready for review April 19, 2023 05:44
Copy link
Contributor

@CpuID CpuID left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM, haven't tested it locally but the tests exist and are passing according to GitHub :)

just a few spelling fixes to apply 👍

func (a *AnalyzeCertificates) Title() string {
title := a.analyzer.CheckName
if title == "" {
return "Cerfiticates Verification"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "Cerfiticates Verification"
return "Certificates Verification"

IsPass: true,
IsWarn: false,
IsFail: false,
Title: "Cerfiticates Verification",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: "Cerfiticates Verification",
Title: "Certificates Verification",

IsPass: false,
IsWarn: false,
IsFail: true,
Title: "Cerfiticates Verification",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: "Cerfiticates Verification",
Title: "Certificates Verification",

IsPass: false,
IsWarn: true,
IsFail: false,
Title: "Cerfiticates Verification",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: "Cerfiticates Verification",
Title: "Certificates Verification",

return a.analyzeAnalyzeCertificatesResult(collectorCertificates, analyzer.Outcomes)
}

func (a *AnalyzeCertificates) analyzeAnalyzeCertificatesResult(certifcates []collect.CertCollection, outcomes []*troubleshootv1beta2.Outcome) ([]*AnalyzeResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (a *AnalyzeCertificates) analyzeAnalyzeCertificatesResult(certifcates []collect.CertCollection, outcomes []*troubleshootv1beta2.Outcome) ([]*AnalyzeResult, error) {
func (a *AnalyzeCertificates) analyzeAnalyzeCertificatesResult(certificates []collect.CertCollection, outcomes []*troubleshootv1beta2.Outcome) ([]*AnalyzeResult, error) {

func (a *AnalyzeCertificates) analyzeAnalyzeCertificatesResult(certifcates []collect.CertCollection, outcomes []*troubleshootv1beta2.Outcome) ([]*AnalyzeResult, error) {
var results []*AnalyzeResult

for _, cert := range certifcates {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, cert := range certifcates {
for _, cert := range certificates {

xavpaice
xavpaice previously approved these changes May 29, 2023
@xavpaice xavpaice dismissed their stale review May 29, 2023 03:30

tests aren't passing

@xavpaice xavpaice merged commit acb1099 into main May 29, 2023
20 checks passed
@xavpaice xavpaice deleted the dx/certificate-analyzer branch May 29, 2023 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants