Miretpl commented on code in PR #70896:
URL: https://github.com/apache/airflow/pull/70896#discussion_r3698776656


##########
chart/tests/helm_tests/airflow_aux/test_airflow_common.py:
##########
@@ -396,6 +396,53 @@ def test_have_all_variables(self):
                 f"Wrong vars in {component}"
             )
 
+    @pytest.mark.parametrize(
+        ("template", "main_container", "expected_jwt_secret"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server", 
True),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler", 
True),
+            ("templates/workers/worker-deployment.yaml", "worker", False),
+            ("templates/triggerer/triggerer-deployment.yaml", "triggerer", 
False),
+            ("templates/dag-processor/dag-processor-deployment.yaml", 
"dag-processor", False),
+        ],
+    )
+    def test_jwt_secret_only_injected_into_api_server_and_scheduler(
+        self, template, main_container, expected_jwt_secret
+    ):
+        docs = render_chart(show_only=[template])
+
+        containers = jmespath.search("spec.template.spec.containers", docs[0])
+        main = next(container for container in containers if container["name"] 
== main_container)
+        env_names = [env["name"] for env in main.get("env") or []]
+        assert env_names.count("AIRFLOW__API_AUTH__JWT_SECRET") == 
int(expected_jwt_secret)
+
+        # the secret must never leak into sidecars or init containers
+        others = [container for container in containers if container["name"] 
!= main_container]
+        others += jmespath.search("spec.template.spec.initContainers", 
docs[0]) or []
+        for container in others:
+            other_env_names = [env["name"] for env in container.get("env") or 
[]]
+            assert "AIRFLOW__API_AUTH__JWT_SECRET" not in other_env_names, (
+                f"JWT secret leaked into {container['name']}"
+            )
+
+    @pytest.mark.parametrize(
+        ("template", "main_container"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server"),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler"),
+        ],
+    )
+    def test_jwt_secret_can_be_disabled(self, template, main_container):
+        docs = render_chart(
+            values={"enableBuiltInSecretEnvVars": 
{"AIRFLOW__API_AUTH__JWT_SECRET": False}},
+            show_only=[template],
+        )
+
+        containers = jmespath.search("spec.template.spec.containers", docs[0])
+        main = next(container for container in containers if container["name"] 
== main_container)
+        env_names = [env["name"] for env in main.get("env") or []]

Review Comment:
   Could you move this logic to `jmespath.search`?



##########
chart/tests/helm_tests/airflow_aux/test_airflow_common.py:
##########
@@ -396,6 +396,53 @@ def test_have_all_variables(self):
                 f"Wrong vars in {component}"
             )
 
+    @pytest.mark.parametrize(
+        ("template", "main_container", "expected_jwt_secret"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server", 
True),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler", 
True),
+            ("templates/workers/worker-deployment.yaml", "worker", False),
+            ("templates/triggerer/triggerer-deployment.yaml", "triggerer", 
False),
+            ("templates/dag-processor/dag-processor-deployment.yaml", 
"dag-processor", False),
+        ],
+    )
+    def test_jwt_secret_only_injected_into_api_server_and_scheduler(
+        self, template, main_container, expected_jwt_secret
+    ):
+        docs = render_chart(show_only=[template])
+
+        containers = jmespath.search("spec.template.spec.containers", docs[0])
+        main = next(container for container in containers if container["name"] 
== main_container)
+        env_names = [env["name"] for env in main.get("env") or []]
+        assert env_names.count("AIRFLOW__API_AUTH__JWT_SECRET") == 
int(expected_jwt_secret)
+
+        # the secret must never leak into sidecars or init containers
+        others = [container for container in containers if container["name"] 
!= main_container]
+        others += jmespath.search("spec.template.spec.initContainers", 
docs[0]) or []
+        for container in others:
+            other_env_names = [env["name"] for env in container.get("env") or 
[]]
+            assert "AIRFLOW__API_AUTH__JWT_SECRET" not in other_env_names, (
+                f"JWT secret leaked into {container['name']}"
+            )
+
+    @pytest.mark.parametrize(
+        ("template", "main_container"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server"),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler"),
+        ],
+    )
+    def test_jwt_secret_can_be_disabled(self, template, main_container):

