> ## Documentation Index
> Fetch the complete documentation index at: https://docs.augmentcode.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate Twingate

## Introduction

In this page we’ll explore how to configure a Cosmos cloud environment to connect to resources (ex: a local .html file) on a remote Linux VM via Twingate.

```mermaid theme={null}
sequenceDiagram
	autonumber
	participant C as Cosmos Cloud Env
	participant TG as Twingate
	participant VM as Linux VM

	C->>TG: Outbound request<br/>(Resource FQDN/IP)
	TG->>TG: Verify identity &<br/>Zero Trust policy
	TG->>VM: Route traffic via<br/>secure tunnel
	VM->>VM: Process request
	VM-->>TG: Response payload
	TG-->>C: Encrypted response
```

## Prerequisites

To configure the connectivity between Cosmos and ADO:

* Cosmos
  * you must have edit access to the cloud env that will connect to a Twingate-protected resource
* Twingate
  * you need a Twingate paid account (or active free trial)
  * you must have permissions to create a service account
  * you must have permissions to add a new connector: set of access token + refresh token to deploy a connector on the resource/network that will later be accessed by the Cosmos cloud env
* AWS/GCP/Azure/on-prem
  * you must have SSH access to the Linux VM - this is where the Twingate connector will be deployed

## Step 1 - Twingate Connector configuration

Go to your Twingate admin console > Network > Overview > Deploy connector > Cloud & Infrastructure > Linux. You should see “Install and Launch Connector Service”:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-01.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=891d2ecf8fb6ea666c45bc92fa034f63" alt="" width="735" height="218" data-path="images/cosmos-integrations/twingate/twingate-01.png" />

Click on ‘Copy Command’, then ssh into your Linux VM and run the command copied above. You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-02.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=61bc0fb71d5a0a0b7f18d1da8fcab6c9" alt="" width="1910" height="1604" data-path="images/cosmos-integrations/twingate/twingate-02.png" />

Then go back to Twingate > Networks > Connectors and observe that your connector has connected:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-03.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=6c128f64cf05668cf6bb4e37e3e41585" alt="" width="1173" height="472" data-path="images/cosmos-integrations/twingate/twingate-03.png" />

Now let’s create a test python server on that VM (that we’ll later allow-list as Resource in Twingate).

First, get the private IP of that VM. From that VM run:

```text theme={null}
hostname -I | awk '{print $1}'
```

You’ll get something like: 172.31.28.194

From that VM:

* Create a test html file:

```text theme={null}
echo "Hello, World!" > index.html
```

* Start a test python server (which will be serving the html file):

```text theme={null}
python3 -c "import http.server, urllib.parse; H = type('H', (http.server.SimpleHTTPRequestHandler,), {'translate_path': lambda s, p: http.server.SimpleHTTPRequestHandler.translate_path(s, urllib.parse.urlparse(p).path)}); http.server.HTTPServer(('0.0.0.0', 8000), H).serve_forever()"
```

You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-04.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=2791be07c78b6ed08be527a16fb3a6bb" alt="" width="976" height="76" data-path="images/cosmos-integrations/twingate/twingate-04.png" />

## Step 2 - Twingate Service Account configuration

Go to your Twingate admin console > Team > Services > Click on “+ Service” > Service Name = Cosmos > Create Service Account:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-05.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=53d93ce5e54c5e75f6d139f5325391d0" alt="" width="372" height="201" data-path="images/cosmos-integrations/twingate/twingate-05.png" />

You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-06.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=5ee8781f0d455545cc284a1c6e7a0be9" alt="" width="1175" height="470" data-path="images/cosmos-integrations/twingate/twingate-06.png" />

Click on the service account name, the click on “+Service Key”:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-07.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=ea8cef483aaee7e3359821fdb48e3b69" alt="" width="1177" height="807" data-path="images/cosmos-integrations/twingate/twingate-07.png" />

Keep expiration = 365 days, then Generate:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-08.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=add62281955d4ec6e3137d543e4e0256" alt="" width="460" height="276" data-path="images/cosmos-integrations/twingate/twingate-08.png" />

You’ll be offered to rename your key and download the service key token (ex: twingate-cosmos01.json). Then click on “Save & Close”

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-09.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=e7a093d44f6583d8ace44e94bd0a2037" alt="" width="463" height="609" data-path="images/cosmos-integrations/twingate/twingate-09.png" />

## Step 3 - Twingate Resource configuration

Now we’ll add the Linux VM as “Resource” in Twingate.

Go to your Twingate admin console > Network > Resources > “+Resource” > Select your network, enter as name “Linux VM”, enter the private IP of your Linux VM > click on Create Resource:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-10.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=2c4dd8aa0cb2401a094fda6bcf8f5c60" alt="" width="787" height="292" data-path="images/cosmos-integrations/twingate/twingate-10.png" />

Then select your Cosmos service account > Grant Access:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-11.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=4636055b61df3668f67b325164ee03e2" alt="" width="661" height="586" data-path="images/cosmos-integrations/twingate/twingate-11.png" />

You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-12.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=6a75045789c3a1ebf427c3bf9063c4b2" alt="" width="1178" height="468" data-path="images/cosmos-integrations/twingate/twingate-12.png" />

If you now go to your Cosmos service account view (Twingate admin console > Team > Services > Cosmos) you should see the granted resource:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-13.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=842170b5393a128f0b2662f40e581ea1" alt="" width="1182" height="600" data-path="images/cosmos-integrations/twingate/twingate-13.png" />

