Skip to content

Commit 0a55ef1

Browse files
rashmi43rwhundley
andauthored
[Audit log forwarding] - update audit-tls secret to IM deployments for audit forwarding support (#1061)
Originating issue: [IBMPrivateCloud/roadmap#67190](https://github.ibm.com/IBMPrivateCloud/roadmap/issues/67190) --------- Signed-off-by: rashmi_kh <[email protected]> Signed-off-by: Rob Hundley <[email protected]> Co-authored-by: Rob Hundley <[email protected]>
1 parent a1a58e4 commit 0a55ef1

12 files changed

+231
-62
lines changed

api/operator/v1alpha1/authentication_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ type ConfigSpec struct {
139139
ICPPort int32 `json:"icpPort"`
140140
FIPSEnabled bool `json:"fipsEnabled"`
141141
ROKSEnabled bool `json:"roksEnabled"`
142+
AuditUrl *string `json:"auditUrl,omitempty"`
143+
AuditSecret *string `json:"auditSecret,omitempty"`
142144
IBMCloudSaas bool `json:"ibmCloudSaas,omitempty"`
143145
OnPremMultipleDeploy bool `json:"onPremMultipleDeploy,omitempty"`
144146
SaasClientRedirectUrl string `json:"saasClientRedirectUrl,omitempty"`

api/operator/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/ibm-iam-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ metadata:
7979
"openshiftPort": 443,
8080
"preferredLogin": "",
8181
"providerIssuerURL": "",
82+
"auditUrl": "",
83+
"auditSecret": "",
8284
"roksEnabled": true,
8385
"roksURL": "https://roks.domain.name:443",
8486
"roksUserPrefix": "changeme",

bundle/manifests/operator.ibm.com_authentications.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ spec:
228228
type: string
229229
providerIssuerURL:
230230
type: string
231+
auditUrl:
232+
type: string
233+
auditSecret:
234+
type: string
231235
roksEnabled:
232236
type: boolean
233237
roksURL:

config/crd/bases/operator.ibm.com_authentications.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ spec:
219219
preferredLogin:
220220
type: string
221221
defaultLogin:
222-
type: string
222+
type: string
223+
auditUrl:
224+
type: string
225+
auditSecret:
226+
type: string
223227
providerIssuerURL:
224228
type: string
225229
roksEnabled:

config/samples/bases/operator_v1alpha1_authentication.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ spec:
6161
preferredLogin: ''
6262
defaultLogin: ''
6363
bootstrapUserId: kubeadmin
64+
auditUrl: ''
65+
auditSecret: ''
6466
providerIssuerURL: ''
6567
claimsSupported: name,family_name,display_name,given_name,preferred_username
6668
claimsMap: name="givenName" family_name="givenName" given_name="givenName" preferred_username="displayName"

internal/controller/bootstrap/authentication_bootstrap_controller.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
corev1 "k8s.io/api/core/v1"
2929
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
3030
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/utils/ptr"
3132
ctrl "sigs.k8s.io/controller-runtime"
3233
"sigs.k8s.io/controller-runtime/pkg/builder"
3334
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -36,8 +37,9 @@ import (
3637
"sigs.k8s.io/controller-runtime/pkg/predicate"
3738
)
3839

39-
// BootStrapReconciler handles modifications to the Authentication CR before it is reconciled by the
40-
// main Authentication controller
40+
// BootStrapReconciler handles modifications to the Authentication CR before it
41+
// is reconciled by the main Authentication controller; this is meant to handle
42+
// edge cases that are encountered during upgrades.
4143
type BootstrapReconciler struct {
4244
client.Client
4345
}
@@ -105,10 +107,13 @@ func (r *BootstrapReconciler) makeAuthenticationCorrections(ctx context.Context,
105107
// writeConfigurationsToAuthenticationCR copies values from the
106108
// platform-auth-idp ConfigMap to the Authentication CR.
107109
func (r *BootstrapReconciler) writeConfigurationsToAuthenticationCR(ctx context.Context, authCR *operatorv1alpha1.Authentication) (err error) {
110+
log := logf.FromContext(ctx, "ConfigMap.Name", "platform-auth-idp").V(1)
108111
platformAuthIDPCM := &corev1.ConfigMap{}
109112
if err = r.Get(ctx, types.NamespacedName{Name: "platform-auth-idp", Namespace: authCR.Namespace}, platformAuthIDPCM); k8sErrors.IsNotFound(err) {
113+
log.Info("ConfigMap not found")
110114
return nil
111115
} else if err != nil {
116+
log.Error(err, "Failed to get ConfigMap")
112117
return fmt.Errorf("failed to get ConfigMap: %w", err)
113118
}
114119
keys := map[string]any{
@@ -129,23 +134,50 @@ func (r *BootstrapReconciler) writeConfigurationsToAuthenticationCR(ctx context.
129134
"IBM_CLOUD_SAAS": &authCR.Spec.Config.IBMCloudSaas,
130135
"SAAS_CLIENT_REDIRECT_URL": &authCR.Spec.Config.SaasClientRedirectUrl,
131136
"ATTR_MAPPING_FROM_CONFIG": &authCR.Spec.Config.AttrMappingFromConfig,
137+
"AUDIT_URL": &authCR.Spec.Config.AuditUrl,
138+
"AUDIT_SECRET": &authCR.Spec.Config.AuditSecret,
132139
}
133140

134141
for key, crField := range keys {
142+
keyLog := log.WithValues("key", key)
135143
cmValue, ok := platformAuthIDPCM.Data[key]
136144
if !ok {
145+
keyLog.Info("Key not found; continuing")
137146
continue
138147
}
148+
keyLog.Info("Key found", "value", cmValue)
139149
switch crValue := crField.(type) {
150+
140151
case *string:
141-
if *crValue != cmValue {
152+
keyLog.Info("Value type is string")
153+
if crValue != nil && *crValue != cmValue {
154+
keyLog.Info("Value of property on CR does not match value for key in ConfigMap")
142155
*crValue = cmValue
156+
} else if crValue != nil {
157+
keyLog.Info("Values match")
158+
}
159+
case **string:
160+
keyLog.Info("Value type is optional string")
161+
if *crValue == nil {
162+
keyLog.Info("Property is not set on CR")
163+
*crValue = ptr.To(cmValue)
164+
} else if **crValue != cmValue {
165+
keyLog.Info("Value of property on CR does not match value for key in ConfigMap")
166+
*crValue = ptr.To(cmValue)
167+
} else {
168+
keyLog.Info("Values match")
143169
}
144170
case *bool:
171+
keyLog.Info("Value type is bool")
145172
cmValueBool, _ := strconv.ParseBool(cmValue)
146-
if *crValue != cmValueBool {
173+
if crValue != nil && *crValue != cmValueBool {
174+
keyLog.Info("Value of property on CR does not match value for key in ConfigMap")
147175
*crValue = cmValueBool
176+
} else if crValue != nil {
177+
keyLog.Info("Values match")
148178
}
179+
default:
180+
keyLog.Info("Value type is unknown; skipping")
149181
}
150182
}
151183

internal/controller/operator/authentication_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ func (r *AuthenticationReconciler) SetupWithManager(mgr ctrl.Manager) error {
443443
}
444444
}), builder.WithPredicates(predicate.Or(globalCMPred, productCMPred)),
445445
)
446+
446447
bootstrappedPred := predicate.NewPredicateFuncs(func(o client.Object) bool {
447448
return o.GetLabels()[ctrlcommon.ManagerVersionLabel] == version.Version
448449
})

internal/controller/operator/configmap.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ func updatePlatformAuthIDP(_ common.SecondaryReconciler, _ context.Context, obse
296296
"IBM_CLOUD_SAAS",
297297
"SAAS_CLIENT_REDIRECT_URL",
298298
"ATTR_MAPPING_FROM_CONFIG",
299+
"AUDIT_URL",
300+
"AUDIT_SECRET",
299301
),
300302
updatesValuesWhen(observedKeyValueSetTo[*corev1.ConfigMap]("OS_TOKEN_LENGTH", "45"),
301303
"OS_TOKEN_LENGTH"),
@@ -437,6 +439,11 @@ func (r *AuthenticationReconciler) generateAuthIdpConfigMap(clusterInfo *corev1.
437439
}
438440
}
439441

442+
// Found AUDIT variables
443+
if authCR.Spec.Config.AuditUrl != nil || authCR.Spec.Config.AuditSecret != nil {
444+
reqLogger.Info("Found audit variables", "AuditUrl", authCR.Spec.Config.AuditUrl, "AuditSecret", authCR.Spec.Config.AuditSecret)
445+
}
446+
440447
// Set the path for SAML connections
441448
var masterPath string
442449
if masterPath, err = r.getMasterPath(ctx, ctrl.Request{NamespacedName: common.GetObjectKey(s.GetPrimary())}); err != nil {

internal/controller/operator/configmap_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ var _ = Describe("ConfigMap handling", func() {
585585
"IDENTITY_MGMT_URL": "https://platform-identity-management:4500",
586586
"MASTER_HOST": ibmcloudClusterInfo.Data["cluster_address"],
587587
"MASTER_PATH": "/idauth",
588+
"AUDIT_URL": "",
589+
"AUDIT_SECRET": "",
588590
"NODE_ENV": "production",
589591
"ENABLE_JIT_EXTRA_ATTR": "false",
590592
"AUDIT_ENABLED_IDPROVIDER": "false",
@@ -682,6 +684,13 @@ var _ = Describe("ConfigMap handling", func() {
682684
"DB_SSL_MODE",
683685
},
684686
},
687+
{
688+
"AUDIT_URL",
689+
[]string{
690+
"AUDIT_URL",
691+
"AUDIT_SECRET",
692+
},
693+
},
685694
{
686695
"SCIM_LDAP_ATTRIBUTES_MAPPING",
687696
[]string{

0 commit comments

Comments
 (0)