Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Add Github controller and jwt helper #66

Closed
wants to merge 2 commits into from

Conversation

sladyn98
Copy link
Contributor

@sladyn98 sladyn98 commented Jul 6, 2020

This PR adds a Github Controller and the required JWT helper. The JWT helper takes care of the signing of the private key and the controller takes care of authenticating the application. We would like to keep this PR separate from the Github Services that will follow.

@sladyn98 sladyn98 requested a review from a team as a code owner July 6, 2020 06:47
Date now = new Date(nowMillis);

//We will sign our JWT with our private key
Key signingKey = get("custom_distribution_private_key.der");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I push this too ?

Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't include secret keys unencrypted, so you'll want to encrypt the key in some way

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 am not too sure how to do that ? because this would be signed using rsa and the APP_ID so I am assuming if we keep the appID safe we can just push this ?


public class GithubController {

private static String APP_IDENTIFIER="";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I load this via environment variables ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's always good to pull things into environment variables

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 put it in the application.properties, is that enough ?

Copy link
Contributor

@martinda martinda left a comment

Choose a reason for hiding this comment

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

Hello Sladyn, I have some questions as I try to understand the project. Thanks in advance.


@PostMapping(path = "/event_handler")
public void handleEvent(@RequestBody String requestBodyString) throws Exception {
System.out.println("Received event handler event");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the logger be used here instead of System.out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah my bad :(

private String getAppIdentifier;

@PostMapping(path = "/event_handler")
public void handleEvent(@RequestBody String requestBodyString) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as the other pull-request, please use javadoc to document methods.

@CrossOrigin("*")
public class GithubController {

@Value("${APP_IDENTIFIER}")
Copy link
Contributor

Choose a reason for hiding this comment

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

The value is read from the properties file. Does the user need to change this value when they run the application?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is hosted no, if it is self-hosted then yes

Copy link
Contributor

Choose a reason for hiding this comment

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

In the case where it is self-hosted, the user needs a way to change the APP_IDENTIFIER value then. I would recommend finding a way to read this value from an environment variable, or a user provided properties file, without having the user change the source code of the application.

Date now = new Date(nowMillis);

//We will sign our JWT with our private key
Key signingKey = get("jenkins-custom-distribution-bot.der");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this private key the same for all users of the application? Excuse my ignorance, but where does this key come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This private key comes from the private key of the bot that one creates on github, so when you create an application on github you get a private key for that bot, which you can then sign and verify yourself

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the private key stored in the .der file? What is stored in the .der file?


public class GithubJwtHelper {

static PrivateKey get(String filename) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I am wrong. I think this method 1) encodes the key, then 2) it encrypts it. Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, then this explanation can be put in the javadoc.

@sladyn98 sladyn98 added this to the [GSoC Phase 2] milestone Jul 20, 2020
@sladyn98 sladyn98 linked an issue Jul 20, 2020 that may be closed by this pull request
3 tasks
@sladyn98
Copy link
Contributor Author

These Pull requests can be opened later when we have concrete evidence that this is a feature that is useful for users

@sladyn98 sladyn98 closed this Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Pull Request Creation for community configurations
3 participants