## Step 4 - Cosmos cloud env configuration

Go to your Cosmos cloud env from where you’d like to access your Twingate-protected resource. If you don’t have any, create a brand new env: [cosmos.augmentcode.com](http://cosmos.augmentcode.com) > Settings > Environments > Create an environment > Cloud Machine:

* Name: Test-Twingate
* Base image: keep the Cosmos default
* Repositories: select your repos
* Refresh: toggle on
* Click on Create Environment

If you reopen your env, top right click on the 3 dots > Terminal:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-14.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=e23cb6c281a1abdd9491c4045595ba50" alt="" width="771" height="323" data-path="images/cosmos-integrations/twingate/twingate-14.png" />

Install Twingate by running:

```text theme={null}
curl -s https://binaries.twingate.com/client/linux/install.sh | bash
```

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-15.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=2de7d60b66fdae710b8551c5ef587274" alt="" width="1127" height="1071" data-path="images/cosmos-integrations/twingate/twingate-15.png" />

Now we’ll bring over the twingate-cosmos01.json key. Run:

```text theme={null}
nano twingate-cosmos01.json
```

Then paste the content of your key, then CTRL-O to save the file, and CTRL-X to exit the file

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-16.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=1a2e8b3e2d9202907fcf53cfc7727add" alt="" width="670" height="278" data-path="images/cosmos-integrations/twingate/twingate-16.png" />

Make sure twingate-cosmos01.json has been created:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-17.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=627a81b48e9f084e128cc5f333075ef4" alt="" width="235" height="37" data-path="images/cosmos-integrations/twingate/twingate-17.png" />

Move up 1 folder:

```text theme={null}
cd ..
```

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-18.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=03eeb88c247de11f0d10f271a9916151" alt="" width="664" height="96" data-path="images/cosmos-integrations/twingate/twingate-18.png" />

Now authenticate to Twingate by running:

```text theme={null}
twingate setup --headless /workspace/twingate-cosmos01.json
```

You should see:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-19.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=bb1a6c48b59fdde0845edd51764cbde2" alt="" width="592" height="77" data-path="images/cosmos-integrations/twingate/twingate-19.png" />

Let’s start Twingate in that terminal session:

```text theme={null}
/sbin/twingated --http-proxy 127.0.0.1:9999 --tun off &
```

Then check that this process is running, paste and enter this:

```text theme={null}
ps aux | grep twingated
```

You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-20.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=b32abb109e83b1bffba9be30443f6c82" alt="" width="947" height="58" data-path="images/cosmos-integrations/twingate/twingate-20.png" />

Now let’s try to reach the index.html page:

```text theme={null}
curl --proxy http://127.0.0.1:9999 http://172.31.28.194:8000
```

And should see your Hello World!:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-21.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=75c263171b0eb0dcd617b0e2299770a1" alt="" width="1063" height="286" data-path="images/cosmos-integrations/twingate/twingate-21.png" />

Now click on “Update environment” to save your cloud env config,

One more step: earlier Twingate was started only in that terminal session. Now we’ll ask Cosmos Advisor to update the cloud env’s startup script so it always starts Twingate upon booting the cloud env across all future sessions.

Open a new Cosmos session (cosmos.augmentcode.com) > New session > select Cosmos Advisor > select the Test-Twingate cloud env, prompt with

```text theme={null}
Incrementally update the existing Test-Twingate environment from its current
snapshot. Do not rebuild or refresh it from the base image. Preserve all
installed software, files, and configuration.

Configure its user-controlled startup hook to run these commands on every VM
startup:

cd ..
/sbin/twingated --http-proxy 127.0.0.1:9999 --tun off &

Preserve any existing startup-hook content unless it directly conflicts with
these commands.

After updating the snapshot, launch a fresh test session using Test-Twingate
and verify:
1. /sbin/twingated still exists.
2. A twingated process is running.
3. The proxy is listening on 127.0.0.1:9999.

Do not report success based only on the environment update completing. Report
the results of all three runtime checks. If any step would require a rebuild,
stop and ask me first.

When you delegate to a worker or background job, do not use its status field as
evidence of completion. Confirm by reading its actual output or transcript. If a
status check is inconclusive twice, switch tools rather than repeating it, and
tell me what you tried. Never tell me "still waiting" more than once without
having read the underlying output directly.
```

You should see:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-22.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=67571c03a2a2ee0a72941726031f11f8" alt="" width="791" height="754" data-path="images/cosmos-integrations/twingate/twingate-22.png" />

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-23.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=2a7d8b5a6134ef437b6f508429df4628" alt="" width="1491" height="1042" data-path="images/cosmos-integrations/twingate/twingate-23.png" />

Any new session stemmed from that Test-Twingate cloud env will now have a Twingate tunnel running.

## Step 5 - Final Test

Final check, start a brand new session without any expert and prompt `execute curl --proxy `[`http://127.0.0.1:9999`](http://127.0.0.1:9999/)` `[`http://172.31.28.194:8000`](http://172.31.28.194:8000/) , you should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/4zXBzN_O-cAt9KVy/images/cosmos-integrations/twingate/twingate-24.png?fit=max&auto=format&n=4zXBzN_O-cAt9KVy&q=85&s=ae28d7ee484798724eb29bde95f360bb" alt="" width="1200" height="865" data-path="images/cosmos-integrations/twingate/twingate-24.png" />

Congrats, you’ve configured Twingate with your Cosmos cloud env! You’re now able to leverage Cosmos experts to orchestrate Twingate-protected resources.
