-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fixes: no name check in docker container command #1331
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1331 +/- ##
==========================================
- Coverage 54.82% 54.79% -0.04%
==========================================
Files 292 293 +1
Lines 19267 19279 +12
==========================================
Hits 10564 10564
- Misses 8044 8056 +12
Partials 659 659 |
18accbe to
8a4e508
Compare
Signed-off-by: Lifubang <lifubang@acmcoder.com>
silvin-lubecki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lifubang for submitting this PR! 😄
I have some comments and questions, but I think it mainly lacks some tests.
cli/names.go
Outdated
| if len(name) == 0 { | ||
| return false | ||
| } | ||
| return validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why trimming the prefix? Is a container "/aaaa" valid? @thaJeztah WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, docker daemon said it's valid.
see https://github.com/moby/moby/blob/master/daemon/names.go#L59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the leading slash is automatically added, and for historic reasons; a container is named /containera, and a container linked to that container (using the legacy --link option on the default network) gets an internal name /containera/containerb (or something along those lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's allowed to manually create a container with a slash though; they should be added automatically by the daemon where needed
lifubang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your wonderful review. I have some code optimizations. Thanks.
233cb09 to
518c3e6
Compare
Signed-off-by: Lifubang <lifubang@acmcoder.com>
thaJeztah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm not sure if this is the right thing to do though; the general design is to defer validation to the daemon; make the daemon / API server responsible for checking which values are valid, and what values are invalid.
The docker CLI can be used against a different (newer/older) version of the daemon, which may accept different characters for "object" names.
In addition, this patch would only handle containers, but (see moby/moby#29126) the same could apply to any other object.
The original issue reported here is not actualy due to an invalid name, but because of the way this name is sent to the daemon; the cli sends redis/../redisps as part of the URL, and this gets expanded/rewritten to redisps.
Here's some older discussions/issues about this; moby/moby#29126 (suggested fix with URLencode; moby/moby#29131, and some related PR's; moby/moby#31831, and moby/moby#32127).
I think the correct fix should be to URLencode values before sending, however (I can't find that discussions, but can dig some more) there were concerns about changing that on the client, as it could result in an incompatible change if the daemon version does not handle this.
|
@thaJeztah That's really right. Thanks for your review. There are so many things need to be considered. I think URLencode is a simple, easy, but maybe a perfect way to fix this issue. I will try and think more. |
|
Thanks! Main thing to look into if URLEncoding is used, is what happens daemon-side, i.e.; the concern is to break compatibility with older daemons; perhaps it's handled automatically (haven't checked), but perhaps not. If it's not handled automatically, URLEncode could still be possible, but in that case it should be versioned (API 1.xx: don't url-encode, API > 1.xx use url-encode) |
|
Please see moby/moby#37857 |
Signed-off-by: Lifubang lifubang@acmcoder.com
- What I did
fix a bug when run docker container client command like this:
docker stop redis/../redisps
The container redisps will be stopped.
It's very strange.
I have fix rm, kill, and stop commands. If this solution is acceptable, I will fix other container commands.
- How I did it
add container check when run these container client cmd.
The regex in names.go is from https://github.com/moby/moby/blob/master/daemon/names/names.go
If we can refer it, it'll be better.
- How to verify it
Before fix:
After fix:
- Description for the changelog
Add container name check when run docker container client command.
- A picture of a cute animal (not mandatory but encouraged)
