Merge pull request from safing/feature/allowed-clients

Add support for --allowed-clients parameter to whitelist binaries that are allowed to talk to the Portmaster API
This commit is contained in:
Patrick Pacher 2024-03-27 13:58:34 +01:00 committed by GitHub
commit 3a55d902a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions
service/firewall

View file

@ -6,6 +6,7 @@ import (
"net"
"net/http"
"path/filepath"
"slices"
"strings"
"time"
@ -164,6 +165,12 @@ func authenticateAPIRequest(ctx context.Context, pktInfo *packet.Info) (retry bo
default: // normal process
// Check if the requesting process is in database root / updates dir.
if realPath, err := filepath.EvalSymlinks(proc.Path); err == nil {
// check if the client has been allowed by flag
if slices.Contains(allowedClients, realPath) {
return false, nil
}
if strings.HasPrefix(realPath, authenticatedPath) {
return false, nil
}

View file

@ -2,7 +2,9 @@ package firewall
import (
"context"
"flag"
"fmt"
"path/filepath"
"strings"
"github.com/safing/portbase/config"
@ -16,7 +18,21 @@ import (
"github.com/safing/portmaster/spn/captain"
)
var module *modules.Module
type stringSliceFlag []string
func (ss *stringSliceFlag) String() string {
return strings.Join(*ss, ":")
}
func (ss *stringSliceFlag) Set(value string) error {
*ss = append(*ss, filepath.Clean(value))
return nil
}
var (
module *modules.Module
allowedClients stringSliceFlag
)
func init() {
module = modules.Register("filter", prep, start, stop, "core", "interception", "intel", "netquery")
@ -28,6 +44,8 @@ func init() {
"config:filter/",
nil,
)
flag.Var(&allowedClients, "allowed-clients", "A list of binaries that are allowed to connect to the Portmaster API")
}
func prep() error {