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

Add support for Docker SecurityOpt (allowing GDB Debugging on unprivileged docker containers) #6856

Merged
merged 9 commits into from
Nov 7, 2017

Conversation

hkolvenbach
Copy link
Contributor

@hkolvenbach hkolvenbach commented Oct 20, 2017

Could someone please review the use of config variables? I am not entirely sure if I understand the translation from CHE_DOCKER_SECURITYOPT in che.env to @Named('che.docker.securityopt') correctly.
This also needs #6855 to be fixed to be tested

What does this PR do?

This PR allows to specify the securityOpt parameter in HostConfig to pass parameters to the docker daemon during container creation. the securityOpt parameter is equal to the command line option --security-opt of the command line. The value seccomp:unconfined allows gdb to run in unprivileged containers. Kubernetes uses seccomp:unconfined by default, but docker does not.

What issues does this PR fix or reference?

Related issues:
#4719
#4524
#5254
#4284

  • Add new config variable che.docker.securityopt / CHE_DOCKER_SECURITYOPT
  • Support for GDB in unprivileged docker containers

Release Notes

  • Support for GDB in unprivileged docker containers

Docs PR

eclipse-che/che-docs#305

@benoitf benoitf added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/bug Outline of a bug - must adhere to the bug report template. labels Oct 20, 2017
@codenvy-ci
Copy link

Build # 4255 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/4255/ to view the results.

@benoitf
Copy link
Contributor

benoitf commented Oct 20, 2017

@hkolvenbach could you please run the command

mvn -o com.coveo:fmt-maven-plugin:2.0.0:format

jenkins CI job is failing to invalid format in your modified files.
thanks

@hkolvenbach
Copy link
Contributor Author

hkolvenbach commented Oct 20, 2017

@benoitf sorry, probably still formatted with the old version. should be fixed now

@benoitf
Copy link
Contributor

benoitf commented Oct 20, 2017

@hkolvenbach yes thanks.
This is related to the new java formatter change I introduced yesterday

Signed-off-by: Hanno Kolvenbach <[email protected]>
@codenvy-ci
Copy link

@benoitf benoitf added kind/enhancement A feature request - must adhere to the feature request template. team/platform and removed kind/bug Outline of a bug - must adhere to the bug report template. labels Oct 20, 2017
@skabashnyuk
Copy link
Contributor

Any volunteers to port to che6? @hkolvenbach @tolusha ?

Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

Nice PR!
You used properties injection correctly.
Can you take a look at my inlined comments?

# Host SecurityOpt Parameters
# This parameter allows to specify text values for the docker "--security-opt" parameter
# or the HostConfig{SecurityOpt:[]} value of the docker machine API
# (https://docs.docker.com/engine/api/v1.33/#operation/ContainerCreate)

Choose a reason for hiding this comment

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

We use 1.21 API by default for compatibility with older docker versions. Can you point to that version instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

# This parameter allows to specify custom security options for the created docker container
# seccomp:unconfined is the default for kubernetes, but not for docker. This is needed
# for debugging with gdbserver
che.docker.securityopt=seccomp:unconfined

Choose a reason for hiding this comment

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

Do we want to change default settings or just allow to change it? @hkolvenbach @tolusha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say yes to behave in the same way as the kubernetes / openshift implementation does. Any comments on this @tolusha?

# This parameter allows to specify custom security options for the created docker container
# seccomp:unconfined is the default for kubernetes, but not for docker. This is needed
# for debugging with gdbserver
che.docker.securityopt=seccomp:unconfined

Choose a reason for hiding this comment

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

Have you tried it on systems that do not support seccomp? Is it just ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@garagatyi didn't try it yet, any specific system I should test with?

Choose a reason for hiding this comment

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

I don't know where to test it and whether it is worth checking, just thought how it can influence users.
I tried to put an invalid value of seccomp profile and another security option. Both failed. So I assume that this would prevent Che starting workspaces if users host doesn't support seccomp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the feedback, i will test with different values for securityopt and see how it behaves. If unsupported values fail, i will leave it empty as default

@@ -333,14 +333,18 @@ public ContainerConfig withExposedPorts(Map<String, Map<String, String>> exposed
return this;
}

// there is no "SecurityOpts" in the docker specification, only HostConfig{"SecurityOpt" .[]}

Choose a reason for hiding this comment

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

Please, use javadocs comments style to provide documentation, e.g.

/*
 * There is no "SecurityOpts" in the docker specification, only HostConfig{"SecurityOpt" .[]}
 */

@@ -161,6 +161,11 @@ che.docker.always_pull_image=true
# to be able to launch their own runtimes which are embedded Docker containers.
che.docker.privileged=false

# This parameter allows to specify custom security options for the created docker container
# seccomp:unconfined is the default for kubernetes, but not for docker. This is needed
# for debugging with gdbserver

Choose a reason for hiding this comment

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

Since it is supposed to be injected as an array can you add comment that values are separated by commas

