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

Can't pass octals to --change-permissions (GIT_SYNC_PERMISSIONS) #320

Closed
akloeckner opened this issue Jan 6, 2021 · 9 comments · Fixed by #321
Closed

Can't pass octals to --change-permissions (GIT_SYNC_PERMISSIONS) #320

akloeckner opened this issue Jan 6, 2021 · 9 comments · Fixed by #321

Comments

@akloeckner
Copy link

Hi there,

Thanks for this nice piece of software!

I'm using git-sync (latest = v3.2.1) to clone a repo into a named volume and access it from another container for some post-processing. I'm struggling with the permissions however. (I'm new to containers, so that might just be me.)

As git-sync creates everything as the 65533 user but my other container obviously does not, I thought I'd set the GIT_SYNC_PERMISSIONS variable to 777. However, that actually changes the permissions to something seemingly random.

After some trial and error, I figured out that the octal 777 was apparently converted to a decimal number and passed on to chmod. But chmod expects an octal number. So, I tried the decimal equivalent of GIT_SYNC_PERMISSIONS='511', which actually worked:

$ /git-sync
I0106 00:44:12.602504      12 main.go:430]  "level"=0 "msg"="starting up"  "args"=["/git-sync"] "pid"=12
[...cloning logs...]
I0106 00:44:26.054483      12 main.go:652]  "level"=0 "msg"="changing file permissions"  "mode"="0777"

$ ls -la
total 20
drwxrwxrwt 5 root     root  4096 Jan  6 00:44 .
drwxr-xr-x 1 root     root  4096 Jan  6 00:43 ..
drwxr-xr-x 9 git-sync 65533 4096 Jan  6 00:44 .git
drwx------ 2 git-sync 65533 4096 Jan  6 00:44 .ssh
lrwxrwxrwx 1 git-sync 65533   44 Jan  6 00:44 deploy -> rev-874f48bce4069af461bc2f23e785d7ffa722ea96
drwxrwxrwx 7 git-sync 65533 4096 Jan  6 00:44 rev-874f48bce4069af461bc2f23e785d7ffa722ea96

$ set
GIT_KNOWN_HOSTS='false'
GIT_SSH_KEY_FILE='/etc/git-secret/id_rsa_docker'
GIT_SYNC_BRANCH='deploy'
GIT_SYNC_DEST='deploy'
GIT_SYNC_PERMISSIONS='511'
GIT_SYNC_REPO='[obscured]'
GIT_SYNC_ROOT='/tmp'
GIT_SYNC_SSH='true'
GIT_SYNC_TIMEOUT='120'
GIT_SYNC_WAIT='30'
HOME='/tmp'
HOSTNAME='c494b3dcc487'
IFS=' 
'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
PPID='0'
PS1='$ '
PS2='> '
PS4='+ '
PWD='/tmp'
TERM='xterm'
_='-la'

In summary, I believe something goes wrong with octal/decimal conversion and it's bound to be in that area:

// Change the file permissions, if requested.

@thockin
Copy link
Member

thockin commented Jan 6, 2021 via email

@thockin
Copy link
Member

thockin commented Jan 6, 2021

Just to follow up:

The YAML spec seems to have changed between 1.1 and 1.2. 1.1 interpreted 0777 as an octal number, but 1.2 interprets that as a decimal, with 0o777 as the octal spelling. I'm flabbergasted that such a breaking change would be allowed, and it's clear that different parsers do/don't get this strictly right.

As such I can not endorse using octal AT ALL in YAML. You just can't know how it will be interpreted.

JSON supports neither syntax, which is similarly baffling, but at least it hasn't CHANGED (and JSON is know to be absurdly reductivist).

@thockin thockin closed this as completed Jan 6, 2021
@akloeckner
Copy link
Author

Thanks for clarifying. Still, I tried 0777 and it gives the same error. I'm not using YAML at all (yet). I'm passing ENV variables in Docker.

What is the recommended way then, to make the checked out files accessible in other containers? Should I use 0o777? Or is there even a cleaner way to pass the data to another container for post-processing (= yarn building a node app in my case).

@thockin
Copy link
Member

thockin commented Jan 6, 2021

OH. I missed that you were setting this through the git-sync mechanism rather than the k8s mechanism.

Yes, you have hit a bug! It mis-parses.

@thockin thockin reopened this Jan 6, 2021
@thockin thockin changed the title Decimal conversion of file permissions? Can't pass octals to --change-permissions (GIT_SYNC_PERMISSIONS) Jan 6, 2021
@akloeckner
Copy link
Author

Thanks for this quick resolution!!

@thockin
Copy link
Member

thockin commented Jan 7, 2021

I'll have to queue up a build

@thockin
Copy link
Member

thockin commented Jan 7, 2021

Available for test as gcr.io/k8s-staging-git-sync/git-sync:v3.2.2

Promotion to prod in kubernetes/k8s.io#1510

@thockin
Copy link
Member

thockin commented Jan 7, 2021

@akloeckner
Copy link
Author

👍 Seems to work. Thanks a lot!

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 a pull request may close this issue.

2 participants