CI / changes (push) Successful in 12s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 25s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m15s
CI / bird2 (push) Successful in 18s
CI / release (push) Successful in 3m59s
Introduced a comprehensive firewall blocklist feature, allowing for the management of firewall clients and their associated rules. This includes endpoints for enrolling clients, listing clients and rules, and reporting apply statuses. Enhanced the API to support firewall operations, including the ability to handle block/accept policies. Updated the documentation to reflect these changes and added necessary components in the web UI for better user interaction. Additionally, modified the agent server to support firewall failover and integrated firewall functionality into the existing architecture.
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"sync"
|
|
|
|
"evobgp/internal/authkey"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
type firewallAuthRow struct {
|
|
tenantID string
|
|
clientID string
|
|
}
|
|
|
|
type firewallTokenResolver struct {
|
|
mu sync.RWMutex
|
|
byHash map[string]firewallAuthRow
|
|
}
|
|
|
|
func newFirewallTokenResolver(st store.Backend) (*firewallTokenResolver, error) {
|
|
r := &firewallTokenResolver{byHash: make(map[string]firewallAuthRow)}
|
|
return r, r.reloadFromStore(st)
|
|
}
|
|
|
|
func (r *firewallTokenResolver) reloadFromStore(st store.Backend) error {
|
|
rows, err := st.ListActiveFirewallClientHashes()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
byHash := make(map[string]firewallAuthRow, len(rows))
|
|
for _, row := range rows {
|
|
if len(row.TokenHash) != 32 {
|
|
continue
|
|
}
|
|
byHash[hex.EncodeToString(row.TokenHash)] = firewallAuthRow{
|
|
tenantID: row.TenantID,
|
|
clientID: row.ID,
|
|
}
|
|
}
|
|
r.mu.Lock()
|
|
r.byHash = byHash
|
|
r.mu.Unlock()
|
|
return nil
|
|
}
|
|
|
|
func (r *firewallTokenResolver) Reload(st store.Backend) error {
|
|
return r.reloadFromStore(st)
|
|
}
|
|
|
|
func (r *firewallTokenResolver) Lookup(raw string) (firewallAuthRow, bool) {
|
|
hash := authkey.HashToken(raw)
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
rec, ok := r.byHash[hex.EncodeToString(hash)]
|
|
return rec, ok
|
|
}
|