Skip to contentSkip to conversation

Exception in ftc if called from privileged directory

Fuego Georg Piewald 2 participants 3 messages Jul 24, 2020 – Jul 25, 2020

lore
Share & tools
lore
#0 lore raw

Hi,

I just experienced a Python exception when executing an "ftc run-test" command:

    Traceback (most recent call last):
      File "/usr/local/bin/ftc", line 5661, in <module>
        main()
      File "/usr/local/bin/ftc", line 5550, in main
        rcode, run_id = do_run_test(conf, options)
      File "/usr/local/bin/ftc", line 4358, in do_run_test
        os.chdir(saved_cur_dir)
    OSError: [Errno 13] Permission denied: '/root'

It turned out that the problem occurred because I called ftc run-test from "/root". Ftc first switches to the non-privileged user "jenkins", then changes the directory, and later wants to switch back to the previous directory, which fails because of missing privileges.

The author of the code was actually aware of that problem (lines 4357 and 4358 in rev 600c12f):

# FIXTHIS: if called as root, we may need to become root again
before moving here
os.chdir(saved_cur_dir)

I believe there is a really simple fix to this. Just remove these lines (and also the corresponding line, where saved_cur_dir is set). I'm 99% sure that changing the current working directory only affects the current process ("sudo python" in this case), and not the parent process. So once this process exits, we'll be back in the original directory anyway. No need to manually switch back.

Greetings,
Georg

#1 lore raw
Quoted 31 lines

-----Original Message-----
From: Georg Piewald

Hi,

I just experienced a Python exception when executing an "ftc run-test" command:

     Traceback (most recent call last):
       File "/usr/local/bin/ftc", line 5661, in <module>
         main()
       File "/usr/local/bin/ftc", line 5550, in main
         rcode, run_id = do_run_test(conf, options)
       File "/usr/local/bin/ftc", line 4358, in do_run_test
         os.chdir(saved_cur_dir)
     OSError: [Errno 13] Permission denied: '/root'

It turned out that the problem occurred because I called ftc run-test from "/root". Ftc first switches to the non-privileged user "jenkins", then changes the directory, and later wants to switch back to the previous directory, which fails because of missing privileges.

The author of the code was actually aware of that problem (lines 4357 and 4358 in rev 600c12f):

# FIXTHIS: if called as root, we may need to become root again
before moving here
os.chdir(saved_cur_dir)

Quoted 6 lines

I believe there is a really simple fix to this. Just remove these lines (and also the corresponding line, where saved_cur_dir is set). I'm 99% sure that changing the current working directory only affects the current process ("sudo python" in this case), and not the parent process. So once this process exits, we'll be back in the original directory anyway. No need to manually switch back.

Thanks for the bug report. I just took a look at the code for do_run_test(), where this occurs, and you are correct. do_run_test() is called from multiple places, though, and I had to double-check that the solution (to just not do the directory change), worked for all callers.

It worked in my quick testing. I made a change and pushed it to the master branch. Can you pull the change (in fuego-core), and let me know if this fixes the behavior for you? (It should, I just tested it here - but, just to be sure...)

Thanks.
-- Tim

P.S. By the way, I added your name and e-mail in the commit message with a "Reported-by:" line. Let me know if you'd rather stay anonymous.

#2 lore raw

Hi Tim,

Quoted 4 lines · Tim

It worked in my quick testing. I made a change and pushed it to the master branch. Can you pull the change (in fuego-core), and let me know if this fixes the behavior for you? (It should, I just tested it here - but, just to be sure...)

Thanks for the fix! Works nicely here too.

Quoted 2 lines

P.S. By the way, I added your name and e-mail in the commit message with a "Reported-by:" line. Let me know if you'd rather stay anonymous.

No worries.

Regards, Georg