Skip to content

[Audit log forwarding] - update audit-tls secret to IM deployments for audit forwarding support #1061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

rashmi43
Copy link
Member

@rashmi43 rashmi43 commented Jul 2, 2025

@ibm-ci-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rashmi43

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rashmi43 rashmi43 requested a review from rwhundley August 4, 2025 16:20
@rashmi43 rashmi43 changed the title [Audit log forwarding] - watch audit-tls secret to update deployments for audit [Audit log forwarding] - update audit-tls secret to IM deployments for audit forwarding support Aug 4, 2025
Signed-off-by: rashmi_kh <[email protected]>
Signed-off-by: rashmi_kh <[email protected]>
Signed-off-by: rashmi_kh <[email protected]>
// cluster, or an empty string when the Secret isn't found or cannot otherwise
// be retrieved. If an error other than NotFound is received when trying to get
// the Secret, that is returned as well.
func (r *AuthenticationReconciler) getAuditSecretNameIfExists(ctx context.Context, namespace string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should just check the Authentication CR for whether the audit values are set - that's ultimately the source of truth for the workload and makes this unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I will change this to check the Authentication CR

@@ -228,6 +228,10 @@ spec:
type: string
providerIssuerURL:
type: string
auditURL:
Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes should also be happening in the config directory, and changes here should be generated with make bundle

@@ -139,6 +139,8 @@ type ConfigSpec struct {
ICPPort int32 `json:"icpPort"`
FIPSEnabled bool `json:"fipsEnabled"`
ROKSEnabled bool `json:"roksEnabled"`
AuditUrl string `json:"auditUrl,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these aren't required, they should be *string, and nil checks should happen on accesses.

@@ -414,7 +414,7 @@ func buildAuthServiceContainer(instance *operatorv1alpha1.Authentication, authSe

}

func buildIdentityProviderContainer(instance *operatorv1alpha1.Authentication, identityProviderImage string, _ string, saasCRNId string) corev1.Container {
func buildIdentityProviderContainer(instance *operatorv1alpha1.Authentication, identityProviderImage string, _ string, saasCRNId string, auditSecretName string) corev1.Container {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You shouldn't need this extra parameter because the secret name should be set on the Authentication CR, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need this to mount the secret if Len > 0

@@ -1129,16 +1087,16 @@ func buildContainers(instance *operatorv1alpha1.Authentication, authServiceImage
return []corev1.Container{authServiceContainer}
}

func buildManagerContainers(instance *operatorv1alpha1.Authentication, identityManagerImage string, icpConsoleURL string) []corev1.Container {
func buildManagerContainers(instance *operatorv1alpha1.Authentication, identityManagerImage string, icpConsoleURL string, auditSecretName string) []corev1.Container {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here - Authentication CR should have this name set on it, correct? So no new param is needed.

},
},
}
volumes = EnsureVolumePresent(volumes, auditVolume)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this extra function is needed; it should be possible with just an append. This function is used to build what the Operator thinks the Deployment should contain, so there's no threat of infinitely appending redundant volumes here.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Collaborator

Choose a reason for hiding this comment

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

It still appears to be here?

rashmi43 and others added 4 commits August 4, 2025 22:31
@@ -731,7 +731,7 @@ func buildIdentityProviderContainer(instance *operatorv1alpha1.Authentication, i

}

func buildIdentityManagerContainer(instance *operatorv1alpha1.Authentication, identityManagerImage string, _ string, auditSecretName string) corev1.Container {
func buildIdentityManagerContainer(instance *operatorv1alpha1.Authentication, identityManagerImage string, _ string, auditSecretName *string) corev1.Container {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -1087,14 +1087,14 @@ func buildContainers(instance *operatorv1alpha1.Authentication, authServiceImage
return []corev1.Container{authServiceContainer}
}

func buildManagerContainers(instance *operatorv1alpha1.Authentication, identityManagerImage string, icpConsoleURL string, auditSecretName string) []corev1.Container {
func buildManagerContainers(instance *operatorv1alpha1.Authentication, identityManagerImage string, icpConsoleURL string, auditSecretName *string) []corev1.Container {
Copy link
Collaborator

Choose a reason for hiding this comment

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


identityManagerContainer := buildIdentityManagerContainer(instance, identityManagerImage, icpConsoleURL, auditSecretName)

return []corev1.Container{identityManagerContainer}
}

func buildProviderContainers(instance *operatorv1alpha1.Authentication, identityProviderImage string, icpConsoleURL string, saasCrnId string, auditSecretName string) []corev1.Container {
func buildProviderContainers(instance *operatorv1alpha1.Authentication, identityProviderImage string, icpConsoleURL string, saasCrnId string, auditSecretName *string) []corev1.Container {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if len(auditSecretName) > 0 {
volumeMounts = EnsureVolumeMountPresent(volumeMounts, GetAuditCertsVolumeMount())

if auditSecretName != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You still want a check on the dereferenced pointer value - an empty name isn't valid, either.

Suggested change
if auditSecretName != nil {
if auditSecretName != nil && *auditSecretName != "" {

Comment on lines 195 to 220
// Check for the presence of audit-endpoint configmap
authIdpConfigMapName := "platform-auth-idp"
authIdpConfigMap := &corev1.ConfigMap{}
idpCMLogger := log.WithValues("ConfigMap.Name", authIdpConfigMapName, "ConfigMap.Namespace", namespace)
if err := r.Get(ctx, types.NamespacedName{Name: authIdpConfigMapName, Namespace: namespace}, authIdpConfigMap); k8sErrors.IsNotFound(err) {
idpCMLogger.Info("ConfigMap was not found")
return nil, nil
} else if err != nil {
idpCMLogger.Error(err, "Failed to get ConfigMap")
return nil, err
}
if authIdpConfigMap.Data == nil {
idpCMLogger.Info("Invalid ConfigMap")
return nil, nil
}
if authIdpConfigMap.Data["AUDIT_URL"] == "" {
idpCMLogger.Info("Audit URL is not specified in ConfigMap; assume no Secret to mount", "key", "AUDIT_URL")
return nil, nil
}
if authIdpConfigMap.Data["AUDIT_SECRET"] == "" {
idpCMLogger.Info("Audit Secret is not specified in ConfigMap; assume no Secret", "key", "AUDIT_SECRET")
return nil, nil
}
auditURL = authIdpConfigMap.Data["AUDIT_URL"]
auditSecretName = authIdpConfigMap.Data["AUDIT_SECRET"]
idpCMLogger.Info("Fetched audit URL and audit Secret from ConfigMap", "AUDIT_SECRET", auditSecretName, "AUDIT_URL", auditURL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I apologize if I said this before - this section is unnecessary and shouldn't be here because the operating assumption is that this configuration is coming from the Authentication CR, not the ConfigMap.

That said, if the configuration is expected to be set on the ConfigMap before the Authentication CR, e.g. some previous support for this configuration in a different release stream, then the bootstrap controller needs to be updated to perform this identification so that the Authentication CR can be updated to have the correct settings on it before it hits the main Authentication controller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For reference, you'd add "AUDIT_URL" and "AUDIT_SECRET" and their respective Auth CR property paths to this map, which handles setting the Auth CR properties you specify using values in the platform-auth-idp ConfigMap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, and all of the fields referenced in that map currently are kept as references, but, assuming you've changed auditUrl and auditSecret to be *string, you should be able to just do something like the following:

// Note no "&" - this property is already a pointer (assuming you've made that change)
"AUDIT_URL": authCR.Spec.Config.AuditUrl,

@@ -1032,4 +1095,42 @@ func buildIdpVolumes(ldapCACert string, routerCertSecret string) []corev1.Volume
},
},
}
if auditSecretName != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if auditSecretName != nil {
if auditSecretName != nil && *auditSecretName != "" {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Though it would be better to do as I suggested here - invert this condition and return if that evaluates as true. Reduces the amount of indentation.

@@ -345,6 +345,10 @@ func updatePlatformAuthIDP(_ common.SecondaryReconciler, _ context.Context, obse
"LDAP_CTX_POOL_PREFERREDSIZE"),
updatesValuesWhen(not(observedKeySet[*corev1.ConfigMap]("MASTER_PATH")),
"MASTER_PATH"),
updatesValuesWhen(not(observedKeySet[*corev1.ConfigMap]("AUDIT_URL")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

In conjunction with this comment, it's my feeling that these should just be added to the updatesAlways call, and, if we're trying to account for an existing setting on the ConfigMap from an upgrade, then we should account for that in the bootstrap controller.

},
},
}
volumes = EnsureVolumePresent(volumes, auditVolume)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It still appears to be here?

rashmi43 and others added 3 commits August 5, 2025 14:24
MountPath: "/pgsql/clientinfo",
},
}
if auditSecretName != nil && *auditSecretName != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, in hindsight, probably better to check if auditSecretName == nil || *auditSecretName == "" and return volumeMounts if true. Then this update to volumeMounts can happen after it without the extra indentation.

@@ -1032,4 +1095,42 @@ func buildIdpVolumes(ldapCACert string, routerCertSecret string) []corev1.Volume
},
},
}
if auditSecretName != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Though it would be better to do as I suggested here - invert this condition and return if that evaluates as true. Reduces the amount of indentation.

@@ -82,7 +82,7 @@ func (r *AuthenticationReconciler) handleDeployments(ctx context.Context, req ct
samlConsoleURL = icpConsoleURL
}

auditSecretName, err := r.getAuditSecretNameIfExists(ctx, req.Namespace)
auditSecretName, err := r.getAuditSecretNameIfExists(context.TODO(), req.Namespace, authCR.Spec.Config.AuditUrl, authCR.Spec.Config.AuditSecret)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be ctx again for the context argument. Also you could just pass the pointer to the authentication, at which point you can check both of the values within the function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You also get the namespace that way, so you go from four params to two.

}
if authIdpConfigMap.Data["AUDIT_URL"] == "" {
idpCMLogger.Info("Audit URL is not specified in ConfigMap; assume no Secret to mount", "key", "AUDIT_URL")
func (r *AuthenticationReconciler) getAuditSecretNameIfExists(ctx context.Context, namespace string, auditUrl *string, auditSecretName *string) (*string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should just take two arguments, a context.Context and an *operatorv1alpha1.Authentication. Then values are obtained via dereference from there.

//var auditURL string
reqLogger := logf.FromContext(ctx)

if auditUrl == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also check for an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants