Skip to content

Commit 4f4b5bc

Browse files
John ZakrzewskiJohn Zakrzewski
authored andcommitted
feat: configure callhome for tls with restapi
Signed-off-by: John Zakrzewski <[email protected]>
1 parent 47b5a17 commit 4f4b5bc

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

call-home/src/bin/callhome/main.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ struct CliArgs {
5252
/// The endpoint to fetch events stats.
5353
#[clap(long, short)]
5454
aggregator_url: Option<Url>,
55+
56+
/// The path to the TLS CA certificate
57+
#[clap(long, short)]
58+
tls_client_ca_path: Option<String>,
5559
}
5660
impl CliArgs {
5761
fn args() -> Self {
@@ -107,12 +111,42 @@ async fn run(logs: Arc<Mutex<VecDeque<LogEntry>>>) -> anyhow::Result<()> {
107111
anyhow::anyhow!("failed to generate metrics receiver client: {:?}", error)
108112
})?;
109113

114+
let ca_certificate_path = args.tls_client_ca_path;
115+
let cert = match ca_certificate_path {
116+
Some(path) => {
117+
let cert = std::fs::read(path).map_err(|error| {
118+
anyhow::anyhow!("Failed to read certificate file, Error: '{:?}'", error)
119+
})?;
120+
Some(cert)
121+
}
122+
None => None,
123+
};
124+
110125
// Generate Mayastor REST client.
111-
let config = Configuration::builder()
112-
.with_timeout(Duration::from_secs(30))
113-
.with_tracing(true)
114-
.build_url(endpoint)
115-
.map_err(|error| anyhow::anyhow!("failed to create openapi configuration: {:?}", error))?;
126+
let config = match (endpoint.scheme(), cert.as_deref()) {
127+
("https", Some(cert)) => Configuration::builder()
128+
.with_timeout(Duration::from_secs(30))
129+
.with_tracing(true)
130+
.with_certificate(cert)
131+
.build_url(endpoint)
132+
.map_err(|error| {
133+
anyhow::anyhow!("failed to create openapi configuration: {:?}", error)
134+
})?,
135+
("https", None) => {
136+
anyhow::bail!("HTTPS endpoint requires a CA certificate path");
137+
}
138+
(_, Some(_path)) => {
139+
anyhow::bail!("TLS certificate is only supported for HTTPS connection")
140+
}
141+
_ => Configuration::builder()
142+
.with_timeout(Duration::from_secs(30))
143+
.with_tracing(true)
144+
.build_url(endpoint)
145+
.map_err(|error| {
146+
anyhow::anyhow!("failed to create openapi configuration: {:?}", error)
147+
})?,
148+
};
149+
116150
let client = openapi::clients::tower::ApiClient::new(config);
117151

118152
loop {

chart/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This removes all the Kubernetes components associated with the chart and deletes
5656
|------------|------|---------|
5757
| | crds | 0.0.0 |
5858
| https://charts.bitnami.com/bitnami | etcd | 8.6.0 |
59+
| https://charts.jetstack.io | cert-manager(cert-manager) | v1.17.0 |
5960
| https://grafana.github.io/helm-charts | loki-stack | 2.9.11 |
6061
| https://jaegertracing.github.io/helm-charts | jaeger-operator | 2.50.1 |
6162
| https://nats-io.github.io/k8s/helm/charts/ | nats | 0.19.14 |
@@ -114,6 +115,7 @@ This removes all the Kubernetes components associated with the chart and deletes
114115
| apis.&ZeroWidthSpace;rest.&ZeroWidthSpace;service.&ZeroWidthSpace;type | Rest K8s service type | `"ClusterIP"` |
115116
| apis.&ZeroWidthSpace;rest.&ZeroWidthSpace;tolerations | Set tolerations, overrides global | `[]` |
116117
| base.&ZeroWidthSpace;cache_poll_period | Cache timeout for core agent & diskpool deployment | `"30s"` |
118+
| base.&ZeroWidthSpace;cert-manager.&ZeroWidthSpace;enabled | Enable cert-manager only if tls is enabled | `false` |
117119
| base.&ZeroWidthSpace;default_req_timeout | Request timeout for rest & core agents | `"5s"` |
118120
| base.&ZeroWidthSpace;logging.&ZeroWidthSpace;color | Enable ansi color code for Pod StdOut/StdErr | `true` |
119121
| base.&ZeroWidthSpace;logging.&ZeroWidthSpace;format | Valid values for format are pretty, json and compact | `"pretty"` |

chart/templates/mayastor/csi/csi-controller-deployment.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ spec:
131131
{{- else }}
132132
- "--rest-endpoint=http://{{ .Release.Name }}-api-rest:8081"
133133
{{- end }}
134-
135134
env:
136135
- name: RUST_LOG
137136
value: {{ .Values.csi.controller.logLevel }}

chart/templates/mayastor/obs/obs-callhome-deployment.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,31 @@ spec:
3737
- name: obs-callhome
3838
image: "{{ .Values.image.registry }}/{{ .Values.image.repo }}/{{ include "image_prefix" . }}-obs-callhome:{{ default .Values.image.tag .Values.image.repoTags.extensions }}"
3939
args:
40-
- "-e http://{{ .Release.Name }}-api-rest:8081"
4140
- "-n {{ .Release.Namespace }}"{{ if .Values.eventing.enabled }}
4241
- "--aggregator-url=http://{{ .Release.Name }}-obs-callhome-stats:9090/stats"{{ end }}
4342
{{ if .Values.obs.callhome.sendReport }}
4443
- "--send-report"
4544
{{ end }}
45+
{{- if .Values.tls.enabled }}
46+
- "--e=https://{{ .Release.Name }}-api-rest:8080"
47+
- "--tls-client-ca-path=/etc/client_cert/ca.crt" # CA cert for client verification with rest
48+
{{- else }}
49+
- "--e=http://{{ .Release.Name }}-api-rest:8081"
50+
{{- end }}
4651
env:
4752
- name: RUST_LOG
4853
value: {{ .Values.obs.callhome.logLevel }}
4954
{{- if .Values.obs.callhome.productName }}
5055
- name: CALLHOME_PRODUCT_NAME
5156
value: {{ .Values.obs.callhome.productName | quote }}
5257
{{- end }}
58+
volumeMounts:
59+
{{- if .Values.tls.enabled }}
60+
- name: ca-cert
61+
mountPath: /etc/client_cert/ca.crt
62+
subPath: ca.crt
63+
readOnly: true
64+
{{- end }}
5365
imagePullPolicy: {{ .Values.image.pullPolicy }}
5466
resources:
5567
limits:
@@ -83,4 +95,11 @@ spec:
8395
cpu: {{ .Values.obs.stats.resources.requests.cpu | quote }}
8496
memory: {{ .Values.obs.stats.resources.requests.memory | quote }}
8597
{{- end }}
98+
volumes:
99+
{{- if .Values.tls.enabled }}
100+
- name: ca-cert
101+
secret:
102+
defaultMode: 420
103+
secretName: api-rest-tls
104+
{{- end }}
86105
{{- end }}

0 commit comments

Comments
 (0)