diff --git a/api/types/constants.go b/api/types/constants.go index 11e1cada4eb8a..d1565ad78dab6 100644 --- a/api/types/constants.go +++ b/api/types/constants.go @@ -800,6 +800,8 @@ const ( DiscoveryAppInsecureSkipVerify = TeleportNamespace + "/insecure-skip-verify" // DiscoveryAppIgnore specifies if a Kubernetes service should be ignored by discovery service. DiscoveryAppIgnore = TeleportNamespace + "/ignore" + // DiscoveryPublicAddr specifies the public address for a discovered app created from a Kubernetes service. + DiscoveryPublicAddr = TeleportNamespace + "/public-addr" // ReqAnnotationApproveSchedulesLabel is the request annotation key at which schedules are stored for access plugins. ReqAnnotationApproveSchedulesLabel = "/schedules" diff --git a/docs/pages/reference/agent-services/kubernetes-application-discovery.mdx b/docs/pages/reference/agent-services/kubernetes-application-discovery.mdx index 4e5c673c26043..1ac99aa612074 100644 --- a/docs/pages/reference/agent-services/kubernetes-application-discovery.mdx +++ b/docs/pages/reference/agent-services/kubernetes-application-discovery.mdx @@ -142,3 +142,11 @@ annotations: value: "Bearer {{internal.jwt}}" ``` +### `teleport.dev/public-addr` + +Controls the public address for the Teleport app we create if needed. + +```yaml +annotations: + teleport.dev/public-addr: "custom.teleport.dev" +``` diff --git a/lib/services/app.go b/lib/services/app.go index 044e963d687f8..c217005e025d4 100644 --- a/lib/services/app.go +++ b/lib/services/app.go @@ -190,6 +190,7 @@ func NewApplicationFromKubeService(service corev1.Service, clusterName, protocol URI: appURI, Rewrite: rewriteConfig, InsecureSkipVerify: getTLSInsecureSkipVerify(service.GetAnnotations()), + PublicAddr: getPublicAddr(service.GetAnnotations()), }) if err != nil { return nil, trace.Wrap(err, "could not create an app from Kubernetes service") @@ -233,6 +234,10 @@ func getAppRewriteConfig(annotations map[string]string) (*types.Rewrite, error) return &rw, nil } +func getPublicAddr(annotations map[string]string) string { + return annotations[types.DiscoveryPublicAddr] +} + func getTLSInsecureSkipVerify(annotations map[string]string) bool { val := annotations[types.DiscoveryAppInsecureSkipVerify] if val == "" { diff --git a/lib/srv/discovery/discovery_test.go b/lib/srv/discovery/discovery_test.go index 116fc9b15920c..ccdf12957a525 100644 --- a/lib/srv/discovery/discovery_test.go +++ b/lib/srv/discovery/discovery_test.go @@ -912,7 +912,7 @@ func TestDiscoveryKubeServices(t *testing.T) { appProtocolHTTP := "http" mockKubeServices := []*corev1.Service{ - newMockKubeService("service1", "ns1", "", map[string]string{"test-label": "testval"}, nil, + newMockKubeService("service1", "ns1", "", map[string]string{"test-label": "testval"}, map[string]string{types.DiscoveryPublicAddr: "custom.example.com"}, []corev1.ServicePort{{Port: 42, Name: "http", Protocol: corev1.ProtocolTCP}}), newMockKubeService("service2", "ns2", "", map[string]string{ "test-label": "testval", @@ -1732,6 +1732,8 @@ func mustConvertKubeServiceToApp(t *testing.T, discoveryGroup, protocol string, port.Name = "" app, err := services.NewApplicationFromKubeService(*kubeService, discoveryGroup, protocol, port) require.NoError(t, err) + require.Equal(t, kubeService.Annotations[types.DiscoveryPublicAddr], app.GetPublicAddr()) + app.GetStaticLabels()[types.TeleportInternalDiscoveryGroupName] = discoveryGroup app.GetStaticLabels()[types.OriginLabel] = types.OriginDiscoveryKubernetes return app