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

Task container port mapping #320

Closed
v36372 opened this issue Jan 19, 2024 · 11 comments
Closed

Task container port mapping #320

v36372 opened this issue Jan 19, 2024 · 11 comments

Comments

@v36372
Copy link
Contributor

v36372 commented Jan 19, 2024

Hi, I'm having a need for one of my tasks to connect to a http server running on the worker node (for my usecase, task containers are spawned from the worker dockerd deamon). To do this, I have thought of several ways:

  • map http server port into the task container (-p 8080:8080)
  • add extra host param for the task container to have access to host.docker.internal hostname (--add-host=host.docker.internal:host-gateway)
  • use host network for task container (--net=host). This isn't a viable option for me due to security reason.

I think port mapping could be the easiest to implement

@runabol
Copy link
Owner

runabol commented Jan 19, 2024

Is that server running on Docker as well? If so, what about creating a docker network for that http server and using the networks property on the task (https://www.tork.run/rest-api)?

@v36372
Copy link
Contributor Author

v36372 commented Jan 19, 2024

The server is running on k8s. I have the docker socket mounted inside to have access to docker API.

@runabol
Copy link
Owner

runabol commented Jan 19, 2024

And you can't access the service through its service endpoint?

@v36372
Copy link
Contributor Author

v36372 commented Jan 20, 2024

No, that would required a k8s service account which is too much of a risk we don't want to do that.

@v36372
Copy link
Contributor Author

v36372 commented Jan 22, 2024

And you can't access the service through its service endpoint?

I misinterpreted your reply. I can not access the service through the service endpoint because the container IP address is blocked by the cluster.

@v36372
Copy link
Contributor Author

v36372 commented Jan 22, 2024

I'm thinking we could go for this:

	hc := container.HostConfig{
		PublishAllPorts: true,
		Mounts:          mounts,
		Resources:       resources,
                ExtraHosts:      t.ExtraHosts,
	}

Task definition:

name: Example
tasks:
  - name: Example
    extra_hosts:
      - host.docker.internal:host-gateway
    run: |
      apk add curl
      curl host.docker.internal:8080 > $TORK_OUTPUT
    image:  alpine:3.18.3

@v36372
Copy link
Contributor Author

v36372 commented Feb 18, 2024

@runabol hi, any update on this? Maybe there is a quick fix to unblock on my end 🤔

@runabol
Copy link
Owner

runabol commented Feb 18, 2024

I guess I still fail to understand why an (internal) service endpoint can't be used to solve your problem.

Allowing tasks to interact with the host machine directly will potentially compromise the isolation of tasks and introduce security risks.

@v36372
Copy link
Contributor Author

v36372 commented Feb 18, 2024

I guess I still fail to understand why an (internal) service endpoint can't be used to solve your problem.

Allowing tasks to interact with the host machine directly will potentially compromise the isolation of tasks and introduce security risks.

mainly because I'm using tork in embedded mode. Worker has /var/run/docker.sock mounted inside, both coordinator & worker are deployed on a k8s cluster (same cluster with the internal service). This cluster only accept connections from the cluster IP range. In order for one of my worker node to reach this internal service, the cluster firewall rules need to be updated to allow new IP range, which is something I don't want to mess with.

@runabol
Copy link
Owner

runabol commented Feb 20, 2024

Have you considered implementing this using a middleware?

@v36372
Copy link
Contributor Author

v36372 commented Feb 22, 2024

Have you considered implementing this using a middleware?

Yeah, I made it work using middleware, letting the coordinator handle this and then pass results back to the task through ENVs. Thanks.

@v36372 v36372 closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants