-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completes core feature binaries #1
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3309878
feat: initialize logging pipeline
kanav99 735ffe5
feat: better logging
kanav99 9546f17
file: adds pam_ssh
kanav99 0de58f1
feat: completes su module
kanav99 20dc290
feat: adds installation scripts
kanav99 6b0a7fd
requested changes
kanav99 6ec008f
create new log file if not exists
kanav99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,75 @@ | ||
|
||
watchdog_config = """ | ||
# SDSLabs Watchdog configuration START | ||
|
||
UsePAM yes | ||
PasswordAuthentication no | ||
AuthorizedKeysCommand /opt/watchdog/bin/auth_keys_cmd %u %h %t %f %k | ||
AuthorizedKeysCommandUser root | ||
|
||
# SDSLabs Watchdog configuration END | ||
""" | ||
|
||
|
||
modified_keys = [ | ||
'AuthorizedKeysCommand', | ||
'AuthorizedKeysCommandUser', | ||
'PasswordAuthentication', | ||
'UsePAM' | ||
] | ||
|
||
inside_watchdog_config = False | ||
|
||
def process_line(line): | ||
global inside_watchdog_config | ||
|
||
if inside_watchdog_config and line == "# SDSLabs Watchdog configuration END\n": | ||
inside_watchdog_config = False | ||
return '' | ||
|
||
if inside_watchdog_config: | ||
return '' | ||
|
||
if line == "# SDSLabs Watchdog configuration START\n": | ||
inside_watchdog_config = True | ||
return '' | ||
|
||
l = line.strip() | ||
i = l.find('#') | ||
if i != -1: | ||
l = l[:i] | ||
if len(l) == 0: | ||
return line | ||
i = l.find(' ') | ||
j = l.find('\t') | ||
if i == -1 and j != -1: | ||
i = j | ||
elif j == -1 and i != -1: | ||
pass | ||
elif j == -1 and i == -1: | ||
return line | ||
else: | ||
i = min(i, j) | ||
key = l[:i] | ||
value = l[i+1:].strip() | ||
if key in modified_keys: | ||
# comment this line | ||
return '# Watchdog: Commenting the line below out\n#' + line | ||
else: | ||
return line | ||
|
||
def main(): | ||
iput = open("/etc/ssh/sshd_config") | ||
oput = open("tmp_sshd_config", "w") | ||
lines = iput.readlines() | ||
for l in lines: | ||
oputline = process_line(l) | ||
oput.write(oputline) | ||
|
||
oput.write(watchdog_config) | ||
|
||
iput.close() | ||
oput.close() | ||
|
||
|
||
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
# Install all the files at right place | ||
mkdir -p /opt/watchdog/bin | ||
|
||
cp ../target/debug/pam_ssh /opt/watchdog/bin/pam_ssh | ||
chown root /opt/watchdog/bin/pam_ssh | ||
chgrp root /opt/watchdog/bin/pam_ssh | ||
chmod 700 /opt/watchdog/bin/pam_ssh | ||
|
||
cp ../target/debug/pam_su /opt/watchdog/bin/pam_su | ||
chown root /opt/watchdog/bin/pam_su | ||
chgrp root /opt/watchdog/bin/pam_su | ||
chmod 700 /opt/watchdog/bin/pam_su | ||
|
||
cp ../target/debug/pam_sudo /opt/watchdog/bin/pam_sudo | ||
chown root /opt/watchdog/bin/pam_sudo | ||
chgrp root /opt/watchdog/bin/pam_sudo | ||
chmod 700 /opt/watchdog/bin/pam_sudo | ||
|
||
cp ../target/debug/auth_keys_cmd /opt/watchdog/bin/auth_keys_cmd | ||
chown root /opt/watchdog/bin/auth_keys_cmd | ||
chgrp root /opt/watchdog/bin/auth_keys_cmd | ||
chmod 700 /opt/watchdog/bin/auth_keys_cmd | ||
|
||
cp ../config.toml /opt/watchdog/config.toml | ||
|
||
# edit `sshd_config` file | ||
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.watchdog.bak | ||
python3 edit-sshd-config.py | ||
cp tmp_sshd_config /etc/ssh/sshd_config | ||
rm tmp_sshd_config | ||
service sshd restart | ||
|
||
# installing pam_exec lines | ||
python3 pam-install-sudo.py | ||
python3 pam-install-su.py | ||
python3 pam-install-ssh.py | ||
|
||
cp tmp_sudo /etc/pam.d/sudo | ||
cp tmp_su /etc/pam.d/su | ||
cp tmp_ssh /etc/pam.d/sshd | ||
|
||
rm tmp_sudo | ||
rm tmp_su | ||
rm tmp_ssh |
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,42 @@ | ||
|
||
watchdog_config = """ | ||
# SDSLabs Watchdog configuration START | ||
|
||
session optional pam_exec.so seteuid /opt/watchdog/bin/pam_ssh | ||
|
||
# SDSLabs Watchdog configuration END | ||
""" | ||
|
||
inside_watchdog_config = False | ||
|
||
def process_line(line): | ||
global inside_watchdog_config | ||
|
||
if inside_watchdog_config and line == "# SDSLabs Watchdog configuration END\n": | ||
inside_watchdog_config = False | ||
return '' | ||
|
||
if inside_watchdog_config: | ||
return '' | ||
|
||
if line == "# SDSLabs Watchdog configuration START\n": | ||
inside_watchdog_config = True | ||
return '' | ||
|
||
return line | ||
|
||
def main(): | ||
iput = open("/etc/pam.d/sshd") | ||
oput = open("tmp_ssh", "w") | ||
lines = iput.readlines() | ||
for l in lines: | ||
oputline = process_line(l) | ||
oput.write(oputline) | ||
|
||
oput.write(watchdog_config) | ||
|
||
iput.close() | ||
oput.close() | ||
|
||
|
||
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
watchdog_config = """ | ||
# SDSLabs Watchdog configuration START | ||
|
||
session optional pam_exec.so seteuid /opt/watchdog/bin/pam_su | ||
|
||
# SDSLabs Watchdog configuration END | ||
""" | ||
|
||
inside_watchdog_config = False | ||
|
||
def process_line(line): | ||
global inside_watchdog_config | ||
|
||
if inside_watchdog_config and line == "# SDSLabs Watchdog configuration END\n": | ||
inside_watchdog_config = False | ||
return '' | ||
|
||
if inside_watchdog_config: | ||
return '' | ||
|
||
if line == "# SDSLabs Watchdog configuration START\n": | ||
inside_watchdog_config = True | ||
return '' | ||
|
||
return line | ||
|
||
def main(): | ||
iput = open("/etc/pam.d/su") | ||
oput = open("tmp_su", "w") | ||
lines = iput.readlines() | ||
for l in lines: | ||
oputline = process_line(l) | ||
oput.write(oputline) | ||
|
||
oput.write(watchdog_config) | ||
|
||
iput.close() | ||
oput.close() | ||
|
||
|
||
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
watchdog_config = """ | ||
# SDSLabs Watchdog configuration START | ||
|
||
session optional pam_exec.so seteuid /opt/watchdog/bin/pam_sudo | ||
|
||
# SDSLabs Watchdog configuration END | ||
""" | ||
|
||
inside_watchdog_config = False | ||
|
||
def process_line(line): | ||
global inside_watchdog_config | ||
|
||
if inside_watchdog_config and line == "# SDSLabs Watchdog configuration END\n": | ||
inside_watchdog_config = False | ||
return '' | ||
|
||
if inside_watchdog_config: | ||
return '' | ||
|
||
if line == "# SDSLabs Watchdog configuration START\n": | ||
inside_watchdog_config = True | ||
return '' | ||
|
||
return line | ||
|
||
def main(): | ||
iput = open("/etc/pam.d/sudo") | ||
oput = open("tmp_sudo", "w") | ||
lines = iput.readlines() | ||
for l in lines: | ||
oputline = process_line(l) | ||
oput.write(oputline) | ||
|
||
oput.write(watchdog_config) | ||
|
||
iput.close() | ||
oput.close() | ||
|
||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
extern crate simplelog; | ||
|
||
use crate::config; | ||
use log::error; | ||
use simplelog::*; | ||
use std::fs::OpenOptions; | ||
|
||
pub fn init(config: &config::Config) { | ||
init_logger(&config); | ||
} | ||
|
||
pub fn init_logger(config: &config::Config) { | ||
let log_file = match OpenOptions::new() | ||
.create_new(true) | ||
.read(true) | ||
.append(true) | ||
.open(&config.error_log_file) | ||
{ | ||
Ok(f) => f, | ||
Err(_) => { | ||
error!("Watchdog: Couldn't open log file"); | ||
panic!("Watchdog: Couldn't open log file"); | ||
} | ||
}; | ||
|
||
let _res = match CombinedLogger::init(vec![WriteLogger::new( | ||
LevelFilter::Info, | ||
Config::default(), | ||
log_file, | ||
)]) { | ||
Ok(_) => {} | ||
Err(_) => error!("Watchdog: Couldnt start logger for some reason"), | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any further implementation we are basing on this? If not I would prefer to name it as logger.rs instead of init.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would include all the initialization of databases if we include it in the future. But for now, its just for initialization of logger.