Skip to content

Commit e26ba1f

Browse files
author
Timothy Dodd
committed
feat: implement SQLite persistence layer for user authentication and session management
- Added initial database migration script to create users, tokens, sessions, and tunnel_events tables. - Created models for User, Token, Session, and TunnelEvent with appropriate methods. - Implemented session management functions including CreateSession, GetSession, DeleteSession, and DeleteUserSessions. - Developed token management functions for creating, retrieving, listing, touching, and revoking tokens. - Added user management functions for creating, counting, retrieving, listing, and disabling users. - Introduced tests for user, token, and session lifecycles to ensure proper functionality. - Established a detailed plan for the authentication and portal features, including UI and API specifications. - Outlined migration strategy from .NET to Go, detailing component mapping and phased execution.
1 parent 4ce0483 commit e26ba1f

74 files changed

Lines changed: 5088 additions & 133 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# VCS, docs, planning, deploy manifests — not needed to build the binaries
2+
.git
3+
.gitignore
4+
.dockerignore
5+
*.md
6+
_legacy
7+
plans
8+
deploy
9+
10+
# CI / editor
11+
.github
12+
.vscode
13+
.idea
14+
.vs
15+
16+
# Build outputs & binaries
17+
host
18+
client
19+
ntunl-host
20+
ntunl-client
21+
*.exe
22+
*.test
23+
*.out
24+
dist
25+
pkg_*
26+
vendor
27+
28+
# Runtime data & secrets (never bake these into an image layer)
29+
cert.pem
30+
key.pem
31+
*.db
32+
*.db-shm
33+
*.db-wal
34+
credentials.json
35+
.env
36+
*.env

.github/workflows/docker-image.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,42 @@ jobs:
1111

1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v3
1518

1619
- name: Set up Docker Buildx
17-
uses: docker/setup-buildx-action@v1
20+
uses: docker/setup-buildx-action@v3
1821

1922
- name: Log in to DockerHub
20-
uses: docker/login-action@v2
23+
uses: docker/login-action@v3
2124
with:
2225
username: ${{ secrets.DOCKERHUB_USERNAME }}
2326
password: ${{ secrets.DOCKERHUB_PASSWORD }}
2427

2528
- name: Build and push NtunlHost
26-
uses: docker/build-push-action@v6.5.0
29+
uses: docker/build-push-action@v6
2730
with:
28-
context: ./src/
29-
file: ./src/NtunlHost/Dockerfile
31+
context: .
32+
file: ./build/Dockerfile.host
33+
platforms: linux/amd64,linux/arm64
3034
push: true
3135
tags: |
3236
${{ secrets.DOCKERHUB_USERNAME }}/ntunl-host:latest
3337
${{ secrets.DOCKERHUB_USERNAME }}/ntunl-host:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max
3440

