Skip to content

Atuin loses track of umask when running scripts #2726

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

Open
papertigers opened this issue Apr 29, 2025 · 0 comments
Open

Atuin loses track of umask when running scripts #2726

papertigers opened this issue Apr 29, 2025 · 0 comments

Comments

@papertigers
Copy link

It looks like Atuin gained a blanket security policy in #1554 which is a fine position to take from a security standpoint, but leads to surprising behavior when running a script via atuin scripts run <script>.

For example let's use the following script locally, and from within atuin to compare the results:

#!/usr/bin/env bash

fatal() {
        echo "$@"
        exit 1
}

tempdir=$(mktemp -d)
[[ -n $tempdir ]] || fatal 'failed to create tmp directory'
pushd "$tempdir" || fatal "failed to cd into $tempdir"

cat << EOF > foo.sh
#!/usr/bin/env bash
echo hello!
EOF

ls -l
pfexec chown root:root foo.sh || fatal 'failed to own foo.sh by root'
pfexec chmod +x foo.sh || fatal 'failed to chmod foo.sh'
ls -l
./foo.sh || fatal 'failed to run foo.sh'


popd || fatal 'failed to popd'
rm -rf "$tempdir" || fatal 'failed to remove $tempdir'

Local execution from current shell:

❯ ./atuin-bug.sh
/faketmpfs/tmp.ucaqer ~/bin
total 1
-rw-r--r--   1 link     staff         32 Apr 29 18:39 foo.sh
total 1
-rwxr-xr-x   1 root     root          32 Apr 29 18:39 foo.sh
hello!
~/bin

atuin scripts execution:

❯ atuin scripts run atuin-bug
/faketmpfs/tmp.U8aOjr ~/bin
total 1
-rw-------   1 link     staff         32 Apr 29 18:40 foo.sh
total 1
-rwx------   1 root     root          32 Apr 29 18:40 foo.sh
/faketmpfs/.tmpTxwhih: line 22: ./foo.sh: Permission denied
failed to run foo.sh
Script exited with code 1

Because the umask is 077 and my shells current umask is 022 chmod is refusing to apply the +x permissions.
From the man page:

                     +
                             Add permissions.

                             If permissions are omitted, nothing is added.

                             If who is omitted, add the file mode bits
                             represented by permissions, except for the those
                             with corresponding bits in the file mode creation
                             mask.

                             If who is present, add the file mode bits
                             represented by the permissions.

There are a few paths forward that come to mind:

  • Document this behavior and let users deal with setting a umask in their script
  • Save the returned umask mode and pipe it through to the script execution env and apply it with Command::pre_exec before execution.
  • Drop the blanket security policy and add helper methods for file creation that explicitly set the permissions (potential for future PRs to bypass and use the wrong permissions)
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

No branches or pull requests

1 participant