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

mkdir permission error for log directory #7

Closed
hildebrau opened this issue Dec 7, 2023 · 10 comments
Closed

mkdir permission error for log directory #7

hildebrau opened this issue Dec 7, 2023 · 10 comments

Comments

@hildebrau
Copy link
Contributor

Somehow a directory lacks permissions to allow autoluv to create the log and subsequent subdirectories.

My docker container is exiting and the logs are showing the following. Granted, this is when I give it one of my old record locator. However, I think it is even dying early on a valid PNR code and not checking in the person. But I can't find a log for that error happening. So, I'm hoping if we fix this issue, it'll fix another related issue.

I found this because I was trying to test the SMTP email function. The autoluv docs say to give it a false record locator and fake name.

To verify your SMTP settings, schedule a check-in with invalid information and a valid email address.

    autoluv schedule AAAAAA Fake Name valid@email.com

So, I fired up the container and launched a bash shell into it.

To me, it looks like it can't create the log directory. That would give me an error unless I ran this first:
sudo chmod a+w //var/lib/gems/2.7.0/gems/autoluv-0.3.1/

For example:

swuser@08dac4f6ce00:/checkin/southwest-checkin$     autoluv schedule AAAAAA Fake Name valid@email.com
Traceback (most recent call last):
        13: from /usr/local/bin/autoluv:23:in `<main>'
        12: from /usr/local/bin/autoluv:23:in `load'
        11: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/bin/autoluv:19:in `<top (required)>'
        10: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv/southwestclient.rb:22:in `schedule'
         9: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv/southwestclient.rb:91:in `departing_flights'
         8: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient.rb:66:in `get'
         7: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
         6: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in `execute'
         5: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in `transmit'
         4: from /usr/lib/ruby/2.7.0/net/http.rb:933:in `start'
         3: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:743:in `block in transmit'
         2: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:836:in `process_result'
         1: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:129:in `return!'
/var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in `exception_with_response': 400 Bad Request (RestClient::BadRequest)
        12: from /usr/local/bin/autoluv:23:in `<main>'
        11: from /usr/local/bin/autoluv:23:in `load'
        10: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/bin/autoluv:12:in `<top (required)>'
         9: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/bin/autoluv:26:in `rescue in <top (required)>'
         8: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv.rb:46:in `notify_user'
         7: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv.rb:29:in `log'
         6: from /usr/lib/ruby/2.7.0/fileutils.rb:211:in `mkdir_p'
         5: from /usr/lib/ruby/2.7.0/fileutils.rb:211:in `each'
         4: from /usr/lib/ruby/2.7.0/fileutils.rb:226:in `block in mkdir_p'
         3: from /usr/lib/ruby/2.7.0/fileutils.rb:226:in `reverse_each'
         2: from /usr/lib/ruby/2.7.0/fileutils.rb:228:in `block (2 levels) in mkdir_p'
         1: from /usr/lib/ruby/2.7.0/fileutils.rb:250:in `fu_mkdir'
/usr/lib/ruby/2.7.0/fileutils.rb:250:in `mkdir': Permission denied @ dir_s_mkdir - /var/lib/gems/2.7.0/gems/autoluv-0.3.1/logs (Errno::EACCES)
swuser@08dac4f6ce00:/checkin/southwest-checkin$ ls -latr /var/lib/gems/2.7.0/gems/autoluv-0.3.1/
total 28
drwxr-xr-x 1 root root   34 Apr 23  2023 lib
drwxr-xr-x 1 root root   46 Apr 23  2023 data
drwxr-xr-x 1 root root   38 Apr 23  2023 bin
-rw-r--r-- 1 root root 1313 Apr 23  2023 autoluv.gemspec
-rw-r--r-- 1 root root   51 Apr 23  2023 Rakefile
-rw-r--r-- 1 root root 4493 Apr 23  2023 README.md
-rw-r--r-- 1 root root 1076 Apr 23  2023 LICENSE.txt
-rw-r--r-- 1 root root   62 Apr 23  2023 Gemfile
-rw-r--r-- 1 root root   44 Apr 23  2023 .gitignore
drwxr-xr-x 1 root root  584 Apr 23  2023 ..
drwxr-xr-x 1 root root  140 Apr 23  2023 .
swuser@08dac4f6ce00:/checkin/southwest-checkin$ sudo chmod a+w /var/lib/gems/2.7.0/gems/autoluv-0.3.1/
swuser@08dac4f6ce00:/checkin/southwest-checkin$ ls -latr /var/lib/gems/2.7.0/gems/autoluv-0.3.1/
total 28
drwxr-xr-x 1 root root   34 Apr 23  2023 lib
drwxr-xr-x 1 root root   46 Apr 23  2023 data
drwxr-xr-x 1 root root   38 Apr 23  2023 bin
-rw-r--r-- 1 root root 1313 Apr 23  2023 autoluv.gemspec
-rw-r--r-- 1 root root   51 Apr 23  2023 Rakefile
-rw-r--r-- 1 root root 4493 Apr 23  2023 README.md
-rw-r--r-- 1 root root 1076 Apr 23  2023 LICENSE.txt
-rw-r--r-- 1 root root   62 Apr 23  2023 Gemfile
-rw-r--r-- 1 root root   44 Apr 23  2023 .gitignore
drwxr-xr-x 1 root root  584 Apr 23  2023 ..
drwxrwxrwx 1 root root  140 Apr 23  2023 .
swuser@08dac4f6ce00:/checkin/southwest-checkin$ autoluv schedule AAAAAA Fake Name myvalid@email.com 
swuser@08dac4f6ce00:/checkin/southwest-checkin$

