Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outposts: Enhance config options for k8s outposts #7363

Merged
merged 9 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions authentik/outposts/controllers/k8s/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# priority than being updated.
if current.spec.selector != reference.spec.selector:
raise NeedsUpdate()
if current.spec.type != reference.spec.type:
raise NeedsUpdate()

Check warning on line 36 in authentik/outposts/controllers/k8s/service.py

View check run for this annotation

Codecov / codecov/patch

authentik/outposts/controllers/k8s/service.py#L35-L36

Added lines #L35 - L36 were not covered by tests
super().reconcile(current, reference)

def get_reference_object(self) -> V1Service:
Expand Down
22 changes: 15 additions & 7 deletions authentik/providers/proxy/controllers/k8s/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
proxy_provider: ProxyProvider
external_host_name = urlparse(proxy_provider.external_host)
expected_hosts.append(external_host_name.hostname)
if external_host_name.scheme == "https":
if (

Check warning on line 58 in authentik/providers/proxy/controllers/k8s/ingress.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/proxy/controllers/k8s/ingress.py#L58

Added line #L58 was not covered by tests
external_host_name.scheme == "https"
and self.controller.outpost.config.kubernetes_ingress_secret_name
):
expected_hosts_tls.append(external_host_name.hostname)
expected_hosts.sort()
expected_hosts_tls.sort()
Expand Down Expand Up @@ -115,7 +118,10 @@
):
proxy_provider: ProxyProvider
external_host_name = urlparse(proxy_provider.external_host)
if external_host_name.scheme == "https":
if (

Check warning on line 121 in authentik/providers/proxy/controllers/k8s/ingress.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/proxy/controllers/k8s/ingress.py#L121

Added line #L121 was not covered by tests
external_host_name.scheme == "https"
and self.controller.outpost.config.kubernetes_ingress_secret_name
):
tls_hosts.append(external_host_name.hostname)
if proxy_provider.mode in [
ProxyMode.FORWARD_SINGLE,
Expand Down Expand Up @@ -159,13 +165,15 @@
rules.append(rule)
tls_config = None
if tls_hosts:
tls_config = V1IngressTLS(
hosts=tls_hosts,
secret_name=self.controller.outpost.config.kubernetes_ingress_secret_name,
)
tls_config = [

Check warning on line 168 in authentik/providers/proxy/controllers/k8s/ingress.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/proxy/controllers/k8s/ingress.py#L168

Added line #L168 was not covered by tests
V1IngressTLS(
hosts=tls_hosts,
secret_name=self.controller.outpost.config.kubernetes_ingress_secret_name,
)
]
spec = V1IngressSpec(
rules=rules,
tls=[tls_config],
tls=tls_config,
)
if self.controller.outpost.config.kubernetes_ingress_class_name:
spec.ingress_class_name = self.controller.outpost.config.kubernetes_ingress_class_name
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/test_outpost_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from authentik.core.tests.utils import create_test_flow
from authentik.lib.config import CONFIG
from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler
from authentik.outposts.controllers.k8s.service import ServiceReconciler
from authentik.outposts.controllers.k8s.triggers import NeedsUpdate
from authentik.outposts.models import KubernetesServiceConnection, Outpost, OutpostType
from authentik.outposts.tasks import outpost_connection_discovery
Expand Down Expand Up @@ -90,6 +91,35 @@ def test_deployment_reconciler(self):

deployment_reconciler.delete(deployment_reconciler.get_reference_object())

@pytest.mark.timeout(120)
def test_service_reconciler(self):
"""test that service requires update"""
controller = ProxyKubernetesController(self.outpost, self.service_connection)
service_reconciler = ServiceReconciler(controller)

self.assertIsNotNone(service_reconciler.retrieve())

config = self.outpost.config
config.kubernetes_service_type = "NodePort"
config.kubernetes_json_patches = {
"service": [
{
"op": "add",
"path": "/spec/ipFamilyPolicy",
"value": "PreferDualStack",
}
]
}
self.outpost.config = config

with self.assertRaises(NeedsUpdate):
service_reconciler.reconcile(
service_reconciler.retrieve(),
service_reconciler.get_reference_object(),
)

service_reconciler.delete(service_reconciler.get_reference_object())

@pytest.mark.timeout(120)
def test_controller_rename(self):
"""test that objects get deleted and re-created with new names"""
Expand Down
2 changes: 1 addition & 1 deletion website/docs/outposts/_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ kubernetes_replicas: 1
kubernetes_namespace: authentik
# Any additional annotations to add to the ingress object, for example cert-manager
kubernetes_ingress_annotations: {}
# Name of the secret that is used for TLS connections
# Name of the secret that is used for TLS connections, leave empty to disable TLS
kubernetes_ingress_secret_name: authentik-outpost-tls
# Service kind created, can be set to LoadBalancer for LDAP outposts for example
kubernetes_service_type: ClusterIP
Expand Down
2 changes: 1 addition & 1 deletion website/docs/outposts/integrations/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The following outpost settings are used:
- `kubernetes_replicas`: Replica count for the deployment of the outpost
- `kubernetes_namespace`: Namespace to deploy in, defaults to the same namespace authentik is deployed in (if available)
- `kubernetes_ingress_annotations`: Any additional annotations to add to the ingress object, for example cert-manager
- `kubernetes_ingress_secret_name`: Name of the secret that is used for TLS connections
- `kubernetes_ingress_secret_name`: Name of the secret that is used for TLS connections, can be empty to disable TLS config
- `kubernetes_ingress_class_name`: Optionally set the ingress class used for the generated ingress, requires authentik 2022.11.0
- `kubernetes_service_type`: Service kind created, can be set to LoadBalancer for LDAP outposts for example
- `kubernetes_disabled_components`: Disable any components of the kubernetes integration, can be any of
Expand Down
Loading