Skip to content

Change uid/gid on 'docker cp' and preserve it on 'docker cp -a'#34099

Open
chipironcin wants to merge 1 commit intomoby:masterfrom
chipironcin:fix_wrong_cp_behavior
Open

Change uid/gid on 'docker cp' and preserve it on 'docker cp -a'#34099
chipironcin wants to merge 1 commit intomoby:masterfrom
chipironcin:fix_wrong_cp_behavior

Conversation

@chipironcin
Copy link
Copy Markdown
Contributor

@chipironcin chipironcin commented Jul 13, 2017

Signed-off-by: Jorge Marin [email protected]
Fixes #34096

- What I did
Modified behavior of docker cp command to revert it back to the original behavior after #28923

- How I did it
Negate a variable and add an explanatory comment.

- How to verify it
Read #34096

- Description for the changelog
Revert docker cp behavior back to old way of setting uid/gid when copying files from host to a container while preserving docker cp -a option for copying all uid/gid information.

- A picture of a cute animal (not mandatory but encouraged)

chamaleon

@chipironcin
Copy link
Copy Markdown
Contributor Author

Actually, I think this would need proper tests.
I am not very familiar with go testing framework, if someone could just take the lead there it would be awesome (supposing this PR makes sense)

@thaJeztah
Copy link
Copy Markdown
Member

Thanks @chipironcin - this change looks correct indeed; while looking for a way to test this, I discovered other issues as well in this functionality; see #34142

I was already looking into the uid/gid case (numeric values)

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

I'm OK with merging this as-is, as the other issues need to be looked into as well, and complicate testing this functionality

open to suggestions though

LGTM

@thaJeztah
Copy link
Copy Markdown
Member

pushed #34143 (work in progress) to see if the uid/gid lookup can be addressed

@tonistiigi
Copy link
Copy Markdown
Member

This doesn't look quite correct yet because of this condition

if container.Config.User == "" {
return daemon.defaultTarCopyOptions(noOverwriteDirNonDir), nil
}
. That condition looks wrong to me, it means that docker cp would rewrite files to root if --user=root is set. If no specific user is defined(still equivalent to root) it would preserve the original owners. That also seems to be the reason why the testcase in https://github.com/moby/moby/pull/28923/files#diff-d16a9bdd478399b633d0f1b343f4b9d1R17 doesn't actually test anything.

@runcom
Copy link
Copy Markdown
Member

runcom commented Sep 18, 2017

any update on this?

@thaJeztah
Copy link
Copy Markdown
Member

ping @erikh could you have a look?

@dnephin
Copy link
Copy Markdown
Member

dnephin commented Nov 30, 2017

@tonistiigi is correct that this is not the right fix. See #34096 (comment)

Since this has not seen any activity in 3 months I'm going to close this PR. If you're still interested in submitting a fix please update and comment here. We can re-open it.

@dnephin dnephin closed this Nov 30, 2017
@thaJeztah
Copy link
Copy Markdown
Member

@dnephin we'll still need a fix though 😅

@chipironcin
Copy link
Copy Markdown
Contributor Author

Pls reopen, I haven't had time to work on this and I have no previous experience with golang :(

@kopaygorodsky
Copy link
Copy Markdown

I'll try to check it out soon

@thaJeztah
Copy link
Copy Markdown
Member

Reopening, let us know if you need help

@thaJeztah thaJeztah reopened this Dec 1, 2017
@sgaweda
Copy link
Copy Markdown

sgaweda commented Aug 23, 2019

Are there any updates on the status of this ticket? I ran into this today and the docs seem to indicate that this behaviour is expected.

@commodis
Copy link
Copy Markdown

I still ran into this problem with Docker version 20.10.7, build f0df350.

@PerMildner
Copy link
Copy Markdown

What is the status of this bug? Was it fixed but just stalled due to a merge conflict?

The bug bit me today and it is a little worrying that docker cp has been broken for so long.

@matejvasek
Copy link
Copy Markdown

I am afraid that at this point fixing this would actually broke existing code that relies on current truly odd behaviour.

@matejvasek
Copy link
Copy Markdown

Folks at podman tried to fix it in their implementation and it broke buildpack build for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker cp behavior changed