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

add Azure config dump #15134

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions awx/main/management/commands/dump_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Command(BaseCommand):
"USER_SEARCH": False,
}

DAB_AZURE_AUTHENTICATOR_KEYS = {
"CALLBACK_URL": False,
"KEY": True,
"SECRET": False,
}

def is_enabled(self, settings, keys):
missing_fields = []
for key, required in keys.items():
Expand Down Expand Up @@ -92,6 +98,13 @@ def get_awx_saml_settings(self) -> dict[str, Any]:

return awx_saml_settings

def get_awx_azure_settings(self) -> dict[str, Any]:
awx_azure_settings = {}
for awx_azure_setting in settings_registry.get_registered_settings(category_slug='azuread-oauth2'):
awx_azure_settings[awx_azure_setting.removeprefix("SOCIAL_AUTH_AZUREAD_OAUTH2_")] = getattr(settings, awx_azure_setting, None)

return awx_azure_settings

def format_config_data(self, enabled, awx_settings, type, keys, name):
config = {
"type": f"ansible_base.authentication.authenticator_plugins.{type}",
Expand Down Expand Up @@ -174,6 +187,22 @@ def handle(self, *args, **options):
else:
data.append({f"LDAP_{awx_ldap_name}_missing_fields": ldap_missing_fields})

# dump AZURE settings
awx_azure_settings = self.get_awx_azure_settings()
awx_azure_enabled, azure_missing_fields = self.is_enabled(awx_azure_settings, self.DAB_AZURE_AUTHENTICATOR_KEYS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that is_enabled is a method that is already established prior to this PR, but I'm concerned that it treats an explicit None the same as a missing key/value. Worse, now that I'm thinking of it, any explicit value that evaluates as false-like. This is IMO a bug waiting to happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I'd deal with it:

  • establish a module variable MISSING = object()
  • condition becomes if required and settings.get(key, MISSING) is MISSING:

if awx_azure_enabled:
data.append(
self.format_config_data(
awx_azure_enabled,
awx_azure_settings,
"azuread",
self.DAB_AZURE_AUTHENTICATOR_KEYS,
"AZUREAD",
)
)
else:
data.append({"AZURE_missing_fields": azure_missing_fields})

# write to file if requested
if options["output_file"]:
# Define the path for the output JSON file
Expand Down
Loading