-
Notifications
You must be signed in to change notification settings - Fork 115
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
RHBK support #17338
Open
lhellebr
wants to merge
3
commits into
SatelliteQE:master
Choose a base branch
from
lhellebr:rhsso_to_rhbk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
RHBK support #17338
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,15 @@ | ||
# section for RHBK integration | ||
RHBK: | ||
# RHBK Hostname | ||
HOST_NAME: # update with rhbk host name | ||
# RHBK port, 8443 by default | ||
HOST_PORT: # update with rhbk host name | ||
# RHBK Host Url | ||
HOST_URL: # update with rhbk environment url | ||
# RHBK Host Admin of Realm | ||
RHBK_USER: sat_admin | ||
# RHBK Host Admin Password | ||
RHBK_PASSWORD: # update with password | ||
# RHBK Host Realm | ||
REALM: satqe | ||
TOTP_SECRET: # update with the totp secret token |
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 |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
CUSTOM_PUPPET_MODULE_REPOS_VERSION, | ||
HAMMER_CONFIG, | ||
KEY_CLOAK_CLI, | ||
RHBK_CLI, | ||
RHSSO_NEW_GROUP, | ||
RHSSO_NEW_USER, | ||
RHSSO_RESET_PASSWORD, | ||
|
@@ -2422,24 +2423,44 @@ def run_orphan_cleanup(self, smart_proxy_id=None): | |
class SSOHost(Host): | ||
"""Class for RHSSO functions and setup""" | ||
|
||
def __init__(self, sat_obj, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not well-thought-through, but would splitting graph TD;
RHBKHost-->SSOHost;
RHSSOHost-->SSOHost;
SSOHost-->Host;
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
def __init__(self, sat_obj, rhbk=False, **kwargs): | ||
self.satellite = sat_obj | ||
kwargs['hostname'] = kwargs.get('hostname', settings.rhsso.host_name) | ||
if rhbk: | ||
self.rhbk = True | ||
self.host_url = settings.rhbk.host_url | ||
self.host_name = settings.rhbk.host_name | ||
self.host_port = settings.rhbk.host_port | ||
self.realm = settings.rhbk.realm | ||
self.user = settings.rhbk.rhbk_user | ||
self.password = settings.rhbk.rhbk_password | ||
self.kcadm = RHBK_CLI | ||
kwargs['hostname'] = kwargs.get('hostname', settings.rhbk.host_name) | ||
else: | ||
self.rhbk = False | ||
self.host_url = settings.rhsso.host_url | ||
self.host_name = settings.rhsso.host_name | ||
self.host_port = 443 | ||
self.realm = settings.rhsso.realm | ||
self.user = settings.rhsso.rhsso_user | ||
self.password = settings.rhsso.rhsso_password | ||
self.kcadm = KEY_CLOAK_CLI | ||
kwargs['hostname'] = kwargs.get('hostname', settings.rhsso.host_name) | ||
kwargs['ipv6'] = kwargs.get('ipv6', settings.server.is_ipv6) | ||
super().__init__(**kwargs) | ||
|
||
def get_rhsso_client_id(self): | ||
"""getter method for fetching the client id and can be used other functions""" | ||
client_name = f'{self.satellite.hostname}-foreman-openidc' | ||
uri = self.host_url if self.rhbk else self.host_url.replace("https://", "http://") | ||
self.execute( | ||
f'{KEY_CLOAK_CLI} config credentials ' | ||
f'--server {settings.rhsso.host_url.replace("https://", "http://")}/auth ' | ||
f'--realm {settings.rhsso.realm} ' | ||
f'--user {settings.rhsso.rhsso_user} ' | ||
f'--password {settings.rhsso.rhsso_password}' | ||
f'{self.kcadm} config credentials ' | ||
f'--server {uri}/auth ' | ||
f'--realm {self.realm} ' | ||
f'--user {self.user} ' | ||
f'--password {self.password}' | ||
) | ||
|
||
result = self.execute(f'{KEY_CLOAK_CLI} get clients --fields id,clientId') | ||
result = self.execute(f'{self.kcadm} get clients --fields id,clientId') | ||
result_json = json.loads(result.stdout) | ||
client_id = None | ||
for client in result_json: | ||
|
@@ -2451,16 +2472,14 @@ def get_rhsso_client_id(self): | |
@lru_cache | ||
def get_rhsso_user_details(self, username): | ||
"""Getter method to receive the user id""" | ||
result = self.execute( | ||
f"{KEY_CLOAK_CLI} get users -r {settings.rhsso.realm} -q username={username}" | ||
) | ||
result = self.execute(f"{self.kcadm} get users -r {self.realm} -q username={username}") | ||
result_json = json.loads(result.stdout) | ||
return result_json[0] | ||
|
||
@lru_cache | ||
def get_rhsso_groups_details(self, group_name): | ||
"""Getter method to receive the group id""" | ||
result = self.execute(f"{KEY_CLOAK_CLI} get groups -r {settings.rhsso.realm}") | ||
result = self.execute(f"{self.kcadm} get groups -r {self.realm}") | ||
group_list = json.loads(result.stdout) | ||
query_group = [group for group in group_list if group['name'] == group_name] | ||
return query_group[0] | ||
|
@@ -2482,8 +2501,8 @@ def create_mapper(self, json_content, client_id): | |
"""Helper method to create the RH-SSO Client Mapper""" | ||
self.upload_rhsso_entity(json_content, "mapper_file") | ||
self.execute( | ||
f'{KEY_CLOAK_CLI} create clients/{client_id}/protocol-mappers/models -r ' | ||
f'{settings.rhsso.realm} -f {"mapper_file"}' | ||
f'{self.kcadm} create clients/{client_id}/protocol-mappers/models -r ' | ||
f'{self.realm} -f {"mapper_file"}' | ||
) | ||
|
||
def create_new_rhsso_user(self, username=None): | ||
|
@@ -2494,35 +2513,33 @@ def create_new_rhsso_user(self, username=None): | |
username = gen_string('alphanumeric') | ||
update_data_user.username = username | ||
update_data_user.email = username + random.choice(valid_emails_list()) | ||
update_data_pass.value = settings.rhsso.rhsso_password | ||
update_data_pass.value = self.password | ||
self.upload_rhsso_entity(update_data_user, "create_user") | ||
self.upload_rhsso_entity(update_data_pass, "reset_password") | ||
self.execute(f"{KEY_CLOAK_CLI} create users -r {settings.rhsso.realm} -f create_user") | ||
self.execute(f"{self.kcadm} create users -r {self.realm} -f create_user") | ||
user_details = self.get_rhsso_user_details(update_data_user.username) | ||
self.execute( | ||
f'{KEY_CLOAK_CLI} update -r {settings.rhsso.realm} ' | ||
f'{self.kcadm} update -r {self.realm} ' | ||
f'users/{user_details["id"]}/reset-password -f {"reset_password"}' | ||
) | ||
return update_data_user | ||
|
||
def update_rhsso_user(self, username, group_name=None): | ||
update_data_user = Box(RHSSO_USER_UPDATE) | ||
user_details = self.get_rhsso_user_details(username) | ||
update_data_user.realm = settings.rhsso.realm | ||
update_data_user.realm = self.realm | ||
update_data_user.userId = f"{user_details['id']}" | ||
if group_name: | ||
group_details = self.get_rhsso_groups_details(group_name=group_name) | ||
update_data_user['groupId'] = f"{group_details['id']}" | ||
self.upload_rhsso_entity(update_data_user, "update_user") | ||
group_path = f"users/{user_details['id']}/groups/{group_details['id']}" | ||
self.execute( | ||
f"{KEY_CLOAK_CLI} update -r {settings.rhsso.realm} {group_path} -f update_user" | ||
) | ||
self.execute(f"{self.kcadm} update -r {self.realm} {group_path} -f update_user") | ||
|
||
def delete_rhsso_user(self, username): | ||
"""Delete the RHSSO user""" | ||
user_details = self.get_rhsso_user_details(username) | ||
self.execute(f"{KEY_CLOAK_CLI} delete -r {settings.rhsso.realm} users/{user_details['id']}") | ||
self.execute(f"{self.kcadm} delete -r {settings.rhsso.realm} users/{user_details['id']}") | ||
|
||
def create_group(self, group_name=None): | ||
"""Create the RHSSO group""" | ||
|
@@ -2532,23 +2549,21 @@ def create_group(self, group_name=None): | |
update_user_group.name = group_name | ||
self.upload_rhsso_entity(update_user_group, "create_group") | ||
result = self.execute( | ||
f"{KEY_CLOAK_CLI} create groups -r {settings.rhsso.realm} -f create_group" | ||
f"{self.kcadm} create groups -r {settings.rhsso.realm} -f create_group" | ||
) | ||
return result.stdout | ||
|
||
def delete_rhsso_group(self, group_name): | ||
"""Delete the RHSSO group""" | ||
group_details = self.get_rhsso_groups_details(group_name) | ||
self.execute( | ||
f"{KEY_CLOAK_CLI} delete -r {settings.rhsso.realm} groups/{group_details['id']}" | ||
) | ||
self.execute(f"{self.kcadm} delete -r {settings.rhsso.realm} groups/{group_details['id']}") | ||
|
||
def update_client_configuration(self, json_content): | ||
"""Update the client configuration""" | ||
client_id = self.get_rhsso_client_id() | ||
self.upload_rhsso_entity(json_content, "update_client_info") | ||
update_cmd = ( | ||
f"{KEY_CLOAK_CLI} update clients/{client_id} " # EOL space important | ||
f"{self.kcadm} update clients/{client_id} " # EOL space important | ||
"-f update_client_info -s enabled=true --merge" | ||
) | ||
assert self.execute(update_cmd).status == 0 | ||
|
@@ -2557,8 +2572,8 @@ def update_client_configuration(self, json_content): | |
def oidc_token_endpoint(self): | ||
"""getter oidc token endpoint""" | ||
return ( | ||
f"https://{settings.rhsso.host_name}/auth/realms/" | ||
f"{settings.rhsso.realm}/protocol/openid-connect/token" | ||
f"https://{self.host_name}:{self.host_port}/auth/realms/" | ||
f"{self.realm}/protocol/openid-connect/token" | ||
) | ||
|
||
def get_oidc_client_id(self): | ||
|
@@ -2568,16 +2583,13 @@ def get_oidc_client_id(self): | |
@cached_property | ||
def oidc_authorization_endpoint(self): | ||
"""getter for the oidc authorization endpoint""" | ||
return ( | ||
f"https://{settings.rhsso.host_name}/auth/realms/" | ||
f"{settings.rhsso.realm}/protocol/openid-connect/auth" | ||
) | ||
return f"https://{self.host_name}/auth/realms/" f"{self.realm}/protocol/openid-connect/auth" | ||
|
||
def get_two_factor_token_rh_sso_url(self): | ||
"""getter for the two factor token rh_sso url""" | ||
return ( | ||
f"https://{settings.rhsso.host_name}/auth/realms/" | ||
f"{settings.rhsso.realm}/protocol/openid-connect/" | ||
f"https://{self.host_name}/auth/realms/" | ||
f"{self.realm}/protocol/openid-connect/" | ||
f"auth?response_type=code&client_id={self.satellite.hostname}-foreman-openidc&" | ||
"redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=openid" | ||
) | ||
|
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
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.
Can you please add validators for this config?