Problem Editing Credentials

Rob Bazinet
Hi everyone,

I setup a new Jumpstart app today from latest master. When I attempt to edit credentials:

rails credentials:edit --environment=development

For any environment, I have an empty file..not filled in as Chris indicates should have all the different services listed.

What am I missing?

     Rob Bazinet
Hi Rob, 

EDITOR="atom --wait" rails credentials:edit --environment=development

You should indicate the editor (atom for me in the example) and --wait
This works for me
Rob Bazinet
 Thank you, that was it! Why is this necessary? Chris didn’t mention this in any of the videos.
Chris Oliver
Add notes to the docs for this.

Thanks for the nudge Rob. You're right that it should be included. 
Rob Bazinet
Awesome Chris, I think that will be helpful.
Nicholas B
One other thing you can do is add this your `.bashrc`

export VISUAL=vim

Ariel Fogel
hi all, I've updated my default editor, but even when I save, the only thing on my STDOUT is:
File encrypted and saved.
I don't actually see a new key file created, either. Did I miss something? Seems I'm not finding what I need in order to set my  RAILS_MASTER_KEY. Thanks!

UPDATE: Issue was that I needed to actually make a modification for the keys to show up. After adding credentials for rollbar, a key showed up and, while it didn't show up in my STDOUT like the video, the key was in the key file.
Martin Curiel
hi all - when I use  
EDITOR="atom --wait" rails credentials:edit --environment=development  I get an error that says:  
Couldn't decrypt config/credentials/development.yml.enc. Perhaps you passed the wrong key? 

I also tried EDITOR="atom --wait" rails credentials:edit  (without the --environment=development) and then my app doesn't run rails server any more. I get this error:  
 `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)

Sorry, it might be because I am a newbie at this rails stuff. Any suggestions?
Chris Oliver
be very careful that you're consistent. --environment=development will edit a different credentials file than without it.

Without, it will edit config/credentials.yml.enc and config/master.key

With --environment, it will edit config/credentials/development.yml.enc and config/credentials/development.key

If it can't decrypt, you're missing the .key file or it has invalid contents. You can also pass that as RAILS_MASTER_KEY=x before the command like you do with EDITOR, but that's usually just for when you're deploying.

Delete them and recreate your credentials from scratch if you need to.
Martin Curiel
Thanks for the quick response. I recreated my credentials from scratch and now I see config/credentials/development.yml.enc  and config/credentials/development.key files.  I confirmed the right key is in the .key file . However, when I run the  
rails credentials:edit --environment development  command again, I am still getting the error:  
Couldn't decrypt config/credentials/development.yml.enc. Perhaps you passed the wrong key?  Any other thoughts on why this could be? 
Martin Curiel
By the way, I also tried with the --staging environment and ran into the same issue that I can't decrypt.
Chris Oliver
Are you definitely sure the contents of the .key file is correct? If it's not, that's why it won't decrypt.

Move them somewhere and create a new credentials file and key and make sure you can open and edit that several times. Then you know your key file got messed up.
Can somebody help me, please? I purchased a license over the weekend and pushed Jumpstart Pro into a new Github repository, then my Github Actions' run tests isn't passing.

Run bin/rails db:test:prepare
2 bin/rails db:test:prepare
3 bin/rails test
4 shell: /bin/bash -e {0}
5 env:
6 PATH: /home/runner/.rubies/ruby-2.7.1/bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin
7 DATABASE_URL: postgres://postgres:password@localhost:5432/test
8 REDIS_URL: redis://localhost:6379/0
9 RAILS_ENV: test
11 PG_USER: postgres
12 rails aborted!
Caused by:
87 ArgumentError: key must be 16 bytes

I've tried editing credentials following the credentials documentation, but I keep getting this error:
nano ~/.bashrc

export EDITOR="code --wait" bin/rails credentials:edit

got this error
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.
Chris Oliver
 looks like you forgot to add the RAILS_MASTER_KEY to GitHub actions.
how can I add the RAILS_MASTER_KEY to GitHub Actions? I tried looking around (forums, SO, and articles), but couldn't find a way to do so.
Thanks for the quick responses and the link. What should be the value of the secret key in this case? Is there a CLI command to generate this? 
Chris Oliver
It's just contents of your test.key file.

I have some docs here for staging and production, but same applies to CI like GitHub actions.

I'll try and update that when I'm finished moving out of my house. 😅
That's exactly what was needed!

Big thanks!

Good luck with the move 🙂
James Kessler
FWIW, I had to create each set of credential files twice for each environment. The first time, each failed with:

Couldn't decrypt config/credentials/<environment>.yml.enc. Perhaps you passed the wrong key?

No amount of re-copying the first key generated, or passing it as `RAILS_MASTER_KEY` on the command line worked. I simply had to destroy and recreate the `.yml.enc` and `.key` files each time.

I tried a few other things different times, like closing out of my editor and re-opening. No luck.

I wonder if anyone else experienced the same and can contribute a solution for new users?
You’re not receiving notifications from this thread.
© 2022 Jumpstart Pro by GoRails, LLC