From 9e0bae07ee8cc9f2a993ac99f19626caeb8aa7c4 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Tue, 15 Nov 2022 16:16:12 -0500 Subject: [PATCH] Added port check to quickstart Added ability to set listener bind port Added tests for new port variable Fixed bug in quickstart test Fixed typo in quickstart test fixed bug in quickstart env file test closes #706 Signed-off-by: gberl002 --- CHANGELOG.md | 8 +++ go.mod | 11 ++++ go.sum | 24 ++++++++- quickstart/docker/image/Dockerfile | 2 +- quickstart/docker/image/run-with-ziti-cli.sh | 2 +- quickstart/docker/image/ziti-cli-functions.sh | 49 ++++++++++++++++- quickstart/test/quickstart_test.go | 22 ++++++-- ziti/cmd/ziti/cmd/config_templates/router.yml | 4 +- ziti/cmd/ziti/cmd/create_config.go | 17 +++--- .../cmd/ziti/cmd/create_config_environment.go | 3 ++ .../cmd/create_config_router_edge_test.go | 54 +++++++++++++++++-- .../cmd/create_config_router_fabric_test.go | 54 +++++++++++++++++-- ziti/cmd/ziti/cmd/create_config_test.go | 1 + ziti/cmd/ziti/cmd/helpers/env_helpers.go | 4 ++ ziti/cmd/ziti/constants/constants.go | 6 ++- 15 files changed, 235 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0562deef..3df694d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# Release 0.26.12 + +## What's New + +- Ziti CLI + - Enhancements: + - [Issue-706](https://github.com/openziti/ziti/issues/706) - Add port check to quickstart + # Release 0.26.11 ## What's New diff --git a/go.mod b/go.mod index 8a898bcc8..dfda598bc 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/Jeffail/gabs/v2 v2.6.1 github.com/MakeNowJust/heredoc v1.0.0 github.com/blang/semver v3.5.1+incompatible + github.com/docker/docker v20.10.21+incompatible github.com/fatih/color v1.13.0 github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa github.com/go-acme/lego/v4 v4.2.0 @@ -56,6 +57,7 @@ require ( github.com/AppsFlyer/go-sundheit v0.5.0 // indirect github.com/MichaelMure/go-term-markdown v0.1.4 // indirect github.com/MichaelMure/go-term-text v0.3.1 // indirect + github.com/Microsoft/go-winio v0.6.0 // indirect github.com/alecthomas/chroma v0.10.0 // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211106181442-e4c1a74c66bd // indirect @@ -66,11 +68,14 @@ require ( github.com/c-bata/go-prompt v0.2.6 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/coreos/go-iptables v0.6.0 // indirect + github.com/creack/pty v1.1.11 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/dgoogauth v0.0.0-20190221195224-5a805980a5f3 // indirect github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663 // indirect github.com/disintegration/imaging v1.6.2 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect + github.com/docker/distribution v2.8.1+incompatible // indirect + github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/ef-ds/deque v1.0.4 // indirect github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect @@ -87,6 +92,7 @@ require ( github.com/go-openapi/swag v0.22.3 // indirect github.com/go-openapi/validate v0.22.0 // indirect github.com/go-resty/resty/v2 v2.7.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c // indirect github.com/google/uuid v1.3.0 // indirect @@ -124,9 +130,13 @@ require ( github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/moby/term v0.0.0-20221105221325-4eb28fa6025c // indirect + github.com/morikuni/aec v1.0.0 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/netfoundry/secretstream v0.1.2 // indirect github.com/oklog/ulid v1.3.1 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.0.2 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openziti/dilithium v0.3.3 // indirect github.com/openziti/jwks v1.0.2 // indirect @@ -168,4 +178,5 @@ require ( google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect + gotest.tools/v3 v3.4.0 // indirect ) diff --git a/go.sum b/go.sum index 5e93949c0..efe5c09f9 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,7 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/AppsFlyer/go-sundheit v0.5.0 h1:/VxpyigCfJrq1r97mn9HPiAB2qrhcTFHwNIIDr15CZM= github.com/AppsFlyer/go-sundheit v0.5.0/go.mod h1:2ZM0BnfqT/mljBQO224VbL5XH06TgWuQ6Cn+cTtCpTY= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= github.com/Azure/go-autorest/autorest/adal v0.1.0/go.mod h1:MeS4XhScH55IST095THyTxElntu7WqB7pNbZo8Q5G3E= @@ -75,6 +76,8 @@ github.com/MichaelMure/go-term-markdown v0.1.4 h1:Ir3kBXDUtOX7dEv0EaQV8CNPpH+T7A github.com/MichaelMure/go-term-markdown v0.1.4/go.mod h1:EhcA3+pKYnlUsxYKBJ5Sn1cTQmmBMjeNlpV8nRb+JxA= github.com/MichaelMure/go-term-text v0.3.1 h1:Kw9kZanyZWiCHOYu9v/8pWEgDQ6UVN9/ix2Vd2zzWf0= github.com/MichaelMure/go-term-text v0.3.1/go.mod h1:QgVjAEDUnRMlzpS6ky5CGblux7ebeiLnuy9dAaFZu8o= +github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= +github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -168,8 +171,9 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -190,6 +194,12 @@ github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dnsimple/dnsimple-go v0.63.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= +github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= +github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v20.10.21+incompatible h1:UTLdBmHk3bEY+w8qeO5KttOhy6OmXWsl/FEet9Uswog= +github.com/docker/docker v20.10.21+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -318,6 +328,7 @@ github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= @@ -631,11 +642,15 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/moby/term v0.0.0-20221105221325-4eb28fa6025c h1:RC8WMpjonrBfyAh6VN/POIPtYD5tRAq0qMqCRjQNK+g= +github.com/moby/term v0.0.0-20221105221325-4eb28fa6025c/go.mod h1:9OcmHNQQUTbk4XCffrLgN1NEKc2mh5u++biHVrvHsSU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= @@ -667,6 +682,10 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= +github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -1229,6 +1248,7 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1467,6 +1487,8 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/quickstart/docker/image/Dockerfile b/quickstart/docker/image/Dockerfile index a7cb29c30..609f6bd77 100644 --- a/quickstart/docker/image/Dockerfile +++ b/quickstart/docker/image/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:rolling RUN apt update && \ - apt install jq curl netcat-openbsd vim inetutils-ping net-tools -y + apt install jq curl netcat-openbsd vim inetutils-ping net-tools lsof -y RUN useradd -ms /bin/bash ziti && \ mkdir /openziti && chown ziti:ziti /openziti && \ diff --git a/quickstart/docker/image/run-with-ziti-cli.sh b/quickstart/docker/image/run-with-ziti-cli.sh index 301848917..13f83d232 100755 --- a/quickstart/docker/image/run-with-ziti-cli.sh +++ b/quickstart/docker/image/run-with-ziti-cli.sh @@ -29,7 +29,7 @@ if [[ -f "${initFile}" ]]; then fi # give the controller scripts time to start and create the ziti environment file if running in docker compose -until $(test -f "${ZITI_HOME}/ziti.env"); do echo "waiting for ziti.env..."; sleep 1; done +until $(test -f "${ZITI_HOME}/ziti.env"); do echo "waiting for ziti.env..."; sleep 2; done . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index e2e158f35..050e50ed3 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -279,6 +279,36 @@ function checkPrereqs { fi } +function _portCheck { + if [[ "${1-}" == "" ]] || [[ "${2-}" == "" ]]; then + echo -e "_portCheck Usage: _portCheck " + return 0 + fi + + envVar="${1-}" + if [[ -n "$ZSH_VERSION" ]]; then + envVarValue="${(P)envVar}" + elif [[ -n "$BASH_VERSION" ]]; then + envVarValue="${!envVar}" + else + echo -e "Unknown/Unsupported shell, cannot check port status" + return 1 + fi + + portCheckResult=$(lsof -w -i :"${envVarValue}" 2> /dev/null) + if [[ "${portCheckResult}" != "" ]]; then # Controller management plane + echo -e "$(RED " ")" + echo -e "$(RED "The intended ${2-} port (${envVarValue}) is currently being used, the process using this port should be closed or the port value should be changed.")" + echo -e "$(RED "To use a different port, set the port value in ${envVar}")" + echo -e "$(RED " ")" + echo -e "$(RED "Example:")" + echo -e "$(RED "export ${envVar}=1234")" + echo -e "$(RED " ")" + return 1 + fi + return 0 +} + function checkControllerName { if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME}" == *['!'@#\$%^\&*\(\)_+]* ]]; then echo -e "$(RED " - The provided Network name contains an invalid character: '!'@#\$%^\&*()_+")" @@ -359,6 +389,7 @@ function generateEnvFile { if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi if [[ "${ZITI_CONTROLLER_HOSTNAME-}" == "" ]]; then export export ZITI_CONTROLLER_HOSTNAME="${ZITI_CONTROLLER_RAWNAME}"; fi if [[ "${ZITI_CTRL_PORT-}" == "" ]]; then export ZITI_CTRL_PORT="6262"; fi + if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" == "" ]]; then export export ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" == "" ]]; then export export ZITI_EDGE_CONTROLLER_HOSTNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}"; fi @@ -468,6 +499,21 @@ function ziti_expressConfiguration { echo "Exiting as env file was not generated" return 1 fi + + # Check Ports + returnCnt=0 + _portCheck "ZITI_CTRL_PORT" "Controller" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_EDGE_ROUTER_PORT" "Edge Router" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_EDGE_CONTROLLER_PORT" "Edge Controller" + returnCnt=$((returnCnt + $?)) + _portcheck "ZITI_CTRL_MGMT_PORT" "Controller Management Plane" + returnCnt=$((returnCnt + $?)) + _portcheck "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" "Router Listener Bind Port" + returnCnt=$((returnCnt + $?)) + if [[ "returnCnt" -gt "0" ]]; then return 1; fi + #checkHostsFile echo " " @@ -1039,7 +1085,8 @@ function ziti_createEnvFile { export ZITI_BIN_ROOT="${ZITI_HOME}/ziti-bin" - if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:10000"; fi + if [[ "${ZITI_CTRL_MGMT_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_PORT="10000"; fi + if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:${ZITI_CTRL_MGMT_PORT}"; fi if [[ "${ZITI_CTRL_IDENTITY_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-client.cert"; fi if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem"; fi if [[ "${ZITI_CTRL_IDENTITY_KEY-}" == "" ]]; then export ZITI_CTRL_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_CONTROLLER_HOSTNAME}-server.key"; fi diff --git a/quickstart/test/quickstart_test.go b/quickstart/test/quickstart_test.go index 1fe747c81..05bf77b5b 100644 --- a/quickstart/test/quickstart_test.go +++ b/quickstart/test/quickstart_test.go @@ -78,6 +78,7 @@ func buildDockerQuickstartTestImage() { defer tw.Close() dockerFile := "TestDockerfile" + imageNameAndTag := "openziti/quickstart:test" filePaths := iterateDir(dir) @@ -99,7 +100,7 @@ func buildDockerQuickstartTestImage() { Context: dockerFileTarReader, Dockerfile: dockerFile, Remove: true, - Tags: []string{"openziti/quickstart:test"}, + Tags: []string{imageNameAndTag}, }) if err != nil { fmt.Println(err) @@ -107,6 +108,20 @@ func buildDockerQuickstartTestImage() { } defer imageBuildResponse.Body.Close() + // Wait until the image finishes building (builds in a background thread) + for { + fmt.Println("Waiting for image build...") + output, err := exec.Command("docker", "images", "-q", imageNameAndTag).Output() + if err != nil { + fmt.Println(err) + } + if string(output) != "" { + fmt.Println("Build complete, continuing with test") + break + } + time.Sleep(5 * time.Second) + } + danglers := filters.NewArgs() danglers.Add("dangling", "true") results, err := cli.ImageList(ctx, types.ImageListOptions{ @@ -224,7 +239,7 @@ func TestQuickStartEnvFile(t *testing.T) { // Wait until it finishes for { - time.Sleep(1) + time.Sleep(1 * time.Second) output, _ := exec.Command("docker", "inspect", "-f", "{{.State.Running}}", containerId).Output() if string(output) == "false\n" { break @@ -299,6 +314,7 @@ func TestSimpleWebService(t *testing.T) { bindHostAddress := "web-test-blue" bindHostPort := 8000 serviceName := "basic.web.smoke.test.service" + wd, _ := os.Getwd() waitForController(ctrlAddress) // Give routers time to enroll themselves time.Sleep(5 * time.Second) @@ -376,7 +392,7 @@ func TestSimpleWebService(t *testing.T) { fmt.Println("Unable to detect a terminator for the edge router") } helloUrl := fmt.Sprintf("http://%s:%d", serviceName, dialPort) - httpClient := createZitifiedHttpClient("/Users/geoffberl/git/NetFoundry/ziti/quickstart/" + testerUsername + ".json") + httpClient := createZitifiedHttpClient(wd + "/" + testerUsername + ".json") resp, e := httpClient.Get(helloUrl) if e != nil { panic(e) diff --git a/ziti/cmd/ziti/cmd/config_templates/router.yml b/ziti/cmd/ziti/cmd/config_templates/router.yml index a487968a4..da216eba7 100644 --- a/ziti/cmd/ziti/cmd/config_templates/router.yml +++ b/ziti/cmd/ziti/cmd/config_templates/router.yml @@ -20,8 +20,8 @@ link: - binding: transport {{ if .Router.IsPrivate }}#{{ end }} listeners: {{ if .Router.IsPrivate }}#{{ end }} - binding: transport -{{ if .Router.IsPrivate }}#{{ end }} bind: tls:0.0.0.0:{{ .Router.Listener.BindPort }} -{{ if .Router.IsPrivate }}#{{ end }} advertise: tls:{{ .Router.Edge.AdvertisedHost }}:{{ .Router.Listener.BindPort }} +{{ if .Router.IsPrivate }}#{{ end }} bind: tls:0.0.0.0:{{ .Router.Edge.ListenerBindPort }} +{{ if .Router.IsPrivate }}#{{ end }} advertise: tls:{{ .Router.Edge.AdvertisedHost }}:{{ .Router.Edge.ListenerBindPort }} {{ if .Router.IsPrivate }}#{{ end }} options: {{ if .Router.IsPrivate }}#{{ end }} outQueueSize: {{ .Router.Listener.OutQueueSize }} diff --git a/ziti/cmd/ziti/cmd/create_config.go b/ziti/cmd/ziti/cmd/create_config.go index 77f0bda76..eb40ce014 100644 --- a/ziti/cmd/ziti/cmd/create_config.go +++ b/ziti/cmd/ziti/cmd/create_config.go @@ -132,11 +132,12 @@ type RouterTemplateValues struct { } type EdgeRouterTemplateValues struct { - Hostname string - Port string - IPOverride string - AdvertisedHost string - LanInterface string + Hostname string + Port string + IPOverride string + AdvertisedHost string + LanInterface string + ListenerBindPort string } type WSSRouterTemplateValues struct { @@ -162,7 +163,6 @@ type RouterForwarderTemplateValues struct { type RouterListenerTemplateValues struct { ConnectTimeout time.Duration GetSessionTimeout time.Duration - BindPort int OutQueueSize int } @@ -256,6 +256,9 @@ func (data *ConfigTemplateValues) populateEnvVars() { zitiEdgeRouterEnrollmentDuration, err := cmdhelper.GetZitiEdgeRouterEnrollmentDuration() handleVariableError(err, constants.ZitiEdgeRouterEnrollmentDurationVarName) + zitiEdgeRouterListenerBindPort, err := cmdhelper.GetZitiEdgeRouterListenerBindPort() + handleVariableError(err, constants.ZitiEdgeRouterListenerBindPortVarName) + data.ZitiHome = zitiHome data.Hostname = hostname data.Controller.Name = zitiCtrlHostname @@ -265,6 +268,7 @@ func (data *ConfigTemplateValues) populateEnvVars() { data.Controller.Edge.ListenerHostPort = zitiEdgeCtrlListenerHostPort data.Controller.Edge.AdvertisedHostPort = zitiEdgeCtrlAdvertisedHostPort data.Router.Edge.Port = zitiEdgeRouterPort + data.Router.Edge.ListenerBindPort = zitiEdgeRouterListenerBindPort data.Controller.Edge.AdvertisedPort = zitiEdgeCtrlAdvertisedPort data.Controller.EdgeIdentityDuration = zitiEdgeIdentityEnrollmentDuration data.Controller.EdgeRouterDuration = zitiEdgeRouterEnrollmentDuration @@ -273,7 +277,6 @@ func (data *ConfigTemplateValues) populateEnvVars() { } func (data *ConfigTemplateValues) populateDefaults() { - data.Router.Listener.BindPort = constants.DefaultListenerBindPort data.Router.Listener.GetSessionTimeout = constants.DefaultGetSessionTimeout data.Controller.MinQueuedConnects = channel.MinQueuedConnects diff --git a/ziti/cmd/ziti/cmd/create_config_environment.go b/ziti/cmd/ziti/cmd/create_config_environment.go index d6a996d1d..9b0a65c5c 100644 --- a/ziti/cmd/ziti/cmd/create_config_environment.go +++ b/ziti/cmd/ziti/cmd/create_config_environment.go @@ -98,6 +98,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { {constants.ZitiCtrlPortVarName, constants.ZitiCtrlPortVarDescription, data.Controller.Port}, {constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname}, {constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port}, + {constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort}, {constants.ZitiEdgeCtrlIdentityCertVarName, constants.ZitiEdgeCtrlIdentityCertVarDescription, data.Controller.Edge.IdentityCert}, {constants.ZitiEdgeCtrlIdentityServerCertVarName, constants.ZitiEdgeCtrlIdentityServerCertVarDescription, data.Controller.Edge.IdentityServerCert}, {constants.ZitiEdgeCtrlIdentityKeyVarName, constants.ZitiEdgeCtrlIdentityKeyVarDescription, data.Controller.Edge.IdentityKey}, @@ -185,6 +186,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { "%-40s %-50s %s\n"+ "%-40s %-50s %s\n"+ "%-40s %-50s %s\n"+ + "%-40s %-50s %s\n"+ "%-40s %-50s %s", constants.ZitiHomeVarName, constants.ZitiHomeVarDescription, data.ZitiHome, constants.ZitiCtrlPortVarName, constants.ZitiCtrlPortVarDescription, data.Controller.Port, @@ -196,6 +198,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.ZitiEdgeCtrlAdvertisedPortVarDescription, data.Controller.Edge.AdvertisedPort, constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname, constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port, + constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort, constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert, constants.ZitiRouterIdentityServerCertVarName, constants.ZitiRouterIdentityServerCertVarDescription, data.Router.IdentityServerCert, constants.ZitiRouterIdentityKeyVarName, constants.ZitiRouterIdentityKeyVarDescription, data.Router.IdentityKey, diff --git a/ziti/cmd/ziti/cmd/create_config_router_edge_test.go b/ziti/cmd/ziti/cmd/create_config_router_edge_test.go index bebf5d2a4..2340771ab 100644 --- a/ziti/cmd/ziti/cmd/create_config_router_edge_test.go +++ b/ziti/cmd/ziti/cmd/create_config_router_edge_test.go @@ -4,6 +4,7 @@ import ( "github.com/openziti/ziti/ziti/cmd/ziti/constants" "github.com/stretchr/testify/assert" "os" + "strings" "testing" "time" ) @@ -189,6 +190,51 @@ func TestBlankEdgeRouterNameBecomesHostname(t *testing.T) { } +func TestDefaultZitiEdgeRouterListenerBindPort(t *testing.T) { + expectedDefaultPort := "10080" + + // Make sure the related env vars are unset + _ = os.Unsetenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT") + + // Create and run the CLI command + config := createRouterConfig([]string{"edge", "--routerName", "testRouter"}) + + // Check that the template data has been updated as expected + assert.Equal(t, expectedDefaultPort, data.Router.Edge.ListenerBindPort) + + // Check that the actual config output has the correct port + for i := 1; i < len(config.Link.Listeners); i++ { + if config.Link.Listeners[i].Binding == "transport" { + // Assert Bind and Advertise use Bind port value + assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + break + } + } +} + +func TestSetZitiEdgeRouterListenerBindPort(t *testing.T) { + myPortValue := "1234" + + // Set the port manually + _ = os.Setenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT", myPortValue) + + // Create and run the CLI command + config := createRouterConfig([]string{"edge", "--routerName", "testRouter"}) + + assert.Equal(t, myPortValue, data.Router.Edge.ListenerBindPort) + + // Check that the actual config output has the correct port + for i := 1; i < len(config.Link.Listeners); i++ { + if config.Link.Listeners[i].Binding == "transport" { + // Assert Bind and Advertise use Bind port value + assert.Equal(t, myPortValue, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + assert.Equal(t, myPortValue, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + break + } + } +} + func TestEdgeRouterCannotBeWSSAndPrivate(t *testing.T) { expectedErrorMsg := "Flags for private and wss configs are mutually exclusive. You must choose private or wss, not both" @@ -219,10 +265,10 @@ func TestEdgeRouterOutputPathDoesNotExist(t *testing.T) { func TestExecuteCreateConfigRouterEdgeHasNonBlankTemplateValues(t *testing.T) { routerName := "MyEdgeRouter" - expectedNonEmptyStringFields := []string{".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} - expectedNonEmptyStringValues := []*string{&data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} - expectedNonEmptyIntFields := []string{".Router.Listener.BindPort", ".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} - expectedNonEmptyIntValues := []*int{&data.Router.Listener.BindPort, &data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} + expectedNonEmptyStringFields := []string{".Router.Edge.ListenerBindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} + expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} + expectedNonEmptyIntFields := []string{".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} + expectedNonEmptyIntValues := []*int{&data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} expectedNonEmptyTimeFields := []string{".Router.Listener.ConnectTimeout", "Router.Listener.GetSessionTimeout", ".Router.Wss.WriteTimeout", ".Router.Wss.ReadTimeout", ".Router.Wss.IdleTimeout", ".Router.Wss.PongTimeout", ".Router.Wss.PingInterval", ".Router.Wss.HandshakeTimeout", ".Router.Forwarder.LatencyProbeInterval"} expectedNonEmptyTimeValues := []*time.Duration{&data.Router.Listener.ConnectTimeout, &data.Router.Listener.GetSessionTimeout, &data.Router.Wss.WriteTimeout, &data.Router.Wss.ReadTimeout, &data.Router.Wss.IdleTimeout, &data.Router.Wss.PongTimeout, &data.Router.Wss.PingInterval, &data.Router.Wss.HandshakeTimeout, &data.Router.Forwarder.LatencyProbeInterval} diff --git a/ziti/cmd/ziti/cmd/create_config_router_fabric_test.go b/ziti/cmd/ziti/cmd/create_config_router_fabric_test.go index 2b1e0cf8a..6f5fb47fb 100644 --- a/ziti/cmd/ziti/cmd/create_config_router_fabric_test.go +++ b/ziti/cmd/ziti/cmd/create_config_router_fabric_test.go @@ -4,16 +4,17 @@ import ( "github.com/openziti/ziti/ziti/cmd/ziti/constants" "github.com/stretchr/testify/assert" "os" + "strings" "testing" "time" ) func TestExecuteCreateConfigRouterFabricHasNonBlankTemplateValues(t *testing.T) { routerName := "MyFabricRouter" - expectedNonEmptyStringFields := []string{".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} - expectedNonEmptyStringValues := []*string{&data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} - expectedNonEmptyIntFields := []string{".Router.Listener.BindPort", ".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} - expectedNonEmptyIntValues := []*int{&data.Router.Listener.BindPort, &data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} + expectedNonEmptyStringFields := []string{".Router.Listener.BindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} + expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} + expectedNonEmptyIntFields := []string{".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} + expectedNonEmptyIntValues := []*int{&data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} expectedNonEmptyTimeFields := []string{".Router.Listener.ConnectTimeout", "Router.Listener.GetSessionTimeout", ".Router.Wss.WriteTimeout", ".Router.Wss.ReadTimeout", ".Router.Wss.IdleTimeout", ".Router.Wss.PongTimeout", ".Router.Wss.PingInterval", ".Router.Wss.HandshakeTimeout", ".Router.Forwarder.LatencyProbeInterval"} expectedNonEmptyTimeValues := []*time.Duration{&data.Router.Listener.ConnectTimeout, &data.Router.Listener.GetSessionTimeout, &data.Router.Wss.WriteTimeout, &data.Router.Wss.ReadTimeout, &data.Router.Wss.IdleTimeout, &data.Router.Wss.PongTimeout, &data.Router.Wss.PingInterval, &data.Router.Wss.HandshakeTimeout, &data.Router.Forwarder.LatencyProbeInterval} @@ -109,3 +110,48 @@ func TestFabricRouterOutputPathDoesNotExist(t *testing.T) { assert.EqualError(t, err, expectedErrorMsg, "Error does not match, expected %s but got %s", expectedErrorMsg, err) } + +func TestDefaultZitiFabricRouterListenerBindPort(t *testing.T) { + expectedDefaultPort := "10080" + + // Make sure the related env vars are unset + _ = os.Unsetenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT") + + // Create and run the CLI command + config := createRouterConfig([]string{"fabric", "--routerName", "testRouter"}) + + // Check that the template data has been updated as expected + assert.Equal(t, expectedDefaultPort, data.Router.Edge.ListenerBindPort) + + // Check that the actual config output has the correct port + for i := 1; i < len(config.Link.Listeners); i++ { + if config.Link.Listeners[i].Binding == "transport" { + // Assert Bind and Advertise use Bind port value + assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + break + } + } +} + +func TestSetZitiFabricRouterListenerBindPort(t *testing.T) { + myPortValue := "1234" + + // Set the port manually + _ = os.Setenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT", myPortValue) + + // Create and run the CLI command + config := createRouterConfig([]string{"fabric", "--routerName", "testRouter"}) + + assert.Equal(t, myPortValue, data.Router.Edge.ListenerBindPort) + + // Check that the actual config output has the correct port + for i := 1; i < len(config.Link.Listeners); i++ { + if config.Link.Listeners[i].Binding == "transport" { + // Assert Bind and Advertise use Bind port value + assert.Equal(t, myPortValue, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + assert.Equal(t, myPortValue, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + break + } + } +} diff --git a/ziti/cmd/ziti/cmd/create_config_test.go b/ziti/cmd/ziti/cmd/create_config_test.go index 59a8b002b..51ed0e9ed 100644 --- a/ziti/cmd/ziti/cmd/create_config_test.go +++ b/ziti/cmd/ziti/cmd/create_config_test.go @@ -40,6 +40,7 @@ func getZitiEnvironmentVariables() []string { "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", "ZITI_EDGE_ROUTER_ADVERTISED_HOST", + "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT", } } diff --git a/ziti/cmd/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/ziti/cmd/helpers/env_helpers.go index 21ee4d8e1..13e93944a 100644 --- a/ziti/cmd/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/ziti/cmd/helpers/env_helpers.go @@ -105,6 +105,10 @@ func GetZitiEdgeRouterPort() (string, error) { return getValueOrSetAndGetDefault(constants.ZitiEdgeRouterPortVarName, constants.DefaultZitiEdgeRouterPort) } +func GetZitiEdgeRouterListenerBindPort() (string, error) { + return getValueOrSetAndGetDefault(constants.ZitiEdgeRouterListenerBindPortVarName, constants.DefaultZitiEdgeRouterListenerBindPort) +} + func GetZitiEdgeCtrlListenerHostPort() (string, error) { // Get the edge controller port to use as the default edgeCtrlPort, err := GetZitiEdgeCtrlAdvertisedPort() diff --git a/ziti/cmd/ziti/constants/constants.go b/ziti/cmd/ziti/constants/constants.go index b4efd27b3..3aacff84d 100644 --- a/ziti/cmd/ziti/constants/constants.go +++ b/ziti/cmd/ziti/constants/constants.go @@ -36,8 +36,8 @@ const ( // Config Template Constants const ( - DefaultListenerBindPort = 10080 - DefaultGetSessionTimeout = 60 * time.Second + DefaultZitiEdgeRouterListenerBindPort = "10080" + DefaultGetSessionTimeout = 60 * time.Second DefaultZitiEdgeRouterPort = "3022" @@ -107,4 +107,6 @@ const ( ZitiEdgeRouterIPOverrideVarDescription = "Override the default edge router IP with a custom IP, this IP will also be added to the PKI" ZitiEdgeRouterAdvertisedHostVarName = "ZITI_EDGE_ROUTER_ADVERTISED_HOST" ZitiEdgeRouterAdvertisedHostVarDescription = "The advertised host of the router" + ZitiEdgeRouterListenerBindPortVarName = "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" + ZitiEdgeRouterListenerBindPortVarDescription = "The port a public router will advertise on" )