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-69081] Track credential usage #113

Merged
merged 4 commits into from
Sep 28, 2022

Conversation

kozell
Copy link
Contributor

@kozell kozell commented Sep 27, 2022

JENKINS-69081 Track credential usage

Calling CredentialsProvider::trackAll to track credential usage, as requested in the ticket.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@kozell kozell requested a review from a team as a code owner September 27, 2022 07:39
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

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

The change looks good to me. Credential use tracking is a nice feature and this makes it even more effective.

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 27, 2022

@kozell I wanted to test this pull request interactively. Unfortunately, I can't find any examples that use a credential in Pipeline.

I don't understand the instructions in the documentation that talk about a centrally configured credential or authentication. My attempts to configure one have failed.

Can you provide some more guidance how I could test credentials with http_request?

I've tried and the snippet generator never offers a credential ID

httpRequest httpMode: 'POST', url: 'https://github.com/MarkEWaite/tasks.git'

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 27, 2022

I believe that I have created a basic example that illustrates the technique. The script looks like this:

pipeline {
    options {
        skipDefaultCheckout()
    }
    environment {
        HTTP_RESPONSE = httpRequest httpMode: 'GET',
                                    consoleLogResponseBody: false,
                                    validResponseContent: 'https://github.com/MarkEWaite', 
                                    quiet: true,
                                    authentication: 'invalid-user-and-password',
                                    url: 'https://api.github.com/users/MarkEWaite'
        URL_SUFFIX = 'manage/credentials/store/system/domain/_/credential/invalid-user-and-password/'
    }
    agent none
    stages {
        stage('Track credentials') {
            steps {
                echo HTTP_RESPONSE
                echo 'Open ' + JENKINS_URL + URL_SUFFIX + ' to confirm this job is using the credential'
            }
        }
    }
}

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 27, 2022

The example worked. With the current release of http_request plugin, the use of the credential is not tracked. With the pre-release built from this pull request, I can see the credential was used by that job. This pull request is ready to merge and release.

It would be nice to include documentation and examples that show how to use a credential with the httpRequest Pipeline step, but that documentation could be done in a separate pull request. It does not need to block the merge and release of this improvement.

@MarkEWaite
Copy link
Contributor

I've placed a verification helper into a repository that I use to check that various behaviors are unchanged. See the Jenkinsfile in the JENKINS-69081 branch for the example

@MarkEWaite
Copy link
Contributor

I added an example to the README in 91c1b5a

@kozell
Copy link
Contributor Author

kozell commented Sep 27, 2022

Excellent, thank you for testing!

@MarkEWaite MarkEWaite changed the title JENKINS-69081 Call CredentialsProvider::trackAll to track credential usage [JENKINS-69081] Call CredentialsProvider::trackAll to track credential usage Sep 27, 2022
@MarkEWaite MarkEWaite changed the title [JENKINS-69081] Call CredentialsProvider::trackAll to track credential usage [JENKINS-69081] Track credential usage Sep 27, 2022
The test generates null pointer exceptions in the stapler code with
the default Jenkins version used for tests.  Whe the plugin requires a
modern Jenkins version like 2.332.4 or 2.346.3 or 2.361.1, it will need
to have a test dependency added for the javax mail api plugin.

Derived from the git plugin credentials tracking test.
@MarkEWaite
Copy link
Contributor

@kozell I've pushed a test that asserts the credential tracking is working as expected. I was able to borrow most of the implementation from the git plugin trackCredentials() test that is checking the same behavior for the git plugin.

The 2.249.1 Jenkins version that is used as the minimum version for the plugin has a null pointer exception that the test reports. The null pointer exception does not prevent the test from completing its assigned tasks, but the message is distracting.

When the plugin updates its minimum Jenkins version to 2.332.4 or newer, it will need the addition of the java mail api plugin as a test dependency. The test passes with 2.346.3, 2.361.1, and 2.371.

I think this is ready to merge and release once the CI confirms the tests pass.

@kozell
Copy link
Contributor Author

kozell commented Sep 28, 2022

All right, now we just need someone who can merge :-)

@MarkEWaite MarkEWaite merged commit 2305571 into jenkinsci:master Sep 28, 2022
@kozell kozell deleted the JENKINS-69081 branch September 28, 2022 12:50
MarkEWaite added a commit to MarkEWaite/repository-permissions-updater that referenced this pull request Jun 22, 2023
The http-request plugin needs a new release to deliver the features
and bug fixes that have accumulated since its last release in Aug 2022.
Some of those new features and bug fixes include:

* Require Jenkins 2.361.4 as minimum Jenkins version
  (jenkinsci/http-request-plugin#128)
* JENKINS-69081 - Track credential usage
  (jenkinsci/http-request-plugin#113)
* JENKINS-69155 - Snapshot authentication credentials
  (jenkinsci/http-request-plugin#111)
* Upgrade HtmlUnit from 2.x to 3.x
  (jenkinsci/http-request-plugin#148)

Documentation improvements include:

* Improve feature descriptions in documentation
  (jenkinsci/http-request-plugin#141)
* Add URL details as part of the exception
  (jenkinsci/http-request-plugin#74)
* Add a response header example to documentation
  (jenkinsci/http-request-plugin#133)
* rewording of abstract section
  (jenkinsci/http-request-plugin#130)
* Drop redundant part of example
  (jenkinsci/http-request-plugin#122)

Maintenance improvements include:

* Remove divBasedFormLayout from jelly files
  (jenkinsci/http-request-plugin#149)

jenkinsci/http-request-plugin#150 is the pull
request that prompted this adoption request

Reverts part of pull request:

* jenkins-infra#2950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants