Identify Heroku user account in running Rails console - ruby-on-rails

Is it possible to identify the heroku username of the current user connected to an app through a running console?
So say I connect to a rails console on my heroku app using
heroku run rails c --app my-app
I'd like to be able to run a command and have it print out:
heroku.user#example.com
Where heroku.user#example.com is the email / username of the user who connected to the console.
I tried a couple basic linux commands like
`whoami`
but you get a generic username like u12345
The goal is to instrument certain fields in our app with audit trails so that we can track when and who accessed sensitive information, as well as how they accessed it (CLI, through the Web UI, etc.)

I just asked heroku this same question via a support ticket, and they do not currently support this functionality. That said, you can use heroku logs to see who and when a rails console was opened.
2019-04-12T15:48:05.727693+00:00 app[api]: Starting process with command `rails console` by user me#mycompany.org

Related

How can I get the username of the loged in user on heroku console?

I am writing a tool that will info me who is logging in to the Heroku console.
I am already getting a message when the console is open, I just can't tell who opened it.
#config/initializers/console_spy.rb
ConsoleSpy.new.send_notification("DevName", "Console was opened")
so I get a notification when the console is open but I don't know who
reference source https://getaround.tech/rails-console-spy/
I don't think this is possible yet via the heroku console.
You can however, track and monitor the heroku logs to find out who, when and at what time accessed the heroku console.
2019-04-12T15:48:05.727693+00:00 app[api]: Starting process with command `rails console` by user me#mycompany.org

Is there a way to log commands from Rails console in Heroku?

Hi I am using Heroku and Ruby on Rails. In heroku I can do
heroku run rails c -a app
Which gives me console access, and I can do administrative things like deleting records
I am working in a company setting and I would like to have a log of all commands entered in the console. So if something is wrong, we can audit the logs.
Is there a way to record what is typed in the rails console?
Rails allows you to store the console history but this won't be saved in Heroku, at least not permanently.
In Heroku, when you run heroku run rails console Heroku will create a one-off dyno which will only live as long as the console session. Rails will store the history of commands on the filesystem but once the console is exited the dyno will be cleaned up and the command history file will be deleted along with it.
Rails console is a Railtie and it has some lifecycle hooks, so you could come up with some custom way to persist commands, but there is no built-in way to do it.
Yes, you can now using Heroku's shield private spaces, https://elements.heroku.com/addons/heroku-private-spaces.

Ruby on Rails / Heroku where are my users emails stored

I am new to Ruby on Rails and Heroku. I have installed the gem 'Devise' in my RoR app and I use Heroku to deploy my app. The sign up process works fine but where are my users emails stored (the users that sign up for my website)? I want to be able to see/extract a list of all the emails.
You can view your users and any other database records by running:
heroku run rails console
from a terminal window. And from there you can run any rails console command as you can on your local machine like User.all
One thing I have found useful is to use either the config variables or the Postgres dashboard to get the URL information for the database. I then use that information to construct the JDBC URL for my IDE, RubyMine, to connect to Heroku. As a result, I can view and manipulate the data in all my tables on Heroku from my IDE. You can do something similar for the SQL tool of your choice.

Why are certain aspects of my Rails app throwing an exception publicly when I deploy to Heroku?

I am working my way through Michael Hartl's Ruby on Rails Tutorial (on Mac OSX 10.7.2/Ruby 1.9.2/Rails 3.1.1) and just finished Chapter 2, which concludes with deploying a demo twitter app to Heroku.
Everything appears to be working properly when I run the app locally AND I was able to successfully deploy the app to Heroku in some capacity because it is available here: http://rich-twitter-baby.heroku.com/
However, what I can't figure out is why the /users and /microposts pages aren't showing up publicly (with lists of users and microposts respectively) as they do locally. I migrated my database to Heroku and pushed the info up there and everything seemed to work properly, but I get this error message when I try to view the pages publicly.
I've tried running "heroku console" but get this error:
Unable to attach to a dyno to open a console session.
Your application may have crashed.
Check the output of "heroku ps" and "heroku logs" for more information.
And the logs say error H13, while the ps looks like this:
Process State Command
------------ ------------------ ------------------------------
web.1 idle for 1h thin -p $PORT -e $RACK_ENV -R $HER..
Let me know if anyone has any ideas or if more info would help.
Thanks!
I would contact Heroku support on this. Dynos can crash and become 'zombiefied' which means they just sit there idle.
Normally these will clear themselves out within a few hours, but it shouldn't happen that often if at all.
Doing a new deploy will also normally restart everything back to clean.
If it's consistently happening, have you tried spinning up the application locally in production mode to try and reproduce the problem
rails server -e production
, or adding something like the Airbrake add-on to your app to capture the error.
Check your log using
$> heroku logs
At the command line of your development system that you used to push to heroku.
Post the log here if you can't figure it out from that.
I contacted Heroku Support about this issue and it turns out that the answer had to do with which stack my app was being deployed to. I did their workaround and everything is now up and running. Here's the full info from them:
It looks like the problem is that you're using Rails 3.1 and our Bamboo stack; we have full >asset pipeline support on our Cedar stack[1]. Since this is just a demo app, an easy >workaround is to precompile locally and commit the files:
rake assets:precompile
git add -A
git commit -m "precompiling assets"
git push heroku master
To get full asset pipeline support, you need to create your app on the Cedar stack and then >repeat the process you did to get your Bamboo app to work.
[1]: http://devcenter.heroku.com/articles/rails31_heroku_cedar

Why doesn't Heroku show the default Rails page?

Following chapter (1) of the Ruby on Rails tutorial, I was able to successfuly push the application to "Heroku" using:
git push heroku master
But, when I open the website, I get a page with the following:
App crashed
This application is temporarily offline.
If you're the administrator of this app, please check your heroku logs for the backtrace.
Why is that? And, why don't I see the default Rails page?
Thanks.
In any situation where heroku gives you an error message in production, type heroku logs into your terminal. This will usually point you in the right direction.
http://docs.heroku.com/logs-exceptions
Also check your localhost and make sure you have migrated the database if one exists.
Are you able navigate to default local rails website at http://localhost:3000 and see the defaut site?

Resources