-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: create userpass service to change the first password
- Loading branch information
Jonathan Dahan
committed
Sep 17, 2024
1 parent
ff89511
commit 16f8c2c
Showing
11 changed files
with
156 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,57 +2,57 @@ | |
|
||
Here are some manual steps after booting the raspberry pi to finnish installaion | ||
|
||
Update the password for the `pi` user | ||
## Create ssh key and connect to the pi | ||
|
||
passwd | ||
On your computer, generate a new key, with a new password | ||
|
||
## Enable firewal | ||
ssh-keygen -f ~/.ssh/solar-protocol | ||
|
||
This will make sure people can only access the website | ||
Add the key to your keychain, using the password you just gave | ||
|
||
sudo ufw allow ssh | ||
sudo ufw allow http comment "Solar Protocol" | ||
sudo ufw allow http-alt comment "Solar Protocol (alt)" | ||
sudo ufw allow https comment "Solar Protocol" | ||
sudo ufw allow 8443 comment "Solar Protocol (alt)" | ||
sudo ufw enable | ||
sudo ufw status | ||
ssh-add ~/.ssh/solar-protocol | ||
|
||
## Forward ports from your router to the raspberry pi | ||
Install it to the raspberry pi - use the regular password | ||
|
||
It is strongly recommended to do this only after key-based authentication has been enabled and password authentication has be disabled. | ||
ssh-copy-id -i ~/.ssh/solar-protocol [email protected] | ||
|
||
Connect to the pi - there should be no password prompt here | ||
|
||
Open and forward these ports on your router | ||
ssh [email protected] | ||
|
||
* 443 -> 443 (https) | ||
* 80 -> 80 (http) | ||
Once connected, disable password authentication | ||
|
||
If your home internet does not allow people to connect on ports 443 or 80, you can use these alternative ports | ||
sudo ./disable-ssh-password-auth | ||
|
||
* 8443 -> 443 (alt-https) | ||
* 8080 -> 80 (alt-http) | ||
* 2222 -> 22 (For SSH) | ||
|
||
## Add SSL Certificates | ||
## Secure firewall and website | ||
|
||
Reach out to a network admin, who will follow the instructions in [network/ssl-management.md]() | ||
Once you have confirmed that key authentication works over ssh, enable the firewall | ||
|
||
## Fix permissions | ||
|
||
Set permissions for all files - this script must be run everytime you pull from the repository | ||
sudo ufw enable | ||
|
||
sh /home/pi/solar-protocol/utilities/setAllPermissions.sh | ||
Next, reach out to a network admin, who will follow the instructions in [network/ssl-management.md]() to add secure certificates for the website | ||
|
||
## Join the network | ||
|
||
Enter api keys to join the network | ||
|
||
Log in to the admin console via the browser [http://solar-protocol.local/admin]() | ||
|
||
Enter API keys and update the gateway list with appropriate credentials | ||
|
||
Enter your info on the settings page | ||
|
||
## Forward ports from your router to the raspberry pi | ||
|
||
Open and forward these ports on your router | ||
|
||
* 443 -> 443 (https) | ||
* 80 -> 80 (http) | ||
|
||
If your home internet does not allow people to connect on ports 443 or 80, you can use these alternative ports | ||
|
||
* 8443 -> 443 (alt-https) | ||
* 8080 -> 80 (alt-http) | ||
* 2222 -> 22 (For SSH) | ||
|
||
## Congratulations | ||
|
||
Give yourself a big hug! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
utilities/build/stage-solar/00-install-solar-protocol/files/10-hello.template
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
utilities/build/stage-solar/00-install-solar-protocol/files/20-warning.template
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
utilities/build/stage-solar/00-install-solar-protocol/files/etc/issue.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
☀️ solar protocol ${VERSION} \l |
15 changes: 15 additions & 0 deletions
15
...ies/build/stage-solar/00-install-solar-protocol/files/etc/systemd/system/userpass.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=User password dialog | ||
After=systemd-user-sessions.service | ||
Before=lightdm.service | ||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/lib/userpass-pi/userpass-service | ||
StandardInput=tty | ||
Restart=on-failure | ||
TTYPath=/dev/tty8 | ||
TTYReset=yes | ||
TTYVHangup=yes | ||
TTYVTDisallocate=yes | ||
[Install] | ||
WantedBy=multi-user.target |
52 changes: 52 additions & 0 deletions
52
utilities/build/stage-solar/00-install-solar-protocol/files/etc/ufw/user.rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
*filter | ||
:ufw-user-input - [0:0] | ||
:ufw-user-output - [0:0] | ||
:ufw-user-forward - [0:0] | ||
:ufw-before-logging-input - [0:0] | ||
:ufw-before-logging-output - [0:0] | ||
:ufw-before-logging-forward - [0:0] | ||
:ufw-user-logging-input - [0:0] | ||
:ufw-user-logging-output - [0:0] | ||
:ufw-user-logging-forward - [0:0] | ||
:ufw-after-logging-input - [0:0] | ||
:ufw-after-logging-output - [0:0] | ||
:ufw-after-logging-forward - [0:0] | ||
:ufw-logging-deny - [0:0] | ||
:ufw-logging-allow - [0:0] | ||
:ufw-user-limit - [0:0] | ||
:ufw-user-limit-accept - [0:0] | ||
### RULES ### | ||
|
||
### tuple ### allow tcp 22 0.0.0.0/0 any 0.0.0.0/0 in | ||
-A ufw-user-input -p tcp --dport 22 -j ACCEPT | ||
|
||
### tuple ### allow tcp 80 0.0.0.0/0 any 0.0.0.0/0 in comment=536f6c61722050726f746f636f6c | ||
-A ufw-user-input -p tcp --dport 80 -j ACCEPT | ||
|
||
### tuple ### allow any 8443 0.0.0.0/0 any 0.0.0.0/0 in comment=536f6c61722050726f746f636f6c2028736563757265292028616c7429 | ||
-A ufw-user-input -p tcp --dport 8443 -j ACCEPT | ||
-A ufw-user-input -p udp --dport 8443 -j ACCEPT | ||
|
||
### tuple ### allow tcp 8080 0.0.0.0/0 any 0.0.0.0/0 in comment=536f6c61722050726f746f636f6c2028616c7429 | ||
-A ufw-user-input -p tcp --dport 8080 -j ACCEPT | ||
|
||
### tuple ### allow any 443 0.0.0.0/0 any 0.0.0.0/0 in comment=536f6c61722050726f746f636f6c202873656375726529 | ||
-A ufw-user-input -p tcp --dport 443 -j ACCEPT | ||
-A ufw-user-input -p udp --dport 443 -j ACCEPT | ||
|
||
### END RULES ### | ||
|
||
### LOGGING ### | ||
-A ufw-after-logging-input -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | ||
-A ufw-after-logging-forward -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | ||
-I ufw-logging-deny -m conntrack --ctstate INVALID -j RETURN -m limit --limit 3/min --limit-burst 10 | ||
-A ufw-logging-deny -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | ||
-A ufw-logging-allow -j LOG --log-prefix "[UFW ALLOW] " -m limit --limit 3/min --limit-burst 10 | ||
### END LOGGING ### | ||
|
||
### RATE LIMITING ### | ||
-A ufw-user-limit -m limit --limit 3/minute -j LOG --log-prefix "[UFW LIMIT BLOCK] " | ||
-A ufw-user-limit -j REJECT | ||
-A ufw-user-limit-accept -j ACCEPT | ||
### END RATE LIMITING ### | ||
COMMIT |
3 changes: 3 additions & 0 deletions
3
...ies/build/stage-solar/00-install-solar-protocol/files/etc/update-motd.d/10-hello.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo ☀️ solar protocol ${VERSION} |
4 changes: 4 additions & 0 deletions
4
...ities/build/stage-solar/00-install-solar-protocol/files/home/pi/disable-ssh-password-auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
sed -i -Ee 's/^#?[[:blank:]]*PubkeyAuthentication[[:blank:]]*no[[:blank:]]*$/PubkeyAuthentication yes/ | ||
s/^#?[[:blank:]]*PasswordAuthentication[[:blank:]]*yes[[:blank:]]*$/PasswordAuthentication no/' "${ROOTFS_DIR}"/etc/ssh/sshd_config |
32 changes: 32 additions & 0 deletions
32
...es/build/stage-solar/00-install-solar-protocol/files/usr/lib/userpass-pi/userpass-service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh -e | ||
|
||
validate_password() { | ||
if [ -z "$NEW_PASS" ]; then | ||
echo "Password cannot be empty." | ||
return 1 | ||
fi | ||
} | ||
|
||
if [ ! "$(raspi-config nonint get_boot_cli)" -eq 0 ]; then | ||
return | ||
fi | ||
|
||
VT="$(tty | sed 's|/dev/tty||')" | ||
ORIG_VT="1" | ||
if [ -t 0 ]; then | ||
chvt "$VT" | ||
fi | ||
FIRST_USER="$(getent passwd 1000 | cut -d: -f1)" | ||
|
||
while true; do | ||
NEW_PASS="$(whiptail --passwordbox "Please set a password for $FIRST_USER:" 20 60 3>&1 1>&2 2>&3)" | ||
if [ "$(whiptail --passwordbox "Please confirm the password:" 20 60 3>&1 1>&2 2>&3)" != "$NEW_PASS" ]; then | ||
MSG="Passwords did not match" | ||
elif MSG=$(validate_password); then | ||
break | ||
fi | ||
whiptail --msgbox "$MSG" 20 60 | ||
done | ||
|
||
echo "$FIRST_USER:$NEW_PASS" | chpasswd | ||
chvt "$ORIG_VT" |