-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: User service ports Traefik Docker labels (#1871)
## Description: As part of the authenticated public http ports feature, we are bringing Traefik inside the Docker cluster to route HTTP traffic to the user service HTTP ports. This PR sets the required Docker labels. This was tested with Traefik running inside the engine enclave with the following static config and the user service enclave network added to the Traefik container list of networks. ``` version: '3' services: reverse-proxy: image: traefik:v2.10 # Enables the web UI and tells Traefik to listen to docker command: - --accesslog=true - --api.debug=true - --api.insecure=true - --api.dashboard=true - --api.disabledashboardad=true - --providers.docker - --entrypoints.web.address=:8000 - --providers.docker.network=bridge - --providers.docker.exposedByDefault=false - --log.level=DEBUG ports: # The HTTP port - "8000:8000" # The Web UI (enabled by --api.insecure=true) - "8080:8080" volumes: # So that Traefik can listen to the Docker events - /var/run/docker.sock:/var/run/docker.sock ``` User service "nginx" port labels: Enclave short UUID: 65d2fb6d6732 Service short UUID: 3771c85af16a HTTP Port number: 80 ``` "traefik.enable": "true" "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.rule": "Host(`80-3771c85af16a-65d2fb6d6732`)" "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.service": "65d2fb6d6732-3771c85af16a-80" "traefik.http.services.65d2fb6d6732-3771c85af16a-80.loadbalancer.server.port": "80" ``` ``` $ curl -I http://localhost:8000 -H "Host: 80-3771c85af16a-65d2fb6d6732" HTTP/1.1 200 OK Accept-Ranges: bytes Content-Length: 615 Content-Type: text/html Date: Wed, 29 Nov 2023 21:32:51 GMT Etag: "6537cac7-267" Last-Modified: Tue, 24 Oct 2023 13:46:47 GMT Server: nginx/1.25. ``` ## Is this change user facing? NO ## References (if applicable): https://www.notion.so/kurtosistech/Public-user-service-HTTP-ports-bdf1107b0d1c4ca990c346fd87473174
- Loading branch information
1 parent
d11cd37
commit d18f20e
Showing
4 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ackend_impls/docker/object_attributes_provider/enclave_object_attributes_provider_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package object_attributes_provider | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/consts" | ||
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" | ||
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" | ||
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
enclaveUuid = "65d2fb6d673249b8b4a91a2f4ae616de" | ||
) | ||
|
||
var ( | ||
portWaitForTest = port_spec.NewWait(5 * time.Second) | ||
) | ||
|
||
func TestForUserServiceContainer(t *testing.T) { | ||
objAttrsProvider := GetDockerObjectAttributesProvider() | ||
enclaveObjAttrsProvider, err := objAttrsProvider.ForEnclave(enclaveUuid) | ||
require.NoError(t, err, "An unexpected error occurred getting the enclave object attributes provider") | ||
|
||
serviceName := service.ServiceName("nginx") | ||
serviceUuid := service.ServiceUUID("3771c85af16a40a18201acf4b4b5ad28") | ||
privateIpAddr := net.IP("1.2.3.4") | ||
port1Id := "port1" | ||
port1Num := uint16(23) | ||
port1Protocol := port_spec.TransportProtocol_TCP | ||
port1Spec, err := port_spec.NewPortSpec(port1Num, port1Protocol, "", portWaitForTest) | ||
require.NoError(t, err, "An unexpected error occurred creating port 1 spec") | ||
port2Id := "port2" | ||
port2Num := uint16(45) | ||
port2Protocol := port_spec.TransportProtocol_TCP | ||
port2ApplicationProtocol := consts.HttpApplicationProtocol | ||
port2Spec, err := port_spec.NewPortSpec(port2Num, port2Protocol, port2ApplicationProtocol, portWaitForTest) | ||
require.NoError(t, err, "An unexpected error occurred creating port 2 spec") | ||
privatePorts := map[string]*port_spec.PortSpec{ | ||
port1Id: port1Spec, | ||
port2Id: port2Spec, | ||
} | ||
userLabels := map[string]string{} | ||
containerAttrs, err := enclaveObjAttrsProvider.ForUserServiceContainer( | ||
serviceName, | ||
serviceUuid, | ||
privateIpAddr, | ||
privatePorts, | ||
userLabels, | ||
) | ||
require.NoError(t, err, "An unexpected error occurred getting the container attributes") | ||
objName := containerAttrs.GetName() | ||
require.Equal(t, objName.GetString(), "nginx--3771c85af16a40a18201acf4b4b5ad28") | ||
objLabels := containerAttrs.GetLabels() | ||
for labelKey, labelValue := range objLabels { | ||
switch labelKey.GetString() { | ||
case docker_label_key.AppIDDockerLabelKey.GetString(): | ||
require.Equal(t, labelValue.GetString(), "kurtosis") | ||
case docker_label_key.ContainerTypeDockerLabelKey.GetString(): | ||
require.Equal(t, labelValue.GetString(), "user-service") | ||
case docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): | ||
require.Equal(t, labelValue.GetString(), "65d2fb6d673249b8b4a91a2f4ae616de") | ||
case "traefik.enable": | ||
require.Equal(t, labelValue.GetString(), "true") | ||
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-23.rule": | ||
require.Fail(t, "A traefik label for port 23 should not be present") | ||
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-45.rule": | ||
require.Equal(t, labelValue.GetString(), "Host(`45-3771c85af16a-65d2fb6d6732`)") | ||
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-45.service": | ||
require.Equal(t, labelValue.GetString(), "65d2fb6d6732-3771c85af16a-45") | ||
case "traefik.http.services.65d2fb6d6732-3771c85af16a-45.loadbalancer.server.port": | ||
require.Equal(t, labelValue.GetString(), "45") | ||
default: | ||
break | ||
} | ||
} | ||
} |