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

fix: TCP+TLS docker daemon connection #1629

Merged
merged 2 commits into from
Mar 16, 2023

Conversation

matejvasek
Copy link
Contributor

@matejvasek matejvasek commented Mar 15, 2023

Changes

  • 🐛 Fix TCP+TLS docker daemon connection. If the DOCKER_TLS_VERIFY environment variable is set then TLS should be applied to the TCP connection to the docker daemon.
fix: TCP+TLS docker daemon connection

resolves #1627

Signed-off-by: Matej Vasek <mvasek@redhat.com>
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 15, 2023
@knative-prow knative-prow bot requested review from maximilien and rhuss March 15, 2023 21:37
@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 15, 2023
@matejvasek
Copy link
Contributor Author

/cc @riverar

@knative-prow
Copy link

knative-prow bot commented Mar 15, 2023

@matejvasek: GitHub didn't allow me to request PR reviews from the following users: riverar.

Note that only knative members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @riverar

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@matejvasek
Copy link
Contributor Author

@riverar please try this out

@matejvasek matejvasek requested review from lance, lkingland and zroubalik and removed request for maximilien and rhuss March 15, 2023 21:38
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Patch coverage: 16.36% and project coverage change: -0.10 ⚠️

Comparison is base (37fa5c8) 63.61% compared to head (4b385c8) 63.51%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1629      +/-   ##
==========================================
- Coverage   63.61%   63.51%   -0.10%     
==========================================
  Files          92       92              
  Lines       11682    11735      +53     
==========================================
+ Hits         7431     7453      +22     
- Misses       3575     3608      +33     
+ Partials      676      674       -2     
Flag Coverage Δ
e2e-test 38.95% <3.63%> (-0.18%) ⬇️
e2e-test-oncluster 34.67% <3.63%> (-0.16%) ⬇️
e2e-test-oncluster-runtime 29.52% <0.00%> (?)
e2e-test-runtime-go 30.22% <3.63%> (?)
e2e-test-runtime-python 30.18% <3.63%> (?)
e2e-test-runtime-quarkus 30.33% <3.63%> (?)
e2e-test-runtime-springboot 30.38% <3.63%> (?)
e2e-test-runtime-typescript 30.33% <3.63%> (?)
integration-tests 49.81% <16.36%> (-0.19%) ⬇️
unit-tests-macos-latest 48.60% <16.36%> (-0.15%) ⬇️
unit-tests-ubuntu-latest 49.51% <16.36%> (-0.21%) ⬇️
unit-tests-windows-latest 48.48% <16.36%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/docker/docker_client.go 62.79% <16.36%> (-22.09%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

tlsVerify, _ := strconv.ParseBool(tlsVerifyStr)
if !tlsVerify {
tlsOpts = append(tlsOpts, func(t *tls.Config) {
t.InsecureSkipVerify = true

Check failure

Code scanning / CodeQL

Disabled TLS certificate check

InsecureSkipVerify should not be used in production code.
Copy link

@riverar riverar Mar 16, 2023

Choose a reason for hiding this comment

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

Would delete this.

Copy link
Contributor Author

@matejvasek matejvasek Mar 16, 2023

Choose a reason for hiding this comment

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

But docker CLI does this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this DOCKER_TLS_VERIFY=0 wouldn't have desired effect, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@matejvasek matejvasek Mar 16, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@matejvasek matejvasek Mar 16, 2023

Choose a reason for hiding this comment

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

@riverar you are right about behaviour of the envvar -- it only matter if its set/empty.
The effect that I described (encryption+non_verify_cert) can be achieved by --tlsverify=false flag.

So I immodestly dare to say that my implementation here is little bit better.
The thing is that we do not have --tlsverify flag, so to achieve similar effect we can use the envvar (even if that deviates from what docker CLI does).

Do you agree?

Copy link

Choose a reason for hiding this comment

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

Agreed. (I continue to be extremely disappointed with Docker, esp. its impl. on Windows.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@riverar Just try out docker --tlsverify=false image ls it will use https but will skip cert verification.

Copy link

@riverar riverar Mar 16, 2023

Choose a reason for hiding this comment

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

@matejvasek Ah ha! It does indeed. (That's a miserable mismatch in behavior, imo.)

@riverar
Copy link

riverar commented Mar 15, 2023

@matejvasek Will check it out, thanks!

Copy link

@riverar riverar left a comment

Choose a reason for hiding this comment

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

Verified func now works in (my) TLS scenarios 🎉

tlsVerify, _ := strconv.ParseBool(tlsVerifyStr)
if !tlsVerify {
tlsOpts = append(tlsOpts, func(t *tls.Config) {
t.InsecureSkipVerify = true
Copy link

@riverar riverar Mar 16, 2023

Choose a reason for hiding this comment

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

Would delete this.

pkg/docker/docker_client.go Show resolved Hide resolved
@knative-prow
Copy link

knative-prow bot commented Mar 16, 2023

@riverar: changing LGTM is restricted to collaborators

In response to this:

Verified func now works in (my) TLS scenarios 🎉

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@matejvasek
Copy link
Contributor Author

@zroubalik @lance PTAL

Signed-off-by: Matej Vasek <mvasek@redhat.com>
@matejvasek
Copy link
Contributor Author

I should add some tests in case of future regression.

Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

/lgtm

Just a gentle reminder: accessing environment variables from anywhere outside of main is fraught with danger. When possible (and I know this isn't practical in many situations, perhaps now being one of them), it seems to me often worth the trouble to plumb these settings through the API rather than access them directly from within the depths. Cue the obligatory diatribe about pursuing idempotency :)

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Mar 16, 2023
@knative-prow
Copy link

knative-prow bot commented Mar 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland, matejvasek, riverar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [lkingland,matejvasek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot merged commit db1b624 into knative:main Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does func support TLS-enabled docker hosts?
3 participants