Island: Fix credential collector parsing for SSH
This commit is contained in:
parent
c96674f834
commit
b224348881
|
@ -23,17 +23,21 @@ IDENTITY_PROCESSORS = {
|
||||||
|
|
||||||
|
|
||||||
def parse_credentials(credentials: dict):
|
def parse_credentials(credentials: dict):
|
||||||
for credential in credentials["credentials"]:
|
|
||||||
if is_ssh_keypair(credentials):
|
for credential in credentials["data"]:
|
||||||
IDENTITY_PROCESSORS[CredentialsType.SSH_KEYPAIR](credential, credentials["monkey_guid"])
|
if is_ssh_keypair(credential):
|
||||||
|
SECRET_PROCESSORS[CredentialsType.SSH_KEYPAIR](credential, credentials["monkey_guid"])
|
||||||
else:
|
else:
|
||||||
for identity in credential["identities"]:
|
for identity in credential["identities"]:
|
||||||
IDENTITY_PROCESSORS[identity["type"]](identity)
|
IDENTITY_PROCESSORS[identity["credential_type"]](identity)
|
||||||
for secret in credential["secrets"]:
|
for secret in credential["secrets"]:
|
||||||
SECRET_PROCESSORS[secret["type"]](secret)
|
SECRET_PROCESSORS[secret["credential_type"]](secret)
|
||||||
|
|
||||||
|
|
||||||
def is_ssh_keypair(credentials: dict) -> bool:
|
def is_ssh_keypair(credential: dict) -> bool:
|
||||||
return bool(
|
return bool(
|
||||||
filter(credentials["secrets"], lambda secret: secret["type"] == CredentialsType.SSH_KEYPAIR)
|
filter(
|
||||||
|
lambda secret: secret["credential_type"] == CredentialsType.SSH_KEYPAIR,
|
||||||
|
credential["secrets"],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,7 +17,7 @@ def process_ssh_key(credentials: dict, monkey_guid: str):
|
||||||
)
|
)
|
||||||
|
|
||||||
for ssh_key in credentials["secrets"]:
|
for ssh_key in credentials["secrets"]:
|
||||||
if not ssh_key["type"] == CredentialsType.SSH_KEYPAIR:
|
if not ssh_key["credential_type"] == CredentialsType.SSH_KEYPAIR.name:
|
||||||
raise SSHKeyProcessingError("SSH credentials contain secrets that are not keypairs")
|
raise SSHKeyProcessingError("SSH credentials contain secrets that are not keypairs")
|
||||||
|
|
||||||
if not ssh_key["public_key"] or not ssh_key["private_key"]:
|
if not ssh_key["public_key"] or not ssh_key["private_key"]:
|
||||||
|
@ -27,6 +27,8 @@ def process_ssh_key(credentials: dict, monkey_guid: str):
|
||||||
ip = Monkey.get_single_monkey_by_guid(monkey_guid).ip_addresses[0]
|
ip = Monkey.get_single_monkey_by_guid(monkey_guid).ip_addresses[0]
|
||||||
username = credentials["identities"][0]["username"]
|
username = credentials["identities"][0]["username"]
|
||||||
|
|
||||||
|
encrypt_system_info_ssh_keys(ssh_key)
|
||||||
|
|
||||||
ConfigService.ssh_add_keys(
|
ConfigService.ssh_add_keys(
|
||||||
user=username,
|
user=username,
|
||||||
public_key=ssh_key["public_key"],
|
public_key=ssh_key["public_key"],
|
||||||
|
|
Loading…
Reference in New Issue