Skip to content

Commit

Permalink
Replace principle by principal in kerberos-related code (#43679)
Browse files Browse the repository at this point in the history
Kerberos has the notion of a [principal](https://web.mit.edu/kerberos/krb5-1.5/krb5-1.5.4/doc/krb5-user/What-is-a-Kerberos-Principal_003f.html). "principle" was a typo.

Signed-off-by: Balthazar Rouberol <brouberol@wikimedia.org>
  • Loading branch information
brouberol authored Nov 19, 2024
1 parent 672056f commit 8daf74e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions airflow/security/kerberos.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class KerberosMode(Enum):
ONE_TIME = "one-time"


def get_kerberos_principle(principal: str | None) -> str:
def get_kerberos_principal(principal: str | None) -> str:
"""Retrieve Kerberos principal. Fallback to principal from Airflow configuration if not provided."""
return principal or conf.get_mandatory_value("kerberos", "principal").replace("_HOST", get_hostname())

Expand All @@ -77,7 +77,7 @@ def renew_from_kt(principal: str | None, keytab: str, exit_on_fail: bool = True)
# minutes to give ourselves a large renewal buffer.
renewal_lifetime = f"{conf.getint('kerberos', 'reinit_frequency')}m"

cmd_principal = get_kerberos_principle(principal)
cmd_principal = get_kerberos_principal(principal)
if conf.getboolean("kerberos", "forwardable"):
forwardable = "-f"
else:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/43679.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Renamed ``airflow.security.kerberos.get_kerberos_principle`` to ``airflow.security.kerberos.get_kerberos_principal`` due to misspelling.
10 changes: 5 additions & 5 deletions tests/security/test_kerberos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import pytest

from airflow.security import kerberos
from airflow.security.kerberos import get_kerberos_principle, renew_from_kt
from airflow.security.kerberos import get_kerberos_principal, renew_from_kt

from tests_common.test_utils.config import conf_vars

Expand Down Expand Up @@ -285,13 +285,13 @@ def test_run(self, mock_sleep, mock_renew_from_kt):
mock.call("test-principal", "/tmp/keytab"),
]

def test_get_kerberos_principle(self):
def test_get_kerberos_principal(self):
expected_principal = "test-principal"
principal = get_kerberos_principle(expected_principal)
principal = get_kerberos_principal(expected_principal)
assert principal == expected_principal

@mock.patch("airflow.security.kerberos.get_hostname", return_value="REPLACEMENT_HOST")
@mock.patch("airflow.security.kerberos.conf.get_mandatory_value", return_value="test-principal/_HOST")
def test_get_kerberos_principle_resolve_null_principal(self, get_madantory_value_mock, get_hostname_mock):
principal = get_kerberos_principle(principal=None)
def test_get_kerberos_principal_resolve_null_principal(self, get_madantory_value_mock, get_hostname_mock):
principal = get_kerberos_principal(principal=None)
assert principal == "test-principal/REPLACEMENT_HOST"

0 comments on commit 8daf74e

Please sign in to comment.