Show password using view.html.erb

I’m building an interactive app for Stable Diffusion WebUI on Open OnDemand v4.0. Since the WebUI requires a username and password for login, my goal is to automatically generate a random password and display it on the job status panel under “My Interactive Sessions.”

I’ve tried several approaches to generate the password—either in before.sh.erb or submit.yml.erb—and then expose it in view.html.erb. However, none of these methods successfully make the password available in the view. It seems that variables generated at runtime aren’t accessible in the view rendering context.

Is there a recommended way to securely generate a password and reliably expose it to view.html.erb in Open OnDemand 4.0?

Here is what I did in submit.yml.erb

<% require 'securerandom' %>
**<% password = SecureRandom.hex(12) %>**
<% host = `hostname`.strip %>

batch_connect:
  template: "basic"
  conn_params:
    - working_path  
script:
  email_on_started: true
  email_on_terminated: true
  email: <%= ENV["USER"] %>@tufts.edu
  before_script: "before.sh.erb"
  script: "script.sh.erb"
  job_environment:
    **PASSWORD: "<%= password %>"**
    host: "<%= host %>"
  native:
    - "--time"
    - "<%= bc_num_hours %>:0:0"

And here is my view.yml.erb:

<% url = "http://#{host}:#{port}" %>


<a class="btn btn-primary" href="<%= url %>" target="_blank">
  <i class="fa fa-eye"></i> Connect to Diffusion
</a>

<p><strong>Username:</strong> <code><%= ENV['USER'] %></code></p>
<p><strong>Password:</strong> <code><%= ENV['PASSWORD'] %></code></p>

I appreciate your suggestions.

Best,
Yucheng

You need to be generating stuff like passwords on the compute node during the job in the before.sh.erb.

Just exporting it is enough, OOD will automatically pass back host, password & port in the connection.yml to be used in the view.html.erb without additional configuration. OOD will additionally pass back anything you’ve added to conn_params like working_path. Though working_path is likely something that was generated upon user submission, not at job runtime, so I’m not sure why you’d need it here.

Here’s our stable diffusion application for reference. Note that we use Kubernetes, so it’s slightly different than what you’d see in other applications.

Specifically, if you see for example how jupyter creates the password it’s though this shell function create_passwd not through a Kubernetes mechanism.

Using the ENV is not likely to work because the ENV on the compute node during the job execution is much different than the ENV the web application is running under.

Hi Jeff,

Thanks for your suggestions! Based on your advice, I updated my view.html.erb, and the password now displays correctly — much appreciated.

I have another question for view.html.erb.

I noticed that it takes approximately 1 minute for the Stable Diffusion server to fully start. This leads to a usability issue: as soon as the job enters the Running state, the Connect to Diffusion button becomes clickable. If the user clicks it too early — before the server is ready — they encounter a “This site can’t be reached” error, as shown below:

I’m wondering if there’s a way to implement a wait function (e.g., sleep or countdown), so that the Connect to Diffusionbutton is disabled for the first minute, and only becomes active after that. This would help avoid user confusion and improve the overall experience.

Below is my current view.html.erb:

<%
  url = "http://#{host}:#{port}"

  user = ENV['USER']

  password_run = "#{password}"
%>


<a class="btn btn-primary" href="<%= url %>" target="_blank">
  <i class="fa fa-eye"></i> Connect to Diffusion
</a>

<p><strong>Username:</strong> <code><%= user %></code></p>
<p><strong>Password:</strong> <code><%= password %></code></p>

You could try to add a sleep 3 or something similar in after.sh.erb. If you look at job_script_content.sh you’ll see the execution flow. after.sh.erb is invoked after the script, but before it creates the yml that will show the connect button. So I think this is the spot to wait/sleep/verify before moving on.

Hi Jeff, this works great. Thanks a lot.

Best,
Yucheng