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

Artifact executable bit lost #675

Closed
lukts30 opened this issue Feb 21, 2024 · 8 comments · Fixed by #727
Closed

Artifact executable bit lost #675

lukts30 opened this issue Feb 21, 2024 · 8 comments · Fixed by #727
Assignees

Comments

@lukts30
Copy link

lukts30 commented Feb 21, 2024

E.g

genrule(
    name = "my_file",
    outs = ["test.sh"],
    cmd =  "echo whoami > $(OUTS); chmod +x $(OUTS)"
)

test.sh will be executable after fetching with bazel only because all artifacts it downloads are set to 0555.
Buck2 on the other hand has no such default. Everything that is not is_executable will be set 644.

With both bazel and buck2 after the test.sh file is copied from the worker to the CAS dir the exec bit is no longer set on the file. Therefore when buck2 fetches test.sh it will set it mode to 644.
Anything buck2 writes through actions.write with is_executable=True will still have the exec bit set, even in the CAS dir.

Not forcing 0555 for every file seems reasonable so for better compatibility with buck2 I suggest not discarding the exec permission.

(I could also be wrong this might need to be fixed in buck2).

@allada
Copy link
Member

allada commented Mar 1, 2024

We do set the execution bit, but I suspect buck2 is likely setting is_executable but and not setting unix_mode.

We can already have a bit for managing this on windows:

unix_mode = Some(unix_mode.unwrap_or(0o444) | 0o111);

I guess we would need to see the exact proto buck2 is sending to understand what action we need to take clearly.

Edit:
In looking over this, I think this line: #[cfg_attr(target_family = "windows", allow(unused_assignments))] (in the link above), should actually be target_family = "unix". I think that was supposed to be handling this case but doing it for windows by accident. Ironically the lint checker caught it, since we have allow(unused_assignments) set, but we missed it.

@allada
Copy link
Member

allada commented Mar 2, 2024

In looking into this, I'm no longer convinced what I stated above is the issue.

I am a bit confused though. You said:

With both bazel and buck2 after the test.sh file is copied from the worker to the CAS dir the exec bit is no longer set on the file. Therefore when buck2 fetches test.sh it will set it mode to 644.

But the permission bits are on the action results. This means that the CAS itself has no knowledge of what is executable and what is not, but the individual AC messages know what the permissions should be.

I do see that we don't ever set the AC's message's node_properties (which is where the unix_mode is set). Is it possible that buck2 only looks at unix_mode and doesn't look at is_executable?

@lukts30
Copy link
Author

lukts30 commented Mar 3, 2024

Nativelink only sets is_executable=true when the executable bit is set for others. I have umask set 0077 therefore is_executable=false which breaks it of course.

Ok((metadata.mode() & 0o001) != 0)

Should instead be: Ok((metadata.mode() & 0o111) != 0)

@allada
Copy link
Member

allada commented Mar 5, 2024

Aaah, so you are saying that the file permissions is something like 744 and we should be setting the is_executable flag?

Yeah, this seems appropriate. The proto spec does not say anything about how to deal with unix_mode + is_executable, so it's a bit confusing.

Maybe this is a good one for @zbirenbaum to dip your hands in, seems fairly straight forward.

@zbirenbaum zbirenbaum self-assigned this Mar 5, 2024
@zbirenbaum
Copy link
Contributor

@adam-singer and I both tested this out and couldn't reproduce it. Could you try following the readme instructions here https://github.com/adam-singer/buck2-example and see if there is anything inconsistent with the situation you described? After running the kill and clean commands the file will be retrieved from the cache by the local machine and remains executable @lukts30

@allada
Copy link
Member

allada commented Mar 6, 2024

I believe what he's saying is that if a file is 0744 it will not be flagged executable, because we only check the last bit.

We should be checking if any of the bits are executable and setting the is_executable flag if any of them are +x.

@zbirenbaum
Copy link
Contributor

zbirenbaum commented Mar 6, 2024

Ah I see now, owner and group permissions are being ignored. 0o111 is the correct mask, nice catch @lukts30!

@lukts30
Copy link
Author

lukts30 commented Mar 6, 2024

Thanks for fixing this.
Sorry for the confusion, indeed my initial reproducer would only work on a system where umask is set to anything ending in 7 (e.g. 0027).

genrule(
    name = "my_file",
    outs = ["test.sh"],
    cmd =  "echo whoami > $(OUTS); chmod +x $(OUTS)"
)

Then test.sh would be created as 0640 and the chmod +x would change it to 0750.

zbirenbaum pushed a commit to zbirenbaum/nativelink that referenced this issue Mar 7, 2024
zbirenbaum pushed a commit to zbirenbaum/nativelink that referenced this issue Mar 7, 2024
zbirenbaum pushed a commit to zbirenbaum/nativelink that referenced this issue Mar 9, 2024
Check owner and group executable bits
Add regression test for (TraceMachina#675): Artifact executable bit lost
zbirenbaum pushed a commit to zbirenbaum/nativelink that referenced this issue Mar 10, 2024
Changes the running action manager to check the owner and group
executable permissions of artifacts instead of just others. Prevents
files from losing executable status when being copied from the worker to
the CAS.

Fixes TraceMachina#675
zbirenbaum pushed a commit to zbirenbaum/nativelink that referenced this issue Mar 10, 2024
Changes the running action manager to check the owner and group
executable permissions of artifacts instead of just others. Prevents
files from losing executable status when being copied from the worker to
the CAS.

Fixes TraceMachina#675
zbirenbaum added a commit that referenced this issue Mar 11, 2024
Changes the running action manager to check the owner and group
executable permissions of artifacts instead of just others. Prevents
files from losing executable status when being copied from the worker to
the CAS.

Fixes #675

Co-Authored-By: Zach Birenbaum <zach@tracemachina.com>
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.

3 participants