Skip to content
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

Fix k8s roles and add aws-ec2 sts settings #7

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion vault_dump/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def get_auth_backends(config_root, vault_token, vault_addr):
for ldap_entity in ["groups", "users"]:
get_ldap_entities(config_root, vault_token, vault_addr, ldap_entity)

if auth_details["type"] == "aws-ec2":
list_sts_accounts = make_request(vault_token, vault_addr, f"v1/auth/{auth_path}config/sts", "LIST")
if list_sts_accounts.status_code not in [403, 404]:
list_sts_data = list_sts_accounts.json()
for account_id in list_sts_data['data']['keys']:
get_sts_settings = make_request(vault_token, vault_addr, f"v1/auth/{auth_path}config/sts/{account_id}")
sts_file = Path(f"{config_root}/auth/{auth_path}config/sts/{account_id}.yaml")
sts_file.parent.mkdir(parents=True, exist_ok=True)
with sts_file.open("w+") as f:
f.write(yaml.safe_dump(get_sts_settings.json()["data"]))

def get_ldap_entities(config_root, vault_token, vault_addr, ldap_entity):
list_ldap_entities_response = make_request(vault_token, vault_addr, f"v1/auth/ldap/{ldap_entity}", "LIST")
Expand All @@ -117,7 +127,8 @@ def get_ldap_entities(config_root, vault_token, vault_addr, ldap_entity):
def get_auth_roles(config_root, vault_token, vault_addr, auth_path, auth_backend_type):
# each auth backend may have roles defined for them
# enumerate them all and get their configuration details
list_roles_response = make_request(vault_token, vault_addr, f"v1/auth/{auth_path}roles", "LIST")
role_or_roles = "role" if auth_backend_type in ["kubernetes"] else "roles"
list_roles_response = make_request(vault_token, vault_addr, f"v1/auth/{auth_path}{role_or_roles}", "LIST")
if not list_roles_response.status_code in [403, 404]:
for role_name in list_roles_response.json()["data"]["keys"]:
# This is necessary because of a silly inconsistency in the vault API
Expand Down