Merge pull request #215 from mattmoyer/fix-upstream-oidc-provider

Fix some issues in the UpstreamOIDCProvider CRD and controller
This commit is contained in:
Matt Moyer 2020-11-13 17:23:10 -06:00 committed by GitHub
commit 84b61fac88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 29 additions and 39 deletions

View File

@ -16,7 +16,7 @@ const (
// PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state. // PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state.
PhaseReady UpstreamOIDCProviderPhase = "Ready" PhaseReady UpstreamOIDCProviderPhase = "Ready"
// PhaseErorr is the phase for an UpstreamOIDCProvider in an unhealthy state. // PhaseError is the phase for an UpstreamOIDCProvider in an unhealthy state.
PhaseError UpstreamOIDCProviderPhase = "Error" PhaseError UpstreamOIDCProviderPhase = "Error"
) )
@ -40,6 +40,7 @@ type UpstreamOIDCProviderStatus struct {
type OIDCAuthorizationConfig struct { type OIDCAuthorizationConfig struct {
// AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization // AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization
// request flow with an OIDC identity provider. By default only the "openid" scope will be requested. // request flow with an OIDC identity provider. By default only the "openid" scope will be requested.
// +optional
AdditionalScopes []string `json:"additionalScopes"` AdditionalScopes []string `json:"additionalScopes"`
} }
@ -47,10 +48,12 @@ type OIDCAuthorizationConfig struct {
type OIDCClaims struct { type OIDCClaims struct {
// Groups provides the name of the token claim that will be used to ascertain the groups to which // Groups provides the name of the token claim that will be used to ascertain the groups to which
// an identity belongs. // an identity belongs.
// +optional
Groups string `json:"groups"` Groups string `json:"groups"`
// Username provides the name of the token claim that will be used to ascertain an identity's // Username provides the name of the token claim that will be used to ascertain an identity's
// username. // username.
// +optional
Username string `json:"username"` Username string `json:"username"`
} }
@ -74,10 +77,12 @@ type UpstreamOIDCProviderSpec struct {
// AuthorizationConfig holds information about how to form the OAuth2 authorization request // AuthorizationConfig holds information about how to form the OAuth2 authorization request
// parameters to be used with this OIDC identity provider. // parameters to be used with this OIDC identity provider.
// +optional
AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"` AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"`
// Claims provides the names of token claims that will be used when inspecting an identity from // Claims provides the names of token claims that will be used when inspecting an identity from
// this OIDC identity provider. // this OIDC identity provider.
// +optional
Claims OIDCClaims `json:"claims"` Claims OIDCClaims `json:"claims"`
// OIDCClient contains OIDC client information to be used used with this OIDC identity // OIDCClient contains OIDC client information to be used used with this OIDC identity

View File

@ -64,8 +64,6 @@ spec:
items: items:
type: string type: string
type: array type: array
required:
- additionalScopes
type: object type: object
claims: claims:
description: Claims provides the names of token claims that will be description: Claims provides the names of token claims that will be
@ -79,9 +77,6 @@ spec:
description: Username provides the name of the token claim that description: Username provides the name of the token claim that
will be used to ascertain an identity's username. will be used to ascertain an identity's username.
type: string type: string
required:
- groups
- username
type: object type: object
client: client:
description: OIDCClient contains OIDC client information to be used description: OIDCClient contains OIDC client information to be used
@ -104,8 +99,6 @@ spec:
pattern: ^https:// pattern: ^https://
type: string type: string
required: required:
- authorizationConfig
- claims
- client - client
- issuer - issuer
type: object type: object

View File

@ -16,7 +16,7 @@ const (
// PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state. // PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state.
PhaseReady UpstreamOIDCProviderPhase = "Ready" PhaseReady UpstreamOIDCProviderPhase = "Ready"
// PhaseErorr is the phase for an UpstreamOIDCProvider in an unhealthy state. // PhaseError is the phase for an UpstreamOIDCProvider in an unhealthy state.
PhaseError UpstreamOIDCProviderPhase = "Error" PhaseError UpstreamOIDCProviderPhase = "Error"
) )
@ -40,6 +40,7 @@ type UpstreamOIDCProviderStatus struct {
type OIDCAuthorizationConfig struct { type OIDCAuthorizationConfig struct {
// AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization // AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization
// request flow with an OIDC identity provider. By default only the "openid" scope will be requested. // request flow with an OIDC identity provider. By default only the "openid" scope will be requested.
// +optional
AdditionalScopes []string `json:"additionalScopes"` AdditionalScopes []string `json:"additionalScopes"`
} }
@ -47,10 +48,12 @@ type OIDCAuthorizationConfig struct {
type OIDCClaims struct { type OIDCClaims struct {
// Groups provides the name of the token claim that will be used to ascertain the groups to which // Groups provides the name of the token claim that will be used to ascertain the groups to which
// an identity belongs. // an identity belongs.
// +optional
Groups string `json:"groups"` Groups string `json:"groups"`
// Username provides the name of the token claim that will be used to ascertain an identity's // Username provides the name of the token claim that will be used to ascertain an identity's
// username. // username.
// +optional
Username string `json:"username"` Username string `json:"username"`
} }
@ -74,10 +77,12 @@ type UpstreamOIDCProviderSpec struct {
// AuthorizationConfig holds information about how to form the OAuth2 authorization request // AuthorizationConfig holds information about how to form the OAuth2 authorization request
// parameters to be used with this OIDC identity provider. // parameters to be used with this OIDC identity provider.
// +optional
AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"` AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"`
// Claims provides the names of token claims that will be used when inspecting an identity from // Claims provides the names of token claims that will be used when inspecting an identity from
// this OIDC identity provider. // this OIDC identity provider.
// +optional
Claims OIDCClaims `json:"claims"` Claims OIDCClaims `json:"claims"`
// OIDCClient contains OIDC client information to be used used with this OIDC identity // OIDCClient contains OIDC client information to be used used with this OIDC identity

View File

@ -64,8 +64,6 @@ spec:
items: items:
type: string type: string
type: array type: array
required:
- additionalScopes
type: object type: object
claims: claims:
description: Claims provides the names of token claims that will be description: Claims provides the names of token claims that will be
@ -79,9 +77,6 @@ spec:
description: Username provides the name of the token claim that description: Username provides the name of the token claim that
will be used to ascertain an identity's username. will be used to ascertain an identity's username.
type: string type: string
required:
- groups
- username
type: object type: object
client: client:
description: OIDCClient contains OIDC client information to be used description: OIDCClient contains OIDC client information to be used
@ -104,8 +99,6 @@ spec:
pattern: ^https:// pattern: ^https://
type: string type: string
required: required:
- authorizationConfig
- claims
- client - client
- issuer - issuer
type: object type: object

View File

@ -16,7 +16,7 @@ const (
// PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state. // PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state.
PhaseReady UpstreamOIDCProviderPhase = "Ready" PhaseReady UpstreamOIDCProviderPhase = "Ready"
// PhaseErorr is the phase for an UpstreamOIDCProvider in an unhealthy state. // PhaseError is the phase for an UpstreamOIDCProvider in an unhealthy state.
PhaseError UpstreamOIDCProviderPhase = "Error" PhaseError UpstreamOIDCProviderPhase = "Error"
) )
@ -40,6 +40,7 @@ type UpstreamOIDCProviderStatus struct {
type OIDCAuthorizationConfig struct { type OIDCAuthorizationConfig struct {
// AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization // AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization
// request flow with an OIDC identity provider. By default only the "openid" scope will be requested. // request flow with an OIDC identity provider. By default only the "openid" scope will be requested.
// +optional
AdditionalScopes []string `json:"additionalScopes"` AdditionalScopes []string `json:"additionalScopes"`
} }
@ -47,10 +48,12 @@ type OIDCAuthorizationConfig struct {
type OIDCClaims struct { type OIDCClaims struct {
// Groups provides the name of the token claim that will be used to ascertain the groups to which // Groups provides the name of the token claim that will be used to ascertain the groups to which
// an identity belongs. // an identity belongs.
// +optional
Groups string `json:"groups"` Groups string `json:"groups"`
// Username provides the name of the token claim that will be used to ascertain an identity's // Username provides the name of the token claim that will be used to ascertain an identity's
// username. // username.
// +optional
Username string `json:"username"` Username string `json:"username"`
} }
@ -74,10 +77,12 @@ type UpstreamOIDCProviderSpec struct {
// AuthorizationConfig holds information about how to form the OAuth2 authorization request // AuthorizationConfig holds information about how to form the OAuth2 authorization request
// parameters to be used with this OIDC identity provider. // parameters to be used with this OIDC identity provider.
// +optional
AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"` AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"`
// Claims provides the names of token claims that will be used when inspecting an identity from // Claims provides the names of token claims that will be used when inspecting an identity from
// this OIDC identity provider. // this OIDC identity provider.
// +optional
Claims OIDCClaims `json:"claims"` Claims OIDCClaims `json:"claims"`
// OIDCClient contains OIDC client information to be used used with this OIDC identity // OIDCClient contains OIDC client information to be used used with this OIDC identity

View File

@ -64,8 +64,6 @@ spec:
items: items:
type: string type: string
type: array type: array
required:
- additionalScopes
type: object type: object
claims: claims:
description: Claims provides the names of token claims that will be description: Claims provides the names of token claims that will be
@ -79,9 +77,6 @@ spec:
description: Username provides the name of the token claim that description: Username provides the name of the token claim that
will be used to ascertain an identity's username. will be used to ascertain an identity's username.
type: string type: string
required:
- groups
- username
type: object type: object
client: client:
description: OIDCClient contains OIDC client information to be used description: OIDCClient contains OIDC client information to be used
@ -104,8 +99,6 @@ spec:
pattern: ^https:// pattern: ^https://
type: string type: string
required: required:
- authorizationConfig
- claims
- client - client
- issuer - issuer
type: object type: object

View File

@ -16,7 +16,7 @@ const (
// PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state. // PhaseReady is the phase for an UpstreamOIDCProvider resource in a healthy state.
PhaseReady UpstreamOIDCProviderPhase = "Ready" PhaseReady UpstreamOIDCProviderPhase = "Ready"
// PhaseErorr is the phase for an UpstreamOIDCProvider in an unhealthy state. // PhaseError is the phase for an UpstreamOIDCProvider in an unhealthy state.
PhaseError UpstreamOIDCProviderPhase = "Error" PhaseError UpstreamOIDCProviderPhase = "Error"
) )
@ -40,6 +40,7 @@ type UpstreamOIDCProviderStatus struct {
type OIDCAuthorizationConfig struct { type OIDCAuthorizationConfig struct {
// AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization // AdditionalScopes are the scopes in addition to "openid" that will be requested as part of the authorization
// request flow with an OIDC identity provider. By default only the "openid" scope will be requested. // request flow with an OIDC identity provider. By default only the "openid" scope will be requested.
// +optional
AdditionalScopes []string `json:"additionalScopes"` AdditionalScopes []string `json:"additionalScopes"`
} }
@ -47,10 +48,12 @@ type OIDCAuthorizationConfig struct {
type OIDCClaims struct { type OIDCClaims struct {
// Groups provides the name of the token claim that will be used to ascertain the groups to which // Groups provides the name of the token claim that will be used to ascertain the groups to which
// an identity belongs. // an identity belongs.
// +optional
Groups string `json:"groups"` Groups string `json:"groups"`
// Username provides the name of the token claim that will be used to ascertain an identity's // Username provides the name of the token claim that will be used to ascertain an identity's
// username. // username.
// +optional
Username string `json:"username"` Username string `json:"username"`
} }
@ -74,10 +77,12 @@ type UpstreamOIDCProviderSpec struct {
// AuthorizationConfig holds information about how to form the OAuth2 authorization request // AuthorizationConfig holds information about how to form the OAuth2 authorization request
// parameters to be used with this OIDC identity provider. // parameters to be used with this OIDC identity provider.
// +optional
AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"` AuthorizationConfig OIDCAuthorizationConfig `json:"authorizationConfig"`
// Claims provides the names of token claims that will be used when inspecting an identity from // Claims provides the names of token claims that will be used when inspecting an identity from
// this OIDC identity provider. // this OIDC identity provider.
// +optional
Claims OIDCClaims `json:"claims"` Claims OIDCClaims `json:"claims"`
// OIDCClient contains OIDC client information to be used used with this OIDC identity // OIDCClient contains OIDC client information to be used used with this OIDC identity

View File

@ -64,8 +64,6 @@ spec:
items: items:
type: string type: string
type: array type: array
required:
- additionalScopes
type: object type: object
claims: claims:
description: Claims provides the names of token claims that will be description: Claims provides the names of token claims that will be
@ -79,9 +77,6 @@ spec:
description: Username provides the name of the token claim that description: Username provides the name of the token claim that
will be used to ascertain an identity's username. will be used to ascertain an identity's username.
type: string type: string
required:
- groups
- username
type: object type: object
client: client:
description: OIDCClient contains OIDC client information to be used description: OIDCClient contains OIDC client information to be used
@ -104,8 +99,6 @@ spec:
pattern: ^https:// pattern: ^https://
type: string type: string
required: required:
- authorizationConfig
- claims
- client - client
- issuer - issuer
type: object type: object

View File

@ -9,7 +9,6 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"sort" "sort"
"strings"
"time" "time"
"github.com/coreos/go-oidc" "github.com/coreos/go-oidc"
@ -208,12 +207,11 @@ func (c *controller) validateIssuer(ctx context.Context, upstream *v1alpha1.Upst
var err error var err error
discoveredProvider, err = oidc.NewProvider(ctx, upstream.Spec.Issuer) discoveredProvider, err = oidc.NewProvider(ctx, upstream.Spec.Issuer)
if err != nil { if err != nil {
err := fmt.Errorf("failed to perform OIDC discovery against %q: %w", upstream.Spec.Issuer, err)
return &v1alpha1.Condition{ return &v1alpha1.Condition{
Type: typeOIDCDiscoverySucceeded, Type: typeOIDCDiscoverySucceeded,
Status: v1alpha1.ConditionFalse, Status: v1alpha1.ConditionFalse,
Reason: reasonUnreachable, Reason: reasonUnreachable,
Message: strings.TrimSpace(err.Error()), Message: fmt.Sprintf("failed to perform OIDC discovery against %q", upstream.Spec.Issuer),
} }
} }

View File

@ -208,8 +208,8 @@ func TestController(t *testing.T) {
wantErr: controllerlib.ErrSyntheticRequeue.Error(), wantErr: controllerlib.ErrSyntheticRequeue.Error(),
wantLogs: []string{ wantLogs: []string{
`upstream-observer "level"=0 "msg"="updated condition" "name"="test-name" "namespace"="test-namespace" "message"="loaded client credentials" "reason"="Success" "status"="True" "type"="ClientCredentialsValid"`, `upstream-observer "level"=0 "msg"="updated condition" "name"="test-name" "namespace"="test-namespace" "message"="loaded client credentials" "reason"="Success" "status"="True" "type"="ClientCredentialsValid"`,
`upstream-observer "level"=0 "msg"="updated condition" "name"="test-name" "namespace"="test-namespace" "message"="failed to perform OIDC discovery against \"invalid-url\": Get \"invalid-url/.well-known/openid-configuration\": unsupported protocol scheme \"\"" "reason"="Unreachable" "status"="False" "type"="OIDCDiscoverySucceeded"`, `upstream-observer "level"=0 "msg"="updated condition" "name"="test-name" "namespace"="test-namespace" "message"="failed to perform OIDC discovery against \"invalid-url\"" "reason"="Unreachable" "status"="False" "type"="OIDCDiscoverySucceeded"`,
`upstream-observer "error"="UpstreamOIDCProvider has a failing condition" "msg"="found failing condition" "message"="failed to perform OIDC discovery against \"invalid-url\": Get \"invalid-url/.well-known/openid-configuration\": unsupported protocol scheme \"\"" "name"="test-name" "namespace"="test-namespace" "reason"="Unreachable" "type"="OIDCDiscoverySucceeded"`, `upstream-observer "error"="UpstreamOIDCProvider has a failing condition" "msg"="found failing condition" "message"="failed to perform OIDC discovery against \"invalid-url\"" "name"="test-name" "namespace"="test-namespace" "reason"="Unreachable" "type"="OIDCDiscoverySucceeded"`,
}, },
wantResultingCache: []provider.UpstreamOIDCIdentityProvider{}, wantResultingCache: []provider.UpstreamOIDCIdentityProvider{},
wantResultingUpstreams: []v1alpha1.UpstreamOIDCProvider{{ wantResultingUpstreams: []v1alpha1.UpstreamOIDCProvider{{
@ -229,7 +229,7 @@ func TestController(t *testing.T) {
Status: "False", Status: "False",
LastTransitionTime: now, LastTransitionTime: now,
Reason: "Unreachable", Reason: "Unreachable",
Message: `failed to perform OIDC discovery against "invalid-url": Get "invalid-url/.well-known/openid-configuration": unsupported protocol scheme ""`, Message: `failed to perform OIDC discovery against "invalid-url"`,
}, },
}, },
}, },

View File

@ -42,7 +42,7 @@ func TestSupervisorUpstreamOIDCDiscovery(t *testing.T) {
Type: "OIDCDiscoverySucceeded", Type: "OIDCDiscoverySucceeded",
Status: v1alpha1.ConditionFalse, Status: v1alpha1.ConditionFalse,
Reason: "Unreachable", Reason: "Unreachable",
Message: `failed to perform OIDC discovery against "https://127.0.0.1:444444/issuer": Get "https://127.0.0.1:444444/issuer/.well-known/openid-configuration": dial tcp: address 444444: invalid port`, Message: `failed to perform OIDC discovery against "https://127.0.0.1:444444/issuer"`,
}, },
}) })
}) })