How to run ruby as nobody - ruby

I am trying to build a service that will only run my ruby app without having a shell and only have a directory that contains the app. I have created a user using the adduser --system --disabled-login --disabled-password --home /usr/local/appname appname When using the command sudo -u appname ruby app.rb The command fails saying ruby command not found

Related

Gitlab-Runner doesn't have sudo access on OSX

I have installed gitlab-runner on a new OSX device. My runner is register and launch correctly.
But when i start a job, I have this error
sudo gem install fastlane
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
What can I do avoid this error and let gitlab-runner have sudo access to execute anything ?
Most probably you granted the sudo permission to your gitlab-runner user, but you did not remove the password restriction for sudo for the gitlab-runner user. Here you can find how to do it.
However I would not recommend using sudo. You could use Bundler and then install fastlane with bundler for this project and not globally.
gem install bundler -> you will get a Gemfile for the current directory (root of the project)
put gem "fastlane" into the Gemfile
install it with bundle install (you can run this command with your gitlab-runner user in jobs)
For running fastlane lanes use: bundle exec fastlane <name_of_the_lane>.

Error when running a ruby script on AWS Lambda with a gem from a github repository (using Docker)

I try to build a simple ruby script that checks the balance on the Kraken crypto exchange using the custom jonatack/kraken_ruby_client gem from github which is not available on ruby gems.
AWS Lambda throws the following error:
"errorMessage": "https://github.com/jonatack/kraken_ruby_client.git (at master#cda6c28) is not yet checked out. Run `bundle install` first.",
"errorType": "Init<Bundler::GitError>",
"stackTrace": ["/var/runtime/gems/bundler-2.1.4/lib/bundler/source/git.rb:204:in `rescue in load_spec_files'",
...
What I'm doing:
1. Gemfile
I've added the gem to the Gemfile as usual:
gem 'kraken_ruby_client', git: 'https://github.com/jonatack/kraken_ruby_client.git'
Everything works perfectly on my local machine.
2. Custom Dockerfile
Since the gem requires curb I created a Dockerfile, based on the AWS Lambda image for Ruby 2.7, to install libcurl:
FROM lambci/lambda:build-ruby2.7
RUN yum install -y curl-devel
RUN gem install curb
3. Deployment
I then "deploy" the script:
docker run -v `pwd`:`pwd` -w `pwd` -i -t kraken-app:latest bundle install --deployment
zip build.zip * -r -x .git/\* \*.sh specs/\* tests/\* \*.zip config/application.yml
aws lambda update-function-code --function-name kraken-app --zip-file fileb://build.zip --region=eu-west-1 --publish --profile XXXX
And it fails with the above error.
What I've tried with multiple StackOverflow answers:
1. Do what the error says - bundle install
I "bundle installed" and "bundled" as much as I could
2. Paths
All gems from Rubygems are installed into vendor/bundle/ruby/2.7.0/gems/, while the gem from github is installed into /vendor/bundle/ruby/2.7.0/bundler/gems/
So I've tried to add the path to $LOADPATH:
load_paths = Dir["./vendor/bundle/ruby/2.7.0/bundler/gems/**/lib"]
$LOAD_PATH.unshift(*load_paths)
As that didn't help, I even manually moved the folder from /bundler/gems to /gems before deploy, but no avail.
3. Local install in Docker image
I amended the Dockerfile to install the gem "locally" in the image by adding:
RUN gem install specific_install
RUN gem specific_install https://github.com/jonatack/kraken_ruby_client.git
I can run the script just fine in Docker in bash:
docker run -it --rm -v "$PWD":/var/task kraken-app:latest bash
Everything works in the Docker container on my local machine but it doesn't work when deployed to Lambda for some reason? Other Lambda functions work perfectly, I just can't get this custom gem to work...
Do you have any idea what else to try?
Thanks in advance!

How to install ruby 2.4.0 in Windows 10

I have ROR projects that need different versions of ruby and one of them need ruby 2.4.0. with Postgresql. I’m using a PC with Windows 10.
How can I install more than one ruby version like in Linux with rvm? and where can I download the Ruby 2.4.0 for Windows? (I saw that rubyinstaller.org doesn’t have this version)
Windows 10 comes with a new feature called Windows Subsystem for Linux (WSL) that allows you to use Bash with the most common Linux tools included the ones you need to install a Ruby Manager Version.
For this tutorial we'll set up Ubuntu on Windows, Ruby 2.4.0, Rails 5.0.1 and PostgreSQL.
Installing Bash On Windows
First enable developer mode on your machine
https://www.youtube.com/watch?v=S6NvjvL3xaI
Next install Windows Subsystem for Linux
https://www.youtube.com/watch?v=g_5hxfFKDL8
And restart your computer.
After the computer reboot open a Command Prompt (CMD) and type
> bash
You will see the next message
This will install Ubuntu on Windows, distributed by Canonical
and licensed under its terms available here:
https://aka.ms/uowterms
Press "y" to continue: y
Press "Y" to continue
Downloading from the Windows Store... 100%
Extracting filesystem, this will take a few minutes….
Bash will ask you for a user, please remember this user because bash will ask you every time you need root permissions in Bash. Also when you time your password you won’t see the keystrokes, it’s normal, only keep typing and press ENTER when you finish.
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms.wslusers
Enter new UNIX username:
Enter new UNIX password:
And your Bash is ready when you see the CMD its in the
mnt/c/Users/your_username directory.
your_username#yourmachine:/mnt/c/Users/your_username$
Installing RVM and Ruby
In your bash copy this line:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Then install gnup2
$ sudo apt-get install gnupg2
Remember your UNIX password because every time you saw a sudo in the command you will be asked for your password.
Install RVM
$ \curl -sSL https://get.rvm.io -o rvm.sh
$ cat rvm.sh | bash -s stable
$ source ~/.rvm/scripts/rvm
Install Ruby
$ rvm install ruby-2.4.0
If you need to install other version of ruby run this same command like this
$ rvm install ruby-2.3.5
And select the ruby version you want to use
$ rvm --default use 2.3.5
To check if it works
$ ruby -v
Installing RubyOnRails
Install the Ruby’s package manager Bundler
$ gem install bundler
Add NodeJS
$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Install Rails
$ gem install rails
Installing PostgreSQL
Download PostgreSQL installer and follow the instructions of the installation
https://www.openscg.com/bigsql/postgresql/installers.jsp/
The installer will ask you for a user and a password, also keep them in a safe place because you will use it to access to PostgreSQL command line and in database.ymlin your ROR project.
When the installation finish, return to bash and type the next command
$psql -p 5432 -h localhost -U your_postgresql_username
Bash will ask you the PostgreSQL password and if everything works you will have access to the Postgres shell prompt
psql (9.5.6, server 9.6.2)
WARNING: psql major version 9.5, server major version 9.6.
Some psql features might not work.
Type "help" for help.
postgres=#
Type \q to exit the Postgres shell.
Running your Rails app
Open the project in your favorite editor and update the database.yml with the PostgreSQL username and password.
development:
database: your_app_name_development
username: your_postgres_user
password: your_postgres_password
host: localhost
port: 5432
test:
database: your_app_name_test
username: your_postgres_user
password: your_postgres_password
host: localhost
port: 5432
In Bash go to the directory where is your rails project, for example:
$ cd Projects/my_app
To learn more about Bash navigation visit
https://www.pluralsight.com/guides/beginner-linux-navigation-manual
Create your database
$ rake db:create
Run the rails server to make sure everything is working
$ rails s
And go to your browser and visit
$ localhost:3000
Every time you need a Bash, open a Command Prompt and type
>bash -l
For more detail of each of the commands in this tutorial, visit
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-and-set-up-a-local-programming-environment-on-windows-10
https://medium.com/#colinrubbert/installing-ruby-on-rails-in-windows-10-w-bash-postgresql-e48e55954fbf

Running ruby project with systemd service cannot find gemfile

I would like to run a ruby project that uses bundle as a systemd service.
The project is: https://github.com/jcs/bitwarden-ruby/
I installed ruby and bundler by running sudo apt-get install ruby-full and sudo gem install bundler
In the project directory I run bundle install --deployment.
In my systemd service I have:
ExecStart=/usr/bin/env RACK_ENV=production ALLOW_SIGNUPS=1 /usr/local/bin/bundle exec rackup -p 4567 /var/lib/bitwarden/bitwarden-ruby/config.ru
Runnning this command in the terminal does work.
However when I start the service I get an error:
bash[7924]: Could not locate Gemfile or .bundle/ directory
The bundle directory is at /var/lib/bitwarden/bitwarden-ruby/.bundle.
Why can it not find it? Thanks!

CodeDeploy agent install Error :: /usr/bin/env : ruby Not found

I am trying to install codeDeploy agent on CentOS6.
What I did
$ > wget https://aws-codedeploy-ap-northeast-2 .s3.amazonaws.com/latest/install
$ > chmod +x ./install
$ > sudo ./install auto
Not found ruby error occurs, So I installed ruby 2.4.2 via tar file. (executable file located in /usr/local/bin)
After that when I try sudo ./install auto, It returns error message
/usr/bin/env: ruby: No such file or directory
When I open install file which download via wget, it starts with #!/usr/bin/env ruby.
I change this to #! /usr/local/bin ruby than it returns sudo: unable to execute ./install: Permission denied without asking password.
Is there any step I forgot or extra job to escape this problem?
Thanks.
Try symlinking the ruby installation to /use/bin/ruby and then run the installer. If the symlink is in place you shouldn't need to update the shebang in install script.

Resources