Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/188.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
In order to support Windows, write Envoy bootstrap configuration to a regular file instead of a named pipe.
```
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ GOBIN ?= $(GOPATH)/bin

# Get local ARCH; on Intel Mac, 'uname -m' returns x86_64 which we turn into amd64.
# Not using 'go env GOOS/GOARCH' here so 'make docker' will work without local Go install.
ARCH = $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
OS = $(shell uname | tr [[:upper:]] [[:lower:]])
ARCH ?= $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
OS ?= $(shell uname | tr [[:upper:]] [[:lower:]])
PLATFORM = $(OS)/$(ARCH)
DIST = dist/$(PLATFORM)
BIN = $(DIST)/$(BIN_NAME)
Expand Down Expand Up @@ -89,6 +89,7 @@ copy-bootstrap-config:
sed '/github.com\/hashicorp\/consul\/api/d' | \
sed 's/api.IntentionDefaultNamespace/"default"/g' | \
sed '1s:^:// Code generated by make copy-bootstrap-config. DO NOT EDIT.\n:' | \
sed '/"initial_metadata": \[/,/\]/d' | \
gofmt \
> $(BOOTSTRAP_PACKAGE_DIR)/$$file; \
done
Expand Down
6 changes: 0 additions & 6 deletions internal/bootstrap/bootstrap_tpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/consuldp/testdata/TestBootstrapConfig/basic.golden
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@
"api_type": "DELTA_GRPC",
"transport_api_version": "V3",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "consul-dataplane"
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/envoy/get_process_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows
// +build !windows

package envoy

import "syscall"

func getProcessAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setpgid: true,
}
}
12 changes: 12 additions & 0 deletions pkg/envoy/get_process_attr_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build windows
// +build windows

package envoy

import "syscall"

func getProcessAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
}
35 changes: 5 additions & 30 deletions pkg/envoy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"sync/atomic"
"syscall"
"time"

"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -158,9 +158,7 @@ func (p *Proxy) Run(ctx context.Context) error {
// Start Envoy in its own process group to avoid directly receiving
// SIGTERM intended for consul-dataplane, let proxy manager handle
// graceful shutdown if configured.
p.cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
p.cmd.SysProcAttr = getProcessAttr()

p.cfg.Logger.Debug("running envoy proxy", "command", strings.Join(p.cmd.Args, " "))
if err := p.cmd.Start(); err != nil {
Expand Down Expand Up @@ -343,40 +341,17 @@ func writeBootstrapConfig(cfg []byte) (string, func() error, error) {
os.TempDir(),
fmt.Sprintf("envoy-%x-bootstrap.json", time.Now().UnixNano()+int64(os.Getpid())),
)
if err := syscall.Mkfifo(path, 0600); err != nil {
return "", nil, err
}

// O_WRONLY causes OpenFile to block until there's a reader (Envoy). Opening
// the pipe with O_RDWR wouldn't block but would result in just sending stuff
// to ourself.
//
// TODO(boxofrad): We don't have a way to cancel this goroutine. If the Envoy
// process never opens the other end of the pipe this will hang forever. The
// workaround we use in `consul connect envoy` is to write to the pipe in a
// subprocess that self-destructs after 10 minutes.
go func() {
file, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
os.Remove(path)
return
}

_, err = file.Write(cfg)
file.Close()

if err != nil {
os.Remove(path)
}
}()
log.Printf("bootstrap config path: %s", path)
err := os.WriteFile(path, cfg, 0600)

return path, func() error {
err := os.Remove(path)
if err == nil || errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}, nil
}, err
}

// buildCommand builds the exec.Cmd to run Envoy with the relevant arguments
Expand Down