Skip to content

Conversation

@garethjevans
Copy link
Contributor

@garethjevans garethjevans commented Mar 13, 2021

This PR adds support for "gitHubApp" credentials.

The GitHub app credential is mapped from "jenkins.io/credentials-type": "gitHubApp", with the parameters appID & privateKey.

Fixes JENKINS-63631

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your master 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


hudson.util.Secret privateKeySecret = null;
try {
privateKeySecret = hudson.util.Secret.fromString(new String(privateKey, "UTF-8"));
Copy link
Member

Choose a reason for hiding this comment

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

This seems wrong.
The convention in the plugin is that the secrets are shared between Jenkins and possibly something else (possibly even multiple Jenkins). As such this should not be a secret. Also seems weird we have a String constructed from utf8 byte array here when that can be done above with a change to call a different method which is already done in the preceding line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've simplified this to call SecretUtils.base64DecodeToString as recommended. The only constructor I seem to have available takes in a Secret so i'm not sure of another way to do this.


String privateKeyBase64 = SecretUtils.getNonNullSecretData(secret, "privateKey", "gitHubApp credential is missing the privateKey");

String appID = SecretUtils.requireNonNull(SecretUtils.base64DecodeToString(appIDBase64), "gitHubApp credential has an invalid appID (must be base64 encoded UTF-8)");
Copy link
Member

Choose a reason for hiding this comment

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

Iiuc appId is an integer numerical type so should be safe to store directly in the secret without encoding?
@bitwiseman ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could go as an annotation? but i think everything underneath the data element will be base64 encoded

Copy link
Member

Choose a reason for hiding this comment

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

no - you are right. this is how a native app would expect it. all k8s secrets are expected to be base64 encoded strings.

Copy link
Member

@jtnord jtnord 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 the PR Gareth.
I've left a few comments inline, if you could let me have your feedback.

@jtnord jtnord added the enhancement New feature or request label Mar 15, 2021
@jtnord jtnord changed the title feat: add support for gitHubApp credentials Add support for GitHub App credentials Mar 15, 2021
@jtnord jtnord changed the title Add support for GitHub App credentials [JENKINS-63631] Add support for GitHub App credentials Mar 15, 2021
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-branch-source</artifactId>
<version>2.7.1</version>

Choose a reason for hiding this comment

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

Really? Have you considered updating to version that isn't almost a year old? There's been a ton of work in this area in that past year.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgrading to the latest introduces a lot of enforcer issues, but i'll give it a go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try and introduce the plugin bom in a separate PR and update some of the dependencies

@garethjevans
Copy link
Contributor Author

#51 introduces the bom for 2.249-x

@garethjevans
Copy link
Contributor Author

@jtnord anything else I need to do to get this merged and a release created?

@jtnord jtnord merged commit ec92cd0 into jenkinsci:master Mar 22, 2021
@jtnord
Copy link
Member

jtnord commented Mar 22, 2021

0.17 released. Thanks Gareth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants