Test configuration fails with "ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' ..."

I have created a configuration for an LSF cluster and tried to test it with

sudo su user -c 'source /opt/ood/ondemand/enable; bin/rake test:jobs:cluster RAILS_ENV=production'

(for local values of “user” and “cluster”), but it fails with message

ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit` (ArgumentError)

        raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I looked in directory /var/lib/ondemand-nginx/config/puns and found files “user.conf” and “user.secret_key_base.txt” (apparently, created when I logged into the web GUI). Can anybody tell me what may be the problem?

Seems like maybe you need to set the environment variable SECRET_KEY_BASE. You may be able to set it to anything because it’s likely unused in this context. Seems like updates to rails since we wrote that documentation have caused that to start failing.

If you continue to get errors, then you can find the user’s secret key base at /var/lib/ondemand-nginx/puns/user.secret_key_base.txt

Greetings, Jeff,

Thank you for the reply. I tried the following, all without success:

export SECRET_KEY_BASE=“X”

sudo su user -c 'source /opt/ood/ondemand/enable; …

export SECRET_KEY_BASE=“/var/lib/ondemand-nginx/config/puns/user.secret_key_base.txt”

sudo su user -c 'source /opt/ood/ondemand/enable; …

export SECRET_KEY_BASE=“/var/lib/ondemand-nginx/config/puns”

sudo su user -c 'source /opt/ood/ondemand/enable; …

Next, taking a cue from the error message

ArgumentError: Missing secret_key_base for ‘production’ environment,\

set this string with bin/rails credentials:edit (ArgumentError)

I tried

(source /opt/ood/ondemand/enable; bin/rails credentials:edit)

and received the following messages:

No $EDITOR to open file in. Assign one like this:

EDITOR=“mate --wait” bin/rails credentials:edit

For editors that fork and exit immediately, it’s important to pass a wait flag,

otherwise the credentials will be saved immediately with no chance to edit.

Next I tried

(source /opt/ood/ondemand/enable; EDITOR=“/bin/vi” bin/rails credentials:edit)

and found myself in vi with the following file:

aws:

access_key_id: 123

secret_access_key: 345

Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.

secret_key_base: XXXX

I exited the editor without making or saving changes and saw messages:

Adding config/master.key to store the encryption key: YYYY

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

create config/master.key

IMPORTANT: Don’t commit config/master.key. Add this to your ignore file:

/config/master.key

on_green

File encrypted and saved.

Then I tried the test command again:

sudo su user -c 'source /opt/ood/ondemand/enable; …

and received the following messages:

rake aborted!

Errno::EACCES: Permission denied @ rb_sysopen - /var/www/ood/apps/sys/dashboard/config/master.key (Errno::EACCES)

Directory “config” now contains the following:

(cd config; ls -lt | more)

-rw-r–r–. 1 root root 464 Jul 16 16:11 credentials.yml.enc

-rw-------. 1 root root 32 Jul 16 16:11 master.key

(everything else at least 2 days older)

First, please reassure me that I have not broken or locked anything irretrievably.

Second, what should I do next?

Regards,

Eric

When you su, I don’t know if the environment variables carry over.

Maybe it’s something like sudo su user -c 'export SECRET_KEY_BASE='X'; source /opt/ood/ondemand/enable; … ?

Also may actually be easier to actually just be the user instead of using sudo su all the time. That way you can rule out sudo/su environment mismatches.

Greetings, Jeff,

Thanks; that makes sense. I am done for today, so I will try in the morning.

Regards,
Eric

Greetings, Jeff,

Running

sudo su emsisson -c 'export SECRET_KEY_BASE=“X”; …

worked, finally. Thank you very much for your help.

Regards,

Eric