Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/operator2/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *authOperator) handleConsoleConfig() *configv1.Console {
// technically this should be an observed config loop
consoleConfig, err := c.console.Get(globalConfigName, metav1.GetOptions{})
if err != nil {
// FIXME: fix when the console team starts using this
glog.Infof("error getting console config: %v", err)
return &configv1.Console{}
}
return consoleConfig
Expand Down
19 changes: 19 additions & 0 deletions pkg/operator2/infrastructure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package operator2

import (
"github.com/golang/glog"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

configv1 "github.com/openshift/api/config/v1"
)

func (c *authOperator) handleInfrastructureConfig() *configv1.Infrastructure {
infrastructureConfig, err := c.infrastructure.Get(globalConfigName, metav1.GetOptions{})
if err != nil {
glog.Infof("error getting infrastructure config: %v", err)
// have a placeholder that will at least look reasonable in the token request endpoint
return &configv1.Infrastructure{Status: configv1.InfrastructureStatus{APIServerURL: "<api_server_url>"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't the invalid URL just break osin later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Osin just prints the value; it does not parse it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I guess that's fine, thanks.

}
return infrastructureConfig
}
38 changes: 6 additions & 32 deletions pkg/operator2/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,23 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/golang/glog"

configv1 "github.com/openshift/api/config/v1"
kubecontrolplanev1 "github.com/openshift/api/kubecontrolplane/v1"
operatorv1 "github.com/openshift/api/operator/v1"
osinv1 "github.com/openshift/api/osin/v1"
routev1 "github.com/openshift/api/route/v1"
"github.com/openshift/library-go/pkg/crypto"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
)

// TODO this code dies once we get our own CLI config
var (
kubeControlplaneScheme = runtime.NewScheme()
kubeControlplaneCodecs = serializer.NewCodecFactory(kubeControlplaneScheme)
kubeControlplaneEncoder = kubeControlplaneCodecs.LegacyCodec(kubecontrolplanev1.GroupVersion) // TODO I think there is a better way to do this
)

func init() {
utilruntime.Must(kubecontrolplanev1.Install(kubeControlplaneScheme))
}

func (c *authOperator) handleOAuthConfig(
operatorConfig *operatorv1.Authentication,
route *routev1.Route,
service *corev1.Service,
consoleConfig *configv1.Console,
infrastructureConfig *configv1.Infrastructure,
) (
*configv1.OAuth,
*corev1.ConfigMap,
Expand Down Expand Up @@ -93,8 +80,7 @@ func (c *authOperator) handleOAuthConfig(

assetPublicURL, corsAllowedOrigins := consoleToDeploymentData(consoleConfig)

// TODO this pretends this is an OsinServerConfig
cliConfig := &kubecontrolplanev1.KubeAPIServerConfig{
cliConfig := &osinv1.OsinServerConfig{
GenericAPIServerConfig: configv1.GenericAPIServerConfig{
ServingInfo: configv1.HTTPServingInfo{
ServingInfo: configv1.ServingInfo{
Expand Down Expand Up @@ -123,15 +109,11 @@ func (c *authOperator) handleOAuthConfig(
},
},
},
OAuthConfig: &osinv1.OAuthConfig{
MasterCA: getMasterCA(), // we have valid serving certs provided by service-ca so we can use the service for loopback
// TODO osin's code needs to be updated to properly use these values
// it should use MasterURL in almost all places except the token request endpoint
// which needs to direct the user to the real public URL (MasterPublicURL)
// that means we still need to get that value from the installer's config
// TODO ask installer team to make it easier to get that URL
OAuthConfig: osinv1.OAuthConfig{
MasterCA: getMasterCA(), // we have valid serving certs provided by service-ca so we can use the service for loopback
MasterURL: fmt.Sprintf("https://%s.%s.svc", service.Name, service.Namespace),
MasterPublicURL: fmt.Sprintf("https://%s", route.Spec.Host),
LoginURL: infrastructureConfig.Status.APIServerURL,
AssetPublicURL: assetPublicURL, // set console route as valid 302 redirect for logout
AlwaysShowProviderSelection: false,
IdentityProviders: identityProviders,
Expand All @@ -153,7 +135,7 @@ func (c *authOperator) handleOAuthConfig(
},
}

cliConfigBytes := encodeOrDieKubeControlplane(cliConfig)
cliConfigBytes := encodeOrDie(cliConfig)

completeConfigBytes, err := resourcemerge.MergeProcessConfig(nil, cliConfigBytes, operatorConfig.Spec.UnsupportedConfigOverrides.Raw)
if err != nil {
Expand All @@ -179,11 +161,3 @@ func getMasterCA() *string {
ca := serviceCAPath // need local var to be able to take address of it
return &ca
}

func encodeOrDieKubeControlplane(obj runtime.Object) []byte {
bytes, err := runtime.Encode(kubeControlplaneEncoder, obj)
if err != nil {
panic(err) // indicates static generated code is broken, unrecoverable
}
return bytes
}
8 changes: 7 additions & 1 deletion pkg/operator2/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type authOperator struct {
authentication configv1client.AuthenticationInterface
oauth configv1client.OAuthInterface
console configv1client.ConsoleInterface
infrastructure configv1client.InfrastructureInterface

resourceSyncer resourcesynccontroller.ResourceSyncer
}
Expand Down Expand Up @@ -120,6 +121,7 @@ func NewAuthenticationOperator(
authentication: configClient.ConfigV1().Authentications(),
oauth: configClient.ConfigV1().OAuths(),
console: configClient.ConfigV1().Consoles(),
infrastructure: configClient.ConfigV1().Infrastructures(),

resourceSyncer: resourceSyncer,
}
Expand All @@ -143,6 +145,7 @@ func NewAuthenticationOperator(
operator.WithInformer(configV1Informers.Authentications(), configNameFilter),
operator.WithInformer(configV1Informers.OAuths(), configNameFilter),
operator.WithInformer(configV1Informers.Consoles(), configNameFilter, controller.WithNoSync()),
operator.WithInformer(configV1Informers.Infrastructures(), configNameFilter, controller.WithNoSync()),
)
}

Expand Down Expand Up @@ -235,7 +238,10 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
consoleConfig := c.handleConsoleConfig()
resourceVersions = append(resourceVersions, consoleConfig.GetResourceVersion())

oauthConfig, expectedCLIconfig, syncData, err := c.handleOAuthConfig(operatorConfig, route, service, consoleConfig)
infrastructureConfig := c.handleInfrastructureConfig()
resourceVersions = append(resourceVersions, infrastructureConfig.GetResourceVersion())

oauthConfig, expectedCLIconfig, syncData, err := c.handleOAuthConfig(operatorConfig, route, service, consoleConfig, infrastructureConfig)
if err != nil {
return err
}
Expand Down