Files
caddy/internal/bindcap_other.go
Francis Lavoie c8341d5b69 core: Raise CAP_NET_BIND_SERVICE when binding privileged ports (#8102)
* core: Raise CAP_NET_BIND_SERVICE when binding privileged ports

When CAP_NET_BIND_SERVICE is in the permitted set but not the effective
set, raise it on a dedicated locked OS thread just for the bind, then
lower it again and let the thread exit.

This allows the binary to be granted the capability with
`setcap cap_net_bind_service=+p` instead of `=+ep`. With the effective
bit set, the kernel refuses to exec the binary at all when the
capability can't be granted (e.g. `docker run --cap-drop ALL`, or an
empty systemd CapabilityBoundingSet), even if no privileged port is
ever bound.

* core: Move bind capability helpers into internal package
2026-10-03 19:10:02 +10:00

24 lines
836 B
Go

// Copyright 2015 Matthew Holt and The Caddy Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !linux
package internal
// WithBindCapability calls listen. Raising capabilities is only
// supported on Linux.
func WithBindCapability(_, _ string, listen func() (any, error)) (any, error) {
return listen()
}