Skip to content

Commit a4c2d22

Browse files
authored
Tesla fleet integration (#166)
* Add Tesla Fleet public-key host for Home Assistant Serve /.well-known/appspecific/com.tesla.3p.public-key.pem on tesla.${CLUSTER_DOMAIN_NAME} via a minimal ConfigMap-backed nginx static server, so the Home Assistant Tesla Fleet integration can host its virtual key for command signing. * Fix Tesla key ingress: use ImplementationSpecific pathType ingress-nginx's admission webhook rejects Exact/Prefix paths containing regex-significant characters (the dots in the .well-known filename). ImplementationSpecific matches the repo's base ingress and serves the literal path.
1 parent 9f4b011 commit a4c2d22

7 files changed

Lines changed: 168 additions & 0 deletions

File tree

apps/TeslaPublicKey.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
apiVersion: kustomize.toolkit.fluxcd.io/v1
3+
kind: Kustomization
4+
metadata:
5+
name: tesla-public-key
6+
namespace: default
7+
spec:
8+
interval: 1h
9+
path: ./apps/generic/overlays/tesla-public-key/
10+
prune: true
11+
sourceRef:
12+
kind: GitRepository
13+
name: k8s-infrastructure
14+
namespace: kube-system
15+
healthChecks:
16+
- apiVersion: apps/v1
17+
kind: Deployment
18+
name: tesla-public-key
19+
namespace: default
20+
postBuild:
21+
substituteFrom:
22+
- kind: Secret
23+
name: secrets
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: tesla-public-key
6+
data:
7+
# Non-secret EC P-256 public key. Must match the private key at
8+
# HA's config/tesla_fleet.key (generated together via openssl).
9+
com.tesla.3p.public-key.pem: |
10+
-----BEGIN PUBLIC KEY-----
11+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEh5ur3PRFsJ16HmHd8IWU92GbyUbZ
12+
QrQu2OShB+CkScC7cH+12mL9YHVP9PR3IeyMW1RJJufigVgL33bzMpvwqQ==
13+
-----END PUBLIC KEY-----
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
namespace: default
5+
resources:
6+
- ../../base/
7+
- configmap.yaml
8+
9+
labels:
10+
- pairs:
11+
app.kubernetes.io/name: tesla-public-key
12+
includeSelectors: true
13+
14+
patches:
15+
- path: patches/deployment.yaml
16+
target:
17+
group: apps
18+
version: v1
19+
kind: Deployment
20+
name: deployment
21+
namespace: default
22+
options:
23+
allowNameChange: true
24+
- path: patches/ingress.yaml
25+
target:
26+
group: networking.k8s.io
27+
version: v1
28+
kind: Ingress
29+
name: ingress
30+
namespace: default
31+
options:
32+
allowNameChange: true
33+
- path: patches/service.yaml
34+
target:
35+
group: ""
36+
version: v1
37+
kind: Service
38+
name: service
39+
namespace: default
40+
options:
41+
allowNameChange: true
42+
# The generic base attaches yasr/backup/main PVCs; this static server only
43+
# needs the public-key ConfigMap, so replace the volumes list entirely.
44+
- patch: |-
45+
- op: replace
46+
path: /spec/template/spec/volumes
47+
value:
48+
- name: pubkey
49+
configMap:
50+
name: tesla-public-key
51+
target:
52+
group: apps
53+
version: v1
54+
kind: Deployment
55+
name: tesla-public-key
56+
- patch: |-
57+
- op: replace
58+
path: /spec/rules/0/host
59+
value: tesla.${CLUSTER_DOMAIN_NAME}
60+
- op: replace
61+
path: /spec/rules/0/http/paths/0/path
62+
value: /.well-known/appspecific/com.tesla.3p.public-key.pem
63+
- op: replace
64+
path: /spec/rules/0/http/paths/0/pathType
65+
value: ImplementationSpecific
66+
- op: replace
67+
path: /spec/rules/0/http/paths/0/backend/service/name
68+
value: tesla-public-key
69+
- op: replace
70+
path: /spec/tls/0/hosts/0
71+
value: tesla.${CLUSTER_DOMAIN_NAME}
72+
target:
73+
group: networking.k8s.io
74+
version: v1
75+
kind: Ingress
76+
name: tesla-public-key
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: tesla-public-key
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: container
10+
image: nginx:alpine
11+
imagePullPolicy: IfNotPresent
12+
ports:
13+
- name: http
14+
containerPort: 80
15+
protocol: TCP
16+
volumeMounts:
17+
- name: pubkey
18+
mountPath: /usr/share/nginx/html/.well-known/appspecific/com.tesla.3p.public-key.pem
19+
subPath: com.tesla.3p.public-key.pem
20+
readOnly: true
21+
livenessProbe:
22+
httpGet:
23+
scheme: HTTP
24+
path: /.well-known/appspecific/com.tesla.3p.public-key.pem
25+
port: http
26+
initialDelaySeconds: 10
27+
timeoutSeconds: 10
28+
readinessProbe:
29+
httpGet:
30+
scheme: HTTP
31+
path: /.well-known/appspecific/com.tesla.3p.public-key.pem
32+
port: http
33+
initialDelaySeconds: 5
34+
timeoutSeconds: 10
35+
resources:
36+
requests:
37+
cpu: 10m
38+
memory: 16Mi
39+
limits:
40+
cpu: 100m
41+
memory: 64Mi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: tesla-public-key
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: tesla-public-key
5+
spec:
6+
ports:
7+
- name: http
8+
port: 80
9+
protocol: TCP
10+
targetPort: http

clusters/rafag/apps/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resources:
77
- ../../../apps/Bitwarden.yaml
88
- ../../../apps/Forecastle.yaml
99
- ../../../apps/HomeAssistant.yaml
10+
- ../../../apps/TeslaPublicKey.yaml
1011
- ../../../apps/MosquitoMQTTBroker.yaml
1112
- ../../../apps/Paperless.yaml
1213
- ../../../apps/Photoprism.yaml

0 commit comments

Comments
 (0)