Skip to content

Add securityDefinitions to the generated OpenAPI spec - #14745

Merged
openshift-bot merged 4 commits into
openshift:masterfrom
simo5:issue/14268
Jun 30, 2017
Merged

openshift-bot merged 4 commits into
openshift:masterfrom
simo5:issue/14268

Conversation

@simo5

@simo5 simo5 commented Jun 19, 2017 •

Copy link
Copy Markdown

Fixes #14268

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

@enj enj left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

}
}
if config.OAuthConfig != nil {
securityDefinitions["Oauth2AccessToken"] = &spec.SecurityScheme{

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

Comment thread pkg/cmd/util/oauth.go
@@ -0,0 +1,22 @@
package util

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

)

func DefaultSupportedScopes() []string {
return []string{

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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"

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

no idea

@simo5

simo5 commented Jun 21, 2017

Copy link
Copy Markdown
Author

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

switch scope {
case UserInfo:
return "Read-only access to your user information (including username, identities, and group membership)", "", nil
fallthrough

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove?

Comment thread pkg/oauth/util/discovery.go Outdated
}

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

Copy link
Copy Markdown
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.

Comment thread pkg/cmd/server/origin/nonapiserver.go Outdated
"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"

@enj enj Jun 21, 2017 •

Copy link
Copy Markdown
Contributor

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

simo5 commented Jun 21, 2017

Copy link
Copy Markdown
Author

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

@enj

enj commented Jun 21, 2017

Copy link
Copy Markdown
Contributor

[test]


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
Copy Markdown
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
Copy Markdown
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

enj commented Jun 21, 2017

Copy link
Copy Markdown
Contributor

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

@enj

enj commented Jun 22, 2017

Copy link
Copy Markdown
Contributor

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

enj commented Jun 23, 2017

Copy link
Copy Markdown
Contributor

@caseyfw are you able to test this?

cc @openshift/security

@enj

enj commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

@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

simo5 commented Jun 27, 2017

Copy link
Copy Markdown
Author

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

enj commented Jun 28, 2017

Copy link
Copy Markdown
Contributor

@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 <[email protected]>
In preparation of future patches where we need to access these helpers
without causing an import cycle

Signed-off-by: Simo Sorce <[email protected]>
Signed-off-by: Simo Sorce <[email protected]>
@simo5

simo5 commented Jun 28, 2017

Copy link
Copy Markdown
Author

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

@simo5

simo5 commented Jun 28, 2017

Copy link
Copy Markdown
Author

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
Copy Markdown
Contributor

Evaluated for origin test up to b088faa

@enj

enj commented Jun 28, 2017

Copy link
Copy Markdown
Contributor

[merge] failures are unrelated flakes.

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

@openshift-bot

Copy link
Copy Markdown
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

simo5 commented Jun 28, 2017

Copy link
Copy Markdown
Author

flaked on #14878

@simo5

simo5 commented Jun 28, 2017

Copy link
Copy Markdown
Author

flaked on #14043

@simo5

simo5 commented Jun 30, 2017

Copy link
Copy Markdown
Author

merge flaked on #14897

@enj

enj commented Jun 30, 2017

Copy link
Copy Markdown
Contributor

re[merge] flaked on #14897

@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin merge up to b088faa

@openshift-bot

openshift-bot commented Jun 30, 2017 •

Copy link
Copy Markdown
Contributor

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

enj commented Jun 30, 2017

Copy link
Copy Markdown
Contributor

@simo5 congrats \o/

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
Copy Markdown
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
Copy Markdown

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

simo5 commented Feb 11, 2019

Copy link
Copy Markdown
Author

@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.

6 participants