Skip to content

Commit 37a18af

Browse files
committed
Skip syslog flag on Windows, add env vars for PKCS11 flags
1 parent b82ecc6 commit 37a18af

8 files changed

+25
-19
lines changed

Dockerfile-test

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ WORKDIR /go/src/github.com/square/ghostunnel
2727
ENV GHOSTUNNEL_TEST_PKCS11=true
2828

2929
# Set params for PKCS11 module
30-
ENV PKCS11_MODULE=/usr/lib/softhsm/libsofthsm2.so
31-
ENV PKCS11_LABEL=ghostunnel-pkcs11-test
32-
ENV PKCS11_PIN=1234
30+
ENV GHOSTUNNEL_TEST_PKCS11_MODULE=/usr/lib/softhsm/libsofthsm2.so
31+
ENV GHOSTUNNEL_TEST_PKCS11_LABEL=ghostunnel-pkcs11-test
32+
ENV GHOSTUNNEL_TEST_PKCS11_PIN=1234
3333

3434
# Set SoftHSM config file
3535
ENV SOFTHSM2_CONF=/etc/softhsm/softhsm2.conf

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ $(INTEGRATION_TESTS): ghostunnel.test
1919
@cd tests && ./runner.py $@
2020

2121
softhsm-import:
22-
softhsm2-util --init-token --slot 0 --label ${PKCS11_LABEL} --so-pin ${PKCS11_PIN} --pin ${PKCS11_PIN}
23-
softhsm2-util --id 01 --token ${PKCS11_LABEL} --label ${PKCS11_LABEL} --import test-keys/server.pkcs8.key --so-pin ${PKCS11_PIN} --pin ${PKCS11_PIN}
22+
softhsm2-util --init-token --slot 0 --label ${GHOSTUNNEL_TEST_PKCS11_LABEL} --so-pin ${GHOSTUNNEL_TEST_PKCS11_PIN} --pin ${GHOSTUNNEL_TEST_PKCS11_PIN}
23+
softhsm2-util --id 01 --token ${GHOSTUNNEL_TEST_PKCS11_LABEL} --label ${GHOSTUNNEL_TEST_PKCS11_LABEL} --import test-keys/server.pkcs8.key --so-pin ${GHOSTUNNEL_TEST_PKCS11_PIN} --pin ${GHOSTUNNEL_TEST_PKCS11_PIN}
2424

2525
docker-build:
2626
docker build -t squareup/ghostunnel .
@@ -29,7 +29,7 @@ docker-test-build:
2929
docker build --build-arg GO_VERSION=${GO_VERSION} -t squareup/ghostunnel-test -f Dockerfile-test .
3030

3131
docker-test-run:
32-
docker run -v /dev/log:/dev/log -v ${PWD}:/go/src/github.com/square/ghostunnel squareup/ghostunnel-test
32+
docker run -v ${PWD}:/go/src/github.com/square/ghostunnel squareup/ghostunnel-test
3333

3434
docker-test: docker-test-build docker-test-run
3535

main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ var (
9292
// Status & logging
9393
statusAddress = app.Flag("status", "Enable serving /_status and /_metrics on given HOST:PORT (or unix:SOCKET).").PlaceHolder("ADDR").String()
9494
enableProf = app.Flag("enable-pprof", "Enable serving /debug/pprof endpoints alongside /_status (for profiling).").Bool()
95-
useSyslog = app.Flag("syslog", "Send logs to syslog instead of stderr (not supported on Windows).").Bool()
9695
)
9796

