Guard the admin API and pprof with a token only root and the server can read
The admin listener answered any local process: models added, nodes upgraded, engine keys listed, the heap dumped. /api and /debug now demand the token the server writes 0600 to its state directory on first start; ctl, the console and node add send it (sudo, LLMGW_ADMIN_TOKEN or --token-file). pprof is off unless debug_pprof. admin_listen off loopback is refused unless admin_remote. Dashboard pages, /metrics and /health are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2d47427cdc
commit
c0421bc7ee
12 files changed
+365
-19
No files matched your search
+19
-8
@@ -19,17 +19,22 @@ import (
|
||||
|
||||
// ctlClient talks to a server's admin API.
|
||||
type ctlClient struct {
|
||||
base string
|
||||
http *http.Client
|
||||
base string
|
||||
http *http.Client
|
||||
token string
|
||||
}
|
||||
|
||||
func newCtlClient(addr string) *ctlClient {
|
||||
// newCtlClient talks to the admin API at addr, with the admin token from
|
||||
// LLMGW_ADMIN_TOKEN or the first of tokenFiles it can read, then the usual
|
||||
// place.
|
||||
func newCtlClient(addr string, tokenFiles ...string) *ctlClient {
|
||||
if !strings.HasPrefix(addr, "http://") && !strings.HasPrefix(addr, "https://") {
|
||||
addr = "http://" + addr
|
||||
}
|
||||
return &ctlClient{
|
||||
base: strings.TrimRight(addr, "/"),
|
||||
http: &http.Client{Timeout: 15 * time.Second},
|
||||
base: strings.TrimRight(addr, "/"),
|
||||
http: &http.Client{Timeout: 15 * time.Second},
|
||||
token: readAdminToken(tokenFiles...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +80,9 @@ func (c *ctlClient) do(ctx context.Context, method, path string, body, out any)
|
||||
// Who made the change, kept with a stored model so a catalog that grew
|
||||
// over months can say where each entry came from.
|
||||
req.Header.Set("X-Llmgw-Actor", actor())
|
||||
if c.token != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
}
|
||||
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
@@ -104,8 +112,9 @@ func (c *ctlClient) do(ctx context.Context, method, path string, body, out any)
|
||||
|
||||
func newCtlCmd() *cobra.Command {
|
||||
var (
|
||||
server string
|
||||
asJSON bool
|
||||
server string
|
||||
asJSON bool
|
||||
tokenFile string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -115,9 +124,11 @@ func newCtlCmd() *cobra.Command {
|
||||
"default) rather than the client-facing port.",
|
||||
}
|
||||
cmd.PersistentFlags().StringVar(&server, "server", "127.0.0.1:9090", "admin API address")
|
||||
cmd.PersistentFlags().StringVar(&tokenFile, "token-file", "",
|
||||
"the admin token's file (default: LLMGW_ADMIN_TOKEN, else "+defaultAdminTokenFile+")")
|
||||
cmd.PersistentFlags().BoolVar(&asJSON, "json", false, "emit JSON")
|
||||
|
||||
client := func() *ctlClient { return newCtlClient(server) }
|
||||
client := func() *ctlClient { return newCtlClient(server, tokenFile) }
|
||||
|
||||
cmd.AddCommand(
|
||||
newNodesCmd(client, &asJSON),
|
||||
|
||||
Reference in new issue
Block a user