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

Docker config file defaults from environment #126

Merged
merged 14 commits into from
Jul 20, 2016

Conversation

stefanoborini
Copy link
Contributor

Fixes #85

@codecov-io
Copy link

codecov-io commented Jul 19, 2016

Current coverage is 85.04%

Merging #126 into master will increase coverage by 2.91%

@@             master       #126   diff @@
==========================================
  Files            37         36     -1   
  Lines          1343       1344     +1   
  Methods           0          0          
  Messages          0          0          
  Branches        123        123          
==========================================
+ Hits           1103       1143    +40   
+ Misses          200        165    -35   
+ Partials         40         36     -4   

Powered by Codecov. Last updated by 734c6f9...1d378b3

@stefanoborini stefanoborini changed the title Docker config file defaults from environment [WIP] Docker config file defaults from environment Jul 19, 2016
@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

I like the fact that default values for tls parameters are extracted from docker.utils.kwargs_from_env. However I would prefer they be defined as traitlet's defaults so that docker.utils.kwargs_from_env is not triggered altogether if one provides all the required parameters in the config file. It might be a bit repetitive but this is because docker.utils.kwargs_from_env automatically checks if the default cert files exist and such check might fail for exactly the same reason why one would want to set the parameters in the file config.
Ref: https://github.com/docker/docker-py/blob/1.8.1/docker/tls.py#L44
https://github.com/docker/docker-py/blob/986a14a152d20df6bb8622516ab2d18af73e5e20/docker/utils/utils.py#L523

@stefanoborini
Copy link
Contributor Author

Well, if you have the environment variables defined but the certificates are not there, you surely want an error to be raised.

@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

Well, if you have the environment variables defined but the certificates are not there, you surely want an error to be raised.

Isn't environment variables such as DOCKER_CERT_PATH set by docker toolbox (and our spawner)? So if one wants to override, e.g. the tls cert parameters, using the file config, the relevant environment variables have to be manually unset? Is this the behaviour we want?

@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

Isn't environment variables such as DOCKER_CERT_PATH set by docker toolbox (and our spawner)? So if one wants to override, e.g. the tls cert parameters, using the file config, the relevant environment variables have to be manually unset? Is this the behaviour we want?

Imagine a scenario where the DOCKER_CERT_PATH is set but it does not have the cert files. Instead you have cert files somewhere else. If my mental compilation of the PR is correct, you'd have to either (1) set the environment variable DOCKER_CERT_PATH appropriately or (2) unset the DOCKER_CERT_PATH and then set the parameters in the config file or (3) put the cert files in the default location.

traitlet_name,
d[traitlet_name])
dict_keys = d.keys()
traitlet_names = traited_instance.traits().keys()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as traited_instance.trait_names()

@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

Regarding the comment on the non-existence of cert/key/ca.pem files in the default cert path, whatever we decide the behaviour should be, I think there should be a test for such scenario.
Apart from this, the rest looks good to merge to me.

self.tls_verify = (env.get("DOCKER_TLS_VERIFY", "") != "")

cert_path = env.get("DOCKER_CERT_PATH", "")
if self.tls_verify or cert_path != "":
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we set these defaults no matter what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because otherwise it will enable the tls verification later on, when you generate the dict...

Copy link
Contributor

Choose a reason for hiding this comment

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

when you generate the dict...

Can you point me to this dict please? Just wanted to understand it better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

docker_config, although I noticed it creates a tls section only if you have tls_verify. It should also check for certificate paths. tls_verify == False does not imply that you don't perform tls.

@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

Two last minor comments, good to merge then! Thanks @sbo!

# This is docker behavior.
if self.tls:
params["tls"] = tls.TLSConfig(
client_cert=(self.tls_cert, self.tls_key),
Copy link
Contributor

@kitchoi kitchoi Jul 20, 2016

Choose a reason for hiding this comment

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

if tls is True but tls_verify is False, the default of tls_cert and tls_key are not set. Why do we need cert and key when tls is True?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that docker.Client(tls=True) does completely different thing: https://github.com/docker/docker-py/blob/master/docker/client.py#L90

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, but we never have tls=True. we have it in the file config but our meaning is the same as the —tls and —tlsverify in docker as a result, we always pass a TLSConfig to the client or nothing, in that case it’s False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if tls is True but tls_verify is False, the default of tls_cert and tls_key are not set. Why do we need cert and key when tls is True?

Yes they are. They are defined on the cert_path variable. Check the init

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant this:

In [1]: from remoteappmanager.file_config import FileConfig

In [2]: tmp = FileConfig(tls=True)

In [3]: tmp.tls_cert, tmp.tls_key
Out[3]: ('', '')

@kitchoi
Copy link
Contributor

kitchoi commented Jul 20, 2016

@sbo merge?

@stefanoborini stefanoborini merged commit 14d01c6 into master Jul 20, 2016
@stefanoborini stefanoborini deleted the 85-config-file-defaults branch July 20, 2016 13:10
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.

3 participants