diff --git a/changelogs/fragments/1270-elbv2-fixes.yml b/changelogs/fragments/1270-elbv2-fixes.yml new file mode 100644 index 00000000000..5da7d386699 --- /dev/null +++ b/changelogs/fragments/1270-elbv2-fixes.yml @@ -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). \ No newline at end of file diff --git a/plugins/module_utils/elbv2.py b/plugins/module_utils/elbv2.py index 533fd75e23d..f63dc3f3653 100644 --- a/plugins/module_utils/elbv2.py +++ b/plugins/module_utils/elbv2.py @@ -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 @@ -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: diff --git a/plugins/modules/elb_application_lb.py b/plugins/modules/elb_application_lb.py index 08d62a7bf10..37b3b35a7ea 100644 --- a/plugins/modules/elb_application_lb.py +++ b/plugins/modules/elb_application_lb.py @@ -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 diff --git a/tests/unit/module_utils/elbv2/test_prune.py b/tests/unit/module_utils/elbv2/test_prune.py index 3a80bf58df8..3a02b9e2e49 100644 --- a/tests/unit/module_utils/elbv2/test_prune.py +++ b/tests/unit/module_utils/elbv2/test_prune.py @@ -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 = [ @@ -121,6 +124,8 @@ UserInfoEndpoint='https://idp.ansible.test/user', ClientId='ExampleClient', UseExistingClientSecret=True, + Scope='openid', + SessionTimeout=604800 ), ), dict( @@ -132,6 +137,7 @@ UserInfoEndpoint='https://idp.ansible.test/user', ClientId='ExampleClient', ClientSecret='MyVerySecretString', + UseExistingClientSecret=True, ), ), ]