Rails 5.2 encrypted credentials not saving
Asked Answered
M

8

14

When I do bin/rails credentials:edit my editor opens a file like credentials.yml.enc.1234 with default content. After I'm done editing, I hit save, and the console reads New credentials encrypted and saved.

After I run bin/rails credentials:edit again, another temp file gets opened (credentials.yml.enc.4321) and the contents are back to default.

How can I make the credentials persist?

Murky answered 31/1, 2018 at 10:4 Comment(3)
Do you set editor?Torus
yes. Not helping so far.Murky
the problem is that it saves the changes OK, I can see them with rails credentials:show, but when re-opening the file - everything is goneMurky
H
3

There is an issue related to this: https://github.com/rails/rails/issues/31286

It's been fixed already in 5.2.0.rc1

Hackney answered 20/2, 2018 at 20:17 Comment(0)
S
28

If you aren't using vim, you need to add a wait flag to the editor.

e.g for atom:

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

I ran into the same thing and found the answer here.

Spacesuit answered 29/5, 2018 at 22:37 Comment(2)
I needed EDITOR="subl --wait" rails credentials:edit but otherwise, thanks!Past
Tried EDITOR="code --wait" rails credentials:edit since I use VSC - works like a charm! Thanks!Meatman
P
4

I also had this problem with using atom as editor. I have tried:

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

and

EDITOR="atom -w" rails credentials:edit

but no results. Finally, I used nano (ubuntu):

EDITOR="nano" rails credentials:edit

For me, this works fine. Maybe, it will be helpful for someone, as an alternative.

Personal answered 24/1, 2019 at 11:47 Comment(0)
H
3

There is an issue related to this: https://github.com/rails/rails/issues/31286

It's been fixed already in 5.2.0.rc1

Hackney answered 20/2, 2018 at 20:17 Comment(0)
G
3

I had this problem in rails 5.2.0 using textmate as the editor. It turns out the credentials file must be closed after save in order for the changes to persist.

Glycerol answered 10/5, 2018 at 10:23 Comment(0)
M
1

You can use the following for opening the credentials file in sublime.

EDITOR="subl --wait" bin/rails credentials:edit

Make sure you close the credentials file in sublime after making the changes. Also restart your server to view the changes.

Maggard answered 22/8, 2020 at 10:36 Comment(0)
L
0

I have struggled a bit with this one due to the fact that I was not capitalizing EDITOR. The commmand

editor="vim" rails credentials:edit

directly saves the credentials without opportunity to edit. The guidance tells you to add the --wait flag. To me, it was not about the --wait flag but about the capitalization. This was working:

EDITOR="vim" rails credentials:edit

(no --wait flat but capitalized EDITOR)

Lemley answered 6/1, 2023 at 3:39 Comment(0)
A
0

I had some trouble myself, eventually got it all working with TextEdit on OS X.

EDITOR="open -a TextEdit --wait" rails credentials:edit

That opens the editing but after saving and closing the file, I still didn't get the changes persisted. I needed to also quit TextEdit.

So if you want to use TextEdit to edit credentials on OS X Ventura you can do it with the above command, then save the file, then quit TextEdit.

Akela answered 20/2, 2023 at 0:33 Comment(0)
M
0

I ran into the same issue with Rails 7.0.1.

First I opened the encrypted YAML:

EDITOR='code --wait' rails credentials:edit

Inside the encrypted YAML I added the needed credential:

devise_jwt_secret_key:
XXXXXXXXXX

Then in VSCode I saved the YAML file and exited out of the file tab (top right of the tab):

Terminal output:

File encrypted and saved.
Marathi answered 27/9, 2023 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.