You want to start your encrypted UnRAID array automatically after a reboot. Normally you’d follow the procedure outlined in this thread, but what if you didn’t want to run another SMB share? What if you didn’t want a server that constantly serves the password file, unprotected?
Well, here’s another solution you can opt for.
main.py
:
#!/usr/bin/env python3
from os.path import exists
import http.server
# Define settings here
PORT = 9999
PASSWORD_FILE_NAME = "password.txt" # in current directory
TIMEOUT = 300 # in seconds
# Read or get password
if exists(PASSWORD_FILE_NAME):
print(f"Password file {PASSWORD_FILE_NAME} exists, reading password from it")
with open(PASSWORD_FILE_NAME) as password_file:
PASSWORD_TO_SEND = password_file.readline().strip()
else:
from getpass import getpass
print("Password file does not exist. Please enter one now.")
PASSWORD_TO_SEND = getpass()
# Set up webserver
class RequestHandler(http.server.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-Type", "text/plain")
s.end_headers()
s.wfile.write(str.encode(PASSWORD_TO_SEND))
httpd = http.server.HTTPServer(('', PORT), RequestHandler)
httpd.timeout = TIMEOUT
httpd.handle_request()
Some notes:
password.txt
file in the same directory as the script and save the encryption password there.password.txt
and the script will prompt you to enter a password when it runs.(Special thanks to @bonienl on the UnRAID forums for the original script. I’ve tweaked it slightly for it to work with this alternate solution.)
If you have the USB stick mounted on another computer, you can omit the /boot/
part from the file path.
Edit /boot/config/go
and add/modify the following lines:
# ...snip...
# Copy scripts to emhttp event directories
install -D /boot/custom/keyscript/fetch_key /usr/local/emhttp/webGui/event/starting/fetch_key
install -D /boot/custom/keyscript/delete_key /usr/local/emhttp/webGui/event/started/delete_key
# Set execute permission
chmod a+x /usr/local/emhttpd/webGui/event/starting/fetch_key
chmod a+x /usr/local/emhttpd/webGui/event/started/delete_key
# Start webGUI
/usr/local/sbin/emhttp &
Create /boot/custom/keyscript/fetch_key
:
#!/bin/bash
if [[ ! -e /root/keyfile ]]; then
curl other-computer:9999 > /root/keyfile # Make sure to substitute port here if you changed it!
fi
Create /boot/custom/keyscript/delete_key
:
#!/bin/bash
rm -f /root/keyfile
Here’s a script that does the above automatically for you:
#!/bin/bash
# Start encryption password server script
python3 main.py &
# SSH into server and issue reboot command
# Make sure to change hostname to correct value
ssh root@unraid-server-hostname reboot
If you get an error about either the UnRAID server or the other computer not being able to find the host, your network may not support hostname-based discovery. To mitigate this, give your machines (both your UnRAID server and your other computer) a static IP, and use static IPs in the scripts instead.
Here are some of the benefits with this approach compared to other solutions:
You may want to review a couple of flaws with this approach:
As I was writing down this blog post I realized that if you already have access to another computer on the same network as the UnRAID server, you could simply access the WebUI and type in the password after the UnRAID server starts up. So this approach is stupid, right?
Well, this approach will also work for computers where you don’t have graphical access to (such as a headless machine without VNC/RDP access). You will still be able to reboot the server by running this script before rebooting.
As this approach is a bit risky in terms of security, you should carefully evaluate your network security and your threat model before you deploy it.