Skip to content

Commit 0e76b77

Browse files
Set username explicitly
1 parent c604f46 commit 0e76b77

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

.github/workflows/cicd.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
runs-on: ubuntu-24.04
8686
timeout-minutes: 120
8787
env:
88-
DOCKERHUB_IMAGE: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }}
88+
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
8989
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
9090

9191
steps:
@@ -108,7 +108,7 @@ jobs:
108108
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
109109
with:
110110
registry: docker.io
111-
username: ${{ secrets.DOCKER_HUB_USERNAME }}
111+
username: fosrl
112112
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
113113

114114
- name: Log in to GHCR
@@ -247,7 +247,7 @@ jobs:
247247
run: |
248248
set -euo pipefail
249249
images="${GHCR_IMAGE}"
250-
if [ -n "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" ] && [ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]; then
250+
if [ -n "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" ] && [ -n "fosrl" ]; then
251251
images="${images}\n${DOCKERHUB_IMAGE}"
252252
fi
253253
{
@@ -290,7 +290,7 @@ jobs:
290290
IMAGE_LICENSE: ${{ env.IMAGE_LICENSE }}
291291
DOCKERHUB_IMAGE: ${{ env.DOCKERHUB_IMAGE }}
292292
GHCR_IMAGE: ${{ env.GHCR_IMAGE }}
293-
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
293+
DOCKER_HUB_USER: fosrl
294294
REPO: ${{ github.repository }}
295295
OWNER: ${{ github.repository_owner }}
296296
WORKFLOW_REF: ${{ github.workflow_ref }}
@@ -311,7 +311,7 @@ jobs:
311311
echo "=== Images ==="
312312
echo "DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE}"
313313
echo "GHCR_IMAGE=${GHCR_IMAGE}"
314-
echo "DOCKER_HUB_USERNAME=${DOCKER_HUB_USER}"
314+
echo "DOCKER_HUB_USERNAME=fosrl
315315
echo
316316
echo "=== GitHub Kontext ==="
317317
echo "repository=${REPO}"
@@ -364,7 +364,7 @@ jobs:
364364
id: attest-dh
365365
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
366366
with:
367-
subject-name: index.docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }}
367+
subject-name: index.docker.io/fosrl/${{ github.event.repository.name }}
368368
subject-digest: ${{ steps.build.outputs.digest }}
369369
push-to-registry: true
370370
show-summary: true
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//go:build freebsd
2+
3+
package permissions
4+
5+
import (
6+
"fmt"
7+
"os"
8+
9+
"github.com/fosrl/newt/logger"
10+
)
11+
12+
const (
13+
// TUN device on FreeBSD
14+
tunDevice = "/dev/tun"
15+
ifnamsiz = 16
16+
iffTun = 0x0001
17+
iffNoPi = 0x1000
18+
)
19+
20+
// ifReq is the structure for TUN interface configuration
21+
type ifReq struct {
22+
Name [ifnamsiz]byte
23+
Flags uint16
24+
_ [22]byte // padding to match kernel structure
25+
}
26+
27+
// CheckNativeInterfacePermissions checks if the process has sufficient
28+
// permissions to create a native TUN interface on FreeBSD.
29+
// This requires root privileges (UID 0).
30+
func CheckNativeInterfacePermissions() error {
31+
logger.Debug("Checking native interface permissions on FreeBSD")
32+
33+
// Check if running as root
34+
if os.Geteuid() == 0 {
35+
logger.Debug("Running as root, sufficient permissions for native TUN interface")
36+
return nil
37+
}
38+
39+
// On FreeBSD, only root can create TUN interfaces
40+
// Try to open the TUN device to verify
41+
return tryOpenTunDevice()
42+
}
43+
44+
// tryOpenTunDevice attempts to open the TUN device to verify permissions.
45+
// On FreeBSD, /dev/tun is a cloning device that creates a new interface
46+
// when opened.
47+
func tryOpenTunDevice() error {
48+
// Try opening /dev/tun (cloning device)
49+
f, err := os.OpenFile(tunDevice, os.O_RDWR, 0)
50+
if err != nil {
51+
return fmt.Errorf("cannot open %s: %v (need root privileges)", tunDevice, err)
52+
}
53+
defer f.Close()
54+
55+
logger.Debug("Successfully opened TUN device, sufficient permissions for native TUN interface")
56+
return nil
57+
}

0 commit comments

Comments
 (0)