35-
# - name: Build and push NtunlClient
36-
# uses: docker/build-push-action@v6.5.0
37-
# with:
38-
# context: ./src/
39-
# file: ./src/NtunlClient/Dockerfile
40-
# push: true
41-
# tags: |
42-
# ${{ secrets.DOCKERHUB_USERNAME }}/ntunl-client:latest
43-
# ${{ secrets.DOCKERHUB_USERNAME }}/ntunl-client:${{ github.ref_name }}
41+
- name: Build and push NtunlClient
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
file: ./build/Dockerfile.client
46+
platforms: linux/amd64,linux/arm64
47+
push: true
48+
tags: |
49+
${{ secrets.DOCKERHUB_USERNAME }}/ntunl-client:latest
50+
${{ secrets.DOCKERHUB_USERNAME }}/ntunl-client:${{ github.ref_name }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max

.github/workflows/pr-check.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@ jobs:
1111

1212
steps:
1313
- name: Checkout code
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

16-
- name: Set up .NET
17-
uses: actions/setup-dotnet@v3
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
1818
with:
19-
dotnet-version: "9.x"
19+
go-version: "1.23"
20+
cache: true
2021

21-
- name: Restore dependencies
22-
run: dotnet restore
22+
- name: Check formatting
23+
# Advisory: reports unformatted files without failing the build.
24+
# Flip to a hard gate (drop `continue-on-error`) once `go fmt ./...` is run.
25+
continue-on-error: true
26+
run: |
27+
unformatted=$(gofmt -l $(git ls-files '*.go'))
28+
if [ -n "$unformatted" ]; then
29+
echo "These files need gofmt:"
30+
echo "$unformatted"
31+
exit 1
32+
fi
2333
24-
- name: Build NtunlClient
25-
run: dotnet build src/NtunlClient/NtunlClient.csproj --configuration Release --no-restore --verbosity minimal
34+
- name: Vet
35+
run: go vet ./...
2636

27-
- name: Build NtunlHost
28-
run: dotnet build src/NtunlHost/NtunlHost.csproj --configuration Release --no-restore --verbosity minimal
37+
- name: Build
38+
run: go build ./...
39+
40+
- name: Test
41+
run: go test ./...

.github/workflows/release.yml

Lines changed: 34 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,47 @@ on:
55
tags:
66
- "release-*"
77

8+
permissions:
9+
contents: write
10+
811
jobs:
9-
build_windows_and_linux:
12+
build_and_release:
1013
runs-on: ubuntu-latest
1114

1215
steps:
1316
- name: Checkout code
14-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1518

16-
- name: Set up .NET
17-
uses: actions/setup-dotnet@v3
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
1821
with:
19-
dotnet-version: "9.x"
20-
21-
- name: Publish NtunlClient (Windows x64)
22-
run: dotnet publish src/NtunlClient/NtunlClient.csproj --configuration Release --output publish/windows-x64/NtunlClient -r win-x64 --self-contained
23-
24-
- name: Publish NtunlHost (Windows x64)
25-
run: dotnet publish src/NtunlHost/NtunlHost.csproj --configuration Release --output publish/windows-x64/NtunlHost -r win-x64 --self-contained
26-
27-
- name: Publish NtunlClient (Linux x64)
28-
run: dotnet publish src/NtunlClient/NtunlClient.csproj --configuration Release --output publish/linux-x64/NtunlClient -r linux-x64 --self-contained
29-
30-
- name: Publish NtunlHost (Linux x64)
31-
run: dotnet publish src/NtunlHost/NtunlHost.csproj --configuration Release --output publish/linux-x64/NtunlHost -r linux-x64 --self-contained
32-
33-
- name: Generate NtunlClient ZIP (Windows x64)
34-
run: |
35-
cd publish/windows-x64/NtunlClient
36-
zip -r ../../../NtunlClient_windows_x64.zip .
37-
38-
- name: Generate NtunlHost ZIP (Windows x64)
39-
run: |
40-
cd publish/windows-x64/NtunlHost
41-
zip -r ../../../NtunlHost_windows_x64.zip .
42-
43-
- name: Generate NtunlClient ZIP (Linux x64)
44-
run: |
45-
cd publish/linux-x64/NtunlClient
46-
zip -r ../../../NtunlClient_linux_x64.zip .
22+
go-version: "1.23"
23+
cache: true
4724

48-
- name: Generate NtunlHost ZIP (Linux x64)
25+
- name: Build cross-platform archives
4926
run: |
50-
cd publish/linux-x64/NtunlHost
51-
zip -r ../../../NtunlHost_linux_x64.zip .
52-
53-
- name: Create Release
54-
id: create_release
55-
uses: actions/create-release@v1
56-
with:
57-
tag_name: ${{ github.ref }}
58-
release_name: Release ${{ github.ref }}
59-
body: |
60-
Release notes for ${{ github.ref }}
61-
draft: false
62-
prerelease: false
63-
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
66-
- name: Upload NtunlClient Release Asset (Windows x64)
67-
uses: actions/upload-release-asset@v1
68-
with:
69-
upload_url: ${{ steps.create_release.outputs.upload_url }}
70-
asset_path: NtunlClient_windows_x64.zip
71-
asset_name: NtunlClient_windows_x64.zip
72-
asset_content_type: application/zip
73-
env:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
76-
- name: Upload NtunlHost Release Asset (Windows x64)
77-
uses: actions/upload-release-asset@v1
78-
with:
79-
upload_url: ${{ steps.create_release.outputs.upload_url }}
80-
asset_path: NtunlHost_windows_x64.zip
81-
asset_name: NtunlHost_windows_x64.zip
82-
asset_content_type: application/zip
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
86-
- name: Upload NtunlClient Release Asset (Linux x64)
87-
uses: actions/upload-release-asset@v1
88-
with:
89-
upload_url: ${{ steps.create_release.outputs.upload_url }}
90-
asset_path: NtunlClient_linux_x64.zip
91-
asset_name: NtunlClient_linux_x64.zip
92-
asset_content_type: application/zip
93-
env:
94-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95-
96-
- name: Upload NtunlHost Release Asset (Linux x64)
97-
uses: actions/upload-release-asset@v1
27+
set -euo pipefail
28+
mkdir -p dist
29+
targets="linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
30+
for t in $targets; do
31+
os=${t%/*}; arch=${t#*/}
32+
ext=""; [ "$os" = "windows" ] && ext=".exe"
33+
out="pkg_${os}_${arch}"
34+
mkdir -p "$out"
35+
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -trimpath -ldflags "-s -w" -o "$out/ntunl-host$ext" ./cmd/host
36+
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -trimpath -ldflags "-s -w" -o "$out/ntunl-client$ext" ./cmd/client
37+
cp README.md LICENSE.txt "$out/" 2>/dev/null || true
38+
cp -r configs "$out/configs" 2>/dev/null || true
39+
if [ "$os" = "windows" ]; then
40+
(cd "$out" && zip -qr "../dist/ntunl_${os}_${arch}.zip" .)
41+
else
42+
tar -czf "dist/ntunl_${os}_${arch}.tar.gz" -C "$out" .
43+
fi
44+
done
45+
ls -la dist
46+
47+
- name: Publish release
48+
uses: softprops/action-gh-release@v2
9849
with:
99-
upload_url: ${{ steps.create_release.outputs.upload_url }}
100-
asset_path: NtunlHost_linux_x64.zip
101-
asset_name: NtunlHost_linux_x64.zip
102-
asset_content_type: application/zip
103-
env:
104-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
files: dist/*
51+
generate_release_notes: true

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,33 @@ __blobstorage*
167167

168168
# Nx
169169
**/.nx/cache/
170+
171+
# Go
172+
/host
173+
/client
174+
/ntunl-host
175+
/ntunl-client
176+
*.exe
177+
*.test
178+
*.out
179+
*.coverprofile
180+
coverage.*
181+
/vendor/
182+
pkg_*/
183+
184+
# Tailwind standalone CLI binary (downloaded for the static CSS build)
185+
/tailwindcss
186+
/tailwindcss.exe
187+
188+
# NTunl runtime data & secrets
189+
cert.pem
190+
key.pem
191+
*.db
192+
*.db-shm
193+
*.db-wal
194+
credentials.json
195+
.env
196+
*.env
197+
198+
# OS
199+
Thumbs.db

0 commit comments

Comments
 (0)