Skip to content

Commit

Permalink
better handle projected SA volume defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
piax93 committed Jun 6, 2024
1 parent feaad97 commit 6ffd941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions task_processing/plugins/kubernetes/task_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from task_processing.plugins.kubernetes.types import ProjectedSAVolume
from task_processing.plugins.kubernetes.types import SecretVolume
from task_processing.plugins.kubernetes.types import SecretVolumeItem
from task_processing.plugins.kubernetes.utils import (
DEFAULT_PROJECTED_SA_TOKEN_EXPIRATION_SECONDS,
)
from task_processing.plugins.kubernetes.utils import get_sanitised_kubernetes_name
from task_processing.plugins.kubernetes.utils import mode_to_int

Expand Down Expand Up @@ -194,6 +197,7 @@ def _valid_secret_volumes(
def _valid_projected_sa_volumes(
sa_volumes: Sequence[ProjectedSAVolume],
) -> Tuple[bool, Optional[str]]:
min_expiration = 600
for volume in sa_volumes:
if not volume.get("audience"):
return (
Expand All @@ -205,10 +209,15 @@ def _valid_projected_sa_volumes(
False,
"No token container_path set for projected service account volume",
)
if volume.get("expiration_seconds", 1800) < 600:
if (
volume.get(
"expiration_seconds", DEFAULT_PROJECTED_SA_TOKEN_EXPIRATION_SECONDS
)
< min_expiration
):
return (
False,
"Expiration for service account projected token must be at least 600 seconds",
f"Expiration for service account projected token must be at least {min_expiration} seconds",
)
return (True, None)

Expand Down
10 changes: 8 additions & 2 deletions task_processing/plugins/kubernetes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
from task_processing.plugins.kubernetes.types import ObjectFieldSelectorSource
from task_processing.plugins.kubernetes.types import ProjectedSAVolume


logger = logging.getLogger(__name__)

DEFAULT_PROJECTED_SA_TOKEN_EXPIRATION_SECONDS = 1800


def get_capabilities_for_capability_changes(
cap_add: PVector[str],
Expand Down Expand Up @@ -374,7 +377,7 @@ def get_pod_service_account_token_volumes(
"""Build projected service account volumes for pod
:param PVector["ProjectedSAVolume"] sa_volumes: list of projected service account volume configs
:return: listof kubernetes pod volume objects
:return: list of kubernetes pod volume objects
"""
return [
V1Volume(
Expand All @@ -384,7 +387,10 @@ def get_pod_service_account_token_volumes(
V1VolumeProjection(
service_account_token=V1ServiceAccountTokenProjection(
audience=volume["audience"],
expiration_seconds=volume.get("expiration_seconds", 1800),
expiration_seconds=volume.get(
"expiration_seconds",
DEFAULT_PROJECTED_SA_TOKEN_EXPIRATION_SECONDS,
),
path="token",
),
),
Expand Down

0 comments on commit 6ffd941

Please sign in to comment.