-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't reuse the "ssh" group for our own access control
The "ssh" group was supposed to be an internal group that was used by openssh itself for privilege separation. It's since been renamed to "_ssh"[1] to clarify that it's internal-only and flagged that we shouldn't be using it either. Instead, create a new "sdssh" group, add our users to it, and use it in the sshd_config. For upgrades, we migrate users to the new group and then update sshd_config and iptables rules. [1] https://salsa.debian.org/ssh-team/openssh/-/blob/eac38305fc5d8eb8301a106294cf6c79447bdeb3/debian/openssh-client.postinst Fixes #7316.
- Loading branch information
Showing
9 changed files
with
86 additions
and
8 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
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
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
68 changes: 68 additions & 0 deletions
68
securedrop/debian/config/usr/bin/securedrop-migrate-ssh-group.py
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,68 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Migrate users from the "ssh" group to "sdssh" | ||
Runs as root on both app and mon servers | ||
""" | ||
|
||
import grp | ||
import subprocess | ||
from pathlib import Path | ||
|
||
SOURCE_GROUP = "ssh" | ||
DEST_GROUP = "sdssh" | ||
|
||
|
||
def main() -> None: | ||
try: | ||
grp.getgrnam(DEST_GROUP) | ||
print(f"Group {DEST_GROUP} already exists") | ||
except KeyError: | ||
print(f"Creating group {DEST_GROUP}") | ||
subprocess.run(["groupadd", DEST_GROUP], check=True) | ||
|
||
source_group_info = grp.getgrnam(SOURCE_GROUP) | ||
source_users = source_group_info.gr_mem | ||
print(f"Need to migrate: {source_users}") | ||
|
||
for username in source_users: | ||
# Add user to new group while preserving other group memberships | ||
subprocess.run(["usermod", "-a", "-G", DEST_GROUP, username], check=True) | ||
print(f"Added {username} to {DEST_GROUP}") | ||
# can't use usermod -r here since focal doesn't support it | ||
subprocess.run(["gpasswd", "-d", username, SOURCE_GROUP], check=True) | ||
print(f"Removed {username} from {SOURCE_GROUP}") | ||
print("User migration complete") | ||
|
||
# Now update sshd_config | ||
sshd_config = Path("/etc/ssh/sshd_config") | ||
text = sshd_config.read_text() | ||
if f"AllowGroups {SOURCE_GROUP}\n" in text: | ||
# Update the AllowGroups stanza | ||
text = text.replace(f"AllowGroups {SOURCE_GROUP}\n", f"AllowGroups {DEST_GROUP}\n") | ||
# And the comment that precedes it | ||
text = text.replace(f"in the {SOURCE_GROUP} group", f"in the {DEST_GROUP} group") | ||
sshd_config.write_text(text) | ||
print("Updated /etc/ssh/sshd_config") | ||
# n.b. we don't restart sshd here, we'll let it take effect on boot | ||
|
||
# Now update iptables rules | ||
iptables = Path("/etc/iptables/rules.v4") | ||
text = iptables.read_text() | ||
if f"--gid-owner {SOURCE_GROUP} -j LOGNDROP" in text: | ||
# Update the --gid-owner stanza | ||
text = text.replace( | ||
f"--gid-owner {SOURCE_GROUP} -j LOGNDROP", f"--gid-owner {DEST_GROUP} -j LOGNDROP" | ||
) | ||
# And the comment that precedes it | ||
text = text.replace( | ||
f"for users in the {SOURCE_GROUP} group", f"for users in the {DEST_GROUP} group" | ||
) | ||
iptables.write_text(text) | ||
print("Updated /etc/iptables/rules.v4") | ||
|
||
print("Done!") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
debian/config/etc / | ||
debian/config/opt / | ||
debian/config/usr / |
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