-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
/unassign |
@enj PTAL |
pkg/cmd/server/origin/master.go
Outdated
@@ -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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better message
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved things around
pkg/oauth/util/discovery.go
Outdated
return oAuthMetadata, fmt.Errorf("Unable to decode External OAuth Metadata file: %v", err) | ||
} | ||
|
||
return oAuthMetadata, nil |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ok
cd0189c
to
88f4c48
Compare
/retest |
fd512ee
to
495bc22
Compare
Integration test is broken, uploaded so @enj can take a look as the suggestion to use two clusters in one test was his |
@enj finally the fully mocked integration test seem to be working, PTAL |
/retest |
2 similar comments
/retest |
/retest |
@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 |
pkg/cmd/server/apis/config/types.go
Outdated
// 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 |
There was a problem hiding this comment.
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.
pkg/cmd/server/apis/config/types.go
Outdated
@@ -871,6 +875,13 @@ type OAuthTemplates struct { | |||
Error string | |||
} | |||
|
|||
type ExternalOAuthConfig struct { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
// 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"` |
There was a problem hiding this comment.
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.
pkg/cmd/server/apis/config/types.go
Outdated
// 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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
api approved. |
Signed-off-by: Simo Sorce <[email protected]>
Signed-off-by: Simo Sorce <[email protected]>
/lgtm |
[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 |
/hold cancel |
/retest Please review the full test history for this PR and help us cut down flakes. |
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.