Review Comment:
   You don't really need the `template` parameter here.



##########
chart/tests/helm_tests/airflow_aux/test_airflow_common.py:
##########
@@ -396,6 +396,53 @@ def test_have_all_variables(self):
                 f"Wrong vars in {component}"
             )
 
+    @pytest.mark.parametrize(
+        ("template", "main_container", "expected_jwt_secret"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server", 
True),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler", 
True),
+            ("templates/workers/worker-deployment.yaml", "worker", False),
+            ("templates/triggerer/triggerer-deployment.yaml", "triggerer", 
False),
+            ("templates/dag-processor/dag-processor-deployment.yaml", 
"dag-processor", False),
+        ],
+    )
+    def test_jwt_secret_only_injected_into_api_server_and_scheduler(

Review Comment:
   I would split this test case into two: when you expect a secret and when you 
don't.



##########
chart/tests/helm_tests/airflow_aux/test_airflow_common.py:
##########
@@ -396,6 +396,53 @@ def test_have_all_variables(self):
                 f"Wrong vars in {component}"
             )
 
+    @pytest.mark.parametrize(
+        ("template", "main_container", "expected_jwt_secret"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server", 
True),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler", 
True),
+            ("templates/workers/worker-deployment.yaml", "worker", False),
+            ("templates/triggerer/triggerer-deployment.yaml", "triggerer", 
False),
+            ("templates/dag-processor/dag-processor-deployment.yaml", 
"dag-processor", False),
+        ],
+    )
+    def test_jwt_secret_only_injected_into_api_server_and_scheduler(
+        self, template, main_container, expected_jwt_secret
+    ):
+        docs = render_chart(show_only=[template])
+
+        containers = jmespath.search("spec.template.spec.containers", docs[0])
+        main = next(container for container in containers if container["name"] 
== main_container)
+        env_names = [env["name"] for env in main.get("env") or []]

Review Comment:
   Could you move this logic to `jmespath.search`?



##########
chart/tests/helm_tests/airflow_aux/test_airflow_common.py:
##########
@@ -396,6 +396,53 @@ def test_have_all_variables(self):
                 f"Wrong vars in {component}"
             )
 
+    @pytest.mark.parametrize(
+        ("template", "main_container", "expected_jwt_secret"),
+        [
+            ("templates/api-server/api-server-deployment.yaml", "api-server", 
True),
+            ("templates/scheduler/scheduler-deployment.yaml", "scheduler", 
True),
+            ("templates/workers/worker-deployment.yaml", "worker", False),
+            ("templates/triggerer/triggerer-deployment.yaml", "triggerer", 
False),
+            ("templates/dag-processor/dag-processor-deployment.yaml", 
"dag-processor", False),
+        ],
+    )
+    def test_jwt_secret_only_injected_into_api_server_and_scheduler(
+        self, template, main_container, expected_jwt_secret
+    ):
+        docs = render_chart(show_only=[template])
+
+        containers = jmespath.search("spec.template.spec.containers", docs[0])
+        main = next(container for container in containers if container["name"] 
== main_container)
+        env_names = [env["name"] for env in main.get("env") or []]
+        assert env_names.count("AIRFLOW__API_AUTH__JWT_SECRET") == 
int(expected_jwt_secret)
+
+        # the secret must never leak into sidecars or init containers
+        others = [container for container in containers if container["name"] 
!= main_container]
+        others += jmespath.search("spec.template.spec.initContainers", 
docs[0]) or []
+        for container in others:
+            other_env_names = [env["name"] for env in container.get("env") or 
[]]
+            assert "AIRFLOW__API_AUTH__JWT_SECRET" not in other_env_names, (
+                f"JWT secret leaked into {container['name']}"
+            )

Review Comment:
   Could you move this logic to `jmespath.search`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to