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(docker): add support for mTLS authentication when connecting to registry #4649

Merged
merged 6 commits into from
Jun 28, 2023

Conversation

manveer94
Copy link
Contributor

Description

Added two new fields in registry options ClientCert and ClientKey. If both of these are not empty then https connection with client certificates will be attempted to the registry.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@manveer94 manveer94 requested a review from knqyf263 as a code owner June 16, 2023 05:47
@CLAassistant
Copy link

CLAassistant commented Jun 16, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Manveer Singh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

return nil, err
}
tr.TLSClientConfig = &tls.Config{
RootCAs: caCertPool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If RootCAs is nil, TLS uses the host's root CA set.

https://pkg.go.dev/crypto/tls#Config

Do we need to set it manually?

if err != nil {
return nil, err
}
tr.TLSClientConfig = &tls.Config{
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, it overwrites InsecureSkipVerify by mistake and leads to a bug.

@@ -124,6 +134,23 @@ func httpTransport(insecure bool) *http.Transport {
return tr
}

func httpTransportWithMtls(insecure bool, clientCert []byte, clientKey []byte) (*http.Transport, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is better to merge this functionality into httpTransport.

	tlsConfig := &tls.Config{InsecureSkipVerify: insecure}
	if len(option.ClientCert) > 0 && len(option.ClientKey) > 0 {
		cert, err := tls.X509KeyPair(option.ClientCert, option.ClientKey)
		if err != nil {
			return nil, err
		}
		tlsConfig.Certificates = []tls.Certificate{cert}
	}
	tr.TLSClientConfig = tlsConfig

pkg/fanal/types/image.go Show resolved Hide resolved
pkg/remote/remote.go Outdated Show resolved Hide resolved
pkg/remote/remote.go Outdated Show resolved Hide resolved
@knqyf263
Copy link
Collaborator

And need to resolve the conflict

@knqyf263 knqyf263 added this pull request to the merge queue Jun 28, 2023
Merged via the queue into aquasecurity:main with commit 26bc911 Jun 28, 2023
AnaisUrlichs pushed a commit to AnaisUrlichs/trivy that referenced this pull request Aug 10, 2023
…registry (aquasecurity#4649)

* feat: add support for mTLS authentication when connecting to registry

* feat: add support for mTLS authentication when connecting to registry - added error handling

* feat: add support for mTLS authentication when connecting to registry
- code quality improvements

* feat: add support for mTLS authentication when connecting to registry
- code quality improvements

* wrap errors

---------

Co-authored-by: knqyf263 <knqyf263@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for mTLS when connecting to the registry
3 participants