9897
var exitFunc = os.Exit
@@ -115,11 +114,11 @@ type Dialer interface {
115114
// Global logger instance
116115
var logger = log.New(os.Stderr, "", log.LstdFlags|log.Lmicroseconds)
117116

118-
func initLogger() (err error) {
117+
func initLogger(syslog bool) (err error) {
119118
// If user has indicated request for syslog, override default stderr
120119
// logger with a syslog one instead. This can fail, e.g. in containers
121120
// that don't have syslog available.
122-
if *useSyslog {
121+
if syslog {
123122
var syslogWriter gsyslog.Syslogger
124123
syslogWriter, err = gsyslog.NewLogger(gsyslog.LOG_INFO, "DAEMON", "")
125124
if err == nil {
@@ -219,7 +218,7 @@ func run(args []string) error {
219218
command := kingpin.MustParse(app.Parse(args))
220219

221220
// Logger
222-
err := initLogger()
221+
err := initLogger(useSyslog())
223222
if err != nil {
224223
fmt.Fprintf(os.Stderr, "error initializing logger: %s\n", err)
225224
os.Exit(1)

main_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ func TestIntegrationMain(t *testing.T) {
8181
}
8282

8383
func TestInitLoggerSyslog(t *testing.T) {
84-
*useSyslog = true
85-
defer func() { *useSyslog = false }()
8684
originalLogger := logger
87-
err := initLogger()
85+
err := initLogger(true)
8886
updatedLogger := logger
8987
if err != nil {
9088
// Tests running in containers often don't have access to syslog,

tests/test-server-pkcs11-module.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
# hack: point target to STATUS_PORT so that /_status doesn't 503.
1818
ghostunnel = run_ghostunnel(['server', '--listen={0}:13001'.format(LOCALHOST),
1919
'--target={0}:{1}'.format(LOCALHOST, STATUS_PORT), '--keystore=../test-keys/server.crt',
20-
'--pkcs11-module={0}'.format(os.environ['PKCS11_MODULE']),
21-
'--pkcs11-token-label={0}'.format(os.environ['PKCS11_LABEL']),
22-
'--pkcs11-pin={0}'.format(os.environ['PKCS11_PIN']),
20+
'--pkcs11-module={0}'.format(os.environ['GHOSTUNNEL_TEST_PKCS11_MODULE']),
21+
'--pkcs11-token-label={0}'.format(os.environ['GHOSTUNNEL_TEST_PKCS11_LABEL']),
22+
'--pkcs11-pin={0}'.format(os.environ['GHOSTUNNEL_TEST_PKCS11_PIN']),
2323
'--cacert=../test-keys/root.crt', '--allow-ou=client',
2424
'--status={0}:{1}'.format(LOCALHOST, STATUS_PORT)])
2525

tls_cgo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
)
2626

2727
var (
28-
pkcs11Module = app.Flag("pkcs11-module", "Path to PKCS11 module (SO) file (optional)").PlaceHolder("PATH").ExistingFile()
29-
pkcs11TokenLabel = app.Flag("pkcs11-token-label", "Token label for slot/key in PKCS11 module (optional)").PlaceHolder("LABEL").String()
30-
pkcs11PIN = app.Flag("pkcs11-pin", "PIN code for slot/key in PKCS11 module (optional)").PlaceHolder("PIN").String()
28+
pkcs11Module = app.Flag("pkcs11-module", "Path to PKCS11 module (SO) file (optional).").Envar("PKCS11_MODULE").PlaceHolder("PATH").ExistingFile()
29+
pkcs11TokenLabel = app.Flag("pkcs11-token-label", "Token label for slot/key in PKCS11 module (optional).").Envar("PKCS11_TOKEN_LABEL").PlaceHolder("LABEL").String()
30+
pkcs11PIN = app.Flag("pkcs11-pin", "PIN code for slot/key in PKCS11 module (optional).").Envar("PKCS11_PIN").PlaceHolder("PIN").String()
3131
)
3232

3333
func newPKCS11(pubkey crypto.PublicKey) (crypto.PrivateKey, error) {

signals_unix.go unix.go

+5
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ import (
2626
var (
2727
shutdownSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM}
2828
refreshSignals = []os.Signal{syscall.SIGUSR1}
29+
syslogFlag = app.Flag("syslog", "Send logs to syslog instead of stderr.").Bool()
2930
)
31+
32+
func useSyslog() bool {
33+
return *syslogFlag
34+
}

signals_windows.go windows.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ var (
2626
shutdownSignals = []os.Signal{os.Interrupt}
2727
refreshSignals = []os.Signal{ /* Not supported on Windows */ }
2828
)
29+
30+
func useSyslog() bool {
31+
return false
32+
}

0 commit comments

Comments
 (0)