diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3cfcef039..390c0bfb9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,6 +103,8 @@ jobs: - name: Build and Test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ziti_ci_gpg_key: ${{ secrets.ZITI_CI_GPG_KEY }} + ziti_ci_gpg_key_id: ${{ secrets.ZITI_CI_GPG_KEY_ID }} run: | sudo apt-get update sudo apt-get -yq install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc-aarch64-linux-gnu diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bcdf2abf..ac382a583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,105 @@ -# Release 0.24.13 +# Release 0.25.2 + +## Deprecations +The Ziti Edge management REST `/database` and `/terminators` endpoints are being deprecated. They belong in the +fabric management API, but there was no fabric REST api at the time when they were added. Now that they are +available under fabric, they will be removed from the edge APIs in a future release, v0.26 or later. + +## What's New + +* Enhancement: Only translate router ids -> names in `ziti edge traceroute` when requested to with flag +* Enhancement: Add the /database rest API from edge to fabric, where they below + * `ziti fabric db` now as the same commands as `ziti edge db` +* Enhancement: Add `ziti agent` command for sending IPC commands. Contains copy of what was under `ziti ps`. +* Enhancement: Add `ziti agent controller snapshot-db ` IPC command + + +# Release 0.25.1 + +* Bug fix: Fix panic caused by race condition at router start up + * Regression since 0.25.0 + +# Release 0.25.0 + +## Breaking Changes +Routers with version 0.25.0 or greater must be used with a controller that is also v0.25 or greater. +Controllers will continue to work with older routers. Router of this version should also continue to interoperate with older routers. + +NOTE: You may be used to seeing two links between routers, if they both have link listeners. Starting with v0.25 expect to see only +a single link between routers, unless you use the new link types feature. + +## What's New * Bug fix: Fixed an issue with the ziti CLI quickstart routine which also affected router and controller config generation leaving many config fields blank or incorrect. + * Note: This fix was previously reported to have been fixed in 0.24.13 but the fix was actually applied to this release. +* Enhancement: Router Link Refactor + * Support for multiple link types + * Existing link notifications + * Link heartbeats/latency have changed + * Inspect and ps upport for links + * Router version dissemination + * Distributed control preparation +* Enhancement: `ziti fabric list routers` now includes the link listener types and advertise addresses + +## Router Link Refactor + +### Multiple Link Types +Routers can now configure multiple link listeners. Listeners now support an option 'type' attribute. If no type is provided, the link type will be derived from the address. For example, given the following configuration: + +``` +link: + dialers: + - binding: transport + listeners: + - binding: transport + bind: tls:127.0.0.1:7878 + advertise: tls:127.0.0.1:7878 + + - binding: transport + bind: tls:127.0.0.1:5876 + advertise: tls:127.0.0.1:5876 + type: cellular +``` + +The first listener will have a type of `tls` and the second listener will have a type of `cellular`. + +Routers will now try to maintain one link of each type available on the target router. + +When using `ziti fabric list links` the link type will now be shown. + +### Existing link notifications +As the controller doesn't persist links, when the controller restarts or loses connection it loses all information about router links. Routers can now notify the controller about existing links when they reconnect. If they receive a link dial request for a link that they already have (based on the target router and link type), they can now report back the existing link. This should prevent the number of links to remain relatively constant. + +### Link Heartbeats + +Because we are now limiting the number of links it is even more vital to ensure that links are healthy, and to respond quickly when links become unresponsive. To that end links now use heartbeats. As data flows across the link, heartbeat headers will be added periodically. Heartbeat responses will be added to return messages. If the link is currently quiet, explicit heartbeat messages will be sent. Heartbeats will also be used to measure latency. If heartbeats are unreturned for a certain amount of time, the link will be considered bad and torn down, so a new one can be established. + +The link.latency metric now is calculated starting when the message is about to be sent. It may have a few extra milliseconds time, as the response waits briefly to see if there's an existing message that the response can piggyback on. + +Previously link.latency include both queue and network time. Now that it only has network time, there's a new metrics, `link.queue_time` which tracks how long it takes messages to get from send requested to just before send. + +### Inspect and ps support for links + +`ziti fabric inspect .* links` can now be used to see what links each router knows about. This can be useful to determine if/how the controller and routers may have gotten out of sync. + +Router can also be interrogated directly for their links via IPC, using `ziti ps`. + +``` +$ ziti ps router dump-links 275061 +id: 4sYO18tZ1Fz4HByXuIp1Dq dest: o.oVU2Qm. type: tls +id: 19V7yhjBpHAc2prTDiTihQ dest: hBjIP2wmxj type: tls +``` + +### Router version dissemination + +Routers now get the version of the router they are dialing a link to, and pass their own version to that router as part of the dial. This allows routers to only enable specific features if both sides of the link support it. + +### Distributed Control preparation + +Giving the routers have more control over the links prepares us for a time when routers may be connected to multiple controllers. Routers will be able to notify controllers of existing links and will be prepared to resolve duplicate link dial requests from multiple sources. + +# Release 0.24.13 + * Enhancement: Added new `noTraversal` field to routers. Configures if a router should allow/disallow traversal. Required on create/update commands. * Enhancement: `ziti edge update edge-router` now supports either `--no-traversal` flag which will allow/disallow a given router from being used to traverse. * Enhancement: `ziti fabric list routers` and `ziti edge list routers` will now display the noTraversal flag of associated routers. diff --git a/go.mod b/go.mod index de9dbdd79..d5f31b50d 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( 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 - github.com/go-openapi/runtime v0.23.1 + github.com/go-openapi/runtime v0.23.2 github.com/go-openapi/strfmt v0.21.2 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/golang/protobuf v1.5.2 @@ -35,9 +35,9 @@ require ( github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 github.com/michaelquigley/pfxlog v0.6.3 - github.com/openziti/channel v0.18.11 - github.com/openziti/foundation v0.17.7 - github.com/openziti/sdk-golang v0.16.14 + github.com/openziti/channel v0.18.14 + github.com/openziti/foundation v0.17.8 + github.com/openziti/sdk-golang v0.16.20 github.com/pborman/uuid v1.2.0 github.com/pkg/errors v0.9.1 github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 @@ -73,6 +73,7 @@ require ( github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // 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.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect @@ -153,11 +154,11 @@ require ( github.com/yusufpapurcu/wmi v1.2.2 // indirect go.mongodb.org/mongo-driver v1.8.3 // indirect go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1 // indirect - golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect + golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect golang.org/x/mod v0.5.1 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect + golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.7 // indirect @@ -172,7 +173,7 @@ require ( require ( github.com/jedib0t/go-pretty/v6 v6.2.4 - github.com/openziti/edge v0.21.115 - github.com/openziti/fabric v0.17.57 + github.com/openziti/edge v0.21.127 + github.com/openziti/fabric v0.17.62 github.com/rivo/uniseg v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index e2c6bd612..308145830 100644 --- a/go.sum +++ b/go.sum @@ -214,6 +214,8 @@ github.com/dgryski/dgoogauth v0.0.0-20190221195224-5a805980a5f3 h1:AqeKSZIG/NIC7 github.com/dgryski/dgoogauth v0.0.0-20190221195224-5a805980a5f3/go.mod h1:hEfFauPHz7+NnjR/yHJGhrKo1Za+zStgwUETx3yzqgY= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= +github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663 h1:fctNkSsavbXpt8geFWZb8n+noCqS8MrOXRJ/YfdZ2dQ= +github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663/go.mod h1:Kad2hux31v/IyD4Rf4wAwIyK48995rs3qAl9IUAhc2k= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= @@ -341,8 +343,8 @@ github.com/go-openapi/runtime v0.19.15/go.mod h1:dhGWCTKRXlAfGnQG0ONViOZpjfg0m2g github.com/go-openapi/runtime v0.19.16/go.mod h1:5P9104EJgYcizotuXhEuUrzVc+j1RiSjahULvYmlv98= github.com/go-openapi/runtime v0.19.24/go.mod h1:Lm9YGCeecBnUUkFTxPC4s1+lwrkJ0pthx8YvyjCfkgk= github.com/go-openapi/runtime v0.21.0/go.mod h1:aQg+kaIQEn+A2CRSY1TxbM8+sT9g2V3aLc1FbIAnbbs= -github.com/go-openapi/runtime v0.23.1 h1:/Drg9R96eMmgKJHVWZADz78XbE39/6QiIiB45mc+epo= -github.com/go-openapi/runtime v0.23.1/go.mod h1:AKurw9fNre+h3ELZfk6ILsfvPN+bvvlaU/M9q/r9hpk= +github.com/go-openapi/runtime v0.23.2 h1:SLoYVM3ovq+lynpgrHQZ5WQcx+CBE0HHHCZU3c2jQoo= +github.com/go-openapi/runtime v0.23.2/go.mod h1:AKurw9fNre+h3ELZfk6ILsfvPN+bvvlaU/M9q/r9hpk= github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= @@ -818,22 +820,18 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+ 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= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/openziti/channel v0.18.9/go.mod h1:pjoD6e9QgDGnaiakRA+s8YT/FzUHWDhJJF573oOJkXg= -github.com/openziti/channel v0.18.11 h1:zT2zRI6m/POr81dXmM8azLpcCjysgeuVPppztl25Zc0= -github.com/openziti/channel v0.18.11/go.mod h1:9z2HLdoYZ3RYm9S8XqlQB5spf3j+BLPof0A1zvjLyzc= +github.com/openziti/channel v0.18.14 h1:MS6Wfo0BklKI/IQ/HQl+wKJBw9rPimTSSqFIeBcsHGQ= +github.com/openziti/channel v0.18.14/go.mod h1:F370DYbKEKpIEhRaZVbEK6xN+pirSZx4qnwbObQAV2I= github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAPD8k= github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo= -github.com/openziti/edge v0.21.115 h1:sIxlCCUEfXgOpUikmd6Ya3Hsn1fhMXaFznkNeUF+OPQ= -github.com/openziti/edge v0.21.115/go.mod h1:2gb49/wivJSAnQwRCC8rAkQ0+3lWjwUgo/Kb7+0WJpM= -github.com/openziti/fabric v0.17.54/go.mod h1:o206EkKYBOoQvDKsFj07rlHI+za6yMpxUXyWj2XVrw0= -github.com/openziti/fabric v0.17.57 h1:mCo89KoEH1oaHeo0lc3p0x3A8G6/LsSiPTpd7NKvND0= -github.com/openziti/fabric v0.17.57/go.mod h1:nPHmXHx1MxgS2LlsjIWrWqq4B92OyPGtsLCdV3GBlXw= -github.com/openziti/foundation v0.17.1/go.mod h1:qzctNeCrOrPDQDr9g70IPHw+awal87qPqRe3UJLwNXw= -github.com/openziti/foundation v0.17.6/go.mod h1:dTaJgdO5OqnKpV+0OPHpnTnqfPpqNGbhJv8O6pMot6o= -github.com/openziti/foundation v0.17.7 h1:lnP+4e78Vmfu/iL1seKqurCiroYWi0Ae0SQEcM7b36A= -github.com/openziti/foundation v0.17.7/go.mod h1:dTaJgdO5OqnKpV+0OPHpnTnqfPpqNGbhJv8O6pMot6o= -github.com/openziti/sdk-golang v0.16.14 h1:PIjHRwQqKcclfJYVjEUnnri2PM9wCAEBLwFhwQ6FSJ4= -github.com/openziti/sdk-golang v0.16.14/go.mod h1:s8T8XNGGCeEeMhtCf5iUi2t97FqoslE6t1TTEbCVfPU= +github.com/openziti/edge v0.21.127 h1:4Z2AlmSjMgw/a0PQt4aYuVIURW0nQVwnR0mSvgyVZcc= +github.com/openziti/edge v0.21.127/go.mod h1:NIOrmA5yEhdTbmARyPm4DOrdpWiaB33OVpJVj4PkEDY= +github.com/openziti/fabric v0.17.62 h1:V1Eavso4AvMSCMXJYtEATu5NQ9Dtpu3s3OYZt+SuVwY= +github.com/openziti/fabric v0.17.62/go.mod h1:8oBcmWriG/nTGF/+8pkv1oAKQY97XXG4ptns8dUTMr4= +github.com/openziti/foundation v0.17.8 h1:vlX6yQHrs5Tcp39xHylJhzohTDOZ6d/VrVlQahw7GBo= +github.com/openziti/foundation v0.17.8/go.mod h1:dTaJgdO5OqnKpV+0OPHpnTnqfPpqNGbhJv8O6pMot6o= +github.com/openziti/sdk-golang v0.16.20 h1:AtSaD0Do5HgkDWFR0dLUVpiOpky2WAh6cf78hcG30jk= +github.com/openziti/sdk-golang v0.16.20/go.mod h1:uQ90QCehBrfO/xmpnWGVr3Jj65BMUrvGPH4I0gRl0og= github.com/oracle/oci-go-sdk v24.2.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= github.com/orcaman/concurrent-map v0.0.0-20210106121528-16402b402231 h1:fa50YL1pzKW+1SsBnJDOHppJN9stOEwS+CRWyUtyYGU= @@ -1133,8 +1131,9 @@ golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 h1:syTAU9FwmvzEoIYMqcPHOcVm4H3U5u90WsvuYgwpETU= +golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1382,8 +1381,9 @@ golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= diff --git a/quickstart/README.md b/quickstart/README.md index ada0fb5cb..f3b528aa0 100644 --- a/quickstart/README.md +++ b/quickstart/README.md @@ -19,7 +19,7 @@ Lastly, you can choose to run [docker](https://docs.docker.com/get-started/) dir more verbose but should you prefer to not use docker-compose it can also illustrate how to establish a Ziti Network piece by piece. -## Prerequisties +## Prerequisites ### Bash @@ -91,7 +91,7 @@ Before running the commands below please do the following: #make a docker network for isolation while allowing the parts to be able to interact docker network create "$zitinw" -### Staring the Containers +### Starting the Containers To start the containers you can simply run these two commands in two different shells. (or choose to daemonize them once you're ready to do so). Take special note of the initial variables used in these commands. The ${zitinw} variable @@ -103,7 +103,7 @@ Ziti Controller: Ziti Edge Router: - routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_RAWNAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-edge-router.sh edge + routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_RAWNAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-router.sh edge diff --git a/quickstart/aws.md b/quickstart/aws.md index ed0624e8b..5a1b02510 100644 --- a/quickstart/aws.md +++ b/quickstart/aws.md @@ -1,171 +1,7 @@ -# Quickstart - AWS + + + -This quickstart is a barebones guide to running a full developer environment in AWS. It is not fault-tolerant. If you require fault tolerance this guide is not for you. This guide also assumes you're at least familiar with AWS's console and cloud development. Feel free to replace any steps along the way you desire but these steps were tested at least a few times and hopefully whenever you're reading this, the steps are still valid. If not file an issue or shoot over to [Discourse](https://openziti.discourse.group/) and start a discussion. +# Content moved -## Setup a Server - -1. After logging into AWS, navigate to the EC2 Dashboard -1. From the EC2 Dashboard, click "Launch Instance" -1. Find "Ubuntu Server 20.04 LTS (HVM), SSD Volume Type" and click 'select' -1. At the bottom of the screen - click the "Review and Launch" button -1. In AWS "Step 7. Review Instance Launch", find the "Security Groups" row and expand it if necessary -1. Click "Edit security groups" -1. Click "Add Rule" and select "Custom TCP Rule" and enter Port Range:"8441" Source: "0.0.0.0/0", Description: "Ziti Controller Port" -1. Click "Add Rule" and select "Custom TCP Rule" and enter Port Range:"8442" Source: "0.0.0.0/0", Description: "Ziti Edge Router Port" -1. Click "Add Rule" and select "Custom TCP Rule" and enter Port Range:"8443" Source: "0.0.0.0/0", Description: "Ziti Console TLS Port" -1. Your console should look like this: - ![security-groups.png](security-groups.png) - -1. click "Review and Launch" and then "Launch" -1. Select your keypair and choose "Launch Instances" - -## SSH to the Server - -1. After ssh'ing to the new ubuntu machine - run: `sudo apt update && sudo apt install jq -y` -1. Set some environment variables which are used to establish a PKI as well as the necessary configuration files. You will need to know the public IPv4 DNS name assigned to this machine. Replace "____EXTERNAL___DNS____" with the proper values. (**IMPORTANT** make sure the name is correct): - - export EXTERNAL_DNS="____EXTERNAL___DNS______FILLIN example: ec2-3-129-206-186.us-east-2.compute.amazonaws.com" - - export EXTERNAL_IP="$(curl -s eth0.me)" - export ZITI_EDGE_CONTROLLER_IP_OVERRIDE="${EXTERNAL_IP}" - export ZITI_EDGE_ROUTER_IP_OVERRIDE="${EXTERNAL_IP}" - export ZITI_EDGE_CONTROLLER_HOSTNAME="${EXTERNAL_DNS}" - export ZITI_EDGE_ROUTER_HOSTNAME="${EXTERNAL_DNS}" - export ZITI_EDGE_CONTROLLER_PORT=8441 - export ZITI_EDGE_ROUTER_PORT=8442 - -1. Run this single command to download and bootstrap the ziti-controller and ziti-router (feel free to read the bash script before running if you like): - - source <(wget -qO- https://raw.githubusercontent.com/openziti/ziti/release-next/quickstart/docker/image/ziti-cli-functions.sh); expressInstall - -1. At this point the controller and router are running and can be accessed from anywhere. Confirm both are running by running: - - ps -ef | grep ziti - root 2520 1 0 May19 ? 00:00:15 /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-bin/ziti-v0.20.2/ziti-controller run /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/controller.yaml - root 2547 1 0 May19 ? 00:00:10 /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-bin/ziti-v0.20.2/ziti-router run /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ip-172-31-22-212-edge-router.yaml - -1. You can also issue this statement from the server and you will see a similar response to this: - - curl -sk "https://${ZITI_EDGE_CONTROLLER_HOSTNAME}:${ZITI_EDGE_CONTROLLER_PORT}/version" - {"data":{"apiVersions":{"edge":{"v1":{"path":"/edge/v1"}}},"buildDate":"2021-05-05 20:59:40","revision":"73dd1db42bf4","runtimeVersion":"go1.16.3","version":"v0.19.13"},"meta":{}} - -## Setting up Ziti Controller and Router as a service - -1. Stop ziti-controller and ziti-router if they are running: - - killall ziti-controller ziti-router -1. copy the two systemd files and refresh systemd - - sudo cp "${ZITI_HOME}/ziti-controller.service" /etc/systemd/system - sudo cp "${ZITI_HOME}/ziti-router-${ZITI_EDGE_ROUTER_RAWNAME}.service" /etc/systemd/system/ziti-router.service - sudo systemctl daemon-reload - sudo systemctl start ziti-controller - sudo systemctl start ziti-router -1. Allow 5 to 10 seconds for the ziti-controller and router to start completely. Run these two commands to verify ziti-controller and ziti-router are running: - - sudo systemctl -q status ziti-controller --lines=0 --no-pager - sudo systemctl -q status ziti-router --lines=0 --no-pager - - #sample output: - ubuntu@ip-172-31-22-212:~$ sudo systemctl -q status ziti-controller --lines=0 --no-pager - ● ziti-controller.service - Ziti-Controller - Loaded: loaded (/etc/systemd/system/ziti-controller.service; disabled; vendor preset: enabled) - Active: active (running) since Thu 2021-05-20 11:24:40 UTC; 5min ago - Main PID: 26848 (ziti-controller) - Tasks: 7 (limit: 1160) - Memory: 50.5M - CGroup: /system.slice/ziti-controller.service - └─26848 /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-bin/ziti-v0.20.2/ziti-controller run /home/ubu… - - ubuntu@ip-172-31-22-212:~$ sudo systemctl -q status ziti-router --lines=0 --no-pager - ● ziti-router.service - Ziti-Router for ip-172-31-22-212-edge-router - Loaded: loaded (/etc/systemd/system/ziti-router.service; disabled; vendor preset: enabled) - Active: active (running) since Thu 2021-05-20 11:24:42 UTC; 5min ago - Main PID: 26864 (ziti-router) - Tasks: 7 (limit: 1160) - Memory: 28.4M - CGroup: /system.slice/ziti-router.service - └─26864 /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-bin/ziti-v0.20.2/ziti-router run /home/ubuntu/… - ubuntu@ip-172-31-22-212:~$ - -## Setting up the Ziti Admin Console - -### By Cloning from Github - -1. clone the ziti-console repo from github: - - git clone https://github.com/openziti/ziti-console.git "${ZITI_HOME}/ziti-console" -1. Install node and npm and get the server ready - - cd "${ZITI_HOME}/ziti-console" - sudo apt install npm nodejs -y - npm install -1. Use the ziti-controller certificates for the Ziti Console: - - ln -s "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.chain.pem" "${ZITI_HOME}/ziti-console/server.chain.pem" - ln -s "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.key" "${ZITI_HOME}/ziti-console/server.key" -1. Emit the Ziti Console systemd file and update systemd to start the Ziti Console - - createZacSystemdFile - sudo cp "${ZITI_HOME}/ziti-console.service" /etc/systemd/system - sudo systemctl daemon-reload - sudo systemctl start ziti-console -1. Verify the Ziti Console is running - sudo systemctl status ziti-console --lines=0 --no-pager - - #sample output of the command: - ubuntu@ip-172-31-22-212:~$ sudo systemctl status ziti-console --lines=0 --no-pager - ● ziti-console.service - Ziti-Console - Loaded: loaded (/etc/systemd/system/ziti-console.service; disabled; vendor preset: enabled) - Active: active (running) since Wed 2021-05-19 22:04:44 UTC; 13h ago - Main PID: 13458 (node) - Tasks: 11 (limit: 1160) - Memory: 33.4M - CGroup: /system.slice/ziti-console.service - └─13458 /usr/bin/node /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-console/server.js - -### By Using Docker - -1. If needed, install docker on the machine. I followed these instructions https://linuxize.com/post/how-to-install-and-use-docker-on-ubuntu-20-04/ but we'll condense them here for you to copy/paste: - - sudo apt update - sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - sudo apt install docker-ce docker-ce-cli containerd.io -y - sudo usermod -aG docker $USER -1. Log out of the server, and log back in to activate docker for your user -1. Copy/paste this command to start the Ziti Admin Console in TLS mode: - - docker run -d \ - --name zac \ - -p 8443:8443 \ - -v "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.key":/usr/src/app/server.key \ - -v "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.chain.pem":/usr/src/app/server.chain.pem \ - openziti/zac - -## Login and use the Ziti Console -1. At this point you should be able to navigate to both: https://${ZITI_EDGE_CONTROLLER_HOSTNAME}:8443 as well as https://$(curl -s eth0.me):8443 and see the ZAC login screen. (The TLS warnings your browser will show you are normal - it's because these steps use a self-signed certificate generated in the install process) -1. Set the controller as shown: - - ![img_1.png](img_1.png) -1. Login with admin/admin - - ![img_2.png](img_2.png) - -1. **IMPORTANT!!!** Edit your profile and change the password - - ![img_3.png](img_3.png) - -## Adding Environment Variables Back to the Shell - -If you log out and log back in again you can source the '.env' file located at: `. ~/.ziti/quickstart/$(hostname)/$(hostname).env`. Below is an example of logging in, not having ZITI_HOME set, sourcing the .env file and then showing ZITI_HOME set: - - Last login: Thu May 20 11:36:25 2021 from 67.246.244.61 - ubuntu@ip-172-31-22-212:~$ echo $ZITI_HOME - - ubuntu@ip-172-31-22-212:~$ . ~/.ziti/quickstart/$(hostname)/$(hostname).env - - adding /home/ubuntu/.ziti/quickstart/ip-172-31-22-212/ziti-bin/ziti-v0.20.2 to the path - ubuntu@ip-172-31-22-212:~$ echo $ZITI_HOME - /home/ubuntu/.ziti/quickstart/ip-172-31-22-212 +This content has been moved to the official doc repository. Find it at https://openziti.github.io/ziti/quickstarts/quickstart-overview.html \ No newline at end of file diff --git a/quickstart/docker/README.md b/quickstart/docker/README.md index 38141c6c0..fa05e51aa 100644 --- a/quickstart/docker/README.md +++ b/quickstart/docker/README.md @@ -1,7 +1,14 @@ Building and Deploying the Latest Quickstart Docker Image ========================== -Build Docker Image +Build Docker Image for Local Dev (probably for docker-compose testing) +------------------ +1. change to this directory: `cd quickstart/docker` +2. run the questionably named `./pushDevBuild.sh` which will create a `openziti/quickstart:dev` tag +3. update `docker-compose.yml` and replace `:latest` with `:dev` +4. run `docker-compose` as normal + +Build Docker Image For Publication ------------------ 1. change to this directory: `cd quickstart/docker` 1. set an environment variable: `export ZITI_HOME=$(pwd)` diff --git a/quickstart/docker/attach.container.to.compose.sh b/quickstart/docker/attach.container.to.compose.sh new file mode 100644 index 000000000..ae92d8bde --- /dev/null +++ b/quickstart/docker/attach.container.to.compose.sh @@ -0,0 +1 @@ +docker run --network docker_zitiblue --rm -it openziti/quickstart /bin/bash diff --git a/quickstart/docker/docker-compose.yml b/quickstart/docker/docker-compose.yml index 871d14bfc..0ae6989c7 100644 --- a/quickstart/docker/docker-compose.yml +++ b/quickstart/docker/docker-compose.yml @@ -32,7 +32,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh edge" + command: "/openziti/scripts/run-router.sh edge" ziti-edge-router-wss: image: openziti/quickstart:latest @@ -49,7 +49,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh wss" + command: "/openziti/scripts/run-router.sh wss" ziti-fabric-router-br: image: openziti/quickstart:latest @@ -65,7 +65,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh fabric" + command: "/openziti/scripts/run-router.sh fabric" ziti-private-red: image: openziti/quickstart:latest @@ -80,7 +80,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh private" + command: "/openziti/scripts/run-router.sh private" ziti-private-blue: image: openziti/quickstart:latest @@ -95,7 +95,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh private" + command: "/openziti/scripts/run-router.sh private" web-test-blue: image: crccheck/hello-world diff --git a/quickstart/docker/image/Dockerfile b/quickstart/docker/image/Dockerfile index eacecb1e5..23e1918d6 100644 --- a/quickstart/docker/image/Dockerfile +++ b/quickstart/docker/image/Dockerfile @@ -22,7 +22,9 @@ RUN mkdir -p "${ZITI_SCRIPTS}" # copy the ziti binaries to a directory already on the path COPY --chown=ziti ziti.ignore "${ZITI_BIN_DIR}" -COPY --chown=ziti *.sh "${ZITI_SCRIPTS}/" +COPY --chown=ziti ziti-cli-functions.sh "${ZITI_SCRIPTS}/" +COPY --chown=ziti run-controller.sh "${ZITI_SCRIPTS}/" +COPY --chown=ziti run-router.sh "${ZITI_SCRIPTS}/" RUN /bin/bash -c "source ${ZITI_SCRIPTS}/ziti-cli-functions.sh; ziti_createEnvFile; echo source ${ZITI_HOME}/ziti.env >> ~/.bashrc" diff --git a/quickstart/docker/image/run-edge-router.sh b/quickstart/docker/image/run-router.sh old mode 100755 new mode 100644 similarity index 95% rename from quickstart/docker/image/run-edge-router.sh rename to quickstart/docker/image/run-router.sh index f3bccfe51..082ca1bc0 --- a/quickstart/docker/image/run-edge-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -1,5 +1,8 @@ #!/bin/bash +# give the controller time to ramp up before running if running in docker-compose +sleep 5 + . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export export ZITI_CONTROLLER_RAWNAME="ziti-controller"; fi @@ -8,7 +11,6 @@ if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then export export ZITI_EDGE_ROUT if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi if [[ "${ZITI_EDGE_ROUTER_HOSTNAME}" == "" ]]; then export ZITI_EDGE_ROUTER_HOSTNAME="${ZITI_EDGE_ROUTER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi -generateEnvFile . ${ZITI_HOME}/ziti.env # shellcheck disable=SC2091 @@ -17,8 +19,6 @@ until $(curl -s -o /dev/null --fail -k "https://${ZITI_EDGE_CTRL_ADVERTISED_HOST sleep 2 done -sleep 2 - createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}" zitiLogin diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index d0b5882ee..cd6f027a4 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -423,15 +423,15 @@ function ziti_expressConfiguration { "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcPublicRouters > /dev/null "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcPublicRouters --edge-router-roles '#public' --service-roles '#all' > /dev/null - createRouterPki - - if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_RAWNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_RAWNAME" else ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router" fi echo "USING ZITI_EDGE_ROUTER_RAWNAME: $ZITI_EDGE_ROUTER_RAWNAME" + + createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}" + createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" #createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}" @@ -635,8 +635,18 @@ function showIssuerAndSubjectForPEM() { } function createRouterPki { - #TODO: this needs to be parameterized to take other router_name - pki_client_server "${ZITI_EDGE_ROUTER_RAWNAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + echo -e " * ERROR: $(RED "routerName needs to be supplied") " + return 1 + fi + mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}" + export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert" + export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert" + export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key" + export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert" + pki_client_server "${router_name}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" } function createPrivateRouterConfig { @@ -673,10 +683,9 @@ function createPrivateRouterConfig { return 1 fi -output_file="${ZITI_HOME-}/${router_name}.yaml" -"${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" - -echo -e "Controller configuration file written to: $(BLUE "${output_file}")" + output_file="${ZITI_HOME-}/${router_name}.yaml" + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" + echo -e "Router configuration file written to: $(BLUE "${output_file}")" } function createPki { @@ -739,10 +748,9 @@ function createFabricRouterConfig { return 1 fi -output_file="${ZITI_HOME}/${router_name}.yaml" -"${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" - -echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")" + output_file="${ZITI_HOME}/${router_name}.yaml" + "${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" + echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")" } function createEdgeRouterWssConfig { @@ -775,10 +783,9 @@ function createEdgeRouterWssConfig { return 1 fi -output_file="${ZITI_HOME-}/${router_name}.yaml" -"${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}" - -echo -e "Edge router wss configuration file written to: $(BLUE "${output_file}")" + output_file="${ZITI_HOME-}/${router_name}.yaml" + "${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}" + echo -e "WSS Edge router wss configuration file written to: $(BLUE "${output_file}")" } # shellcheck disable=SC2120 @@ -814,17 +821,8 @@ function createEdgeRouterConfig { output_file="${ZITI_HOME}/${router_name}.yaml" - mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}" - export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert" - export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert" - export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key" - export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert" "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}" echo -e "edge router configuration file written to: $(BLUE "${output_file}")" - unset ZITI_ROUTER_IDENTITY_CERT - unset ZITI_ROUTER_IDENTITY_SERVER_CERT - unset ZITI_ROUTER_IDENTITY_KEY - unset ZITI_ROUTER_IDENTITY_CA } function createFabricIdentity { @@ -956,8 +954,6 @@ function ziti_createEnvFile { export ZITI_BIN_ROOT="${ZITI_HOME}/ziti-bin" - if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router"; fi - if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:10000"; 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 diff --git a/quickstart/docker/simplified-docker-compose.yml b/quickstart/docker/simplified-docker-compose.yml index 32a9318c1..c31c57704 100644 --- a/quickstart/docker/simplified-docker-compose.yml +++ b/quickstart/docker/simplified-docker-compose.yml @@ -30,7 +30,7 @@ services: volumes: - ziti-fs:/openziti entrypoint: /bin/bash - command: "/openziti/scripts/run-edge-router.sh edge" + command: "/openziti/scripts/run-router.sh edge" ziti-console: image: openziti/zac diff --git a/quickstart/img_1.png b/quickstart/img_1.png deleted file mode 100644 index a350b34a7..000000000 Binary files a/quickstart/img_1.png and /dev/null differ diff --git a/quickstart/img_2.png b/quickstart/img_2.png deleted file mode 100644 index 14f6a36b6..000000000 Binary files a/quickstart/img_2.png and /dev/null differ diff --git a/quickstart/img_3.png b/quickstart/img_3.png deleted file mode 100644 index bc8d9694c..000000000 Binary files a/quickstart/img_3.png and /dev/null differ diff --git a/quickstart/security-groups.png b/quickstart/security-groups.png deleted file mode 100644 index 242053ced..000000000 Binary files a/quickstart/security-groups.png and /dev/null differ diff --git a/version b/version index fd137eb17..7d385d419 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.24 +0.25 diff --git a/ziti-controller/subcmd/run.go b/ziti-controller/subcmd/run.go index c7878abed..aa25cb8cb 100644 --- a/ziti-controller/subcmd/run.go +++ b/ziti-controller/subcmd/run.go @@ -25,6 +25,7 @@ import ( "github.com/openziti/ziti/common/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "io" "os" "os/signal" "syscall" @@ -59,12 +60,6 @@ func run(cmd *cobra.Command, args []string) { startLogger = startLogger.WithField("nodeId", config.Id.Token) startLogger.Info("starting ziti-controller") - if cliAgentEnabled { - if err := agent.Listen(agent.Options{Addr: cliAgentAddr}); err != nil { - pfxlog.Logger().WithError(err).Error("unable to start CLI agent") - } - } - var fabricController *controller.Controller if fabricController, err = controller.NewController(config, version.GetCmdBuildInfo()); err != nil { fmt.Printf("unable to create fabric controller %+v\n", err) @@ -78,6 +73,18 @@ func run(cmd *cobra.Command, args []string) { } edgeController.Initialize() + + if cliAgentEnabled { + options := agent.Options{Addr: cliAgentAddr} + fabricController.RegisterDefaultAgentOps() + options.CustomOps = map[byte]func(conn io.ReadWriter) error{ + agent.CustomOp: fabricController.HandleCustomAgentOp, + } + if err := agent.Listen(options); err != nil { + pfxlog.Logger().WithError(err).Error("unable to start CLI agent") + } + } + go waitForShutdown(fabricController, edgeController) edgeController.Run() if err := fabricController.Run(); err != nil { diff --git a/ziti/cmd/ziti/cmd/agent.go b/ziti/cmd/ziti/cmd/agent.go new file mode 100644 index 000000000..38dd96693 --- /dev/null +++ b/ziti/cmd/ziti/cmd/agent.go @@ -0,0 +1,88 @@ +/* + Copyright NetFoundry, Inc. + + 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 + + https://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. +*/ + +package cmd + +import ( + "github.com/openziti/edge/router/debugops" + "github.com/openziti/fabric/controller" + "github.com/openziti/fabric/router" + cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" + "github.com/spf13/cobra" + "io" +) + +type AgentAppId byte + +const ( + AgentAppController = AgentAppId(controller.AgentAppId) + AgentAppRouter = AgentAppId(router.AgentAppId) +) + +func NewAgentCmd(out io.Writer, errOut io.Writer) *cobra.Command { + agentCmd := &cobra.Command{ + Use: "agent", + Short: "Interact with ziti processes using the the IPC agent", + Run: func(cmd *cobra.Command, args []string) { + cmdhelper.CheckErr(cmd.Help()) + }, + } + + ctrlCmd := &cobra.Command{ + Use: "controller", + Aliases: []string{"c"}, + Short: "Interact with a ziti-controller process using the IPC agent", + Run: func(cmd *cobra.Command, args []string) { + cmdhelper.CheckErr(cmd.Help()) + }, + } + + agentCmd.AddCommand(ctrlCmd) + ctrlCmd.AddCommand(NewSimpleAgentCustomCmd("snapshot-db", AgentAppController, controller.AgentOpSnapshotDbSnaps, out, errOut)) + + routerCmd := &cobra.Command{ + Use: "router", + Aliases: []string{"r"}, + Short: "Interact with a ziti-router process using the IPC agent", + Run: func(cmd *cobra.Command, args []string) { + cmdhelper.CheckErr(cmd.Help()) + }, + } + + agentCmd.AddCommand(routerCmd) + + routerCmd.AddCommand(NewCmdPsRoute(out, errOut)) + routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-routes", AgentAppRouter, router.DumpForwarderTables, out, errOut)) + routerCmd.AddCommand(NewSimpleAgentCustomCmd("disconnect", AgentAppRouter, router.CloseControlChannel, out, errOut)) + routerCmd.AddCommand(NewSimpleAgentCustomCmd("reconnect", AgentAppRouter, router.OpenControlChannel, out, errOut)) + routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-api-sessions", AgentAppRouter, debugops.DumpApiSessions, out, errOut)) + routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-links", AgentAppRouter, router.DumpLinks, out, errOut)) + + agentCmd.AddCommand(NewCmdPsGoversion(out, errOut)) + agentCmd.AddCommand(NewCmdPsGc(out, errOut)) + agentCmd.AddCommand(NewCmdPsSetgc(out, errOut)) + agentCmd.AddCommand(NewCmdPsStack(out, errOut)) + agentCmd.AddCommand(NewCmdPsMemstats(out, errOut)) + agentCmd.AddCommand(NewCmdPsStats(out, errOut)) + agentCmd.AddCommand(NewCmdPsPprofHeap(out, errOut)) + agentCmd.AddCommand(NewCmdPsPprofCpu(out, errOut)) + agentCmd.AddCommand(NewCmdPsTrace(out, errOut)) + agentCmd.AddCommand(NewCmdPsSetLogLevel(out, errOut)) + agentCmd.AddCommand(NewCmdPsSetChannelLogLevel(out, errOut)) + agentCmd.AddCommand(NewCmdPsClearChannelLogLevel(out, errOut)) + + return agentCmd +} diff --git a/ziti/cmd/ziti/cmd/ps_router_add_route.go b/ziti/cmd/ziti/cmd/agent_router_add_route.go similarity index 86% rename from ziti/cmd/ziti/cmd/ps_router_add_route.go rename to ziti/cmd/ziti/cmd/agent_router_add_route.go index ef4b677da..19cb804a8 100644 --- a/ziti/cmd/ziti/cmd/ps_router_add_route.go +++ b/ziti/cmd/ziti/cmd/agent_router_add_route.go @@ -22,7 +22,6 @@ import ( "github.com/openziti/fabric/pb/ctrl_pb" "github.com/openziti/fabric/router" "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -36,13 +35,12 @@ type PsRouteOptions struct { } // NewCmdPsRoute creates a command object for the "create" command -func NewCmdPsRoute(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsRoute(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsRouteOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } @@ -92,14 +90,15 @@ func (o *PsRouteOptions) Run() error { return err } - fullBuf := make([]byte, len(buf)+5) - fullBuf[0] = router.UpdateRoute + fullBuf := make([]byte, len(buf)+6) + fullBuf[0] = byte(AgentAppRouter) + fullBuf[1] = router.UpdateRoute sizeBuf := make([]byte, 4) binary.LittleEndian.PutUint32(sizeBuf, uint32(len(buf))) - copy(fullBuf[1:], sizeBuf) - copy(fullBuf[5:], buf) + copy(fullBuf[2:], sizeBuf) + copy(fullBuf[6:], buf) return agent.MakeRequest(addr, agent.CustomOp, fullBuf, os.Stdout) } diff --git a/ziti/cmd/ziti/cmd/ps_router_basic.go b/ziti/cmd/ziti/cmd/agent_simple.go similarity index 75% rename from ziti/cmd/ziti/cmd/ps_router_basic.go rename to ziti/cmd/ziti/cmd/agent_simple.go index 93cb5f7de..f5257f473 100644 --- a/ziti/cmd/ziti/cmd/ps_router_basic.go +++ b/ziti/cmd/ziti/cmd/agent_simple.go @@ -18,24 +18,22 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" "os" ) -type PsBasicRouterCmdOptions struct { +type SimpleAgentCmdOptions struct { PsOptions } -func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { - options := &PsBasicRouterCmdOptions{ +func NewSimpleAgentCustomCmd(name string, appId AgentAppId, op byte, out io.Writer, errOut io.Writer) *cobra.Command { + options := &SimpleAgentCmdOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } @@ -46,7 +44,7 @@ func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writ Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args - err := options.Run(op) + err := options.Run(appId, op) cmdhelper.CheckErr(err) }, } @@ -57,13 +55,13 @@ func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writ } // Run implements the command -func (o *PsBasicRouterCmdOptions) Run(op byte) error { +func (o *SimpleAgentCmdOptions) Run(appId AgentAppId, op byte) error { addr, err := agent.ParseGopsAddress(o.Args) if err != nil { return err } - buf := []byte{op} + buf := []byte{byte(appId), op} return agent.MakeRequest(addr, agent.CustomOp, buf, os.Stdout) } diff --git a/ziti/cmd/ziti/cmd/cmd.go b/ziti/cmd/ziti/cmd/cmd.go index c8fb557f6..d8e361f5d 100644 --- a/ziti/cmd/ziti/cmd/cmd.go +++ b/ziti/cmd/ziti/cmd/cmd.go @@ -131,7 +131,8 @@ func NewCmdRoot(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Comm createCommands := NewCmdCreate(f, out, err) updateCommands := NewCmdUpdate(f, out, err) executeCommands := NewCmdExecute(f, out, err) - psCommands := NewCmdPs(f, out, err) + agentCommands := NewAgentCmd(out, err) + psCommands := NewCmdPs(out, err) pkiCommands := NewCmdPKI(f, out, err) fabricCommand := fabric.NewFabricCmd(p) edgeCommand := edge.NewCmdEdge(f, out, err) @@ -161,6 +162,7 @@ func NewCmdRoot(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Comm Message: "Executing Ziti components:", Commands: []*cobra.Command{ executeCommands, + agentCommands, psCommands, pkiCommands, unwrapIdentityFileCommand, diff --git a/ziti/cmd/ziti/cmd/common.go b/ziti/cmd/ziti/cmd/common.go index 3f675dd09..a83fdbd3a 100644 --- a/ziti/cmd/ziti/cmd/common.go +++ b/ziti/cmd/ziti/cmd/common.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" - "github.com/openziti/ziti/ziti/cmd/ziti/cmd/table" "github.com/openziti/ziti/ziti/cmd/ziti/internal/log" "github.com/spf13/cobra" "io" @@ -57,10 +56,6 @@ func (c *CommonOptions) Stdout() io.Writer { return os.Stdout } -func (c *CommonOptions) CreateTable() table.Table { - return c.Factory.CreateTable(c.Stdout()) -} - // Debugf outputs the given text to the console if verbose mode is enabled func (c *CommonOptions) Debugf(format string, a ...interface{}) { if c.Verbose { diff --git a/ziti/cmd/ziti/cmd/create_config_router_common.go b/ziti/cmd/ziti/cmd/create_config_router_common.go index 2556c3d5b..8ac190ee4 100644 --- a/ziti/cmd/ziti/cmd/create_config_router_common.go +++ b/ziti/cmd/ziti/cmd/create_config_router_common.go @@ -32,6 +32,8 @@ func SetZitiRouterIdentity(r *RouterTemplateValues, routerName string) { val := os.Getenv(constants.ZitiEdgeRouterRawNameVarName) if val != "" { r.Edge.Hostname = val + } else { + r.Edge.Hostname, _ = os.Hostname() } } func SetZitiRouterIdentityCert(r *RouterTemplateValues, routerName string) { diff --git a/ziti/cmd/ziti/cmd/edge/traceroute.go b/ziti/cmd/ziti/cmd/edge/traceroute.go index 3d370d3bf..8c49a10e4 100644 --- a/ziti/cmd/ziti/cmd/edge/traceroute.go +++ b/ziti/cmd/ziti/cmd/edge/traceroute.go @@ -20,6 +20,7 @@ type traceRouteOptions struct { hops uint8 configFile string timeout time.Duration + lookupRouterName bool } func newTraceRouteCmd(out io.Writer, errOut io.Writer) *cobra.Command { @@ -50,6 +51,7 @@ func newTraceRouteCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().Uint8Var(&options.hops, "hops", 0, "Maximum number of hops") cmd.Flags().DurationVarP(&options.timeout, "timeout", "t", 5*time.Second, "Trace route response timeout") cmd.Flags().BoolVarP(&options.Verbose, "verbose", "", false, "Enable verbose logging") + cmd.Flags().BoolVarP(&options.lookupRouterName, "get-router-names", "n", false, "Lookup and output router names instead of ids. Requires admin privileges") return cmd } @@ -99,10 +101,12 @@ func (o *traceRouteOptions) Run() error { hopLabel := result.HopId if result.HopType == "forwarder" { - hopLabel, err = mapIdToName("transit-routers", result.HopId, o.Options) - if err != nil { - hopLabel = result.HopId - routerNameLookupsFailed = true + if o.lookupRouterName { + hopLabel, err = mapIdToName("transit-routers", result.HopId, o.Options) + if err != nil { + hopLabel = result.HopId + routerNameLookupsFailed = true + } } } diff --git a/ziti/cmd/ziti/cmd/fabric/db.go b/ziti/cmd/ziti/cmd/fabric/db.go new file mode 100644 index 000000000..849db59ff --- /dev/null +++ b/ziti/cmd/ziti/cmd/fabric/db.go @@ -0,0 +1,24 @@ +package fabric + +import ( + "github.com/openziti/ziti/ziti/cmd/ziti/cmd/common" + cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" + "github.com/spf13/cobra" +) + +func newDbCmd(p common.OptionsProvider) *cobra.Command { + cmd := &cobra.Command{ + Use: "db", + Short: "Database management operations for the Ziti Edge Controller", + Run: func(cmd *cobra.Command, args []string) { + err := cmd.Help() + cmdhelper.CheckErr(err) + }, + } + + cmd.AddCommand(newDbSnapshotCmd(p)) + cmd.AddCommand(newDbCheckIntegrityCmd(p)) + cmd.AddCommand(newDbCheckIntegrityStatusCmd(p)) + + return cmd +} diff --git a/ziti/cmd/ziti/cmd/fabric/db_check_integrity.go b/ziti/cmd/ziti/cmd/fabric/db_check_integrity.go new file mode 100644 index 000000000..46d9fb153 --- /dev/null +++ b/ziti/cmd/ziti/cmd/fabric/db_check_integrity.go @@ -0,0 +1,140 @@ +package fabric + +import ( + "fmt" + "github.com/Jeffail/gabs" + "github.com/openziti/ziti/ziti/cmd/ziti/cmd/api" + "github.com/openziti/ziti/ziti/cmd/ziti/cmd/common" + cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" + "github.com/openziti/ziti/ziti/cmd/ziti/util" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "net/http" +) + +type dbCheckIntegrityOptions struct { + api.Options + fix bool +} + +func newDbCheckIntegrityCmd(p common.OptionsProvider) *cobra.Command { + options := &dbCheckIntegrityOptions{ + Options: api.Options{CommonOptions: p()}, + } + + cmd := &cobra.Command{ + Use: "start-check-integrity", + Short: "starts background operation checking integrity of database references and constraints", + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) { + options.Cmd = cmd + options.Args = args + err := runCheckIntegrityDb(options) + cmdhelper.CheckErr(err) + }, + SuggestFor: []string{}, + } + + // allow interspersing positional args and flags + cmd.Flags().SetInterspersed(true) + cmd.Flags().BoolVarP(&options.fix, "fix-errors", "f", false, "Attempt to fix any detected errors") + options.AddCommonFlags(cmd) + + return cmd +} + +func runCheckIntegrityDb(o *dbCheckIntegrityOptions) error { + var target string + if o.fix { + target = "database/fix-data-integrity" + } else { + target = "database/check-data-integrity" + } + + if _, err := util.ControllerUpdate("edge", target, "", o.Out, http.MethodPost, o.OutputJSONRequest, o.OutputJSONResponse, o.Options.Timeout, o.Options.Verbose); err != nil { + return err + } + + _, err := fmt.Fprint(o.Out, "check integrity operation started\n") + return err +} + +func newDbCheckIntegrityStatusCmd(p common.OptionsProvider) *cobra.Command { + options := &dbCheckIntegrityOptions{ + Options: api.Options{CommonOptions: p()}, + } + + cmd := &cobra.Command{ + Use: "check-integrity-status", + Short: "shows current results from background operation checking integrity of database references and constraints", + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) { + options.Cmd = cmd + options.Args = args + err := runCheckIntegrityStatus(options) + cmdhelper.CheckErr(err) + }, + SuggestFor: []string{}, + } + + // allow interspersing positional args and flags + cmd.Flags().SetInterspersed(true) + options.AddCommonFlags(cmd) + + return cmd +} + +func runCheckIntegrityStatus(o *dbCheckIntegrityOptions) error { + body, err := util.EdgeControllerList("database/data-integrity-results", nil, o.OutputJSONResponse, o.Out, o.Options.Timeout, o.Options.Verbose) + if err != nil { + return err + } + + data := body.S("data") + inProgress := data.S("inProgress").Data() + if _, err = fmt.Fprintf(o.Out, "In Progress: %v\n", inProgress); err != nil { + return err + } + + fixingErrors := data.S("fixingErrors").Data() + if _, err = fmt.Fprintf(o.Out, "Fixing Errors: %v\n", fixingErrors); err != nil { + return err + } + + tooManyErrors := data.S("tooManyErrors").Data() + if _, err = fmt.Fprintf(o.Out, "Too Many Errors: %v (if true, additional errors can be found in controller log)\n", tooManyErrors); err != nil { + return err + } + + startTime := data.S("startTime").Data() + if _, err = fmt.Fprintf(o.Out, "Started At: %v\n", startTime); err != nil { + return err + } + + endTime := data.S("endTime").Data() + if _, err = fmt.Fprintf(o.Out, "Finished At: %v\n", endTime); err != nil { + return err + } + + opError := data.S("error").Data() + if _, err = fmt.Fprintf(o.Out, "Operation Error: %v\n", opError); err != nil { + return err + } + + results := data.S("results") + children, err := results.Children() + if len(children) == 0 || errors.Is(gabs.ErrNotObjOrArray, err) { + _, err = fmt.Fprintln(o.Out, "no data integrity errors found") + } + + for _, child := range children { + desc := child.S("description").Data().(string) + fixed := child.S("fixed").Data().(bool) + + if _, err = fmt.Fprintf(o.Out, "Issue: %v. Fixed: %v\n", desc, fixed); err != nil { + return err + } + } + + return err +} diff --git a/ziti/cmd/ziti/cmd/fabric/db_snapshot.go b/ziti/cmd/ziti/cmd/fabric/db_snapshot.go new file mode 100644 index 000000000..3c82124ee --- /dev/null +++ b/ziti/cmd/ziti/cmd/fabric/db_snapshot.go @@ -0,0 +1,60 @@ +/* + Copyright NetFoundry, Inc. + + 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 + + https://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. +*/ + +package fabric + +import ( + "github.com/openziti/ziti/ziti/cmd/ziti/cmd/api" + "github.com/openziti/ziti/ziti/cmd/ziti/cmd/common" + cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" + "github.com/openziti/ziti/ziti/cmd/ziti/util" + "github.com/spf13/cobra" + "net/http" +) + +type dbSnapshotOptions struct { + api.Options +} + +func newDbSnapshotCmd(p common.OptionsProvider) *cobra.Command { + options := &dbSnapshotOptions{ + Options: api.Options{CommonOptions: p()}, + } + + cmd := &cobra.Command{ + Use: "snapshot", + Short: "creates a database snapshot", + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) { + options.Cmd = cmd + options.Args = args + err := runSnapshotDb(options) + cmdhelper.CheckErr(err) + }, + SuggestFor: []string{}, + } + + // allow interspersing positional args and flags + cmd.Flags().SetInterspersed(true) + options.AddCommonFlags(cmd) + + return cmd +} + +func runSnapshotDb(o *dbSnapshotOptions) error { + _, err := util.ControllerUpdate("edge", "database/snapshot", "", o.Out, http.MethodPost, false, false, o.Options.Timeout, o.Options.Verbose) + return err +} diff --git a/ziti/cmd/ziti/cmd/fabric/inspect.go b/ziti/cmd/ziti/cmd/fabric/inspect.go index 677ebd840..c17406ddc 100644 --- a/ziti/cmd/ziti/cmd/fabric/inspect.go +++ b/ziti/cmd/ziti/cmd/fabric/inspect.go @@ -51,12 +51,16 @@ func (self *ListCmd) run(cmd *cobra.Command, args []string) error { return err } + if self.OutputResponseJson() { + return nil + } + result := inspectOk.Payload if *result.Success { fmt.Printf("\nResults: (%d)\n", len(result.Values)) for _, value := range result.Values { fmt.Printf("%v.%v\n", stringz.OrEmpty(value.AppID), stringz.OrEmpty(value.Name)) - fmt.Printf("%v\n\n", stringz.OrEmpty(value.Value)) + fmt.Printf("%+v\n\n", value.Value) } } else { fmt.Printf("\nEncountered errors: (%d)\n", len(result.Errors)) diff --git a/ziti/cmd/ziti/cmd/fabric/list.go b/ziti/cmd/ziti/cmd/fabric/list.go index 3a941bded..87eb7283c 100644 --- a/ziti/cmd/ziti/cmd/fabric/list.go +++ b/ziti/cmd/ziti/cmd/fabric/list.go @@ -184,10 +184,11 @@ func outputLinks(o *api.Options, children []*gabs.Container, pagingInfo *api.Pag columnConfigs[4] = table.ColumnConfig{Align: text.AlignRight} columnConfigs[5] = table.ColumnConfig{Align: text.AlignRight} t.SetColumnConfigs(columnConfigs) - t.AppendHeader(table.Row{"ID", "Dialer", "Acceptor", "Static Cost", "Src Latency", "Dst Latency", "State", "Status", "Full Cost"}) + t.AppendHeader(table.Row{"ID", "Type", "Dialer", "Acceptor", "Static Cost", "Src Latency", "Dst Latency", "State", "Status", "Full Cost"}) for _, entity := range children { id := entity.Path("id").Data().(string) + linkType := entity.Path("type").Data().(string) srcRouter := entity.Path("sourceRouter.name").Data().(string) dstRouter := entity.Path("destRouter.name").Data().(string) staticCost := entity.Path("staticCost").Data().(float64) @@ -202,7 +203,7 @@ func outputLinks(o *api.Options, children []*gabs.Container, pagingInfo *api.Pag status = "down" } - t.AppendRow(table.Row{id, srcRouter, dstRouter, staticCost, + t.AppendRow(table.Row{id, linkType, srcRouter, dstRouter, staticCost, fmt.Sprintf("%.2vms", srcLatency), fmt.Sprintf("%.2vms", dstLatency), state, status, cost}) @@ -291,7 +292,7 @@ func outputRouters(o *api.Options, children []*gabs.Container, pagingInfo *api.P t := table.NewWriter() t.SetStyle(table.StyleRounded) - t.AppendHeader(table.Row{"ID", "Name", "Online", "Cost", "No Traversal", "Version"}) + t.AppendHeader(table.Row{"ID", "Name", "Online", "Cost", "No Traversal", "Version", "Listeners"}) for _, entity := range children { id := entity.Path("id").Data().(string) @@ -307,7 +308,17 @@ func outputRouters(o *api.Options, children []*gabs.Container, pagingInfo *api.P arch := versionInfo.Path("arch").Data().(string) version = fmt.Sprintf("%v on %v/%v", v, os, arch) } - t.AppendRow(table.Row{id, name, connected, cost, noTraversal, version}) + var listeners []string + listenerAddresses := entity.Path("listenerAddresses") + if listenerAddresses != nil { + children, _ := listenerAddresses.Children() + for idx, child := range children { + addr := child.Path("address").Data().(string) + linkType := child.Path("type").Data().(string) + listeners = append(listeners, fmt.Sprintf("%v: %v (%v)", idx+1, addr, linkType)) + } + } + t.AppendRow(table.Row{id, name, connected, cost, noTraversal, version, strings.Join(listeners, "\n")}) } renderTable(o, t, pagingInfo) diff --git a/ziti/cmd/ziti/cmd/fabric/root.go b/ziti/cmd/ziti/cmd/fabric/root.go index 1061f9ebd..2266757c4 100644 --- a/ziti/cmd/ziti/cmd/fabric/root.go +++ b/ziti/cmd/ziti/cmd/fabric/root.go @@ -33,6 +33,7 @@ func NewFabricCmd(p common.OptionsProvider) *cobra.Command { fabricCmd.AddCommand(newAddIdentityCmd(p), newRemoveIdentityCmd(p)) fabricCmd.AddCommand(newCreateCommand(p), newListCmd(p), newUpdateCommand(p), newDeleteCmd(p)) fabricCmd.AddCommand(newInspectCmd(p)) + fabricCmd.AddCommand(newDbCmd(p)) return fabricCmd } diff --git a/ziti/cmd/ziti/cmd/ps.go b/ziti/cmd/ziti/cmd/ps.go index f8bbfd78c..f4a75a29a 100644 --- a/ziti/cmd/ziti/cmd/ps.go +++ b/ziti/cmd/ziti/cmd/ps.go @@ -19,8 +19,6 @@ package cmd import ( "bytes" "fmt" - "github.com/openziti/edge/router/debugops" - "github.com/openziti/fabric/router" "github.com/spf13/cobra" "io" "os" @@ -28,7 +26,6 @@ import ( "strconv" "strings" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates" "github.com/openziti/ziti/ziti/goprocess" @@ -52,12 +49,11 @@ var ( ) // NewCmdPs Pss a command object for the "Ps" command -func NewCmdPs(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPs(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, } @@ -73,52 +69,23 @@ func NewCmdPs(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command }, } - routerCmd := &cobra.Command{ - Use: "router", - Short: "Show Ziti router process info", - Long: psLong, - Run: func(cmd *cobra.Command, args []string) { - options.Cmd = cmd - options.Args = args - err := options.Run() - cmdhelper.CheckErr(err) - }, - } + cmd.AddCommand(NewCmdPsGet(out, errOut)) + cmd.AddCommand(NewCmdPsGoversion(out, errOut)) + cmd.AddCommand(NewCmdPsGc(out, errOut)) + cmd.AddCommand(NewCmdPsSetgc(out, errOut)) + cmd.AddCommand(NewCmdPsStack(out, errOut)) + cmd.AddCommand(NewCmdPsMemstats(out, errOut)) + cmd.AddCommand(NewCmdPsStats(out, errOut)) + cmd.AddCommand(NewCmdPsPprofHeap(out, errOut)) + cmd.AddCommand(NewCmdPsPprofCpu(out, errOut)) + cmd.AddCommand(NewCmdPsTrace(out, errOut)) + cmd.AddCommand(NewCmdPsSetLogLevel(out, errOut)) + cmd.AddCommand(NewCmdPsSetChannelLogLevel(out, errOut)) + cmd.AddCommand(NewCmdPsClearChannelLogLevel(out, errOut)) - cmd.AddCommand(routerCmd) - cmd.AddCommand(NewCmdPsGet(f, out, errOut)) - cmd.AddCommand(NewCmdPsGoversion(f, out, errOut)) - cmd.AddCommand(NewCmdPsGc(f, out, errOut)) - cmd.AddCommand(NewCmdPsSetgc(f, out, errOut)) - cmd.AddCommand(NewCmdPsStack(f, out, errOut)) - cmd.AddCommand(NewCmdPsMemstats(f, out, errOut)) - cmd.AddCommand(NewCmdPsStats(f, out, errOut)) - cmd.AddCommand(NewCmdPsPprofHeap(f, out, errOut)) - cmd.AddCommand(NewCmdPsPprofCpu(f, out, errOut)) - cmd.AddCommand(NewCmdPsTrace(f, out, errOut)) - cmd.AddCommand(NewCmdPsSetLogLevel(f, out, errOut)) - cmd.AddCommand(NewCmdPsSetChannelLogLevel(f, out, errOut)) - cmd.AddCommand(NewCmdPsClearChannelLogLevel(f, out, errOut)) - - routerCmd.AddCommand(NewCmdPsRoute(f, out, errOut)) - routerCmd.AddCommand(NewCmdPsBasicRouterCmd("dump-routes", router.DumpForwarderTables, f, out, errOut)) - routerCmd.AddCommand(NewCmdPsBasicRouterCmd("disconnect", router.CloseControlChannel, f, out, errOut)) - routerCmd.AddCommand(NewCmdPsBasicRouterCmd("reconnect", router.OpenControlChannel, f, out, errOut)) - routerCmd.AddCommand(NewCmdPsBasicRouterCmd("dump-api-sessions", debugops.DumpApiSessions, f, out, errOut)) - - // cmd.AddCommand(NewCmdPsController(f, out, errOut)) - // cmd.AddCommand(NewCmdPsMgmt(f, out, errOut)) - // cmd.AddCommand(NewCmdPsMgmtGw(f, out, errOut)) - // cmd.AddCommand(NewCmdPsRouter(f, out, errOut)) - - options.addPsFlags(cmd) return cmd } -func (options *PsOptions) addPsFlags(cmd *cobra.Command) { - // cmd.Flags().StringVarP(&options.Flags.Identity, "identity", "", "", "Which identity to use.") -} - // Run implements this command func (o *PsOptions) Run() error { fmt.Println("ps is running") diff --git a/ziti/cmd/ziti/cmd/ps_clear_channel_log_level.go b/ziti/cmd/ziti/cmd/ps_clear_channel_log_level.go index ade37810c..391dc1076 100644 --- a/ziti/cmd/ziti/cmd/ps_clear_channel_log_level.go +++ b/ziti/cmd/ziti/cmd/ps_clear_channel_log_level.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/binary" "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -33,20 +32,20 @@ type PsClearChannelLogLevelOptions struct { } // NewCmdPsClearChannelLogLevel creates a command object for the "create" command -func NewCmdPsClearChannelLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsClearChannelLogLevel(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsClearChannelLogLevelOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "clear-channel-log-level target channel", - Args: cobra.MinimumNArgs(1), + Use: "clear-channel-log-level target channel", + Short: "Clears a channel-specific log level in the target application", + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_gc.go b/ziti/cmd/ziti/cmd/ps_gc.go index 6eb66f8ba..3b00584b4 100644 --- a/ziti/cmd/ziti/cmd/ps_gc.go +++ b/ziti/cmd/ziti/cmd/ps_gc.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -32,20 +31,20 @@ type PsGcOptions struct { } // NewCmdPsGc creates a command object for the "create" command -func NewCmdPsGc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsGc(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsGcOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "gc ", - Args: cobra.MaximumNArgs(1), + Use: "gc ", + Short: "Run garbage collection in the target application", + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_get.go b/ziti/cmd/ziti/cmd/ps_get.go index d5178b540..546415686 100644 --- a/ziti/cmd/ziti/cmd/ps_get.go +++ b/ziti/cmd/ziti/cmd/ps_get.go @@ -23,7 +23,6 @@ import ( "io" "strconv" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/cmd/ziti/internal/log" ) @@ -36,19 +35,19 @@ type PsGetOptions struct { } // NewCmdPsGet creates a command object for the "create" command -func NewCmdPsGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsGet(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsGetOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "get", + Use: "get", + Short: "Returns information about the target process", Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_goversion.go b/ziti/cmd/ziti/cmd/ps_goversion.go index e7ab5dcf5..c846d8e64 100644 --- a/ziti/cmd/ziti/cmd/ps_goversion.go +++ b/ziti/cmd/ziti/cmd/ps_goversion.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -32,20 +31,20 @@ type PsGoversionOptions struct { } // NewCmdPsGoversion creates a command object for the "create" command -func NewCmdPsGoversion(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsGoversion(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsGoversionOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "goversion ", - Args: cobra.MaximumNArgs(1), + Use: "goversion ", + Short: "Returns the golang version of the target application", + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_memstats.go b/ziti/cmd/ziti/cmd/ps_memstats.go index a9fbb9df3..733e5e3fc 100644 --- a/ziti/cmd/ziti/cmd/ps_memstats.go +++ b/ziti/cmd/ziti/cmd/ps_memstats.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -32,20 +31,20 @@ type PsMemstatsOptions struct { } // NewCmdPsMemstats creates a command object for the "create" command -func NewCmdPsMemstats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsMemstats(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsMemstatsOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "memstats ", - Args: cobra.MaximumNArgs(1), + Use: "memstats ", + Short: "Returns memory use summary of the target application", + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_pprof_cpu.go b/ziti/cmd/ziti/cmd/ps_pprof_cpu.go index 0f6273bfb..6abb8e9c7 100644 --- a/ziti/cmd/ziti/cmd/ps_pprof_cpu.go +++ b/ziti/cmd/ziti/cmd/ps_pprof_cpu.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -32,20 +31,20 @@ type PsPprofCpuOptions struct { } // NewCmdPsPprofCpu creates a command object for the "create" command -func NewCmdPsPprofCpu(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsPprofCpu(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsPprofCpuOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "pprof-cpu", - Args: cobra.MaximumNArgs(2), + Use: "pprof-cpu", + Short: "Runs and emits a 30 second pprof from the target application", + Args: cobra.MaximumNArgs(2), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_pprof_heap.go b/ziti/cmd/ziti/cmd/ps_pprof_heap.go index 371c38ae3..ca7a383f3 100644 --- a/ziti/cmd/ziti/cmd/ps_pprof_heap.go +++ b/ziti/cmd/ziti/cmd/ps_pprof_heap.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -31,19 +30,19 @@ type PsPprofHeapOptions struct { } // NewCmdPsPprofHeap creates a command object for the "create" command -func NewCmdPsPprofHeap(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsPprofHeap(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsPprofHeapOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "pprof-heap", + Use: "pprof-heap", + Short: "Returns a memory heap pprof of the target application", Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_router_reconnect.go b/ziti/cmd/ziti/cmd/ps_router_reconnect.go deleted file mode 100644 index c4f1a9ce1..000000000 --- a/ziti/cmd/ziti/cmd/ps_router_reconnect.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - 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 - - https://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. -*/ - -package cmd - -import ( - "github.com/openziti/fabric/router" - "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" - cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" - "github.com/spf13/cobra" - "io" - "os" -) - -// PsRouteOptions the options for the create spring command -type PsRouterReconnectOptions struct { - PsOptions - CtrlListener string -} - -// NewCmdPsRouterReconnect creates a command object for the "router-disconnect" command -func NewCmdPsRouterReconnect(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { - options := &PsRouterReconnectOptions{ - PsOptions: PsOptions{ - CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, - }, - }, - } - - cmd := &cobra.Command{ - Args: cobra.MaximumNArgs(1), - Use: "router-reconnect ", - Run: func(cmd *cobra.Command, args []string) { - options.Cmd = cmd - options.Args = args - err := options.Run() - cmdhelper.CheckErr(err) - }, - } - - options.addCommonFlags(cmd) - - return cmd -} - -// Run implements the command -func (o *PsRouterReconnectOptions) Run() error { - addr, err := agent.ParseGopsAddress(o.Args) - if err != nil { - return err - } - - buf := []byte{router.OpenControlChannel} - - return agent.MakeRequest(addr, agent.CustomOp, buf, os.Stdout) -} diff --git a/ziti/cmd/ziti/cmd/ps_set_channel_log_level.go b/ziti/cmd/ziti/cmd/ps_set_channel_log_level.go index 4a1bd5a54..d3ec563fa 100644 --- a/ziti/cmd/ziti/cmd/ps_set_channel_log_level.go +++ b/ziti/cmd/ziti/cmd/ps_set_channel_log_level.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/binary" "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -36,20 +35,20 @@ type PsSetChannelLogLevelOptions struct { } // NewCmdPsSetChannelLogLevel creates a command object for the "create" command -func NewCmdPsSetChannelLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsSetChannelLogLevel(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsSetChannelLogLevelOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "set-channel-log-level target channel log-level (panic, fatal, error, warn, info, debug, trace)", - Args: cobra.MinimumNArgs(2), + Use: "set-channel-log-level target channel log-level (panic, fatal, error, warn, info, debug, trace)", + Short: "Sets a channel-specific log level in the target application", + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_set_log_level.go b/ziti/cmd/ziti/cmd/ps_set_log_level.go index bf0d473df..347fdd4bc 100644 --- a/ziti/cmd/ziti/cmd/ps_set_log_level.go +++ b/ziti/cmd/ziti/cmd/ps_set_log_level.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -35,20 +34,20 @@ type PsSetLogLevelOptions struct { } // NewCmdPsLogLevel creates a command object for the "create" command -func NewCmdPsSetLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsSetLogLevel(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsSetLogLevelOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "set-log-level target log-level (panic, fatal, error, warn, info, debug, trace)", - Args: cobra.MinimumNArgs(1), + Use: "set-log-level target log-level (panic, fatal, error, warn, info, debug, trace)", + Short: "Sets the global logrus logging level in the target application", + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_setgc.go b/ziti/cmd/ziti/cmd/ps_setgc.go index 4acb78e97..3101cb9f8 100644 --- a/ziti/cmd/ziti/cmd/ps_setgc.go +++ b/ziti/cmd/ziti/cmd/ps_setgc.go @@ -19,7 +19,6 @@ package cmd import ( "encoding/binary" "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -34,20 +33,20 @@ type PsSetgcOptions struct { } // NewCmdPsSetgc creates a command object for the "create" command -func NewCmdPsSetgc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsSetgc(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsSetgcOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "setgc target gc-percentage", - Args: cobra.MinimumNArgs(1), + Use: "setgc target gc-percentage", + Short: "Sets the GC percentage in the target application", + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_stack.go b/ziti/cmd/ziti/cmd/ps_stack.go index 856a9edf2..d55ca6a36 100644 --- a/ziti/cmd/ziti/cmd/ps_stack.go +++ b/ziti/cmd/ziti/cmd/ps_stack.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -34,20 +33,20 @@ type PsStackOptions struct { } // NewCmdPsStack creates a command object for the "create" command -func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsStack(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsStackOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Args: cobra.MaximumNArgs(1), - Use: "stack []", + Args: cobra.MaximumNArgs(1), + Use: "stack []", + Short: "Emits a go-routine stack dump from the target application", Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_stats.go b/ziti/cmd/ziti/cmd/ps_stats.go index 3b617baf1..485dc1a78 100644 --- a/ziti/cmd/ziti/cmd/ps_stats.go +++ b/ziti/cmd/ziti/cmd/ps_stats.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -32,20 +31,20 @@ type PsStatsOptions struct { } // NewCmdPsStats creates a command object for the "create" command -func NewCmdPsStats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsStats(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsStatsOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "stats ", - Args: cobra.MaximumNArgs(1), + Use: "stats ", + Short: "Emits some runtime information (# go-routines, threads, cpus, etc) from the target application", + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/ps_trace.go b/ziti/cmd/ziti/cmd/ps_trace.go index 6d27d863b..885f8d5b8 100644 --- a/ziti/cmd/ziti/cmd/ps_trace.go +++ b/ziti/cmd/ziti/cmd/ps_trace.go @@ -18,7 +18,6 @@ package cmd import ( "github.com/openziti/foundation/agent" - cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/spf13/cobra" "io" @@ -31,19 +30,19 @@ type PsTraceOptions struct { } // NewCmdPsTrace creates a command object for the "create" command -func NewCmdPsTrace(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { +func NewCmdPsTrace(out io.Writer, errOut io.Writer) *cobra.Command { options := &PsTraceOptions{ PsOptions: PsOptions{ CommonOptions: CommonOptions{ - Factory: f, - Out: out, - Err: errOut, + Out: out, + Err: errOut, }, }, } cmd := &cobra.Command{ - Use: "trace", + Use: "trace", + Short: "Turn tracing on for 5 seconds in the target application", Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/ziti/cmd/pscmd.go b/ziti/cmd/ziti/cmd/pscmd.go deleted file mode 100644 index 497a7b025..000000000 --- a/ziti/cmd/ziti/cmd/pscmd.go +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - 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 - - https://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. -*/ - -package cmd - -import ( - "errors" - "fmt" - "github.com/openziti/foundation/agent" - "io" - "io/ioutil" - "net" - "os" - "os/exec" - "strconv" - "strings" - - "github.com/openziti/ziti/ziti/util" -) - -func trace(addr net.TCPAddr, _ []string) error { - fmt.Println("Tracing now, will take 5 secs...") - out, err := cmd(addr, agent.Trace) - if err != nil { - return err - } - if len(out) == 0 { - return errors.New("nothing has traced") - } - tmpfile, err := ioutil.TempFile("", "trace") - if err != nil { - return err - } - if err := ioutil.WriteFile(tmpfile.Name(), out, 0); err != nil { - return err - } - fmt.Printf("Trace dump saved to: %s\n", tmpfile.Name()) - // If go tool chain not found, stopping here and keep trace file. - if _, err := exec.LookPath("go"); err != nil { - return nil - } - defer os.Remove(tmpfile.Name()) - cmd := exec.Command("go", "tool", "trace", tmpfile.Name()) - cmd.Env = os.Environ() - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return cmd.Run() -} - -// targetToAddr tries to parse the target string, be it remote host:port -// or local process's PID. -func targetToAddr(target string) (*net.TCPAddr, error) { - if strings.Contains(target, ":") { - // addr host:port passed - var err error - addr, err := net.ResolveTCPAddr("tcp", target) - if err != nil { - return nil, fmt.Errorf("couldn't parse dst address: %v", err) - } - return addr, nil - } - // try to find port by pid then, connect to local - pid, err := strconv.Atoi(target) - if err != nil { - return nil, fmt.Errorf("couldn't parse PID: %v", err) - } - port, err := util.GetPort(pid) - if err != nil { - return nil, fmt.Errorf("couldn't get port for PID %v: %v", pid, err) - } - addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port) - return addr, nil -} - -func cmd(addr net.TCPAddr, c byte, params ...byte) ([]byte, error) { - conn, err := cmdLazy(addr, c, params...) - if err != nil { - return nil, fmt.Errorf("couldn't get port by PID: %v", err) - } - - all, err := ioutil.ReadAll(conn) - if err != nil { - return nil, err - } - return all, nil -} - -func cmdLazy(addr net.TCPAddr, c byte, params ...byte) (io.Reader, error) { - conn, err := net.DialTCP("tcp", nil, &addr) - if err != nil { - return nil, err - } - buf := []byte{c} - buf = append(buf, params...) - if _, err := conn.Write(buf); err != nil { - return nil, err - } - return conn, nil -} diff --git a/ziti/cmd/ziti/cmd/version.go b/ziti/cmd/ziti/cmd/version.go index 5792c176b..c8ce5a858 100644 --- a/ziti/cmd/ziti/cmd/version.go +++ b/ziti/cmd/ziti/cmd/version.go @@ -22,6 +22,8 @@ import ( "github.com/openziti/ziti/ziti/cmd/ziti/cmd/table" "github.com/openziti/ziti/ziti/cmd/ziti/internal/log" "io" + "os" + // "strings" "github.com/openziti/ziti/common/version" @@ -77,19 +79,19 @@ func (o *VersionOptions) Run() error { info := util.ColorInfo - table := o.CreateTable() - table.AddRow("NAME", "VERSION") + t := table.CreateTable(os.Stdout) + t.AddRow("NAME", "VERSION") - table.AddRow(c.ZITI, info(version.GetBuildMetadata(o.Verbose))) + t.AddRow(c.ZITI, info(version.GetBuildMetadata(o.Verbose))) - o.versionPrintZitiApp(c.ZITI_CONTROLLER, &table) - o.versionPrintZitiApp(c.ZITI_FABRIC, &table) - o.versionPrintZitiApp(c.ZITI_PROX_C, &table) - o.versionPrintZitiApp(c.ZITI_ROUTER, &table) - o.versionPrintZitiApp(c.ZITI_TUNNEL, &table) - o.versionPrintZitiApp(c.ZITI_EDGE_TUNNEL, &table) + o.versionPrintZitiApp(c.ZITI_CONTROLLER, &t) + o.versionPrintZitiApp(c.ZITI_FABRIC, &t) + o.versionPrintZitiApp(c.ZITI_PROX_C, &t) + o.versionPrintZitiApp(c.ZITI_ROUTER, &t) + o.versionPrintZitiApp(c.ZITI_TUNNEL, &t) + o.versionPrintZitiApp(c.ZITI_EDGE_TUNNEL, &t) - table.Render() + t.Render() if !o.NoVersionCheck && !o.Verbose { return o.versionCheck()