Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: fix cli when admin endpoint uses new unix socket permission format #5696

Merged
merged 3 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io
origin := "http://" + parsedAddr.JoinHostPort(0)
if parsedAddr.IsUnixNetwork() {
origin = "http://127.0.0.1" // bogus host is a hack so that http.NewRequest() is happy

// the unix address at this point might still contain the optional
// unix socket permissions, which are part of the address/host.
// those need to be removed first, as they aren't part of the
// resulting unix file path
addr, _, err := caddy.SplitUnixSocketPermissionsBits(parsedAddr.Host)
if err != nil {
return nil, err
}
parsedAddr.Host = addr
}

// form the request
Expand Down
6 changes: 3 additions & 3 deletions listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
// is independent of permissions bits
if na.IsUnixNetwork() {
var err error
address, unixFileMode, err = splitUnixSocketPermissionsBits(na.Host)
address, unixFileMode, err = SplitUnixSocketPermissionsBits(na.Host)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func IsUnixNetwork(netw string) bool {
// include write perms (e.g. `0422` or `022`).
// Symbolic permission representation (e.g. `u=w,g=w,o=w`)
// is not supported and will throw an error for now!
func splitUnixSocketPermissionsBits(addr string) (path string, fileMode fs.FileMode, err error) {
func SplitUnixSocketPermissionsBits(addr string) (path string, fileMode fs.FileMode, err error) {
mholt marked this conversation as resolved.
Show resolved Hide resolved
addrSplit := strings.SplitN(addr, "|", 2)

if len(addrSplit) == 2 {
Expand Down Expand Up @@ -377,7 +377,7 @@ func ParseNetworkAddressWithDefaults(addr, defaultNetwork string, defaultPort ui
network = defaultNetwork
}
if IsUnixNetwork(network) {
_, _, err := splitUnixSocketPermissionsBits(host)
_, _, err := SplitUnixSocketPermissionsBits(host)
return NetworkAddress{
Network: network,
Host: host,
Expand Down
2 changes: 1 addition & 1 deletion listeners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func TestSplitUnixSocketPermissionsBits(t *testing.T) {
expectErr: true,
},
} {
actualPath, actualFileMode, err := splitUnixSocketPermissionsBits(tc.input)
actualPath, actualFileMode, err := SplitUnixSocketPermissionsBits(tc.input)
if tc.expectErr && err == nil {
t.Errorf("Test %d: Expected error but got: %v", i, err)
}
Expand Down
Loading