Skip to content

Commit

Permalink
feat: add MTLS.permitMetrics to optionally enable Istio permissive mo…
Browse files Browse the repository at this point in the history
…de on the metrics port
  • Loading branch information
sobotklp committed Jan 24, 2025
1 parent 210b0da commit 6842868
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/temporalcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ type MTLSSpec struct {
// Useless if mTLS provider is not cert-manager.
// +optional
RenewBefore *metav1.Duration `json:"renewBefore,omitempty"`
// PermitMetrics allows insecure HTTP requests to the metrics endpoint.
// This is handy if the metrics collector does not support mTLS.
// Useless if mTLS provider is not istio
// +optional
PermitMetrics bool `json:"permitMetrics"`
}

func (m *MTLSSpec) InternodeEnabled() bool {
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/temporal.io_temporalclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,12 @@ spec:
description: Enabled defines if the operator should enable mTLS for network between cluster nodes.
type: boolean
type: object
permitMetrics:
description: |-
PermitMetrics allows insecure HTTP requests to the metrics endpoint.
This is handy if the metrics collector does not support mTLS.
Useless if mTLS provider is not istio
type: boolean
provider:
default: cert-manager
description: Provider defines the tool used to manage mTLS certificates.
Expand Down
18 changes: 16 additions & 2 deletions docs/api/v1beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,20 @@ issued certificate’s duration. Minimum accepted value is 5 minutes.
Useless if mTLS provider is not cert-manager.</p>
</td>
</tr>
<tr>
<td>
<code>permitMetrics</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>PermitMetrics allows insecure HTTP requests to the metrics endpoint.
This is handy if the metrics collector does not support mTLS.
Useless if mTLS provider is not istio</p>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -2388,7 +2402,7 @@ map[string]string
<td>
<code>override</code><br>
<em>
<a href="https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ServiceMonitorSpec">
<a href="https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.ServiceMonitorSpec">
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1.ServiceMonitorSpec
</a>
</em>
Expand All @@ -2403,7 +2417,7 @@ All fields can be overwritten except &ldquo;endpoints&rdquo;, &ldquo;selector&rd
<td>
<code>metricRelabelings</code><br>
<em>
<a href="https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.RelabelConfig">
<a href="https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.RelabelConfig">
[]github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1.RelabelConfig
</a>
</em>
Expand Down
15 changes: 14 additions & 1 deletion docs/features/mtls/istio.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ spec:
# [...]
```

The Operator creates for each temporal services a `DestinationRule` and a `PeerAuthentication`. They both ensure mutual and strict mTLS.
The Operator creates for each temporal services a `DestinationRule` and a `PeerAuthentication`. They both ensure mutual and strict mTLS.

# Allowing permissive mTLS for metrics

If your metrics collector isn't using Istio or is otherwise unable to connect using mTLS, you can enable permissive mode for the metrics port.

```yaml
spec:
# [...]
mTLS:
provider: istio
permitMetrics: true
# [...]
```
8 changes: 8 additions & 0 deletions internal/resource/mtls/istio/peer_authentication_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func (b *PeerAuthenticationBuilder) Update(object client.Object) error {
},
}

if b.instance.Spec.Metrics.IsEnabled() && b.instance.Spec.MTLS.PermitMetrics {
pa.Spec.PortLevelMtls = map[uint32]*istioapisecurityv1beta1.PeerAuthentication_MutualTLS{
uint32(*b.instance.Spec.Metrics.Prometheus.ListenPort): {

Check failure on line 83 in internal/resource/mtls/istio/peer_authentication_builder.go

View workflow job for this annotation

GitHub Actions / Lint files

G115: integer overflow conversion int32 -> uint32 (gosec)
Mode: istioapisecurityv1beta1.PeerAuthentication_MutualTLS_PERMISSIVE,
},
}
}

if err := controllerutil.SetControllerReference(b.instance, pa, b.scheme); err != nil {
return fmt.Errorf("failed setting controller reference: %w", err)
}
Expand Down

0 comments on commit 6842868

Please sign in to comment.