Integration API creates Newt sites with an invalid address prefix
- Dominant language
- TypeScript
- Stars
- 22.8k
- Forks
- 783
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 52
Description
### Describe the Bug
### Integration API creates Newt sites with an invalid address prefix
**Version:** Pangolin 1.21.1
**Edition:** Community / OSS
**Database:** SQLite
When creating a Newt site through the Integration API:
```http
PUT /v1/org/{orgId}/site
```
with:
```json
{
"name": "integration-test",
"type": "newt"
}
```
the created site receives an address without the organization's CIDR prefix.
For example:
```json
"address": "100.90.128.2"
```
Starting Newt with the returned credentials successfully establishes the websocket and tunnel connection, but then fails while configuring connectivity with:
```text
Failed to ensure WireGuard interface: invalid IP address format: 100.90.128.2
```
The issue appears to come from `server/routers/site/createSite.ts`:
```ts
const { value: newClientAddress, release } =
await getNextAvailableClientSubnet(orgId);
releaseSubnetLock = release;
updatedAddress = newClientAddress.split("/")[0];
```
`getNextAvailableClientSubnet()` intentionally allocates individual `/32` addresses, while its implementation also notes that site/client addresses are stored using the organization's block size.
The Dashboard site-creation flow results in addresses such as:
```text
100.90.128.2/20
```
A tested fix is:
```ts
updatedAddress =
`${newClientAddress.split("/")[0]}/${org.subnet!.split("/")[1]}`;
```
After rebuilding Pangolin 1.21.1 with this change, a site created through the Integration API was stored as:
```text
100.90.128.4/20
```
and Newt successfully completed setup:
```text
Websocket connected
Tunnel connection to server established successfully!
Client connectivity setup. Ready to accept connections from clients!
```
I can submit a pull request with the change if this matches the intended behavior.
### Environment
- OS Type & Version: Ubuntu 24.04
- Pangolin Version: 1.21.1
- Edition (Community or Enterprise): Community / OSS
- Gerbil Version: 1.4.2
- Traefik Version: 3.6
- Newt Version: 1.14.0
- Client Version: N/A
### To Reproduce
Run Pangolin 1.21.1 Community / OSS with the Integration API enabled.
Create a Newt site through the Integration API:
PUT /v1/org/{orgId}/site
with:
{
"name": "integration-test",
"type": "newt"
}
Observe that the created site address is returned without the organization CIDR prefix, for example:
100.90.128.2
Start Newt using the returned newtId and secret.
Newt connects to the Pangolin server and establishes the tunnel, but then fails during interface setup with:
Failed to ensure WireGuard interface: invalid IP address format: 100.90.128.2
### Expected Behavior
A Newt site created through the Integration API should be assigned and stored with the same address format used by the Dashboard site creation flow.
For example, if the organization subnet is /20, the site address should be stored as:
100.90.128.2/20
Newt should then be able to complete its connectivity setup successfully without an invalid IP address format error.
Contributor guide
Research direction
Start in server/routers/site/createSite.ts and compare the Integration API site-creation path with the Dashboard flow that preserves the organization CIDR prefix. Verify that a Newt site created through PUT /v1/org/{orgId}/site stores an address with the organization subnet suffix and that Newt completes connectivity setup without the invalid IP address error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100