Skip to content

Commit

Permalink
Added trusted bundles management
Browse files Browse the repository at this point in the history
  • Loading branch information
Juansasa committed Mar 3, 2025
1 parent 437fbdf commit 5a5038e
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 195 deletions.
9 changes: 2 additions & 7 deletions api/v1alpha1/keycloak_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type KeycloakSpec struct {
Instances *int32 `json:"instances"`

// +optional
// Truststore configurations
Truststore []Truststore `json:"truststore,omitempty"`
// Trusted CA bundle from configmap
TrustedCABundles *v1.LocalObjectReference `json:"trustedCABundles,omitempty"`

// +optional
// Admin credentials
Expand All @@ -62,11 +62,6 @@ type AdminUser struct {
Password SecretOption `json:"password,omitempty"`
}

type Truststore struct {
File SecretOption `json:"file,omitempty"`
Password *v1.SecretKeySelector `json:"password,omitempty"`
}

type Features struct {
Enabled []string `json:"enabled,omitempty"`
Disabled []string `json:"disabled,omitempty"`
Expand Down
31 changes: 4 additions & 27 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions catalog/channels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ schema: olm.channel
package: rhbk-operator
name: preview
entries:
- name: rhbk-operator.v0.0.4
replaces: rhbk-operator.v0.0.3
- name: rhbk-operator.v0.0.3
replaces: rhbk-operator.v0.0.2
- name: rhbk-operator.v0.0.2
Expand Down
79 changes: 16 additions & 63 deletions config/crd/bases/sso.stakater.com_keycloaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,69 +334,22 @@ spec:
- url
type: object
type: array
truststore:
description: Truststore configurations
items:
properties:
file:
properties:
secret:
description: SecretKeySelector selects a key of a Secret.
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
optional:
description: Specify whether the Secret or its key must
be defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
value:
type: string
type: object
password:
description: SecretKeySelector selects a key of a Secret.
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
optional:
description: Specify whether the Secret or its key must
be defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
type: array
trustedCABundles:
description: Trusted CA bundle from configmap
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
required:
- database
- instances
Expand Down
12 changes: 6 additions & 6 deletions config/samples/sso_v1alpha1_keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ spec:
secret:
name: rhbk-pguser-rhbk
key: password
# providers:
# - name: keycloak-metrics-spi-6.0.0.jar
# url:
# secret:
# name: custom-spi
# key: metrics-spi
trustedCABundles:
name: openshift-service-ca.crt
providers:
- name: spi-keycloak-emailnotification-1.0.1.jar
url:
value: "https://github.com/zene22/keycloak-spi-example/releases/download/V1.0.1/spi-keycloak-emailnotification-1.0.1.jar"
42 changes: 0 additions & 42 deletions config/samples/sso_v1alpha1_keycloak_restore.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions internal/constants/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package constants

const (
RHBKContainerName = "rhbk"
TrustedCaVolume = "trusted-ca"
TrustedCaVolumeMountPath = "conf/truststores"
)
2 changes: 1 addition & 1 deletion internal/controller/keycloak_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Keycloak Controller", func() {
Expect(statefulSet.Spec.Template.Spec.InitContainers).To(HaveLen(1))
Expect(statefulSet.Spec.Template.Spec.InitContainers[0].Args).To(Equal([]string{
"-c",
"mkdir -p /opt/keycloak/providers; curl -LJ --show-error --capath /var/run/secrets/kubernetes.io -o /opt/keycloak/providers/keycloak-metrics-spi-6.0.0.jar $(KEYCLOAK_METRICS_SPI_6_0_0_JAR)",
"mkdir -p /opt/keycloak/providers; curl -LJ --show-error --capath conf/truststores -o /opt/keycloak/providers/keycloak-metrics-spi-6.0.0.jar $(KEYCLOAK_METRICS_SPI_6_0_0_JAR)",
}))
})

Expand Down
7 changes: 6 additions & 1 deletion internal/resources/providers_import_init_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"fmt"
"github.com/stakater/rhbk-operator/internal/constants"
"regexp"
"strings"
"unicode"
Expand All @@ -18,7 +19,7 @@ func GetInitContainer(cr *v1alpha1.Keycloak) []v1.Container {
return nil
}

runArg := fmt.Sprintf("mkdir -p %s; curl -LJ --show-error --capath /var/run/secrets/kubernetes.io", ProvidersPATH)
runArg := fmt.Sprintf("mkdir -p %s; curl -LJ --show-error --capath %s", ProvidersPATH, constants.TrustedCaVolumeMountPath)
downloadContainer := v1.Container{
Name: "fetch",
Image: BusyboxImage,
Expand All @@ -34,6 +35,10 @@ func GetInitContainer(cr *v1alpha1.Keycloak) []v1.Container {
Name: "providers",
MountPath: ProvidersPATH,
},
{
Name: constants.TrustedCaVolume,
MountPath: constants.TrustedCaVolumeMountPath,
},
},
}

Expand Down
Loading

0 comments on commit 5a5038e

Please sign in to comment.