mirror of
https://github.com/h44z/wg-portal.git
synced 2026-12-05 11:46:09 +01:00
cleanup
This commit is contained in:
@@ -14,7 +14,14 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-n-push:
|
build-n-push:
|
||||||
name: Build and Push
|
name: Build and Push (${{ matrix.target }})
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- target: standard
|
||||||
|
suffix: ''
|
||||||
|
- target: amneziawg
|
||||||
|
suffix: '-amneziawg,onlatest=true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
@@ -55,7 +62,7 @@ jobs:
|
|||||||
flavor: |
|
flavor: |
|
||||||
latest=auto
|
latest=auto
|
||||||
prefix=
|
prefix=
|
||||||
suffix=
|
suffix=${{ matrix.suffix }}
|
||||||
tags: |
|
tags: |
|
||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
@@ -71,6 +78,7 @@ jobs:
|
|||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
target: ${{ matrix.target }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@@ -80,6 +88,7 @@ jobs:
|
|||||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
||||||
|
|
||||||
- name: Export binaries from images
|
- name: Export binaries from images
|
||||||
|
if: matrix.target == 'standard'
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
@@ -89,45 +98,15 @@ jobs:
|
|||||||
build-args: |
|
build-args: |
|
||||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
||||||
|
|
||||||
- name: Extract metadata for AmneziaWG image
|
|
||||||
id: meta-awg
|
|
||||||
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
wgportal/wg-portal
|
|
||||||
ghcr.io/${{ github.repository }}
|
|
||||||
flavor: |
|
|
||||||
latest=auto
|
|
||||||
suffix=-amneziawg,onlatest=true
|
|
||||||
tags: |
|
|
||||||
type=ref,event=tag
|
|
||||||
type=ref,event=branch
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
type=semver,pattern=v{{major}}.{{minor}}
|
|
||||||
type=semver,pattern=v{{major}}
|
|
||||||
|
|
||||||
- name: Build and push AmneziaWG Docker image
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
target: amneziawg
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
tags: ${{ steps.meta-awg.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta-awg.outputs.labels }}
|
|
||||||
annotations: ${{ steps.meta-awg.outputs.annotations }}
|
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
||||||
build-args: |
|
|
||||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
|
||||||
|
|
||||||
- name: Rename binaries
|
- name: Rename binaries
|
||||||
|
if: matrix.target == 'standard'
|
||||||
run: |
|
run: |
|
||||||
for file in binaries/linux*/wg-portal; do
|
for file in binaries/linux*/wg-portal; do
|
||||||
mv $file binaries/wg-portal_$(basename $(dirname $file))
|
mv $file binaries/wg-portal_$(basename $(dirname $file))
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Upload binaries
|
- name: Upload binaries
|
||||||
|
if: matrix.target == 'standard'
|
||||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||||
with:
|
with:
|
||||||
name: binaries
|
name: binaries
|
||||||
|
|||||||
@@ -95,17 +95,3 @@ func (c AmneziaWGController) SaveInterface(ctx context.Context, id domain.Interf
|
|||||||
}
|
}
|
||||||
return c.updateLowLevelInterface(iface)
|
return c.updateLowLevelInterface(iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c AmneziaWGController) DeleteInterface(_ context.Context, id domain.InterfaceIdentifier) error {
|
|
||||||
link, err := c.nl.LinkByName(string(id))
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := errors.AsType[netlink.LinkNotFoundError](err); ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if link.Type() != "amneziawg" {
|
|
||||||
return fmt.Errorf("interface %s is not an AmneziaWG kernel device", id)
|
|
||||||
}
|
|
||||||
return c.nl.LinkDel(link)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -404,6 +404,9 @@ func (c LocalController) deleteLowLevelInterface(id domain.InterfaceIdentifier)
|
|||||||
return fmt.Errorf("unable to find low level interface: %w", err)
|
return fmt.Errorf("unable to find low level interface: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.importSource == domain.ControllerTypeAmneziaWG && link.Type() != "amneziawg" {
|
||||||
|
return fmt.Errorf("interface %s is not an AmneziaWG kernel device", id)
|
||||||
|
}
|
||||||
err = c.nl.LinkDel(link)
|
err = c.nl.LinkDel(link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to delete low level interface: %w", err)
|
return fmt.Errorf("failed to delete low level interface: %w", err)
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
# Core settings
|
# Core settings
|
||||||
PrivateKey = {{ .Interface.KeyPair.PrivateKey }}
|
PrivateKey = {{ .Interface.KeyPair.PrivateKey }}
|
||||||
{{- if .Interface.AmneziaWG }}
|
{{- with .Interface.AmneziaWG }}
|
||||||
{{ .Interface.AmneziaWG.ConfigLines -}}
|
{{ range $key, $value := . }}{{ $key }} = {{ $value }}
|
||||||
{{- end }}
|
{{ end }}{{ end }}
|
||||||
Address = {{ CidrsToString .Interface.Addresses }}
|
Address = {{ CidrsToString .Interface.Addresses }}
|
||||||
|
|
||||||
# Misc. settings (optional)
|
# Misc. settings (optional)
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
# Core settings
|
# Core settings
|
||||||
PrivateKey = {{ .Peer.Interface.KeyPair.PrivateKey }}
|
PrivateKey = {{ .Peer.Interface.KeyPair.PrivateKey }}
|
||||||
{{- if .Peer.Interface.AmneziaWG }}
|
{{- with .Peer.Interface.AmneziaWG }}
|
||||||
{{ .Peer.Interface.AmneziaWG.ConfigLines -}}
|
{{ range $key, $value := . }}{{ $key }} = {{ $value }}
|
||||||
{{- end }}
|
{{ end }}{{ end }}
|
||||||
{{- if eq .Style "wgquick"}}
|
{{- if eq .Style "wgquick"}}
|
||||||
Address = {{ CidrsToString .Peer.Interface.Addresses }}
|
Address = {{ CidrsToString .Peer.Interface.Addresses }}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package domain
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
|
||||||
"slices"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -69,12 +67,3 @@ func ParseAmneziaWGRange(value string, bits int) (uint64, uint64, error) {
|
|||||||
}
|
}
|
||||||
return lo, hi, nil
|
return lo, hi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigLines is deterministic so saved files and QR codes use the same options.
|
|
||||||
func (o AmneziaWGOptions) ConfigLines() string {
|
|
||||||
var result strings.Builder
|
|
||||||
for _, key := range slices.Sorted(maps.Keys(o)) {
|
|
||||||
_, _ = fmt.Fprintf(&result, "%s = %s\n", key, o[key])
|
|
||||||
}
|
|
||||||
return result.String()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -182,19 +182,10 @@ func encodeAmneziaWGSockaddr(endpoint *net.UDPAddr) ([]byte, error) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate lengths before using netlink's attribute decoder, including padding
|
// With an aligned buffer, a valid attribute and its padding both fit.
|
||||||
// that would otherwise let a truncated attribute panic during decoding.
|
|
||||||
func amneziaWGAttrs(data []byte) ([]syscall.NetlinkRouteAttr, error) {
|
func amneziaWGAttrs(data []byte) ([]syscall.NetlinkRouteAttr, error) {
|
||||||
for rest := data; len(rest) != 0; {
|
if len(data)%unix.RTA_ALIGNTO != 0 {
|
||||||
if len(rest) < unix.SizeofRtAttr {
|
return nil, fmt.Errorf("unaligned AmneziaWG attributes")
|
||||||
return nil, fmt.Errorf("truncated AmneziaWG attribute")
|
|
||||||
}
|
|
||||||
length := int(nl.NativeEndian().Uint16(rest))
|
|
||||||
padded := (length + 3) &^ 3
|
|
||||||
if length < unix.SizeofRtAttr || padded > len(rest) {
|
|
||||||
return nil, fmt.Errorf("invalid AmneziaWG attribute length")
|
|
||||||
}
|
|
||||||
rest = rest[padded:]
|
|
||||||
}
|
}
|
||||||
return nl.ParseRouteAttr(data)
|
return nl.ParseRouteAttr(data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user