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

Test with root access in GitHub workflows #1173

Merged
merged 1 commit into from
Mar 7, 2024
Merged

Conversation

arbourd
Copy link
Member

@arbourd arbourd commented Mar 5, 2024

To enable tests that require privileged root access, this commit tests with sudo. The Java and Python jobs have additional permissions issues, so they are also configured and made with sudo.

A small permissions fix is required before running tests to allow non-root users to execute within the /home/runner directory.

This change also removes the custom directories that were required without root access.

@arbourd arbourd marked this pull request as ready for review March 5, 2024 18:42
Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

EDIT: GH done me again! this was supposed to come after the other two comments...

A more general question is do we need to do all the configuring and compiling as root?

I know this is just a throwaway environment, but from a principle of least privilege, is it really only the actual pytests that need to be run as root?

Comment on lines 110 to 116

- name: Configure unit
run: |
./configure \
--prefix=${{ steps.dir.outputs.prefix }} \
--sbindir=${{ steps.dir.outputs.bin }} \
--logdir=${{ steps.dir.outputs.var }}/log \
--log=${{ steps.dir.outputs.var }}/log/unit/unit.log \
--runstatedir=${{ steps.dir.outputs.var }}/run \
--pid=${{ steps.dir.outputs.var }}/run/unit/unit.pid \
--control=unix:${{ steps.dir.outputs.var }}/run/unit/control.sock \
--modules=${{ steps.dir.outputs.prefix }}/lib/unit/modules \
--statedir=${{ steps.dir.outputs.var }}/state/unit \
sudo ./configure \
--tests \
--openssl \
--njs \
Copy link
Member

Choose a reason for hiding this comment

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

Right, Unit doesn't have to be installed to run the pytests...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think these have defaults as well in /usr yes?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, /usr/local

Comment on lines +299 to +305
# /home/runner will be root only after calling sudo above
# Ensure all users and processes can execute
- name: Fix permissions
run: |
sudo chmod -R +x /home/runner
namei -l ${{ github.workspace }}

Copy link
Member

Choose a reason for hiding this comment

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

Heh, you passed the test and didn't just chmod 777 the whole thing!

@arbourd
Copy link
Member Author

arbourd commented Mar 5, 2024

Re: @ac000

A more general question is do we need to do all the configuring and compiling as root?

I know this is just a throwaway environment, but from a principle of least privilege, is it really only the actual pytests that need to be run as root?

This is actually how I started, but, there are issues with the Java and Python tests: for whatever reasons there are issues with requiring sudo either during the configure or make steps. I am happy to try and make it work though, if we want to try and use sudo as little as possible.

Specifically:

  • dlopen("/home/runner/work/unit/unit/build/lib/unit/modules/python3.unit.so"), failed: "libpython3.11.so.1.0: cannot open shared object file: No such file or directory"
  • Failed: Can't run javac process.

@arbourd arbourd force-pushed the privileged branch 13 times, most recently from 24fb5f0 to c48974a Compare March 6, 2024 00:17
@arbourd arbourd requested a review from ac000 March 6, 2024 00:18
@ac000
Copy link
Member

ac000 commented Mar 6, 2024

Even if we can do most of it without sudo and only use sudo for the bits that currently require it...

@arbourd
Copy link
Member Author

arbourd commented Mar 6, 2024

@ac000 All done. I will rebase and clean up the commits before merging. 2nd commit is the specific-sudoing.

@ac000
Copy link
Member

ac000 commented Mar 6, 2024

I would like to see the final result before merging...

@arbourd arbourd force-pushed the privileged branch 2 times, most recently from 8d4e67d to 602e9ec Compare March 7, 2024 15:10
@ac000
Copy link
Member

ac000 commented Mar 7, 2024

OK, change looks good.

Commit message just needs re-wrapping. We want to wrap commit messages after 72 chars. Keep in mind that when viewing commit messages in git, it will put 4 chars of padding at the beginning of each line, so in a standard 80 char terminal you will get your message centred with 4 chars of padding each side.

And seeing as you asked, I've added your Signed-off-by and my Reviewed-by to the message. So it looks like

Test with root access in GitHub workflows                                          
                                                                                
To enable tests that require privileged root access, this commit tests          
with `sudo`. The Java and Python jobs have additional permissions               
issues, so they are also configured and made with `sudo`.                       
                                                                                
A small permissions fix is required before running tests to allow               
non-root users to execute within the `/home/runner` directory.                  
                                                                                
This change also removes the custom directories that were required              
without root access.                                                            
                                                                                
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>                               
Signed-off-by: Dylan Arbour <d.arbour@f5.com>

and in git it looks like

commit 639bff661a12ca999c34477c93ad39d105b44e93 (HEAD -> sutest)
Author: Dylan Arbour <d.arbour@f5.com>
Date:   Tue Feb 27 09:41:07 2024 -0500

    Test with root access in GitHub workflows
    
    To enable tests that require privileged root access, this commit tests
    with `sudo`. The Java and Python jobs have additional permissions
    issues, so they are also configured and made with `sudo`.
    
    A small permissions fix is required before running tests to allow
    non-root users to execute within the `/home/runner` directory.
    
    This change also removes the custom directories that were required
    without root access.
    
    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
    Signed-off-by: Dylan Arbour <d.arbour@f5.com>

You'll notice I also made a couple of minor tweaks to the message while I was at it...

  • Tweaked the subject
  • s/folders/directories/

@arbourd arbourd changed the title Build and test with root access Test with root access in GitHub workflows Mar 7, 2024
To enable tests that require privileged root access, this commit tests
with `sudo`. The Java and Python jobs have additional permissions
issues, so they are also configured and made with `sudo`.

A small permissions fix is required before running tests to allow
non-root users to execute within the `/home/runner` directory.

This change also removes the custom directories that were required
without root access.

Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Dylan Arbour <d.arbour@f5.com>
Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

OK, looks good. Thanks!

@arbourd arbourd merged commit 8032ce3 into nginx:master Mar 7, 2024
17 checks passed
@arbourd arbourd deleted the privileged branch March 7, 2024 19:17
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 this pull request may close these issues.

2 participants