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 securityDefinitions to the generated OpenAPI spec #14745

Merged
merged 4 commits into from
Jun 30, 2017

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Jun 19, 2017

Fixes #14268

@simo5 simo5 assigned enj and simo5 Jun 19, 2017
@simo5 simo5 requested a review from enj June 19, 2017 13:38
Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

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

Add OAuth2 bits, remove x509 I guess...

}
}
if configapi.UseTLS(config.ServingInfo.ServingInfo) {
// TODO: How is this represented ?
Copy link
Contributor

Choose a reason for hiding this comment

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

So based on http://swagger.io/specification/#securityDefinitionsObject I would have to say there is no way to assert our use of x509 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not supported indeed:
OAI/OpenAPI-Specification#1004

@@ -642,7 +642,22 @@ func BuildKubernetesMasterConfig(
return kmaster, nil
}

func DefaultOpenAPIConfig() *openapicommon.Config {
func DefaultOpenAPIConfig(config configapi.MasterConfig) *openapicommon.Config {
securityDefinitions := spec.SecurityDefinitions{}
Copy link
Contributor

Choose a reason for hiding this comment

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

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 sure where to source the right info, for example about flow type and scopes, and no other code in the origin repo uses the oauth2 type yet, it seem any outh based on any kind of token is defined just as an apikey bearer token...

SecuritySchemeProps: spec.SecuritySchemeProps{
Type: "oauth2",
Flow: "accessCode",
AuthorizationURL: config.OAuthConfig.MasterURL + "/oauth/authorize",
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 I want to use config.OAuthConfig.MasterURL here because then it is easy for generated code to not line up between local env and Jenkins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what should we use ?
Initially I have MasterPublicURL, but it seems you object to use these variables completely ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this would work (hopefully there is not an import cycle):

...
AuthorizationURL: OpenShiftOAuthAuthorizeURL("https://localhost:8443"),
TokenURL: OpenShiftOAuthTokenURL("https://localhost:8443"),
...

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I thought about this some more and we should be able to use the variables. We just need to make sure that the Swagger generation script always starts a server on localhost.

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 the script should start a server ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We end up in an import cycle if I try to import pkg/cmd/server/origin in order to access auth.OpenShiftOAuthAuthorizeURL ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why the script should start a server ?

hack/update-generated-swagger-spec.sh must build the swagger spec from a running server (there is no other way to get its final runtime state). The script already uses 127.0.0.1 so you are good to use the variables.

@@ -654,6 +654,16 @@ func DefaultOpenAPIConfig(config configapi.MasterConfig) *openapicommon.Config {
},
}
}
if config.OAuthConfig != nil {
securityDefinitions["Oauth2AccessToken"] = &spec.SecurityScheme{
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect to see all flows from #10845 (comment):

root@test:/# curl -k https://openshift.default.svc/.well-known/oauth-authorization-server
{
  "issuer": "https://10.13.129.56:8443",
  "authorization_endpoint": "https://10.13.129.56:8443/oauth/authorize",
  "token_endpoint": "https://10.13.129.56:8443/oauth/token",
  "scopes_supported": [
    "user:full",
    "user:info",
    "user:check-access",
    "user:list-scoped-projects",
    "user:list-projects"
  ],
  "response_types_supported": [
    "code",
    "token"
  ],
  "grant_types_supported": [
    "authorization_code",
    "implicit"
  ],
  "code_challenge_methods_supported": [
    "plain",
    "S256"
  ]
}

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 do not see any flows defined in that PR ?

Copy link
Contributor

Choose a reason for hiding this comment

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

implicit and accessCode (each with the scopes and URLs).

@@ -0,0 +1,22 @@
package util
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to pkg/oauth/util/util.go or maybe combine with pkg/oauth/discovery/discovery.go.

}
if configapi.UseTLS(config.ServingInfo.ServingInfo) {
// No support in Swagger's OpenAPI sepc v.2 ¯\_(ツ)_/¯
// TODO: Add x509 specification once available
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a separate GitHub issue to track this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@simo5 tag the issue you opened here.

@@ -135,6 +135,16 @@ const (
UserFull = UserIndicator + "full"
)

func DefaultSupportedScopes() []string {
return []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this list a private var and have this function return it (convention we use everywhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

for _, s := range scope.DefaultSupportedScopes() {
defScopes[s] = ""
}
securityDefinitions["Oauth2Immediate"] = &spec.SecurityScheme{
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did Immediate 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.

Word salads from my brain

UserFull: `Full read/write access with all of your permissions`,
}

func DefaultSupportedScopes() []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need this to have a consistent order so use return sets.StringKeySet(defaultSupportedScopesMap).List() (you can store this as a variable if you want to).

sets = "k8s.io/apimachinery/pkg/util/sets"

@@ -154,15 +176,15 @@ func (userEvaluator) Validate(scope string) error {
func (userEvaluator) Describe(scope string) (string, string, error) {
switch scope {
case UserInfo:
return "Read-only access to your user information (including username, identities, and group membership)", "", nil
return defaultSupportedScopesMap[UserInfo], "", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Collapse the first four cases since they are the same and use defaultSupportedScopesMap[scope] for all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed a commit for this

scope.UserListAllProjects,
},
// Note: this list is incomplete, which is allowed per the draft spec
ScopesSupported: scope.DefaultSupportedScopes(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You will have to update the unit test if the order of the scopes changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and another for this

}
}
},
"security": [
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 curious what this is trying to convey...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no idea

@simo5
Copy link
Contributor Author

simo5 commented Jun 21, 2017

combined pkg/oauth/util/util.go and pkg/oauth/discovery/discovery.go under a new pkg/oauth/util including a url.go and a discovery.go files

@@ -154,15 +177,15 @@ func (userEvaluator) Validate(scope string) error {
func (userEvaluator) Describe(scope string) (string, string, error) {
switch scope {
case UserInfo:
return "Read-only access to your user information (including username, identities, and group membership)", "", nil
fallthrough
Copy link
Contributor

Choose a reason for hiding this comment

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

case UserFull, UserAccessCheck, ...: (no fallthrough please)

return sets.StringKeySet(defaultSupportedScopesMap).List()
// scopes := make([]string, len(defaultSupportedScopesMap))
// i := 0
// for k := range defaultSupportedScopesMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

@@ -38,19 +38,14 @@ type OauthAuthorizationServerMetadata struct {
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
}

func Get(masterPublicURL, authorizeURL, tokenURL string) OauthAuthorizationServerMetadata {
func GetOauthMetadata(masterPublicURL, authorizeURL, tokenURL string) OauthAuthorizationServerMetadata {
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to just take masterPublicURL and use the helpers inside.

@@ -11,7 +11,7 @@ import (

"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
"github.com/openshift/origin/pkg/cmd/util/plug"
"github.com/openshift/origin/pkg/oauth/discovery"
"github.com/openshift/origin/pkg/oauth/util"
Copy link
Contributor

@enj enj Jun 21, 2017

Choose a reason for hiding this comment

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

Call it oauthutil like the rest of the imports.

@simo5 simo5 force-pushed the issue/14268 branch 2 times, most recently from 4260fd6 to 266ab70 Compare June 21, 2017 17:07
@simo5
Copy link
Contributor Author

simo5 commented Jun 21, 2017

With this latest push/rebase I thikn I have addressed all the concerns.

@enj
Copy link
Contributor

enj commented Jun 21, 2017

[test]

@@ -8,7 +8,7 @@ import (
)

func TestGet(t *testing.T) {
actual := Get("https://localhost:8443", "https://localhost:8443/oauth/authorize", "https://localhost:8443/oauth/token")
actual := GetOauthMetadata("https://localhost:8443")
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalize the A in OAuth: GetOauthMetadata -> GetOAuthMetadata (sorry I missed this earlier)

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, this is consistent with the containing file and the whole code base is really inconsistent on this anyway.

@enj enj changed the title [WIP] Add securityDefinitions to the generated OpenAPI spec Add securityDefinitions to the generated OpenAPI spec Jun 21, 2017
@enj enj unassigned simo5 Jun 21, 2017
@enj
Copy link
Contributor

enj commented Jun 21, 2017

@simo5 please fix the failing test: github.com/openshift/origin/pkg/oauth/util.TestGet

@enj
Copy link
Contributor

enj commented Jun 22, 2017

cc @liggitt in case you want to take a look as well.

@simo5 simo5 force-pushed the issue/14268 branch 2 times, most recently from dc07994 to 8a01a78 Compare June 22, 2017 17:34
@enj
Copy link
Contributor

enj commented Jun 23, 2017

@caseyfw are you able to test this?

cc @openshift/security

@enj
Copy link
Contributor

enj commented Jun 26, 2017

@simo5 master is open again so I can tag this if you fix the conflicts.

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2017
@simo5
Copy link
Contributor Author

simo5 commented Jun 27, 2017

Rebased

@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 27, 2017
@enj enj removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2017
@enj
Copy link
Contributor

enj commented Jun 28, 2017

@simo5 you will have to rebase on top of master again and then regenerate again since the spec changed for other reasons.

Also add helper function to return scope:description map used in a later commit

Signed-off-by: Simo Sorce <simo@redhat.com>
In preparation of future patches where we need to access these helpers
without causing an import cycle

Signed-off-by: Simo Sorce <simo@redhat.com>
Signed-off-by: Simo Sorce <simo@redhat.com>
Signed-off-by: Simo Sorce <simo@redhat.com>
@simo5
Copy link
Contributor Author

simo5 commented Jun 28, 2017

Rebased once again, let's hope this time it will stick

@simo5
Copy link
Contributor Author

simo5 commented Jun 28, 2017

FWIW: for some reason I had to git clean -f -x -d -f and then make again, only then the swagger update script generated some changes ...

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to b088faa

@enj
Copy link
Contributor

enj commented Jun 28, 2017

[merge] failures are unrelated flakes.

@simo5 please tag the flakes so we can track them.

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/2746/) (Base Commit: 6bbad88) (PR Branch Commit: b088faa)

@simo5
Copy link
Contributor Author

simo5 commented Jun 28, 2017

flaked on #14878

@simo5
Copy link
Contributor Author

simo5 commented Jun 28, 2017

flaked on #14043

@simo5
Copy link
Contributor Author

simo5 commented Jun 30, 2017

merge flaked on #14897

@enj
Copy link
Contributor

enj commented Jun 30, 2017

re[merge] flaked on #14897

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to b088faa

@openshift-bot
Copy link
Contributor

openshift-bot commented Jun 30, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/1189/) (Base Commit: 7004e83) (PR Branch Commit: b088faa) (Image: devenv-rhel7_6416)

@openshift-bot openshift-bot merged commit 848f52e into openshift:master Jun 30, 2017
@enj
Copy link
Contributor

enj commented Jun 30, 2017

@simo5 congrats \o/

@@ -27,6 +27,7 @@ import (
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/server/crypto"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
oauthutil "github.com/openshift/origin/pkg/oauth/util"
Copy link
Contributor

Choose a reason for hiding this comment

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

This package dependency was previously excluded intentionally. The asset server should not depend on the oauth package at all. The two are logically independent.

@ioggstream
Copy link

FYI @simo5 we just merged mutualTLS in OAS3.1. Still we didn't add further specs as we didn't find an agreement on the description model. A proposal could be very interesting though.

@simo5
Copy link
Contributor Author

simo5 commented Feb 11, 2019

@mrogers950 or @enj can you take a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants