Compare commits
No commits in common. "af3636bcc1b1e60bfb60997d1898d5f39eec61c7" and "a0564432245d176c20a00be45527a1bdf9f8013d" have entirely different histories.
af3636bcc1
...
a056443224
|
|
@ -1,8 +1,5 @@
|
||||||
# bifroyst
|
# bifroyst
|
||||||
|
|
||||||
zur Verwaltung von SSH-Zugängen
|
|
||||||
|
|
||||||
|
|
||||||
## Erstellung
|
## Erstellung
|
||||||
|
|
||||||
### Voraussetzungen
|
### Voraussetzungen
|
||||||
|
|
@ -20,11 +17,9 @@ zur Verwaltung von SSH-Zugängen
|
||||||
### Voraussetzungen
|
### Voraussetzungen
|
||||||
|
|
||||||
- Python3
|
- Python3
|
||||||
- OpenSSL
|
|
||||||
- KeepassXC
|
- KeepassXC
|
||||||
|
|
||||||
|
|
||||||
### Anweisungen
|
### Anweisungen
|
||||||
|
|
||||||
- siehe `bifroyst -h`
|
- siehe `bifroyst -h`
|
||||||
|
|
||||||
|
|
|
||||||
140
source/main.py
140
source/main.py
|
|
@ -32,65 +32,6 @@ def action_init(
|
||||||
|
|
||||||
|
|
||||||
def action_key_add(
|
def action_key_add(
|
||||||
source_directory,
|
|
||||||
group,
|
|
||||||
name,
|
|
||||||
key_path,
|
|
||||||
options = None
|
|
||||||
):
|
|
||||||
options = (
|
|
||||||
{
|
|
||||||
"remove_private_key": False,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
(options or {})
|
|
||||||
)
|
|
||||||
directory_key = _os.path.join(source_directory, group, "keys")
|
|
||||||
path_key_private = key_path
|
|
||||||
path_key_public = ("%s.pub" % path_key_private)
|
|
||||||
__helpers_misc.directory_create(directory_key)
|
|
||||||
## transfer private key to keepass database
|
|
||||||
if True:
|
|
||||||
keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx")
|
|
||||||
keepass_authfile_path = _os.path.join(source_directory, "private_keys.keyx")
|
|
||||||
__helpers_keepass.action_mkdir(
|
|
||||||
keepass_db_path,
|
|
||||||
group,
|
|
||||||
{
|
|
||||||
"key_file": keepass_authfile_path,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
__helpers_keepass.action_add(
|
|
||||||
keepass_db_path,
|
|
||||||
group,
|
|
||||||
name,
|
|
||||||
{
|
|
||||||
"key_file": keepass_authfile_path,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
__helpers_keepass.action_attachment_import(
|
|
||||||
keepass_db_path,
|
|
||||||
group,
|
|
||||||
name,
|
|
||||||
'ssh private key',
|
|
||||||
path_key_private,
|
|
||||||
{
|
|
||||||
"key_file": keepass_authfile_path,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
## remove private key file
|
|
||||||
if (options["remove_private_key"]):
|
|
||||||
__helpers_misc.shell_exec(
|
|
||||||
__helpers_misc.string_coin(
|
|
||||||
"rm --force {{path}}",
|
|
||||||
{
|
|
||||||
"path": path_key_private,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def action_key_generate(
|
|
||||||
source_directory,
|
source_directory,
|
||||||
group,
|
group,
|
||||||
name
|
name
|
||||||
|
|
@ -148,7 +89,6 @@ def action_key_generate(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def action_key_remove(
|
def action_key_remove(
|
||||||
source_directory,
|
source_directory,
|
||||||
group,
|
group,
|
||||||
|
|
@ -188,43 +128,28 @@ def action_put(
|
||||||
):
|
):
|
||||||
sshconf = ""
|
sshconf = ""
|
||||||
for group in _os.listdir(source_directory):
|
for group in _os.listdir(source_directory):
|
||||||
path_temp = _os.path.join(source_directory, group)
|
conf_path = _os.path.join(source_directory, group, "conf.json")
|
||||||
if (
|
conf_content = __helpers_misc.file_read(conf_path)
|
||||||
not
|
conf_data = _json.loads(conf_content)
|
||||||
(
|
# conf
|
||||||
_os.path.isdir(path_temp)
|
if True:
|
||||||
and
|
sshconf = (sshconf + "\n" + __helpers_ssh.sshconf_encode(conf_data))
|
||||||
(group == ".")
|
# public keys
|
||||||
and
|
if True:
|
||||||
(group == "..")
|
__helpers_misc.directory_create(target_directory)
|
||||||
and
|
for name in _os.listdir(_os.path.join(source_directory, group, "keys")):
|
||||||
(group == ".git")
|
|
||||||
)
|
|
||||||
):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
conf_path = _os.path.join(source_directory, group, "conf.json")
|
|
||||||
conf_content = __helpers_misc.file_read(conf_path)
|
|
||||||
conf_data = _json.loads(conf_content)
|
|
||||||
# conf
|
|
||||||
if True:
|
|
||||||
sshconf = (sshconf + "\n" + __helpers_ssh.sshconf_encode(conf_data))
|
|
||||||
# public keys
|
|
||||||
if True:
|
|
||||||
__helpers_misc.directory_create(target_directory)
|
|
||||||
for name in _os.listdir(_os.path.join(source_directory, group, "keys")):
|
|
||||||
_shutil.copy(
|
|
||||||
_os.path.join(source_directory, group, "keys", name),
|
|
||||||
_os.path.join(target_directory, "%s%s" % (conf_data["settings"]["prefix"], name, ))
|
|
||||||
)
|
|
||||||
# private keys
|
|
||||||
if True:
|
|
||||||
keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx")
|
|
||||||
_shutil.copy(
|
_shutil.copy(
|
||||||
keepass_db_path,
|
_os.path.join(source_directory, group, "keys", name),
|
||||||
_os.path.join(target_directory, "private_keys.kdbx")
|
_os.path.join(target_directory, "%s%s" % (conf_data["settings"]["prefix"], name, ))
|
||||||
)
|
)
|
||||||
## todo: keyfile
|
# private keys
|
||||||
|
if True:
|
||||||
|
keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx")
|
||||||
|
_shutil.copy(
|
||||||
|
keepass_db_path,
|
||||||
|
_os.path.join(target_directory, "private_keys.kdbx")
|
||||||
|
)
|
||||||
|
## todo: keyfile
|
||||||
__helpers_misc.file_write(_os.path.join(target_directory, "config"), sshconf)
|
__helpers_misc.file_write(_os.path.join(target_directory, "config"), sshconf)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -244,13 +169,12 @@ def main():
|
||||||
choices = [
|
choices = [
|
||||||
"init",
|
"init",
|
||||||
"key-add",
|
"key-add",
|
||||||
"key-generate",
|
|
||||||
"key-remove",
|
"key-remove",
|
||||||
"put",
|
"put",
|
||||||
],
|
],
|
||||||
default = "put",
|
default = "put",
|
||||||
metavar = "<action>",
|
metavar = "<action>",
|
||||||
help = "options: init | key-add | key-generate | key-remove | put",
|
help = "options: init | key-add | key-remove | put",
|
||||||
)
|
)
|
||||||
argument_parser.add_argument(
|
argument_parser.add_argument(
|
||||||
"-s",
|
"-s",
|
||||||
|
|
@ -280,18 +204,6 @@ def main():
|
||||||
default = None,
|
default = None,
|
||||||
metavar = "<name>",
|
metavar = "<name>",
|
||||||
)
|
)
|
||||||
argument_parser.add_argument(
|
|
||||||
"-k",
|
|
||||||
"--key-path",
|
|
||||||
type = str,
|
|
||||||
default = None,
|
|
||||||
metavar = "<key-path>",
|
|
||||||
)
|
|
||||||
argument_parser.add_argument(
|
|
||||||
"-r",
|
|
||||||
"--remove-private-key",
|
|
||||||
action = "store_true",
|
|
||||||
)
|
|
||||||
args = argument_parser.parse_args()
|
args = argument_parser.parse_args()
|
||||||
|
|
||||||
## exec
|
## exec
|
||||||
|
|
@ -301,16 +213,6 @@ def main():
|
||||||
)
|
)
|
||||||
elif (args.action == "key-add"):
|
elif (args.action == "key-add"):
|
||||||
action_key_add(
|
action_key_add(
|
||||||
args.source_directory,
|
|
||||||
args.group,
|
|
||||||
args.name,
|
|
||||||
args.key_path,
|
|
||||||
{
|
|
||||||
"remove_private_key": args.remove_private_key,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
elif (args.action == "key-generate"):
|
|
||||||
action_key_generate(
|
|
||||||
args.source_directory,
|
args.source_directory,
|
||||||
args.group,
|
args.group,
|
||||||
args.name
|
args.name
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue