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

jenkins_plugin: also use false value for force_basic_auth param #9130

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AMartindale98
Copy link

SUMMARY

force_basic_auth param is specified in documentation: https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_plugin_module.html
I noticed this was not actually being used in the jenkins plugin module. We need to set authorization headers when downloading plugins in certain situations so if force_basic_auth is set to true, we create basic auth headers.

ISSUE TYPE

jenkins_plugin

ADDITIONAL INFORMATION

We found that when we have SSO enabled on our Jenkins instance, we have issues with retrieving a crumb to download our plugins: https://webpagefx.mangoapps.com/msc/MjAyNTYyNl8xNDIwNTQ1Mw
We can get around this problem by using an API token instead, but we need to create basic auth headers and use the API token in place of the password - this can be controlled by the force_basic_auth param which previously was not being used in the module.
After this update, we are able to install plugins without issues: https://webpagefx.mangoapps.com/msc/MjAzNjk4MV8xNDIzMDMyOQ

@ansibullbot
Copy link
Collaborator

The test licenses failed with 2 errors:

changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: found no copyright notice
changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: must have at least one license

The test ansible-test sanity --test changelog [explain] failed with 1 error:

changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: extension must be one of: .yml, .yaml

The test ansible-test sanity --test compile --python 2.7 [explain] failed with 1 error:

plugins/modules/jenkins_plugin.py:370:56: SyntaxError: credentials = f"{self.username}:{self.password}"

The test ansible-test sanity --test import --python 2.7 [explain] failed with 1 error:

plugins/modules/jenkins_plugin.py:370:56: traceback: SyntaxError: invalid syntax

The test ansible-test sanity --test changelog [explain] failed with 1 error:

changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: extension must be one of: .yml, .yaml

The test ansible-test sanity --test changelog [explain] failed with 1 error:

changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: extension must be one of: .yml, .yaml

The test ansible-test sanity --test changelog [explain] failed with 1 error:

changelogs/fragments/add_force_basic_auth_param_to_jenkins_plugin_module:0:0: extension must be one of: .yml, .yaml

click here for bot help

@ansibullbot
Copy link
Collaborator

cc @jtyr
click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) labels Nov 14, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch labels Nov 14, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I noticed this was not actually being used in the jenkins plugin module.

That's right, because the parameter is handled by fetch_url: https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py#L1199

Basically the module always forces the parameter to true, and ignores that the user might have explicitly said false.

@@ -821,6 +844,7 @@ def main():
url_password=dict(no_log=True),
version=dict(),
with_dependencies=dict(default=True, type='bool'),
force_basic_auth=dict(default=False, type='bool') # Add force_basic_auth to arguments
Copy link
Collaborator

Choose a reason for hiding this comment

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

For backwards compatibility the default needs to be True. Also please remove the comment, and add a trailing comma:

Suggested change
force_basic_auth=dict(default=False, type='bool') # Add force_basic_auth to arguments
force_basic_auth=dict(default=True, type='bool'),

You also need to add this default to the documentation in DOCUMENTATION, something like:

options:
  [...]
  force_basic_auth:
    default: true


# If force_basic_auth is True, add the Authorization header
if self.force_basic_auth:
headers["Authorization"] = self._create_basic_auth_header()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this assignment/computation is necessary since fetch_url is already doing that.

@@ -0,0 +1,2 @@
bugfixes:
- jenkins_plugin - use force_basic_auth param to create basic auth headers if set to true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- jenkins_plugin - use force_basic_auth param to create basic auth headers if set to true
- jenkins_plugin - actually use the value of the ``force_basic_auth`` parameter. Until now the module behaved as if it was set to ``true`` (https://github.com/ansible-collections/community.general/pull/9130).

@felixfontein felixfontein added the backport-9 Automatically create a backport for the stable-9 branch label Nov 14, 2024
@felixfontein felixfontein changed the title Add force_basic_auth param to jenkins_plugin module and create headers accordingly jenkins_plugin: also use false value for force_basic_auth param Nov 14, 2024
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

Other than thing already pointed by Felix, I have some questions on the handling of headers. Otherwise this LGTM.

Comment on lines +447 to +450
custom_headers = kwargs.get('headers', {})

# Merge custom headers with self.crumb, ensuring self.crumb is always included
headers = {**self.crumb, **custom_headers}
Copy link
Collaborator

Choose a reason for hiding this comment

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

By my testing, this will always give priority to elements in custom_headers. Do we really want that? Is there anything users might add in headers that would overwrite something from self.crumb and screw the module up? If so, do we care to shield the module from that or do we delegate to the user?

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Nov 23, 2024
@felixfontein
Copy link
Collaborator

@AMartindale98 ping!

needs_info

@ansibullbot ansibullbot added the needs_info This issue requires further information. Please answer any outstanding questions label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch bug This issue/PR relates to a bug check-before-release PR will be looked at again shortly before release and merged if possible. module module needs_info This issue requires further information. Please answer any outstanding questions needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants