Skip to content
Merged
11 changes: 11 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ If release name contains chart name it will be used as a full name.
name: {{ template "webserver_secret_key_secret" . }}
key: webserver-secret-key
{{- end }}
{{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__API_AUTH__JWT_SECRET }}
- name: AIRFLOW__API_AUTH__JWT_SECRET
valueFrom:
secretKeyRef:
name: {{ template "jwt_secret" . }}
key: jwt-secret
{{- end }}
{{- if or (contains "CeleryExecutor" .Values.executor) (contains "CeleryKubernetesExecutor" .Values.executor) }}
{{- if or (semverCompare "<2.4.0" .Values.airflowVersion) (.Values.data.resultBackendSecretName) (.Values.data.resultBackendConnection) }}
{{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CELERY__CELERY_RESULT_BACKEND }}
Expand Down Expand Up @@ -396,6 +403,10 @@ If release name contains chart name it will be used as a full name.
{{- default (printf "%s-fernet-key" .Release.Name) .Values.fernetKeySecretName }}
{{- end }}

{{- define "jwt_secret" -}}
{{- default (printf "%s-jwt-secret" .Release.Name) .Values.jwtSecretName }}
{{- end }}

{{- define "webserver_secret_key_secret" -}}
{{- default (printf "%s-webserver-secret-key" (include "airflow.fullname" .)) .Values.webserverSecretKeySecretName }}
{{- end }}
Expand Down
45 changes: 45 additions & 0 deletions chart/templates/secrets/jwt-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/}}

############################################
## Airflow JWT Secret
############################################
{{- if not .Values.jwtSecretName }}
{{ $generated_secret_key := (randAlphaNum 32 | b64enc) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "airflow.fullname" . }}-jwt-secret
labels:
tier: airflow
component: api-server
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
"helm.sh/hook": "pre-install"
"helm.sh/hook-delete-policy": "before-hook-creation"
"helm.sh/hook-weight": "0"
type: Opaque
data:
jwt-secret: {{ (default $generated_secret_key .Values.jwtSecret) | b64enc | quote }}
{{- end }}
23 changes: 23 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@
"type": "boolean",
"default": true
},
"AIRFLOW__API_AUTH__JWT_SECRET": {
"description": "Enable ``AIRFLOW__API_AUTH__JWT_SECRET`` variable to be read from the JWT Secret",
"type": "boolean",
"default": true
},
"AIRFLOW__WEBSERVER__SECRET_KEY": {
"description": "Enable ``AIRFLOW__WEBSERVER__SECRET_KEY`` variable to be read from the Webserver Secret Key Secret",
"type": "boolean",
Expand Down Expand Up @@ -1459,6 +1464,24 @@
"type": "string"
}
},
"jwtSecret": {
"description": "Secret key used to encode and decode JWTs to authenticate to public and private APIs (can only be set during install, not upgrade).",
"type": [
"string",
"null"
],
"x-docsSection": "Common",
"default": null
},
"jwtSecretName": {
"description": "The JWT secret name.",
"type": [
"string",
"null"
],
"x-docsSection": "Airflow",
"default": null
},
"webserverSecretKey": {
"description": "The Flask secret key for Airflow Webserver to encrypt browser session.",
"type": [
Expand Down
5 changes: 5 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ enableBuiltInSecretEnvVars:
AIRFLOW__CORE__SQL_ALCHEMY_CONN: true
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: true
AIRFLOW_CONN_AIRFLOW_DB: true
AIRFLOW__API_AUTH__JWT_SECRET: true
AIRFLOW__WEBSERVER__SECRET_KEY: true
AIRFLOW__CELERY__CELERY_RESULT_BACKEND: true
AIRFLOW__CELERY__RESULT_BACKEND: true
Expand Down Expand Up @@ -556,6 +557,10 @@ webserverSecretKey: ~
webserverSecretAnnotations: {}
webserverSecretKeySecretName: ~

# Secret key used to encode and decode JWTs: `[api_auth] jwt_secret` in airflow.cfg
jwtSecret: ~
jwtSecretName: ~

# In order to use kerberos you need to create secret containing the keytab file
# The secret name should follow naming convention of the application where resources are
# name {{ .Release-name }}-<POSTFIX>. In case of the keytab file, the postfix is "kerberos-keytab"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def test_should_disable_some_variables(self):
"enableBuiltInSecretEnvVars": {
"AIRFLOW__CORE__SQL_ALCHEMY_CONN": False,
"AIRFLOW__DATABASE__SQL_ALCHEMY_CONN": False,
"AIRFLOW__API_AUTH__JWT_SECRET": False,
"AIRFLOW__WEBSERVER__SECRET_KEY": False,
# the following vars only appear if remote logging is set, so disabling them in this test is kind of a no-op
"AIRFLOW__ELASTICSEARCH__HOST": False,
Expand Down Expand Up @@ -370,6 +371,7 @@ def test_have_all_variables(self):
"AIRFLOW__DATABASE__SQL_ALCHEMY_CONN",
"AIRFLOW_CONN_AIRFLOW_DB",
"AIRFLOW__WEBSERVER__SECRET_KEY",
"AIRFLOW__API_AUTH__JWT_SECRET",
"AIRFLOW__CELERY__BROKER_URL",
]
expected_vars_in_worker = ["DUMB_INIT_SETSID"] + expected_vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
("Secret", "test-basic-airflow-metadata"),
("Secret", "test-basic-broker-url"),
("Secret", "test-basic-fernet-key"),
("Secret", "test-basic-airflow-jwt-secret"),
("Secret", "test-basic-airflow-webserver-secret-key"),
("Secret", "test-basic-redis-password"),
("Secret", "test-basic-postgresql"),
Expand Down Expand Up @@ -136,6 +137,7 @@ def test_basic_deployments(self, version):
("Secret", "test-basic-metadata"),
("Secret", "test-basic-broker-url"),
("Secret", "test-basic-fernet-key"),
("Secret", "test-basic-jwt-secret"),
("Secret", "test-basic-webserver-secret-key"),
("Secret", "test-basic-postgresql"),
("Secret", "test-basic-redis-password"),
Expand Down Expand Up @@ -236,6 +238,7 @@ def test_basic_deployment_with_standalone_dag_processor(self, version):
("Secret", "test-basic-metadata"),
("Secret", "test-basic-broker-url"),
("Secret", "test-basic-fernet-key"),
("Secret", "test-basic-jwt-secret"),
("Secret", "test-basic-webserver-secret-key"),
("Secret", "test-basic-postgresql"),
("Secret", "test-basic-redis-password"),
Expand Down
1 change: 1 addition & 0 deletions helm-tests/tests/helm_tests/security/test_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
("StatefulSet", "test-rbac-worker"),
("Secret", "test-rbac-broker-url"),
("Secret", "test-rbac-fernet-key"),
("Secret", "test-rbac-jwt-secret"),
("Secret", "test-rbac-redis-password"),
("Secret", "test-rbac-webserver-secret-key"),
("Job", "test-rbac-create-user"),
Expand Down