Skip to content

Allows users to configure to include system certs pool in the request  #7774

@splunkericl

Description

@splunkericl

Is your feature request related to a problem? Please describe.
As a user of TLSSetting, I want an option to allow appending ca certs on top of the system certs pool. Today, if the user specify any CA file for TLSSetting it will only use that.

The background is the the application our exporter calls can have either cacert that is well known(e.g: Digi cert that is available in os) or private(e.g: Splunk CMP stack). We want the exporter to be able to communicate to both.

Describe the solution you'd like
Add a new config option in TLSSetting

type TLSSetting struct {
   UseSystemCACerts bool
}

when loading ca cert:

func (c TLSSetting) loadCert(caPath string) (*x509.CertPool, error) {
	caPEM, err := os.ReadFile(filepath.Clean(caPath))
	if err != nil {
		return nil, fmt.Errorf("failed to load CA %s: %w", caPath, err)
	}

	var certPool *x509.CertPool
	if c.UseSystemCACerts {
		certPool, _ = x509.SystemCertPool()
	}
	if certPool == nil {
		certPool = x509.NewCertPool()
	}
	if !certPool.AppendCertsFromPEM(caPEM) {
		return nil, fmt.Errorf("failed to parse CA %s", caPath)
	}
	return certPool, nil
}

Describe alternatives you've considered
An alternative is to always load system certs in the ca pool. However, this would increase HTTPs traffic payload for everyone

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions