Skip to content

Commit 7092bb9

Browse files
[release-1.15] Support explicit protocol configuration in KafkaChannel secret (#4131)
* Support explicit `protocol` configuration in KafkaChannel secret KafkaChannel has historically used the "legacy" secret format, however, it has limitations as not having the explitic protocol configuration, we're left with guessing the protocol. We will continue supporting the "legacy" format, however, we will encourage users to use the new secret format, so that it can also be used for Kafka Broker, KafkaChannel and KafkaSink. Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com> * Remove unnecessary saslType in non-legacy test user secrets Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com> * Use sasl.mechanism in KafkaSource tests Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com> --------- Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com> Co-authored-by: Pierangelo Di Pilato <pierdipi@redhat.com>
1 parent dae1f5f commit 7092bb9

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

control-plane/pkg/reconciler/channel/channel.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,15 @@ func (r *Reconciler) getChannelContractResource(ctx context.Context, topic strin
708708
resource.Auth = &contract.Resource_MultiAuthSecret{
709709
MultiAuthSecret: auth.MultiSecretReference,
710710
}
711+
} else if auth != nil && auth.VirtualSecret != nil {
712+
resource.Auth = &contract.Resource_AuthSecret{
713+
AuthSecret: &contract.Reference{
714+
Uuid: string(auth.VirtualSecret.UID),
715+
Namespace: auth.VirtualSecret.Namespace,
716+
Name: auth.VirtualSecret.Name,
717+
Version: auth.VirtualSecret.ResourceVersion,
718+
},
719+
}
711720
}
712721

713722
if channel.Status.Address != nil && channel.Status.Address.Audience != nil {

control-plane/pkg/reconciler/consumer/consumer.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,21 @@ func (r *Reconciler) reconcileAuth(ctx context.Context, c *kafkainternals.Consum
240240
return fmt.Errorf("failed to get secret: %w", err)
241241
}
242242

243-
if _, ok := secret.Data[security.ProtocolKey]; !ok {
244-
authContext, err := security.ResolveAuthContextFromLegacySecret(secret)
245-
if err != nil {
246-
return err
247-
}
248-
243+
authContext, err := security.ResolveAuthContextFromLegacySecret(secret)
244+
if err != nil {
245+
return err
246+
}
247+
if authContext.MultiSecretReference != nil {
249248
resource.Auth = &contract.Resource_MultiAuthSecret{
250249
MultiAuthSecret: authContext.MultiSecretReference,
251250
}
252-
} else {
251+
} else if authContext.VirtualSecret != nil {
253252
resource.Auth = &contract.Resource_AuthSecret{
254253
AuthSecret: &contract.Reference{
255-
Uuid: string(secret.UID),
256-
Namespace: secret.Namespace,
257-
Name: secret.Name,
258-
Version: secret.ResourceVersion,
254+
Uuid: string(authContext.VirtualSecret.UID),
255+
Namespace: authContext.VirtualSecret.Namespace,
256+
Name: authContext.VirtualSecret.Name,
257+
Version: authContext.VirtualSecret.ResourceVersion,
259258
},
260259
}
261260
}

control-plane/pkg/security/secrets_provider_legacy_channel_secret.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func ResolveAuthContextFromLegacySecret(s *corev1.Secret) (*NetSpecAuthContext,
2929
return &NetSpecAuthContext{}, nil
3030
}
3131

32+
// Check if the secret is a legacy secret format without the explicit `protocol` key
33+
if v, ok := s.Data[ProtocolKey]; ok && len(v) > 0 {
34+
// The secret is explicitly using `protocol` configuration, no need to guess it.
35+
return &NetSpecAuthContext{VirtualSecret: s}, nil
36+
}
37+
3238
protocolStr, protocolContract := getProtocolFromLegacyChannelSecret(s)
3339

3440
virtualSecret := s.DeepCopy()

control-plane/pkg/security/secrets_provider_net_spec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
corelisters "k8s.io/client-go/listers/core/v1"
28+
2829
bindings "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/bindings/v1beta1"
2930

3031
"knative.dev/eventing-kafka-broker/control-plane/pkg/contract"

test/e2e-common.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ function create_sasl_secrets() {
459459
--from-literal=user="my-sasl-user" \
460460
--from-literal=protocol="SASL_SSL" \
461461
--from-literal=sasl.mechanism="SCRAM-SHA-512" \
462-
--from-literal=saslType="SCRAM-SHA-512" \
463462
--dry-run=client -o yaml | kubectl apply -n "${SYSTEM_NAMESPACE}" -f -
464463

465464
kubectl create secret --namespace "${SYSTEM_NAMESPACE}" generic strimzi-sasl-secret-legacy \
@@ -474,7 +473,6 @@ function create_sasl_secrets() {
474473
--from-literal=user="my-sasl-user" \
475474
--from-literal=protocol="SASL_PLAINTEXT" \
476475
--from-literal=sasl.mechanism="SCRAM-SHA-512" \
477-
--from-literal=saslType="SCRAM-SHA-512" \
478476
--dry-run=client -o yaml | kubectl apply -n "${SYSTEM_NAMESPACE}" -f -
479477

480478
kubectl create secret --namespace "${SYSTEM_NAMESPACE}" generic strimzi-sasl-plain-secret-legacy \

test/rekt/features/kafka_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func kafkaSourceFeature(name string,
344344
kafkasource.WithSASLEnabled(),
345345
kafkasource.WithSASLUser(secretName, "user"),
346346
kafkasource.WithSASLPassword(secretName, "password"),
347-
kafkasource.WithSASLType(secretName, "saslType"),
347+
kafkasource.WithSASLType(secretName, "sasl.mechanism"),
348348
kafkasource.WithTLSEnabled(),
349349
kafkasource.WithTLSCACert(secretName, "ca.crt"),
350350
)

test/rekt/features/kafka_source_create_secrets_after.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func CreateSecretsAfterKafkaSource() *feature.Feature {
4848
kafkasource.WithSASLEnabled(),
4949
kafkasource.WithSASLUser(saslSecretName, "user"),
5050
kafkasource.WithSASLPassword(saslSecretName, "password"),
51-
kafkasource.WithSASLType(saslSecretName, "saslType"),
51+
kafkasource.WithSASLType(saslSecretName, "sasl.mechanism"),
5252
kafkasource.WithTLSEnabled(),
5353
kafkasource.WithTLSCACert(tlsSecretName, "ca.crt"),
5454
))

0 commit comments

Comments
 (0)