login: handle non-tty scenario consistently#5401
Merged
thaJeztah merged 1 commit intodocker:masterfrom Sep 3, 2024
Merged
Conversation
Running `docker login` in a non-interactive environment sometimes errors
out if no username/pwd is provided. This handling is somewhat
inconsistent – this commit addresses that.
Before:
| `--username` | `--password` | Result |
|:------------:|:------------:| ------------------------------------------------------------------ |
| ✅ | ✅ | ✅ |
| ❌ | ❌ | `Error: Cannot perform an interactive login from a non TTY device` |
| ✅ | ❌ | `Error: Cannot perform an interactive login from a non TTY device` |
| ❌ | ✅ | hangs |
After:
| `--username` | `--password` | Result |
|:------------:|:------------:| ------------------------------------------------------------------ |
| ✅ | ✅ | ✅ |
| ❌ | ❌ | `Error: Cannot perform an interactive login from a non TTY device` |
| ✅ | ❌ | `Error: Cannot perform an interactive login from a non TTY device` |
| ❌ | ✅ | `Error: Cannot perform an interactive login from a non TTY device` |
It's worth calling out a separate scenario – if there are previous,
valid credentials, then running `docker login` with no username or
password provided will use the previously stored credentials, and not
error out.
```console
cat ~/.docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "xxxxxxxxxxx"
}
}
}
⭑ docker login 0>/dev/null
Authenticating with existing credentials...
Login Succeeded
```
This commit also applies the same non-interactive handling logic to the
new web-based login flow, which means that now, if there are no prior
credentials stored and a user runs `docker login`, instead of initiating
the new web-based login flow, an error is returned.
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
ae23729 to
bbb6e76
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5401 +/- ##
==========================================
- Coverage 60.94% 59.73% -1.22%
==========================================
Files 304 345 +41
Lines 21346 23394 +2048
==========================================
+ Hits 13010 13974 +964
- Misses 7407 8450 +1043
- Partials 929 970 +41 |
vvoland
approved these changes
Sep 3, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
docker loginin a non-interactive environment sometimes errors out if no username/password is provided.Before:
--username--passwordError: Cannot perform an interactive login from a non TTY deviceError: Cannot perform an interactive login from a non TTY deviceAfter:
--username--passwordError: Cannot perform an interactive login from a non TTY deviceError: Cannot perform an interactive login from a non TTY deviceError: Cannot perform an interactive login from a non TTY deviceIt's worth calling out a separate scenario – if there are previous, valid credentials, then running
docker loginwith no username or password provided will use the previously stored credentials, and not error out.- What I did
This PR makes this handling consistent, and also adds some tests.
- How I did it
Made the non-tty handling consistent by also erroring out when a user runs
docker login --password bork(with no username) when stdin is not a tty.Also applied the same non-interactive handling logic to the new web-based login flow, which means that now, if there are no prior credentials stored and a user runs
docker login, instead of initiating the new web-based login flow, an error is returned.- How to verify it
Run the added tests, or
docker login 0>/dev/nulldocker login -u [username] -p [password] 0>/dev/nulldocker login -u [username] 0>/dev/nulldocker login -p [password] 0>/dev/null- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)