Skip to content
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

[release-1.15] Support explicit protocol configuration in KafkaChannel secret #4131

Open
wants to merge 3 commits into
base: release-1.15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions control-plane/pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,15 @@
resource.Auth = &contract.Resource_MultiAuthSecret{
MultiAuthSecret: auth.MultiSecretReference,
}
} else if auth != nil && auth.VirtualSecret != nil {
resource.Auth = &contract.Resource_AuthSecret{
AuthSecret: &contract.Reference{
Uuid: string(auth.VirtualSecret.UID),
Namespace: auth.VirtualSecret.Namespace,
Name: auth.VirtualSecret.Name,
Version: auth.VirtualSecret.ResourceVersion,
},

Check warning on line 718 in control-plane/pkg/reconciler/channel/channel.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/channel/channel.go#L712-L718

Added lines #L712 - L718 were not covered by tests
}
}

if channel.Status.Address != nil && channel.Status.Address.Audience != nil {
Expand Down
21 changes: 10 additions & 11 deletions control-plane/pkg/reconciler/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,21 @@
return fmt.Errorf("failed to get secret: %w", err)
}

if _, ok := secret.Data[security.ProtocolKey]; !ok {
authContext, err := security.ResolveAuthContextFromLegacySecret(secret)
if err != nil {
return err
}

authContext, err := security.ResolveAuthContextFromLegacySecret(secret)
if err != nil {
return err

Check warning on line 245 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/consumer/consumer.go#L243-L245

Added lines #L243 - L245 were not covered by tests
}
if authContext.MultiSecretReference != nil {

Check warning on line 247 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

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

Added line #L247 was not covered by tests
resource.Auth = &contract.Resource_MultiAuthSecret{
MultiAuthSecret: authContext.MultiSecretReference,
}
} else {
} else if authContext.VirtualSecret != nil {

Check warning on line 251 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

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

Added line #L251 was not covered by tests
resource.Auth = &contract.Resource_AuthSecret{
AuthSecret: &contract.Reference{
Uuid: string(secret.UID),
Namespace: secret.Namespace,
Name: secret.Name,
Version: secret.ResourceVersion,
Uuid: string(authContext.VirtualSecret.UID),
Namespace: authContext.VirtualSecret.Namespace,
Name: authContext.VirtualSecret.Name,
Version: authContext.VirtualSecret.ResourceVersion,

Check warning on line 257 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/consumer/consumer.go#L254-L257

Added lines #L254 - L257 were not covered by tests
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
return &NetSpecAuthContext{}, nil
}

// Check if the secret is a legacy secret format without the explicit `protocol` key
if v, ok := s.Data[ProtocolKey]; ok && len(v) > 0 {

Check warning on line 33 in control-plane/pkg/security/secrets_provider_legacy_channel_secret.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/security/secrets_provider_legacy_channel_secret.go#L33

Added line #L33 was not covered by tests
// The secret is explicitly using `protocol` configuration, no need to guess it.
return &NetSpecAuthContext{VirtualSecret: s}, nil

Check warning on line 35 in control-plane/pkg/security/secrets_provider_legacy_channel_secret.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/security/secrets_provider_legacy_channel_secret.go#L35

Added line #L35 was not covered by tests
}

protocolStr, protocolContract := getProtocolFromLegacyChannelSecret(s)

virtualSecret := s.DeepCopy()
Expand Down
1 change: 1 addition & 0 deletions control-plane/pkg/security/secrets_provider_net_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corelisters "k8s.io/client-go/listers/core/v1"

bindings "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/bindings/v1beta1"

"knative.dev/eventing-kafka-broker/control-plane/pkg/contract"
Expand Down
2 changes: 0 additions & 2 deletions test/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ function create_sasl_secrets() {
--from-literal=user="my-sasl-user" \
--from-literal=protocol="SASL_SSL" \
--from-literal=sasl.mechanism="SCRAM-SHA-512" \
--from-literal=saslType="SCRAM-SHA-512" \
--dry-run=client -o yaml | kubectl apply -n "${SYSTEM_NAMESPACE}" -f -

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

kubectl create secret --namespace "${SYSTEM_NAMESPACE}" generic strimzi-sasl-plain-secret-legacy \
Expand Down
2 changes: 1 addition & 1 deletion test/rekt/features/kafka_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func kafkaSourceFeature(name string,
kafkasource.WithSASLEnabled(),
kafkasource.WithSASLUser(secretName, "user"),
kafkasource.WithSASLPassword(secretName, "password"),
kafkasource.WithSASLType(secretName, "saslType"),
kafkasource.WithSASLType(secretName, "sasl.mechanism"),
kafkasource.WithTLSEnabled(),
kafkasource.WithTLSCACert(secretName, "ca.crt"),
)
Expand Down
2 changes: 1 addition & 1 deletion test/rekt/features/kafka_source_create_secrets_after.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CreateSecretsAfterKafkaSource() *feature.Feature {
kafkasource.WithSASLEnabled(),
kafkasource.WithSASLUser(saslSecretName, "user"),
kafkasource.WithSASLPassword(saslSecretName, "password"),
kafkasource.WithSASLType(saslSecretName, "saslType"),
kafkasource.WithSASLType(saslSecretName, "sasl.mechanism"),
kafkasource.WithTLSEnabled(),
kafkasource.WithTLSCACert(tlsSecretName, "ca.crt"),
))
Expand Down
Loading