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

Enable envoy tls termination #41

Merged
merged 4 commits into from
Mar 17, 2022
Merged

Conversation

dobrerazvan
Copy link

Q A
Bug fix? no/yes
New feature? no/yes
API breaks? no/yes
Deprecations? no/yes
Related tickets fixes #X, partially #Y, mentioned in #Z
License Apache 2.0

What's in this PR?

Why?

Additional context

Checklist

  • Implementation tested
  • Error handling code meets the guideline
  • Logging code meets the guideline
  • User guide and development docs updated (if needed)

To Do

  • If the PR is not complete but you want to discuss the approach, list what remains to be done here

@dobrerazvan dobrerazvan added enhancement New feature or request WIP Work in progress - do not merge labels Jan 27, 2022
@@ -1035,6 +1035,9 @@ func (r *Reconciler) createExternalListenerStatuses(log logr.Logger) (map[string
if err != nil {
return nil, err
}
if eListener.ExternalStartingPort == -1 {
Copy link

Choose a reason for hiding this comment

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

same comment, eListener offers a HostnameOverride field that can be used here?

@amuraru
Copy link

amuraru commented Jan 31, 2022

we also need unit-tests added

api/v1beta1/kafkacluster_types.go Outdated Show resolved Hide resolved
charts/kafka-operator/templates/crds.yaml Outdated Show resolved Hide resolved
pkg/resources/envoy/configmap.go Show resolved Hide resolved
pkg/resources/envoy/configmap.go Outdated Show resolved Hide resolved
// Create an any cast broker access point
if elistener.ExternalStartingPort == -1 {
// append l[AnyCastPort] with another filter for the same listener
filterChain = &envoylistener.FilterChain{
Copy link

Choose a reason for hiding this comment

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

Could we avoid somehow code duplication here? I see that only the hostname is different from the broker specific filter.

Copy link

Choose a reason for hiding this comment

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

@dobrerazvan please don't forget about this code duplicate, too

@dobrerazvan
Copy link
Author

@alungu @amuraru I implemented the requested review. I think it works. Next, unit tests.

@@ -373,6 +385,29 @@ func (c IngressServiceSettings) GetServiceType() corev1.ServiceType {
return c.ServiceType
}

// Replace {{.Id}} in brokerHostnameTemplate with actual broker id
Copy link

Choose a reason for hiding this comment

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

Suggestion to do string replace here instead of template engine from Go.
Reasons are that we are doing the same process here (not calling any extra functions to require template engine), current deployment spec is done via Helm (need to escape double templating).
wdyt?

Copy link

@alungu alungu left a comment

Choose a reason for hiding this comment

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

Mainly looks good 👍
There are only some minor changes that I think it would make the code a bit easier to read.

{
CertificateChain: &envoycore.DataSource{
Specifier: &envoycore.DataSource_Filename{
Filename: "/certs/certificate.crt",
Copy link

Choose a reason for hiding this comment

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

If these paths are hard coded, it means that we always have to mount the secrets to these paths, right?
Should we add this information the CRD?

Copy link
Author

Choose a reason for hiding this comment

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

Since this is generated and used un the envoy deployment to mount the ssl cert, i think it could be hardcoded, doesn't really matter where is mounted as long as it's mounted somewhere.

}

if elistener.TLSEnabled() {
// tls
Copy link

Choose a reason for hiding this comment

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

minor: should we drop this comment (and the one below non tls? The condition is very clear.


for _, p := range ports {

if elistener.ExternalStartingPort == -1 {
Copy link

Choose a reason for hiding this comment

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

could we replace this with the method helper TLSEnabled?

@@ -66,6 +65,26 @@ func (r *Reconciler) deployment(log logr.Logger, extListener v1beta1.ExternalLis
},
}

if extListener.ExternalStartingPort == -1 && extListener.TLSSecretName != "" {
Copy link

Choose a reason for hiding this comment

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

could we replace this with the method helper TLSEnabled?

TargetPort: intstr.FromInt(int(extListener.ExternalStartingPort) + brokerId),
Protocol: corev1.ProtocolTCP,
})
if extListener.ExternalStartingPort != -1 {
Copy link

Choose a reason for hiding this comment

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

could we replace this with the method helper TLSEnabled?

},
},
}
pbTlsContext, _ := anypb.New(tlsContext)
Copy link

Choose a reason for hiding this comment

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

Should we check the returned error, too?

// Create an any cast broker access point
if elistener.ExternalStartingPort == -1 {
// append l[AnyCastPort] with another filter for the same listener
filterChain = &envoylistener.FilterChain{
Copy link

Choose a reason for hiding this comment

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

@dobrerazvan please don't forget about this code duplicate, too

ports = append(ports, int(p))
}
sort.Ints(ports)

Copy link

Choose a reason for hiding this comment

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

minor: extra newline

for _, p := range ports {

if elistener.ExternalStartingPort == -1 {
listeners = append(listeners, &envoylistener.Listener{
Copy link

Choose a reason for hiding this comment

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

The Listener is the same object for both TLS and non-TLS. could we reuse the code?

@@ -226,37 +259,48 @@ func GenerateEnvoyConfig(kc *v1beta1.KafkaCluster, elistener v1beta1.ExternalLis
Cluster: fmt.Sprintf("broker-%d", brokerId),
},
}

Copy link

Choose a reason for hiding this comment

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

This method (GenerateEnvoyConfig) has almost 400 lines. Could we split it in multiple functions, please?

Copy link
Author

Choose a reason for hiding this comment

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

I added dedicated functions that generate tls specifics

@@ -407,6 +428,8 @@ type IngressServiceSettings struct {
// In case of external listeners using NodePort access method the broker instead of node public IP (see "brokerConfig.nodePortExternalIP")
// is advertised on the address having the following format: <kafka-cluster-name>-<broker-id>.<namespace><value-specified-in-hostnameOverride-field>
HostnameOverride string `json:"hostnameOverride,omitempty"`
// Template used to generate broker hostnames for tls enabled envoy. %id will be replaced with brokerId value
BrokerHostnameTemplate string `json:"brokerHostnameTemplate,omitempty"`
Copy link

Choose a reason for hiding this comment

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

@dobrerazvan can this be moved to KafkaClusterSpec.EnvoyConfig ?

The reason for this is that the comment says it applies to "envoy" ingress while this IngressServiceSettings is generic for all kafka ingresses (istio, envoy)

Copy link
Author

Choose a reason for hiding this comment

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

@amuraru Implemented the review.

@amuraru
Copy link

amuraru commented Mar 14, 2022

@dobrerazvan please rebase this on top of master. I just force rebased the master branch to sync with upstream banzaicloud/master branch

amuraru and others added 3 commits March 15, 2022 18:00
…adobe/kafka docker hub repos

- build the koperator docker image
- build Apache kafka docker image
When `kafka-*` tags are created a github action is triggered
to build and push a new adobe/kafka docker image version
@dobrerazvan
Copy link
Author

@dobrerazvan please rebase this on top of master. I just force rebased the master branch to sync with upstream banzaicloud/master branch

Did that.

@@ -377,6 +390,16 @@ func (c IngressServiceSettings) GetServiceType() corev1.ServiceType {
return c.ServiceType
}

// Replace %id in brokerHostnameTemplate with actual broker id
func (c EnvoyConfig) GetBrokerHostname(brokerId int32) string {
Copy link

Choose a reason for hiding this comment

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

Suggested change
func (c EnvoyConfig) GetBrokerHostname(brokerId int32) string {
func (c EnvoyConfig) Get BrokerHostnameTemplate(brokerId int32) string {

@amuraru amuraru removed the WIP Work in progress - do not merge label Mar 15, 2022
@dobrerazvan dobrerazvan merged commit c7d6614 into adobe:master Mar 17, 2022
amuraru pushed a commit that referenced this pull request Mar 21, 2022
amuraru pushed a commit that referenced this pull request Mar 30, 2022
amuraru pushed a commit that referenced this pull request Apr 22, 2022
amuraru pushed a commit that referenced this pull request May 3, 2022
amuraru pushed a commit that referenced this pull request May 3, 2022
amuraru pushed a commit that referenced this pull request May 8, 2022
amuraru pushed a commit that referenced this pull request May 11, 2022
amuraru pushed a commit that referenced this pull request May 11, 2022
amuraru pushed a commit that referenced this pull request May 13, 2022
amuraru pushed a commit that referenced this pull request May 23, 2022
amuraru pushed a commit that referenced this pull request May 27, 2022
amuraru pushed a commit that referenced this pull request Jun 17, 2022
amuraru pushed a commit that referenced this pull request Jun 29, 2022
azun pushed a commit that referenced this pull request Jul 28, 2022
azun pushed a commit that referenced this pull request Jul 29, 2022
amuraru pushed a commit that referenced this pull request Jul 29, 2022
amuraru pushed a commit that referenced this pull request Aug 22, 2022
amuraru pushed a commit that referenced this pull request Sep 10, 2022
alungu pushed a commit that referenced this pull request Jan 5, 2023
aguzovatii pushed a commit to aguzovatii/koperator that referenced this pull request Mar 22, 2023
aguzovatii pushed a commit to aguzovatii/koperator that referenced this pull request Mar 22, 2023
aguzovatii pushed a commit to aguzovatii/koperator that referenced this pull request Mar 23, 2023
amuraru pushed a commit that referenced this pull request May 16, 2023
ctrlaltluc added a commit that referenced this pull request May 19, 2023
* [INTERNAL] [BUILD] Publish docker images to adobe/kafka-operator and adobe/kafka docker hub repos

- build the koperator docker image
- build Apache kafka docker image
When `kafka-*` tags are created a github action is triggered
to build and push a new adobe/kafka docker image version

* [INTERNAL] make manifests should be called manually, if needed (#25)

We made some chnages for spinnaker annotations and `preserveUnknownFields` that would be overriden by `make manifests`

* [INTERNAL] Allow Kafka to use External DNS for inter-broker protocol (#17) (#22)

* [INTERNAL] Allow external listeners to be used for inner communication (#26)

* [INTERNAL] Ensure external listerners are always the first the advertised.listeners configuration

This is needed for old clients connecting to kafka through Zookeeper that does not have a way
to infer the right listener.
In this case, the first listener in the advertised.listener config is used to connect to brokers.
This patch ensures the external listeners (those reachable from outside) are listed before internal ones

* [INTERNAL] Generate CRDs resources

* [INTERNAL] Upgrade to Kafka 2.8.1 (#36)

* Enable envoy idleTimeout and TCP keep-alive for connections to kafka and clients

1/ Kafka broker defines connections.max.idle.ms=600s
To ensure envoy as a client for kafka broker is terminating
the connection first to avoid network disconnects
this patch is setting the idleTimeout to value slightly less
than that

2/ Enable tcp-keep alive for all TCP connections established by envoy to kafka
and to client (or fronting Load Balancer)

* Enable envoy tls termination (#41)

* [INTERNAL] Build kafka 3.1.1 using Oracle OpenJDK

* Envoy config generated by the operator is invalid in envoy 1.22


Added explicit typeconfig for envoy.filters.http.router

```
[2022-06-16 13:27:58.425][1][info][main] [source/server/server.cc:939] exiting
Didn't find a registered implementation for 'envoy.filters.http.router' with type URL: ''
```

* Added TaintedBrokersSelector to kafkaClusterSpec (#48)

Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>

* Build kafka 3.2.2

* Upgrade kafka to 3.2.3

* Upgrade kafka to 3.3.1

* [Internal] Update helm for adobe builds (#52)

* [INTERNAL] Use local replacement for sub-modules (#54)

As part of banzaicloud#929, the local
replacement for sub-modules was removed in favor of using valid tags.
Adobe Koperator fork has some internal changes in the api sub-module,
so we need to use the local version of the sub-module instead of
the upstream version, so we are  forced to revert the changes from banzaicloud#929.

* Upgrade kafka to 3.4.0

---------

Co-authored-by: Adi Muraru <amuraru@adobe.com>
Co-authored-by: Adrian Lungu <adrian.lungu89@gmail.com>
Co-authored-by: Razvan Dobre <dobre.razvan@gmail.com>
Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>
Co-authored-by: Adrian Coman <acoman@adobe.com>
Co-authored-by: aguzovatii <guzovatii.anatolii@gmail.com>
ctrlaltluc pushed a commit that referenced this pull request Jun 8, 2023
ctrlaltluc added a commit that referenced this pull request Jun 8, 2023
* [INTERNAL] [BUILD] Publish docker images to adobe/kafka-operator and adobe/kafka docker hub repos

- build the koperator docker image
- build Apache kafka docker image
When `kafka-*` tags are created a github action is triggered
to build and push a new adobe/kafka docker image version

* [INTERNAL] make manifests should be called manually, if needed (#25)

We made some chnages for spinnaker annotations and `preserveUnknownFields` that would be overriden by `make manifests`

* [INTERNAL] Allow Kafka to use External DNS for inter-broker protocol (#17) (#22)

* [INTERNAL] Allow external listeners to be used for inner communication (#26)

* [INTERNAL] Ensure external listerners are always the first the advertised.listeners configuration

This is needed for old clients connecting to kafka through Zookeeper that does not have a way
to infer the right listener.
In this case, the first listener in the advertised.listener config is used to connect to brokers.
This patch ensures the external listeners (those reachable from outside) are listed before internal ones

* [INTERNAL] Generate CRDs resources

* [INTERNAL] Upgrade to Kafka 2.8.1 (#36)

* Enable envoy idleTimeout and TCP keep-alive for connections to kafka and clients

1/ Kafka broker defines connections.max.idle.ms=600s
To ensure envoy as a client for kafka broker is terminating
the connection first to avoid network disconnects
this patch is setting the idleTimeout to value slightly less
than that

2/ Enable tcp-keep alive for all TCP connections established by envoy to kafka
and to client (or fronting Load Balancer)

* Enable envoy tls termination (#41)

* [INTERNAL] Build kafka 3.1.1 using Oracle OpenJDK

* Envoy config generated by the operator is invalid in envoy 1.22


Added explicit typeconfig for envoy.filters.http.router

```
[2022-06-16 13:27:58.425][1][info][main] [source/server/server.cc:939] exiting
Didn't find a registered implementation for 'envoy.filters.http.router' with type URL: ''
```

* Added TaintedBrokersSelector to kafkaClusterSpec (#48)

Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>

* Build kafka 3.2.2

* Upgrade kafka to 3.2.3

* Upgrade kafka to 3.3.1

* [Internal] Update helm for adobe builds (#52)

* [INTERNAL] Use local replacement for sub-modules (#54)

As part of banzaicloud#929, the local
replacement for sub-modules was removed in favor of using valid tags.
Adobe Koperator fork has some internal changes in the api sub-module,
so we need to use the local version of the sub-module instead of
the upstream version, so we are  forced to revert the changes from banzaicloud#929.

* Upgrade kafka to 3.4.0

---------

Co-authored-by: Adi Muraru <amuraru@adobe.com>
Co-authored-by: Adrian Lungu <adrian.lungu89@gmail.com>
Co-authored-by: Razvan Dobre <dobre.razvan@gmail.com>
Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>
Co-authored-by: Adrian Coman <acoman@adobe.com>
Co-authored-by: aguzovatii <guzovatii.anatolii@gmail.com>
ctrlaltluc pushed a commit that referenced this pull request Jun 8, 2023
ctrlaltluc added a commit that referenced this pull request Jun 8, 2023
* [INTERNAL] [BUILD] Publish docker images to adobe/kafka-operator and adobe/kafka docker hub repos

- build the koperator docker image
- build Apache kafka docker image
When `kafka-*` tags are created a github action is triggered
to build and push a new adobe/kafka docker image version

* [INTERNAL] make manifests should be called manually, if needed (#25)

We made some chnages for spinnaker annotations and `preserveUnknownFields` that would be overriden by `make manifests`

* [INTERNAL] Allow Kafka to use External DNS for inter-broker protocol (#17) (#22)

* [INTERNAL] Allow external listeners to be used for inner communication (#26)

* [INTERNAL] Ensure external listerners are always the first the advertised.listeners configuration

This is needed for old clients connecting to kafka through Zookeeper that does not have a way
to infer the right listener.
In this case, the first listener in the advertised.listener config is used to connect to brokers.
This patch ensures the external listeners (those reachable from outside) are listed before internal ones

* [INTERNAL] Generate CRDs resources

* [INTERNAL] Upgrade to Kafka 2.8.1 (#36)

* Enable envoy idleTimeout and TCP keep-alive for connections to kafka and clients

1/ Kafka broker defines connections.max.idle.ms=600s
To ensure envoy as a client for kafka broker is terminating
the connection first to avoid network disconnects
this patch is setting the idleTimeout to value slightly less
than that

2/ Enable tcp-keep alive for all TCP connections established by envoy to kafka
and to client (or fronting Load Balancer)

* Enable envoy tls termination (#41)

* [INTERNAL] Build kafka 3.1.1 using Oracle OpenJDK

* Envoy config generated by the operator is invalid in envoy 1.22


Added explicit typeconfig for envoy.filters.http.router

```
[2022-06-16 13:27:58.425][1][info][main] [source/server/server.cc:939] exiting
Didn't find a registered implementation for 'envoy.filters.http.router' with type URL: ''
```

* Added TaintedBrokersSelector to kafkaClusterSpec (#48)

Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>

* Build kafka 3.2.2

* Upgrade kafka to 3.2.3

* Upgrade kafka to 3.3.1

* [Internal] Update helm for adobe builds (#52)

* [INTERNAL] Use local replacement for sub-modules (#54)

As part of banzaicloud#929, the local
replacement for sub-modules was removed in favor of using valid tags.
Adobe Koperator fork has some internal changes in the api sub-module,
so we need to use the local version of the sub-module instead of
the upstream version, so we are  forced to revert the changes from banzaicloud#929.

* Upgrade kafka to 3.4.0

---------

Co-authored-by: Adi Muraru <amuraru@adobe.com>
Co-authored-by: Adrian Lungu <adrian.lungu89@gmail.com>
Co-authored-by: Razvan Dobre <dobre.razvan@gmail.com>
Co-authored-by: Adrian Muraru <adi.muraru@gmail.com>
Co-authored-by: Adrian Coman <acoman@adobe.com>
Co-authored-by: aguzovatii <guzovatii.anatolii@gmail.com>
amuraru pushed a commit that referenced this pull request Jun 10, 2023
amuraru pushed a commit that referenced this pull request Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants