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

[PR #1270/c6906a3f backport][stable-5] elbv2: respect UseExistingClientSecret #1387

Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions changelogs/fragments/1270-elbv2-fixes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- module_utils/elbv2 - respect ``UseExistingClientSecret`` parameter in ``authenticate-oidc`` rules (https://github.com/ansible-collections/amazon.aws/pull/1270).
- module_utils/elbv2 - fix change detection by adding default values for ``Scope`` and ``SessionTimeout`` parameters in ``authenticate-oidc`` rules (https://github.com/ansible-collections/amazon.aws/pull/1270).
28 changes: 22 additions & 6 deletions plugins/module_utils/elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,31 @@ def _prune_ForwardConfig(action):
return newAction


# the AWS api won't return the client secret, so we'll have to remove it
# or the module will always see the new and current actions as different
# and try to apply the same config
# remove the client secret if UseExistingClientSecret, because aws won't return it
# add default values when they are not requested
def _prune_secret(action):
if action['Type'] != 'authenticate-oidc':
return action

action['AuthenticateOidcConfig'].pop('ClientSecret', None)
if not action['AuthenticateOidcConfig'].get('Scope', False):
action['AuthenticateOidcConfig']['Scope'] = 'openid'

if not action['AuthenticateOidcConfig'].get('SessionTimeout', False):
action['AuthenticateOidcConfig']['SessionTimeout'] = 604800

if action['AuthenticateOidcConfig'].get('UseExistingClientSecret', False):
action['AuthenticateOidcConfig'].pop('UseExistingClientSecret')
action['AuthenticateOidcConfig'].pop('ClientSecret', None)

return action


# while AWS api also won't return UseExistingClientSecret key
# it must be added, because it's requested and compared
def _append_use_existing_client_secretn(action):
if action['Type'] != 'authenticate-oidc':
return action

action['AuthenticateOidcConfig']['UseExistingClientSecret'] = True

return action

Expand Down Expand Up @@ -996,9 +1011,10 @@ def _compare_rule(self, current_rule, new_rule):
current_actions_sorted = _sort_actions(current_rule['Actions'])
new_actions_sorted = _sort_actions(new_rule['Actions'])

new_current_actions_sorted = [_append_use_existing_client_secretn(i) for i in current_actions_sorted]
new_actions_sorted_no_secret = [_prune_secret(i) for i in new_actions_sorted]

if [_prune_ForwardConfig(i) for i in current_actions_sorted] != [_prune_ForwardConfig(i) for i in new_actions_sorted_no_secret]:
if [_prune_ForwardConfig(i) for i in new_current_actions_sorted] != [_prune_ForwardConfig(i) for i in new_actions_sorted_no_secret]:
modified_rule['Actions'] = new_rule['Actions']
# If the action lengths are different, then replace with the new actions
else:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/elb_application_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
- A list of ALB Listener Rules.
- 'For the complete documentation of possible Conditions and Actions please see the boto3 documentation:'
- 'https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_rule'
- >
Keep in mind that AWS uses default values for parameters that are not requested. For example for I(Scope)
and I(SessionTimeout) when the action type is C(authenticate-oidc).
suboptions:
Conditions:
type: list
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/module_utils/elbv2/test_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
TokenEndpoint='https://idp.ansible.test/token',
UserInfoEndpoint='https://idp.ansible.test/user',
ClientId='ExampleClient',
Scope='openid',
SessionTimeout=604800,
UseExistingClientSecret=True,
),
)
oidc_actions = [
Expand All @@ -121,6 +124,8 @@
UserInfoEndpoint='https://idp.ansible.test/user',
ClientId='ExampleClient',
UseExistingClientSecret=True,
Scope='openid',
SessionTimeout=604800
),
),
dict(
Expand All @@ -132,6 +137,7 @@
UserInfoEndpoint='https://idp.ansible.test/user',
ClientId='ExampleClient',
ClientSecret='MyVerySecretString',
UseExistingClientSecret=True,
),
),
]
Expand Down