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

Add option to configure an external OAuth server #18969

Merged
merged 2 commits into from
Apr 2, 2018

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Mar 13, 2018

This helps replacing our internal Oauth Server with an external one.
REquires a metadata file to be generated by the external OAuth server and be provided for config.

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 13, 2018
@simo5 simo5 added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 13, 2018
@juanvallejo
Copy link
Contributor

/unassign

@simo5
Copy link
Contributor Author

simo5 commented Mar 13, 2018

@enj PTAL

enj
enj previously requested changes Mar 14, 2018
@@ -84,12 +84,15 @@ func (c *MasterConfig) newOpenshiftNonAPIConfig(kubeAPIServerConfig apiserver.Co
SharedInformerFactory: c.ClientGoKubeInformers,
},
ExtraConfig: NonAPIExtraConfig{
EnableOAuth: c.Options.OAuthConfig != nil,
EnableOAuth: c.Options.OAuthConfig != nil || c.Options.ExternalOAuthConfig != nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

undo this

@@ -60,7 +61,7 @@ func (c completedOpenshiftNonAPIConfig) New(delegationTarget genericapiserver.De
// TODO move this up to the spot where we wire the oauth endpoint
// Set up OAuth metadata only if we are configured to use OAuth
if c.ExtraConfig.EnableOAuth {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead have this also check the length of the metadata file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is this better ?
Validation already checks the lenght of the metadata file you can't run if it is 0

var err error
oAuthMetadata, err = oauthutil.DecodeOAuthMetadataFile(ExtraConfig.OAuthMetadataFile)
if err != nil {
glog.Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Better message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The message is already provided by DecodeOAuthMetadataFile() I do not see why we need to re-wrap it, there is nothing to add really.

if err != nil {
glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err)
return
}

mux.UnlistedHandleFunc(path, func(w http.ResponseWriter, req *http.Request) {
mux.UnlistedHandleFunc(oauthMetadataEndpoint, func(w http.ResponseWriter, req *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why you removed the path.

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 moved things around

return oAuthMetadata, fmt.Errorf("Unable to decode External OAuth Metadata file: %v", err)
}

return oAuthMetadata, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs validation on the actual fields


if len(ExtraConfig.OAuthMetadataFile) > 0 {
var err error
oAuthMetadata, err = oauthutil.DecodeOAuthMetadataFile(ExtraConfig.OAuthMetadataFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if it makes more sense to literally return the file data the user provided after it has passed validation. Then they could include extra fields that osin does not support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhmm, that may be a good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking more about this, I do not see how you can put more data without failing to unmarshal the json for verification. So I'll just add fields validation now.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is not how unmarshalling works. Unknown fields are always ignored. Otherwise you could never add a new field to any serialized object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, ok

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 14, 2018
@simo5 simo5 requested review from deads2k and removed request for juanvallejo March 15, 2018 14:21
@simo5 simo5 force-pushed the noauthsrv branch 2 times, most recently from cd0189c to 88f4c48 Compare March 15, 2018 20:37
@simo5
Copy link
Contributor Author

simo5 commented Mar 16, 2018

/retest

@simo5 simo5 force-pushed the noauthsrv branch 2 times, most recently from fd512ee to 495bc22 Compare March 19, 2018 17:41
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 19, 2018
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 19, 2018
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 19, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 23, 2018

Integration test is broken, uploaded so @enj can take a look as the suggestion to use two clusters in one test was his

@simo5
Copy link
Contributor Author

simo5 commented Mar 27, 2018

@enj finally the fully mocked integration test seem to be working, PTAL

@stevekuznetsov
Copy link
Contributor

/retest

2 similar comments
@stevekuznetsov
Copy link
Contributor

/retest

@simo5
Copy link
Contributor Author

simo5 commented Mar 27, 2018

/retest

@simo5 simo5 added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 29, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 29, 2018

@deads2k we discussed about always using a file for oauth metadata, however I think the new PrepOauthMetadata() function I added is a reasonable compromise for 3.10, PTAL

// MetadataFile is a path to a file containing the discovery endpoint for OAuth 2.0 Authorization Server Metadata
// for an External OAuth server.
// See IETF Draft: // https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-2
MetadataFile string
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this field is fine.

@@ -871,6 +875,13 @@ type OAuthTemplates struct {
Error string
}

type ExternalOAuthConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

@liggitt you ready to start an AuthenticationConfig or shall we wait until we split configs and just a little more ugly here? I don't feel strongly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want me to move this under MasterAuthConfig like for the WebToken stuff ?
Wasn't sure this was appropriate.

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 can have a simple ExternalOAuthMetadataFile string in there and avoid a new structure

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 2, 2018
// OAuthMetadataFile is a path to a file containing the discovery endpoint for OAuth 2.0 Authorization
// Server Metadata for an external OAuth server.
// See IETF Draft: // https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-2
OAuthMetadataFile string `json:"oauthMetadataFile"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this is optional and mutually exclusive in the doc.

// OAuthMetadataFile is a path to a file containing the discovery endpoint for OAuth 2.0 Authorization
// Server Metadata for an external OAuth server.
// See IETF Draft: // https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-2
OAuthMetadataFile string
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to update GetMasterFileReferences? I don't see it.

@@ -171,6 +174,12 @@ func ValidateMasterConfig(config *configapi.MasterConfig, fldPath *field.Path) V
func ValidateMasterAuthConfig(config configapi.MasterAuthConfig, fldPath *field.Path) ValidationResults {
validationResults := ValidationResults{}

if len(config.OAuthMetadataFile) > 0 {
if _, _, err := oauthutil.LoadOAuthMetadataFile(config.OAuthMetadataFile); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check has made the oauthmetadatafile format part of our API. Make a TODO to fix the package dependency order and promote the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in discovery.go, I have a card to deal with this as a followup

@simo5
Copy link
Contributor Author

simo5 commented Apr 2, 2018

@deads2k @enj this last push should fix all nits, PTAL

@deads2k
Copy link
Contributor

deads2k commented Apr 2, 2018

api approved.

@enj
Copy link
Contributor

enj commented Apr 2, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 2, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enj, simo5

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 Apr 2, 2018
@enj
Copy link
Contributor

enj commented Apr 2, 2018

/hold cancel

@simo5 simo5 removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 2, 2018
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 5213e07 into openshift:master Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. needs-api-review size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants