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

Exit from docker login on SIGTERM and SIGINT. #1317

Merged
merged 26 commits into from
Sep 3, 2013

Conversation

calavera
Copy link
Contributor

This should allow to capture an interruption signal and exit when the login command is waiting for the credentials.

I'm completely new to docker's source code, so this might be incomplete. I'd really appreciate some 👀 on it.

Fixes #1299.

@creack
Copy link
Contributor

creack commented Jul 27, 2013

LGTM

@calavera
Copy link
Contributor Author

Oh, I see that you use your own term. This needs more work than I anticipated.

@creack
Copy link
Contributor

creack commented Jul 27, 2013

@calavera hmmm? What do you mean?

@calavera
Copy link
Contributor Author

Sorry, sometimes I cannot even understand myself.

The input comes from the raw terminal. Those signals are never triggered, although it looks like they should be captured by the channel at:

https://github.com/dotcloud/docker/blob/master/term/term.go#L47

@calavera
Copy link
Contributor Author

@creack what's the reason to put the term in raw mode? is it only to disable echo back when users type the password? The history is not really useful on why you decided to do that in 64f3467.

@calavera
Copy link
Contributor Author

I finally could figure out what the problem was. Allowing to generate signals in the new termios fixes the problem. A little gift with this working as expected:

docker-login

/cc @creack

@vieux
Copy link
Contributor

vieux commented Jul 29, 2013

@unclejack could you take a look as you worked on #1249

@creack
Copy link
Contributor

creack commented Jul 29, 2013

@calavera The login used to be handled 100% server side, that's why we used the raw mode. Now that the login is handle client side, I guess we could remove it.

@calavera
Copy link
Contributor Author

Oh, that makes sense. The echo still needs to be disabled for the password, but the ECHO flag can be disabled in the right moment for that.

* master: (54 commits)
  Return JSONError for HTTPResponse error
  Fix TestEnv
  Revert "Bind daemon to 0.0.0.0 in Vagrant. Fixes moby#1304"
  Add unit tests for build no cache
  Add no cache for docker build
  Move note about officially supported kernel
  Solved the logo being squished in Safari
  Add hostname to the container environment.
  fix same issue in api.go
  improve tests
  Return registy status code in error
  update http://get.docker.io/latest
  Add check that the request is good
  fix tests about refactor checksums
  add ufw doc
  Fixed a couple of minor syntax errors.
  Updated the description of run -d
  Make sure the index also receives the checksums
  Switch json/payload order
  Remove unused parameter
  ...
It only disables echo asking for the password and lets the terminal to handle everything else.
It fixes moby#1392 since blank spaces are not discarded as they did before.
It also cleans the login code a little bit to improve readability.
@calavera
Copy link
Contributor Author

calavera commented Aug 4, 2013

@creack with the last changes the login stops using the raw terminal. I didn't remove the function because it's used somewhere else and I'd like to isolate the changes as much as possible.

I think removing the raw terminal also fixes #1392.

@calavera
Copy link
Contributor Author

calavera commented Aug 4, 2013

I believe this is ready to merge, but I'd really appreciate some 👀 on it.

@creack
Copy link
Contributor

creack commented Aug 5, 2013

@calavera there is a \n issue. The client sends 'creack\n' as login instead of 'creack'

@@ -33,7 +33,7 @@ func MakeRaw(fd uintptr) (*State, error) {

newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON)
newState.Oflag &^= syscall.OPOST
newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to remove the ISIG flag? Now when doing 'ctrl-c' within a shell, it kills the client (docker run -i -t ubuntu bash)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the initial cause of the problem with the login command. I can put this back since the login command doesn't use this code anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do so, it breaks the tty behavior.

@calavera
Copy link
Contributor Author

@creack I've put the ISIG sygnal back and remove the writer. I couldn't find any good solution without complicating the term more than it is now.

@vieux
Copy link
Contributor

vieux commented Aug 29, 2013

@calavera could you please rebase this ?

It only disables echo asking for the password and lets the terminal to handle everything else.
It fixes moby#1392 since blank spaces are not discarded as they did before.
It also cleans the login code a little bit to improve readability.
* master: (23 commits)
  Made calling changelog before run return empty. Fixes moby#1705.
  fix error in docker build when param is not a directory
  Document FROM <image>:<tag> Dockerfile instruction.
  Install Ubuntu raring backported kernel from official archives directly.
  Updated "Use -> The Basics" to use ubuntu:12.10.
  hide version when not available
  added a Dockerfile which installs all deps and builds the docs.
  Unable to find image error should print to stderr
  remove message during tests
  use init function
  add TEST env var during tests and silenced parserun during tests
  Update python_web_app.rst
  Update remaining upstart scripts to wait for lxc-net
  Fixed a minor syntax error.
  Add privileged flag in documentation for container creation
  Fix moby#1685: Notes on production use. General installation cleanup.
  Fix bash completion, remove have
  added apt-key finger tip and fingerprint in ubuntu installation page
  Improve formatting with 'go fmt' as stated in CONTRIBUTING.md
  Start docker after lxc-net to prevent ip forwarding race
  ...
…o login_signal

* 'login_signal' of https://github.com/calavera/docker:
  Use flag.StringVar to capture the command line flags.
  Fix syscall name.
  Remove unused imports.
  Simplify term signal handler.
  Add the ISIG syscall back to not kill the client withing a shell with ctrl+c.
  Print a new line after getting the password from stdin.
  Exit if there is any error reading from stdin.
  Stop making a raw terminal to ask for registry login credentials.
  Allow to generate signals when termios is in raw mode.
  Use a more idiomatic syntax to capture the exit.
  Exit from `docker login` on SIGTERM and SIGINT.
Load the auth config before it's used.
@calavera
Copy link
Contributor Author

calavera commented Sep 1, 2013

@vieux I've synchronized my branch with master. Everything looks to still be working.

I can rebase the branch if you want, but I rather not. I think history is important.

Can you please take it a look?

@creack
Copy link
Contributor

creack commented Sep 3, 2013

LGTM

1 similar comment
@crosbymichael
Copy link
Contributor

LGTM

crosbymichael added a commit that referenced this pull request Sep 3, 2013
Exit from `docker login` on SIGTERM and SIGINT.
@crosbymichael crosbymichael merged commit d13c2ed into moby:master Sep 3, 2013
@calavera calavera deleted the login_signal branch August 6, 2015 21:44
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.

Allow CTRL-C in docker login
4 participants