only allow admin access via unix socket

This commit is contained in:
ston1th 2023-03-15 12:54:21 +01:00
commit 13780f1c74
5 changed files with 73 additions and 16 deletions

View file

@ -5,7 +5,6 @@ package server
import (
"encoding/json"
"net/http"
"net/netip"
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
"git.giftfish.de/ston1th/keyctl/pkg/api/v1/schema"
@ -14,16 +13,21 @@ import (
func local(h types.CtxHandler) types.CtxHandler {
return func(ctx *types.Context) {
addr, err := netip.ParseAddr(ctx.ClientIP())
if err != nil {
ctx.Err(types.ErrForbidden)
ip := ctx.ClientIP()
if ip == "@" {
h(ctx)
return
}
if !addr.IsLoopback() {
ctx.Err(types.ErrForbidden)
return
}
h(ctx)
//addr, err := netip.ParseAddr(ip)
//if err != nil {
// ctx.Err(types.ErrForbidden)
// return
//}
//if addr.IsLoopback() {
// h(ctx)
// return
//}
ctx.Err(types.ErrForbidden)
}
}