# This parameter allows to specify custom security options for the created docker container
# seccomp:unconfined is the default for kubernetes, but not for docker. This is needed
# for debugging with gdbserver
che.docker.securityopt=seccomp:unconfined

Choose a reason for hiding this comment

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

Can you elaborate on how to set this option to default docker behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@garagatyi default would be an empty parameter

# This is useful if you want to run e.g. Cpp debugging within the container through gdbserver
# See https://github.com/eclipse/che/issues/4284 for details. This is only necessary for docker,
# openshift seems to set "seccomp:unconfined" by default
#CHE_DOCKER_SECURITYOPT="seccomp:unconfined"

Choose a reason for hiding this comment

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

I think that quotes should not be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@hkolvenbach
Copy link
Contributor Author

Thanks for the remarks, I will fix them. Regarding the Che6 port: I can look into it, but not sure if I will manage to do it this week.

Signed-off-by: Hanno Kolvenbach <[email protected]>
@garagatyi
Copy link

@hkolvenbach Che6 has this area massively refactored. If you need any help you can contact me

@garagatyi
Copy link

@hkolvenbach I think that in case CHE_DOCKER_SECURITYOPT is set to empty value, e.g.:

CHE_DOCKER_SECURITYOPT=

the current default behavior will be used, right?
I'm afraid container creation would fail in that case. Can you check? If I'm correct, please, take a look at this class for the hint.

@hkolvenbach
Copy link
Contributor Author

hkolvenbach commented Oct 24, 2017

@garagatyi thanks for the support, i will come back to it when i am working on the che6 port.

i did a few more tests and can confirm that docker will definitely fail if any unknown value is provided. so i will change it do not provide anything on default. null or empty string seems to work though (at least on linux).

i will also check if an empty string will result in the default behavior.

@hkolvenbach
Copy link
Contributor Author

hkolvenbach commented Oct 24, 2017

@garagatyi i just confirmed that container creation will fail with an empty string, only null is allowed. do i understand correctly, that i need to implement a SecurityOptProvider similar to the dnsResolversProvider and create a seperate named parameter for it? or is there any easier way to check the che.docker.securityopt parameter for empty strings and set it to null instead?

@garagatyi
Copy link

I think that unconfined might be OK as a default value. I just wanted to mention it to hear a feedback from the community if any. Wrong values in other places of che.env would definitely brake workspaces start also, so it is not the case.
But the empty value has to be fixed because it is definitely what someone might use. Yes, you need a provider similar to DnsResolversprovider to fix that issue. But you don't have to inject provider as named string - just inject provider directly and get value from it in the constructor of MachineProviderImpl.

@hkolvenbach
Copy link
Contributor Author

@garagatyi @eivantsov from my side I would consider my implementation for che 5.x ready. I have tested it with empty values, single values and multiple values for CHE_DOCKER_HOSTCONFIG_SECURITYOPT and this works for docker.

i will now start to look into the che 6 port.

@garagatyi
Copy link

@hkolvenbach take a look on direct usage of provider in tests garagatyi@2685f22

@hkolvenbach
Copy link
Contributor Author

@garagatyi thanks, i integrated your changes and adapted everything to use CHE_DOCKER_SECURITYOPT again. somehow your commit doesn't pass validation, should I squash and sign it?

@hkolvenbach
Copy link
Contributor Author

@garagatyi I am a bit lost in the Che6 source code. Could you point me to the file where the configuration for the docker container is generated? I hope i can take it from there

@ghost
Copy link

ghost commented Oct 31, 2017

Just checked gdb on OpenShift. I was able to start gdb and debug a binary using command line.

@garagatyi
Copy link

Great! @eivantsov maybe we should change defaults to that behavior?

@ghost
Copy link

ghost commented Oct 31, 2017

@garagatyi i think it's safe enough to do so.

Hanno Kolvenbach added 2 commits November 2, 2017 09:23
@hkolvenbach
Copy link
Contributor Author

hkolvenbach commented Nov 6, 2017

@garagatyi I finally found time to port this pull request to che6. Tested it with empty configuration, 1 configuration value seccomp:unconfined and 2 values seccomp:unconfined,apparmor:unconfined

here it is #7203

@garagatyi
Copy link

@skabashnyuk there is a port for che6 already

@garagatyi
Copy link

@benoitf can you take a look?

@benoitf benoitf changed the title Allow GDB Debugging on unprivileged docker containers Add support for Docker SecurityOpt (allowing GDB Debugging on unprivileged docker containers) Nov 7, 2017
@benoitf
Copy link
Contributor

benoitf commented Nov 7, 2017

ci-build

@benoitf benoitf merged commit 2c8cd59 into eclipse-che:master Nov 7, 2017
@benoitf
Copy link
Contributor

benoitf commented Nov 7, 2017

thanks @hkolvenbach

@benoitf benoitf added this to the 5.21.0 milestone Nov 7, 2017
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Nov 7, 2017
@codenvy-ci
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants