Skip to content

Commit 385261a

Browse files
authored
Merge pull request redpanda-data#6282 from pvsune/enterprise/pvsune/rp-console
Console Google SSO support in operator
2 parents 42b6d3a + 62be321 commit 385261a

25 files changed

+986
-107
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package v1alpha1
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
corev1 "k8s.io/api/core/v1"
8+
"sigs.k8s.io/controller-runtime/pkg/client"
9+
)
10+
11+
// SecretKeyRef contains enough information to inspect or modify the referred Secret data
12+
// REF https://pkg.go.dev/k8s.io/api/core/v1#ObjectReference
13+
type SecretKeyRef struct {
14+
// Name of the referent.
15+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
16+
Name string `json:"name"`
17+
18+
// Namespace of the referent.
19+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
20+
Namespace string `json:"namespace"`
21+
22+
// +optional
23+
// Key in Secret data to get value from
24+
Key string `json:"key,omitempty"`
25+
}
26+
27+
// GetSecret fetches the referenced Secret
28+
func (s *SecretKeyRef) GetSecret(ctx context.Context, cl client.Client) (*corev1.Secret, error) {
29+
secret := &corev1.Secret{}
30+
if err := cl.Get(ctx, client.ObjectKey{Namespace: s.Namespace, Name: s.Name}, secret); err != nil {
31+
return nil, fmt.Errorf("getting Secret %s/%s: %w", s.Namespace, s.Name, err)
32+
}
33+
return secret, nil
34+
}
35+
36+
// GetValue extracts the value from the specified key or default
37+
func (s *SecretKeyRef) GetValue(secret *corev1.Secret, defaultKey string) ([]byte, error) {
38+
key := s.Key
39+
if key == "" {
40+
key = defaultKey
41+
}
42+
43+
value, ok := secret.Data[key]
44+
if !ok {
45+
return nil, fmt.Errorf("getting value from Secret %s/%s: key %s not found", s.Namespace, s.Name, key) // nolint:goerr113 // no need to declare new error type
46+
}
47+
return value, nil
48+
}
49+
50+
// NamespaceNameRef contains namespace and name to inspect or modify the referred object
51+
// REF https://pkg.go.dev/k8s.io/api/core/v1#ObjectReference
52+
type NamespaceNameRef struct {
53+
// Name of the referent.
54+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
55+
Name string `json:"name"`
56+
57+
// Namespace of the referent.
58+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
59+
Namespace string `json:"namespace"`
60+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package v1alpha1
2+
3+
import corev1 "k8s.io/api/core/v1"
4+
5+
// Enterprise defines configurable fields for features that require license
6+
type Enterprise struct {
7+
// Console uses role-based access control (RBAC) to restrict system access to authorized users
8+
RBAC EnterpriseRBAC `json:"rbac"`
9+
}
10+
11+
// EnterpriseRBAC defines configurable fields for specifying RBAC Authorization
12+
type EnterpriseRBAC struct {
13+
Enabled bool `json:"enabled"`
14+
15+
// RoleBindingsRef is the ConfigMap that contains the RBAC file
16+
// The ConfigMap should contain "rbac.yaml" key
17+
RoleBindingsRef corev1.LocalObjectReference `json:"roleBindingsRef"`
18+
}
19+
20+
// EnterpriseLogin defines configurable fields to enable SSO Authentication for supported login providers
21+
type EnterpriseLogin struct {
22+
Enabled bool `json:"enabled"`
23+
24+
// JWTSecret is the Secret that is used to sign and encrypt the JSON Web tokens that are used by the backend for session management
25+
// If not provided, the default key is "jwt"
26+
JWTSecretRef SecretKeyRef `json:"jwtSecretRef"`
27+
28+
Google *EnterpriseLoginGoogle `json:"google,omitempty"`
29+
}
30+
31+
// IsGoogleLoginEnabled returns true if Google SSO provider is enabled
32+
func (c *Console) IsGoogleLoginEnabled() bool {
33+
login := c.Spec.Login
34+
return login != nil && login.Google != nil && login.Google.Enabled
35+
}
36+
37+
// EnterpriseLoginGoogle defines configurable fields for Google provider
38+
type EnterpriseLoginGoogle struct {
39+
Enabled bool `json:"enabled"`
40+
41+
// ClientCredentials is the Secret that contains SSO credentials
42+
// The Secret should contain keys "clientId", "clientSecret"
43+
ClientCredentialsRef NamespaceNameRef `json:"clientCredentialsRef"`
44+
45+
// Use Google groups in your RBAC role bindings.
46+
Directory *EnterpriseLoginGoogleDirectory `json:"directory,omitempty"`
47+
}
48+
49+
// EnterpriseLoginGoogleDirectory defines configurable fields for enabling RBAC Google groups sync
50+
type EnterpriseLoginGoogleDirectory struct {
51+
// ServiceAccountRef is the ConfigMap that contains the Google Service Account json
52+
// The ConfigMap should contain "sa.json" key
53+
ServiceAccountRef corev1.LocalObjectReference `json:"serviceAccountRef"`
54+
55+
// TargetPrincipal is the user that shall be impersonated by the service account
56+
TargetPrincipal string `json:"targetPrincipal"`
57+
}

src/go/k8s/apis/redpanda/v1alpha1/console_types.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ type ConsoleSpec struct {
3535
SchemaRegistry Schema `json:"schema"`
3636

3737
// The referenced Redpanda Cluster
38-
ClusterKeyRef corev1.ObjectReference `json:"clusterKeyRef"`
38+
ClusterRef NamespaceNameRef `json:"clusterRef"`
3939

4040
Deployment Deployment `json:"deployment"`
4141
Connect Connect `json:"connect"`
42+
43+
Enterprise *Enterprise `json:"enterprise,omitempty"`
44+
45+
// If you don't provide an enterprise license, Console ignores configurations for enterprise features
46+
// REF https://docs.redpanda.com/docs/console/reference/config/
47+
// If key is not provided in the SecretRef, Secret data should have key "license"
48+
LicenseRef *SecretKeyRef `json:"licenseRef,omitempty"`
49+
50+
// Login contains all configurations in order to protect Console with a login screen
51+
// Configure one or more of the below identity providers in order to support SSO
52+
// This feature requires an Enterprise license
53+
// REF https://docs.redpanda.com/docs/console/single-sign-on/identity-providers/google/
54+
Login *EnterpriseLogin `json:"login,omitempty"`
4255
}
4356

4457
// Server is the Console app HTTP server config
@@ -203,12 +216,12 @@ var AllowConsoleAnyNamespace bool
203216

204217
// IsAllowedNamespace returns true if Console is valid to be created in current namespace
205218
func (c *Console) IsAllowedNamespace() bool {
206-
return AllowConsoleAnyNamespace || c.GetNamespace() == c.Spec.ClusterKeyRef.Namespace
219+
return AllowConsoleAnyNamespace || c.GetNamespace() == c.Spec.ClusterRef.Namespace
207220
}
208221

209222
// GetClusterRef returns the NamespacedName of referenced Cluster object
210223
func (c *Console) GetClusterRef() types.NamespacedName {
211-
return types.NamespacedName{Name: c.Spec.ClusterKeyRef.Name, Namespace: c.Spec.ClusterKeyRef.Namespace}
224+
return types.NamespacedName{Name: c.Spec.ClusterRef.Name, Namespace: c.Spec.ClusterRef.Namespace}
212225
}
213226

214227
//+kubebuilder:object:root=true

src/go/k8s/apis/redpanda/v1alpha1/zz_generated.deepcopy.go

Lines changed: 136 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)