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

Support both v4 and v3 GitLab User APIs #19961

Closed
wants to merge 1 commit into from

Conversation

enj
Copy link
Contributor

@enj enj commented Jun 11, 2018

This change adds logic that attempts to use the v4 GitLab User API. If that fails, it falls back to the legacy v3 API. This will allow OpenShift's GitLab integration to work with newer versions of GitLab while still supporting older versions.

Signed-off-by: Monis Khan [email protected]

Fixes #19937

/kind bug

Per https://gitlab.com/gitlab-org/gitlab-ce/issues/47565#note_80751232, this legacy v3 User API will not be removed.

/assign @liggitt @simo5
@openshift/sig-security
cc @alikhajeh1

This change adds logic that attempts to use the v4 GitLab User API.
If that fails, it falls back to the legacy v3 API.  This will allow
OpenShift's GitLab integration to work with newer versions of GitLab
while still supporting older versions.

Signed-off-by: Monis Khan <[email protected]>
@openshift-ci-robot
Copy link

@enj: GitHub didn't allow me to assign the following users: simo.

Note that only openshift members and repo collaborators can be assigned.

In response to this:

This change adds logic that attempts to use the v4 GitLab User API. If that fails, it falls back to the legacy v3 API. This will allow OpenShift's GitLab integration to work with newer versions of GitLab while still supporting older versions.

Signed-off-by: Monis Khan [email protected]

Fixes #19937

/kind bug

Per https://gitlab.com/gitlab-org/gitlab-ce/issues/47565#note_80751232, this legacy v3 User API will not be removed.

/assign @liggitt @Simo
@openshift/sig-security
cc @alikhajeh1

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 11, 2018
@openshift-ci-robot openshift-ci-robot added sig/security size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 11, 2018
@enj enj added this to the v3.11 milestone Jun 11, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 11, 2018
@enj
Copy link
Contributor Author

enj commented Jun 11, 2018

/hold

3.11

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 11, 2018
@enj
Copy link
Contributor Author

enj commented Jun 11, 2018

/assign @simo5

@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 11, 2018

@enj: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/extended_conformance_install 3875b3a link /test extended_conformance_install

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

)

type provider struct {
providerName string
transport http.RoundTripper
authorizeURL string
tokenURL string
userAPIURL string
userAPIURLV3 string
userAPIURLV4 string
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may want to keep just userAPIURL and populate it with V4 endpoint.
On the first attempt if we get a not found error we check if the URL is the V4 and we switch it to V3 and retry.
I do not think it makes sense to keep falling back at every request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will require adding some form of locking.

Copy link
Contributor

Choose a reason for hiding this comment

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

or an atomic holding an index to a 2 elements array with the two strings

userdata, err := p.getUserDataURL(token, p.userAPIURLV4)
if err == nil {
return userdata, nil
}
Copy link
Contributor

@simo5 simo5 Jun 11, 2018

Choose a reason for hiding this comment

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

See above, plus we shouldn't fall back for every error, but just for errors that indicate the endpoint does not exist.
If it does and it returns an error we should just return the error and not try any fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just for errors that indicate the endpoint does not exist

A 404?

return p.getUserDataURL(token, p.userAPIURLV3)
}

func (p *provider) getUserDataURL(token, url string) (*gitlabUser, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like wrapping getUserIdentity with a retry with fallback to V3 only on specific errors and only once and for all would makes for less code changes too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

specific errors

Unclear to me what those errors are.

only once

Unclear to me how to do that without locking.

Copy link
Contributor

Choose a reason for hiding this comment

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

specific errors -> 404 or other if gitlab returnssomething special for missing endpoints
only once -> do we have a way to atomically replace a pointer ?

@enj
Copy link
Contributor Author

enj commented Jun 11, 2018

@simo5 @liggitt with regards to https://gitlab.com/gitlab-org/gitlab-ce/issues/47565#note_80751232 and https://trello.com/c/DXntmEOV we may want to consider deprecating the use of older versions of GitLab and move the internal code to OIDC (and probably just closing this PR).

@liggitt
Copy link
Contributor

liggitt commented Jun 11, 2018

@simo5 @liggitt with regards to https://gitlab.com/gitlab-org/gitlab-ce/issues/47565#note_80751232 and https://trello.com/c/DXntmEOV we may want to consider deprecating the use of older versions of GitLab and move the internal code to OIDC (and probably just closing this PR).

If gitlab supports oidc, and we can pull matching identity info out of its userinfo/token claims, we should definitely collapse onto that rather than updating this. Documenting this is only for the v3 API seems fine to me

@simo5 simo5 removed request for adelton and deads2k June 11, 2018 19:08
@simo5
Copy link
Contributor

simo5 commented Jun 11, 2018

@enj can we use the OIDC plugin without needing any other infrastructure work ?

@enj
Copy link
Contributor Author

enj commented Jun 13, 2018

Per https://gitlab.com/gitlab-org/gitlab-ce/issues/47791#note_81269161 GitLab 11.1 will have OIDC support that works for OpenShift. @simo5 @liggitt how should we go about deprecating the use of older versions of GitLab?

cc @kalexand-rh

@enj
Copy link
Contributor Author

enj commented Jun 13, 2018

See #19997

@enj
Copy link
Contributor Author

enj commented Jun 13, 2018

Let us continue any discussion on #19997

@enj enj closed this Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. sig/security size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants