Skip to content

Commit a706a5c

Browse files
pcapriottijschaulakshaymankar
authored
Support client certificates in federator (#1682)
This adds support for client authentication using TLS certificates when making requests to a remote backend. Summary of changes - Added new configuration options for client certificate and private key - Configured demo nginz to require client certificates - Read client certificate on federator startup - Use client certificate when creating a GRPC client - Upgrade haskell packages tls and cryptonite - Add script to serve helm charts in a repository running at http://localhost:4001 Co-authored-by: jschaul <[email protected]> Co-authored-by: Akshay Mankar <[email protected]>
1 parent d22bbc7 commit a706a5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+568
-131
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# [unreleased]
2424

25-
[please put all changes that only affect federation into this section to unclutter the rest of the release notes.]
25+
[please put all changes that only affect federation into the "Federation changes" section to unclutter the rest of the release notes.]
2626
[if something is both an API change and a feature, please mention it twice (you can abbreviate the second mention and add "see above").]
2727

2828
## Release Notes
@@ -37,6 +37,9 @@
3737

3838
## Internal changes
3939

40+
## Federation changes
41+
42+
* Added client certificate support for server to server authentication (#1682)
4043

4144
# [2021-08-16]
4245

@@ -72,7 +75,6 @@ This is a routine release requiring only the routine upgrade steps.
7275
* Added a mechanism to derive `AsUnion` instances automatically (#1693)
7376
* Integration test coverage (#1696, #1704)
7477

75-
7678
# [2021-08-02]
7779

7880
## Release Notes
@@ -124,7 +126,6 @@ Upgrade nginz (#1658)
124126
* Renamed `DomainHeader` type to `OriginDomainHeader` (#1689)
125127
* Added golden tests for protobuf serialisation / deserialisation (#1644).
126128

127-
128129
# [2021-07-09]
129130

130131
## Release Notes

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ chart-%:
334334
.PHONY: charts-integration
335335
charts-integration: $(foreach chartName,$(CHARTS_INTEGRATION),chart-$(chartName))
336336

337+
.PHONY: charts-serve
338+
charts-serve: charts-integration
339+
./hack/bin/serve-charts.sh $(CHARTS_INTEGRATION)
340+
337341
# Usecase for this make target:
338342
# 1. for releases of helm charts
339343
# 2. for testing helm charts more generally

charts/federator/templates/ca.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: "federator-ca"
5+
labels:
6+
wireService: federator
7+
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
data:
11+
{{- if .Values.remoteCAContents }}
12+
ca.crt: {{ .Values.remoteCAContents | quote }}
13+
{{- else }}
14+
{}
15+
{{- end }}

charts/federator/templates/configmap-ca.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

charts/federator/templates/configmap.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ data:
4343
# Filepath to one or more PEM-encoded server certificates to use as a trust
4444
# store when making grpc requests to remote backends
4545
{{- if $.Values.remoteCAContents }}
46-
remoteCAStore: "/etc/wire/federator/ca/remote-ca.pem"
46+
remoteCAStore: "/etc/wire/federator/ca/ca.crt"
4747
{{- end }}
48+
clientCertificate: "/etc/wire/federator/secrets/tls.crt"
49+
clientPrivateKey: "/etc/wire/federator/secrets/tls.key"
4850
useSystemCAStore: {{ .useSystemCAStore }}
4951
federationStrategy:
5052
{{- if .federationStrategy.allowAll }}

charts/federator/templates/deployment.yaml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,43 @@ spec:
2525
annotations:
2626
# An annotation of the configmap checksum ensures changes to the configmap cause a redeployment upon `helm upgrade`
2727
checksum/configmap: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
28-
checksum/configmap-ca: {{ include (print .Template.BasePath "/configmap-ca.yaml") . | sha256sum }}
28+
{{- if not .Values.tls.shareFederatorSecret }}
29+
checksum/secret: {{ include (print .Template.BasePath "/secret.yaml") . | sha256sum }}
30+
{{- end }}
2931
fluentbit.io/parser: json
3032
spec:
3133
volumes:
3234
- name: "federator-config"
3335
configMap:
3436
name: "federator"
35-
# federator-ca holds CA certificates to use as a trust store
36-
# when making requests to remote backends
37-
- name: "federator-ca"
37+
38+
# federator-secrets contains the client certificate and the
39+
# corresponding private key to use when making requests to remote
40+
# backends.
41+
# NOTE: if tls.useSharedFederatorSecret is set, we use the same secret
42+
# as the one for the federator ingress
43+
- name: "federator-secrets"
3844
secret:
39-
secretName: "federator-ca"
45+
secretName: {{ if .Values.tls.useSharedFederatorSecret -}}
46+
"federator-certificate-secret"
47+
{{- else if .Values.clientCertificateContents -}}
48+
"federator-secret"
49+
{{- else }}
50+
{{ fail "must set .Values.tls.useSharedFederatorSecret to true or specify .Values.clientCertificateContents" }}
51+
{{- end }}
52+
53+
- name: "federator-ca"
54+
configMap:
55+
name: "federator-ca"
4056
containers:
4157
- name: federator
4258
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
4359
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
4460
volumeMounts:
4561
- name: "federator-config"
4662
mountPath: "/etc/wire/federator/conf"
63+
- name: "federator-secrets"
64+
mountPath: "/etc/wire/federator/secrets"
4765
- name: "federator-ca"
4866
mountPath: "/etc/wire/federator/ca"
4967
ports:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if not .Values.tls.useSharedFederatorSecret -}}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: "federator-secret"
6+
labels:
7+
wireService: federator
8+
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
9+
release: {{ .Release.Name }}
10+
heritage: {{ .Release.Service }}
11+
type: kubernetes.io/tls
12+
data:
13+
{{- if .Values.clientPrivateKeyContents }}
14+
tls.key: {{ .Values.clientPrivateKeyContents | b64enc | quote }}
15+
{{- end -}}
16+
{{- if .Values.clientCertificateContents }}
17+
tls.crt: {{ .Values.clientCertificateContents | b64enc | quote }}
18+
{{- end -}}
19+
{{- end -}}

charts/federator/templates/tests/federator-integration.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ spec:
1313
- name: "federator-config"
1414
configMap:
1515
name: "federator"
16+
# integration tests need access to the client certificate private key
17+
- name: "federator-secrets"
18+
secret:
19+
secretName: "federator-secret"
1620
# integration tests need access to the CA
1721
- name: "federator-ca"
18-
secret:
19-
secretName: "federator-ca"
22+
configMap:
23+
name: "federator-ca"
2024
containers:
2125
- name: integration
2226
command: ["federator-integration"]
@@ -26,6 +30,8 @@ spec:
2630
mountPath: "/etc/wire/integration"
2731
- name: "federator-config"
2832
mountPath: "/etc/wire/federator/conf"
33+
- name: "federator-secrets"
34+
mountPath: "/etc/wire/federator/secrets"
2935
- name: "federator-ca"
3036
mountPath: "/etc/wire/federator/ca"
3137
restartPolicy: Never

charts/federator/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ service:
88
internalFederatorPort: 8080
99
externalFederatorPort: 8081
1010

11+
tls:
12+
# if enabled, federator will get its client certificate and private key from
13+
# the secret used by the federator ingress
14+
useSharedFederatorSecret: false
15+
1116
resources:
1217
# FUTUREWORK: come up with numbers which didn't appear out of thin air
1318
requests:
@@ -30,6 +35,9 @@ config:
3035
#
3136
# Using custom CA doesn't automatically disable system CA store, it should
3237
# be disabled explicitly by setting useSystemCAStore to false.
38+
#
39+
# A client certificate and corresponding private key can be specified
40+
# similarly to a custom CA store.
3341
useSystemCAStore: true
3442
federationStrategy:
3543
allowedDomains: []
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- /* This is the CA used by the federator ingress to verify client
2+
certificates. This does not need to be a secret in principle, but the ingress
3+
controller requires it to be. Also, this could in principle be bundled with the
4+
corresponding certificate (in secret_federator.yaml), but it is a separate
5+
secret because cert-manager interferes with the ca.crt field when setting the
6+
certificate in a secret. */ -}}
7+
8+
{{- if .Values.federator.enabled -}}
9+
apiVersion: v1
10+
kind: Secret
11+
metadata:
12+
name: federator-ca-secret
13+
labels:
14+
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
15+
release: "{{ .Release.Name }}"
16+
heritage: "{{ .Release.Service }}"
17+
data:
18+
ca.crt: {{ .Values.secrets.tlsClientCA | b64enc | quote }}
19+
{{- end -}}

0 commit comments

Comments
 (0)