Skip to content

Database refactor #123

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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e8a3428
feat(api)!: move authentication to timescale
gsanchietti Jun 18, 2025
5f6c637
fix(ci): start timescale for tests
gsanchietti Jun 18, 2025
7680463
chore(api): add tests for accounts and 2FA
gsanchietti Jun 19, 2025
ba4e6b9
feat(api)!: move 2FA to database
gsanchietti Jun 19, 2025
163aa56
feat(api): add /health endpoint
gsanchietti Jun 20, 2025
daf85d5
feat(api): support multiple listen addresses
gsanchietti Jun 23, 2025
d4e6656
feat(api): add trusted IP middleware
gsanchietti Jun 20, 2025
bf7e052
chore(api): test add and get info
gsanchietti Jun 24, 2025
dcc4402
feat(api)!: save unit info inside db
gsanchietti Jun 24, 2025
070bde2
feat(api): add /auth API
gsanchietti Jun 24, 2025
8fc4cf3
feat(api): add /platform endpoint
gsanchietti Jun 24, 2025
6ab4a74
chore(api): cleanup deps with go mod tidy
gsanchietti Jun 25, 2025
f995403
feat(api): improve register endpoint
gsanchietti Jun 25, 2025
4401afa
feat(api)!: add unit groups management
gsanchietti Jun 26, 2025
9169ae8
feat(proxy): add IP middleware
gsanchietti Jun 26, 2025
99eb6bf
feat(api)!: implement unit authorizations
gsanchietti Jun 26, 2025
a4e4964
fix(api): correctly migrate users from sqlite
gsanchietti Jun 27, 2025
8e430b4
fix(api): do not delete vpn config on migration
gsanchietti Jul 1, 2025
c39afa9
chore(proxy): support traefik v3
gsanchietti Jul 1, 2025
bf97f69
feat(api): add CIDR utils
gsanchietti Jul 2, 2025
961e1c5
feat(api)!: move unit vpn info inside db
gsanchietti Jul 2, 2025
eb8d6e4
feat(vpn): write vpn info inside db
gsanchietti Jul 3, 2025
5d7b2cf
feat(api)!: move unit credentials to db
gsanchietti Jul 3, 2025
511f371
fix(api): fix static lint warning
gsanchietti Jul 3, 2025
c288a14
feat(api)!: move JWT tokens to RAM
gsanchietti Jul 3, 2025
4033bd8
feat(vpn,api): remove ccd files
gsanchietti Jul 3, 2025
4436f35
chore(vpn): bump Alpine and OpenVPN
gsanchietti Jul 3, 2025
22fcce5
chore(build): cleanup container_ui
gsanchietti Jul 4, 2025
b0fa344
fix(api): update password on UpdateAccount
gsanchietti Jul 4, 2025
a69a923
fix(api): don't fail if SECRETS_DIR is not defined
gsanchietti Jul 7, 2025
9e11a0c
feat(dev): setup env for UI development
gsanchietti Jul 7, 2025
297452f
fix(api): sync access to active tokens
gsanchietti Jul 7, 2025
21125c8
chore(api): add comments to db sql
gsanchietti Jul 8, 2025
fcc1d4c
chore(api): AddUnit, log errors
gsanchietti Jul 8, 2025
0d54c8f
feat(api): units, return also groups
gsanchietti Jul 8, 2025
402c2d0
fix(api): test, improve platform check
gsanchietti Jul 9, 2025
bd3ab86
feat(api): unit_groups, add used_by field
gsanchietti Jul 9, 2025
5413056
fix(api): migration, only set one admin user
gsanchietti Jul 10, 2025
567f33d
TEST: pull new UI
gsanchietti Jul 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ jobs:
name: API Tests
runs-on: ubuntu-24.04
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Checkout
uses: actions/checkout@v4
- name: Run tests
uses: docker/build-push-action@v6
- name: Install Podman
run: |
sudo apt-get update
sudo apt-get install -y podman oathtool
- name: Start TimescaleDB
run: |
podman run --rm -d --name timescaledb -p 5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=report timescale/timescaledb-ha:pg17
# Wait for DB to be ready
for i in {1..30}; do
podman exec timescaledb pg_isready -U report && break
sleep 1
done
- name: Setup Go
uses: actions/setup-go@v5
with:
push: false
context: api
target: test
cache-to: type=gha,mode=max,scope=api-testing
cache-from: type=gha,scope=api-testing
file: api/Containerfile
go-version: '1.24.4'
- name: Test with the Go CLI
run: cd api && go test
56 changes: 48 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,68 @@ Firewalls can register to the server using [ns-plug](https://github.com/NethServ
- create a route inside the proxy to access the firewall Luci RPC
- store credentials to access the remote firewall

## Quickstart
## Development environment

You can install it on [NS8](https://github.com/NethServer/ns8-nethsecurity-controller#install).
You can install the controller on [NS8](https://github.com/NethServer/ns8-nethsecurity-controller#install).

Otherwise, first make sure to have [podman](https://podman.io/) installed on your server.
If you need a development environment, you can use the `dev.sh` script to start a podman pod with all the containers needed to run the controller.
First make sure to have [podman](https://podman.io/) installed on your server.
Containers should run under non-root users, but first you need to configure the tun device and the user.

As root, execute:
```
useradd -m controller
loginctl enable-linger controller

ip tuntap add dev tunsec mod tun
ip addr add 172.21.0.1/16 dev tunsec
ip link set dev tunsec up
```

If you're running the dev environment on a distro with SELinux enabled, you also may need to create a module to allow the controller to access the tun device.
Just execute:
```
checkmodule -M -m -o controller.mod controller.te
semodule_package -o controller.pp -m controller.mod
semodule -i controller.pp
```

Then change to non-root user, clone this repository and execute:
```
su - controller

./start.sh
./dev.sh start
```

The server will be available at `http://<fqdn>:8080/ui`.
To stop the pod, execute:
```
./dev.sh stop
```

To run a specific image tag, you can use:
```
IMAGE_TAG=<tag> ./dev.sh start
```

The server will be available at `http://localhost:8080/`.
Default credentials are: `admin/admin`.

### UI development

If you need to the develop the UI:

- clone the [nethsecurity-ui](https://github.com/nethserver/nethsecurity-ui)
- start the controller using the `dev.sh` script
- start the UI in dev mode
- access to the dev UI URL generated by vite, usually `http://localhost:5173/`
```
IMAGE_TAG=pr-123 ./dev.sh start
git clone git@github.com:NethServer/nethsecurity-ui.git
cd nethsecurity-ui
cat <<EOF > .env.development
VITE_API_SCHEME=http
VITE_CONTROLLER_API_HOST=localhost:8080
VITE_UI_MODE=controller
EOF
./dev.sh
```

## How it works

Expand Down Expand Up @@ -74,6 +111,9 @@ The following environment variables can be used to configure the containers:
- `PROXY_PORT`: proxy listening port, default is `8080`
- `PROXY_BIND_IP`: proxy binding IP, default is `0.0.0.0`
- `REPORT_DB_URI`: Timescale DB URI, like `postgresql://user:password@host:port/dbname`
- `ALLOWED_IPS`: comma-separated list of allowed IPs, if empty, all IPs are allowed, default is empty
- `PUBLIC_ENDPOINTS`: comma-separated list of public endpoints, that can be accessed even if `ALLOWED_IPS` is set, default is empty
If ALLOWED_IPS is set, the public endpoints should allow registration and ingestions from units, a good value should be: `/api/ingest,/api/units/register`

## REST API

Expand Down
Loading
Loading