Robust cron firewall and deployment permissions

During the installation on AWS Elastic Beanstalk, I want to do two things:

  • Take the cron entry file and put this file in /etc/cron.d/
  • Change the file permissions on shell scripts contained in the same directory so that they can be run by cron

In my .ebextensions folder, I have the following:

container_commands: 00fix_script_permissions: command: "chmod u+x /var/app/current/scripts/*" 01setup_cron: command: "cat .ebextensions/propel_mis_crons.txt > /etc/cron.d/propel_mis_crons && chmod 644 /etc/cron.d/propel_mis_crons" leader_only: true 

And the propel_mis_crons.txt file in the .ebextensions folder has:

 # mh dom mon dow command MAILTO=" dev@23sparks.com " * * * * * root /var/app/current/scripts/current_time.sh 

I checked the deployment logs and I see the following:

 2013-08-09 14:27:13,633 [DEBUG] Running command 00fix_permissions_dirs 2013-08-09 14:27:13,633 [DEBUG] Generating defaults for command 00fix_permissions_dirs <<< 2013-08-09 14:27:13,736 [DEBUG] No test for command 00fix_permissions_dirs 2013-08-09 14:27:13,752 [INFO] Command 00fix_permissions_dirs succeeded 2013-08-09 14:27:13,753 [DEBUG] Command 00fix_permissions_dirs output: 2013-08-09 14:27:13,753 [DEBUG] Running command 01setup_cron 2013-08-09 14:27:13,753 [DEBUG] Generating defaults for command 01setup_cron <<< 2013-08-09 14:27:13,829 [DEBUG] Running test for command 01setup_cron 2013-08-09 14:27:13,846 [DEBUG] Test command output: 2013-08-09 14:27:13,847 [DEBUG] Test for command 01setup_cron passed 2013-08-09 14:27:13,871 [INFO] Command 01setup_cron succeeded 2013-08-09 14:27:13,872 [DEBUG] Command 01setup_cron output: 

However, when deploying, permissions for all files in the script directory are set incorrectly, and cron does not start. I'm not sure cron is not working due to permission problems or if something else prevents this. This runs on a 64-bit instance of Amazon Linux in PHP5.4.

Thank you for your help. It is possible that over time, new shell scripts will be added that will be launched by cron.

+4
source share
2 answers
 container_commands: 00_fix_script_permissions: command: "chmod u+x /opt/python/ondeck/app/scripts/*" 

I am Linux and AWS Noob, however I found that modifying your command as above has succeeded for my use.

/ opt / python / current / app / scripts / createadmin now has execute permission for the user

+3
source

@Ed seems correct if it suggests chmod'ing the ondeck file as opposed to current .

Also, this is how I configure my cron jobs through the elastic beanstalk.config .config file. Of course, this is not the best way, but it works for my application.

 `"files":{ "/home/ec2-user/cronjobs.txt":{ "mode":"000777", "owner":"ec2-user", "group":"ec2-user", "source":"https://s3.amazonaws.com/xxxxxxxxxx/cronjobs.txt" } } "container_commands":{ "01-setupcron":{ "command": "crontab /home/ec2-user/cronjobs.txt -u ec2-user", "leader_only": true },` 

First I insert the cronjobs text file and save it in the ec2-user folder. Then in the container_commands files I apply this file to crontab.

Again, I'm not an expert, but this is the best I could think of, and it worked very well for us.

+2
source

Source: https://habr.com/ru/post/1496533/


All Articles