-
Notifications
You must be signed in to change notification settings - Fork 370
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
Do not enforce GitHub app to comes from the same org as the repo org. The GH app can come from another org as log as it is installed in the org with the target git repo there is no security issue #744
Conversation
… The GH app can come from another org as log as it is installed in the org with the target git repo there is no security issue Signed-off-by: Olivier Lamy <[email protected]>
This does not look right. I suspect the configuration problem was misdiagnosed. Perhaps the owner field was set incorrectly in the Jenkins credentials? Or could simply have been left blank? |
@jglick no the owner of the GH App Jenkins credentials is not blank but have another org.
Well I could create cred B with same key but owner org c. |
@jglick any comment or it's all good for you? |
I also have the feeling this fix is not correct. The plugin seems to be able to support multiple installations of the app and handles that, e.g. in the generateAppInstallationToken, however, the withOwner method seems require that if the owner field is set, you can only use it for repos that have the same owner, i.e. the app must be owned by the owner of the repo. The fix will return a GitHubAppCredentials instance which has an owner different from the owner of the repo that it should access. In the generateAppInstallationToken method, when we generate the actual installation token to access the repo, it will only work correctly, if the app has exactly a single installation. If there are multiple installations, a different code path is used which will look for installations matching the current owner. So I believe the correct fix would be something like that:
|
@netomi sounds a good catch. would you provide a PR for it? |
I can work on a improved fix, but would like to test the case that I described so might take a bit. |
so I tested the current fix:
it works, however, it will use tokens that are created for the app installation of org A. As long as the plugin only accesses public information you will not notice a problem as any token can access them, but if the plugin tries to access restricted data you will see failures (e.g. setting up a webhook). With the fix as outlined above this works as expected, tokens are created for the right app installation based on the required owner organization: --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java
+++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java
@@ -325,7 +325,7 @@ public class GitHubAppCredentials extends BaseStandardCredentials implements Sta
@NonNull
public synchronized GitHubAppCredentials withOwner(@NonNull String owner) {
- if (this.owner != null) {
+ if (this.owner != null && this.owner.equals(owner)) {
return this;
}
if (byOwner == null) { I can easily create a PR to fix that, however I am unsure if I should add a test for this. There is an existing test for this class but it mainly uses mocking which I guess is not of much help in this case. |
@netomi sounds like a good fix. Yes it's not easy to create tests in this area. Let''s have a PR first! |
So this was actually doing exactly what it was designed to - the Credential was only being allowed to use the org (owner) that it was configured for. You should just delete the owner if you do not want to restrict the credential usage. |
That is the reason why an owner has to be configured when setting up the GitHubAppCredential from the start: Now the plugin itself deals with multiple installations and its also written in the documentation that this is working in general. However the existing code is in contradiction to that, thus the fixes. |
(some more discussion in #745 (comment)) |
|
Signed-off-by: Olivier Lamy [email protected]
Description
A brief summary describing the changes in this pull request. See
JENKINS-XXXXX for further information.
Submitter checklist
Reviewer checklist
Documentation changes
Users/aliases to notify