Then the email works (since I have a fixed ~swuser/.autoluv.env file with updated SMTP settings.
Which, as a side note, I'm providing that file via the volume mount on the CLI:
docker run -itd -v /path/on/local/filesystem/to/.autoluv.env:/home/swuser/.autoluv.env altodd/southwest-docker schedule PNRCODE FIRST LAST email@address.com

@hildebrau
Copy link
Contributor Author

in southwest-checkin/lib/autoluv.rb around line 29 (of probably an older version of src code I had laying around) it shows:

  LOG_DIR = File.expand_path("../logs/", __dir__)

  def self.log(confirmation_number, first_name, last_name, message, exception)
    log_path = "#{LOG_DIR}/#{first_name} #{last_name}"
    FileUtils.mkdir_p(log_path) unless Dir.exist?(log_path)

So, the log folder is created by autoluv, which you have no control over. But perhaps you DO have control over the permissions of the /var/lib/gems/2.7.0/gems/autoluv-0.3.1/ folder inside the container.

Maybe the fix is to add this line to the Dockerfile:

RUN chmod a+w /var/lib/gems/2.7.0/gems/autoluv-0.3.1/

@hildebrau
Copy link
Contributor Author

@altodd you made mention of running as non-root user in this comment. #6 (comment)
Perhaps that is when this broke? Though, I feel like it worked since then.. so probably somewhat related; but then something else changed, likely.

@altodd
Copy link
Owner

altodd commented Dec 7, 2023 via email

@hildebrau hildebrau mentioned this issue Dec 7, 2023
@hildebrau
Copy link
Contributor Author

hildebrau commented Dec 7, 2023

pull-request done.. man, I am terrible at github.. so my apologies if I screwed any of that up. I think I've done it twice now and I have to re-learn it all each time.

Yes, your readme gave some hints on how to clone the required packages after cloning yours first.. I made my changes to the Dockerfile and tested via this:

docker build --tag 'swa' .
docker stop southwest
docker rm southwest
docker run -itd --name southwest -v /path/to/local/.autoluv.env:/home/swuser/.autoluv.env swa schedule AAAAAA Fake Name realemail@gmail.com
docker logs -f southwest

Eventually it didn't throw an error and I received an email saying:
Something's not right here. Verify your information and try again. For further assistance call us at 1-800-<redacted>.

@altodd
Copy link
Owner

altodd commented Dec 13, 2023

Glad you got it figured out! Thanks for the pull request.

@altodd altodd closed this as completed Dec 13, 2023
@hildebrau
Copy link
Contributor Author

Did anyone test this new version w/ a check in yet? I have a check in on 12/20 and would love to know it works again before then. ;)

@hildebrau
Copy link
Contributor Author

@altodd

Maybe I did something wrong; but when I tried using the :latest of this project, I'm still getting an error..
/var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in exception_with_response': 400 Bad Request (RestClient::BadRequest) 12: from /usr/local/bin/autoluv:23:in

'
11: from /usr/local/bin/autoluv:23:in load' 10: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/bin/autoluv:12:in <top (required)>'
9: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/bin/autoluv:26:in rescue in <top (required)>' 8: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv.rb:46:in notify_user'
7: from /var/lib/gems/2.7.0/gems/autoluv-0.3.1/lib/autoluv.rb:29:in log' 6: from /usr/lib/ruby/2.7.0/fileutils.rb:211:in mkdir_p'
5: from /usr/lib/ruby/2.7.0/fileutils.rb:211:in each' 4: from /usr/lib/ruby/2.7.0/fileutils.rb:226:in block in mkdir_p'
3: from /usr/lib/ruby/2.7.0/fileutils.rb:226:in reverse_each' 2: from /usr/lib/ruby/2.7.0/fileutils.rb:228:in block (2 levels) in mkdir_p'
1: from /usr/lib/ruby/2.7.0/fileutils.rb:250:in fu_mkdir' /usr/lib/ruby/2.7.0/fileutils.rb:250:in mkdir': Permission denied @ dir_s_mkdir - /var/lib/gems/2.7.0/gems/autoluv-0.3.1/logs (Errno::EACCES)

@altodd
Copy link
Owner

altodd commented Dec 14, 2023 via email

@altodd
Copy link
Owner

altodd commented Dec 15, 2023

I was trying to build it this morning on my macbook, I need to boot up my linux desktop later, not sure what's up with it but the build seems to not be cooperating from some weird reason. Will try to get an official updated image soon.

@altodd
Copy link
Owner

altodd commented Dec 16, 2023

Okay, made a couple other changes and built/pushed the latest image. Verified I'm getting an email - you should also be able to just use the image to send e-mail without other settings changes. I have a good setting in the image but cant push it to github without it getting invalidated as sendgrid monitors github.

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

2 participants