Skip to content

Commit

Permalink
Merge pull request #665 from openziti/tidy-examples
Browse files Browse the repository at this point in the history
let examples build checked out sdk
  • Loading branch information
qrkourier authored Jan 23, 2025
2 parents a195721 + afd095c commit 4c6f31e
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 147 deletions.
55 changes: 46 additions & 9 deletions example/curlz/README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
# Overview
This example is a zitified cURL (cURLz) example. In part 1 of this example, a call will be made to an endpoint which

This example is a zitified cURL (cURLz) example. In part 1 of this example, a call will be made to an endpoint which
is not on the overlay network. In part 2, a call is made to an endpoint that *is* on the overlay network.

This example demonstrates:

* Dialing a service

## Requirements

* an OpenZiti network. If you do not have one, you can use one of the [quickstarts](https://openziti.github.io/ziti/quickstarts/quickstart-overview.html) to set one up.
* OpenZiti CLI to create services and identities on the OpenZiti Network

## Build the examples

Refer to the [example README](../README.md) to build the SDK examples

## Part 1: Set up a cURLz to a non-zitified endpoint
These steps will configure the service using the OpenZiti CLI. In this example, the traffic starts on the overlay zero
trust network and then is offloaded onto the underlay network.

These steps will configure the service using the OpenZiti CLI. In this example, the traffic starts on the overlay zero
trust network and then is offloaded onto the underlay network.

### Part 1 Architecture Overview

![image](unzitified.png)

At the end of these steps you will have created:

* a service called `web.endpoint`
* an identity to connect to (dial) the service
* the service config to connect the service to the overlay
* the service policies required to authorize the identities for bind and dial

Steps:

1. Log into OpenZiti. The host:port and username/password will vary depending on your network.

```bash
ziti edge login localhost:1280 -u admin -p admin
```

1. Determine your edge router's name and populate this environment variable with it.

```bash
ziti edge list edge-routers
export ZITI_EDGE_ROUTER=<name-of-edge-router>
```

1. Run this script to create everything you need.

```bash
echo Changing to build directory
cd $ZITI_SDK_BUILD_DIR

Expand All @@ -54,55 +69,76 @@ Steps:
echo Run policy advisor to check
ziti edge policy-advisor services
```

1. Run the cURLz example for `web.endpoint`

```bash
./curlz https://web.endpoint curlz.json
```

### Example Output

The following is the output you'll see from the cURLz request to `web.endpoint`.
```

```bash
$ ./curlz https://web.endpoint curlz.json
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en">
... <a lot of html code>
</body></html>
```

## Part 2: Set up a cURLz to a zitified endpoint
These steps will utilize the service and identities created in simple-server to provide an example of using cURLz with
a zitified endpoint. In this example, the traffic never leaves the zero trust overlay.

These steps will utilize the service and identities created in simple-server to provide an example of using cURLz with
a zitified endpoint. In this example, the traffic never leaves the zero trust overlay.

### Part 2 Architecture Overview

![image](zitified.png)

At the end of these steps you will have created:

* an identity to connect to (dial) the service

Steps:
1. Follow all steps in the simple-service example up to, and including, running the server but **do not** enroll the

1. Follow all steps in the simple-service example up to, and including, running the server but **do not** enroll the
`simple-client` identity with the Ziti Desktop Edge client. We will do that with the CLI for this example
1. Open a new terminal and cd into the example build directory

```bash
echo Changing to build directory
cd $ZITI_SDK_BUILD_DIR
```

1. Run this script to create everything you need.

```bash
echo Enroll the simple-client identity
ziti edge enroll --jwt simple-client.jwt
```

1. Run the cURLz example for `simpleService`

```bash
./curlz http://simpleService simple-client.json
```

### Example Output

The following is the output you'll see from the cURLz request to `simpleService`.
```

```bash
$ ./curlz http://simpleService.ziti simple-client.json
Who are you?
```

## Teardown

Done with the example? This script will remove everything created during setup.
```

```bash
ziti edge login localhost:1280 -u admin -p admin

echo Removing service policies
Expand All @@ -118,4 +154,5 @@ ziti edge delete identity curlz
echo Removing service
ziti edge delete service web.endpoint
```

**NOTE:** If you followed **Part 2** of this example, refer to teardown in the `simple-server` [example README](../simple-server/README.md)
57 changes: 30 additions & 27 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ go 1.21

toolchain go1.22.1

replace github.com/openziti/sdk-golang => ../

require (
github.com/Jeffail/gabs v1.4.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/michaelquigley/pfxlog v0.6.10
github.com/openziti/foundation/v2 v2.0.47
github.com/openziti/foundation/v2 v2.0.56
github.com/openziti/runzmd v1.0.33
github.com/openziti/sdk-golang v0.23.39
github.com/openziti/sdk-golang v0.0.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.17.0
github.com/zitadel/oidc v1.13.5
golang.org/x/text v0.16.0
golang.org/x/text v0.21.0
google.golang.org/grpc v1.59.0
google.golang.org/grpc/examples v0.0.0-20231107231549-482de2224942
gopkg.in/resty.v1 v1.12.0
Expand Down Expand Up @@ -50,13 +52,13 @@ require (
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-resty/resty/v2 v2.13.1 // indirect
github.com/go-resty/resty/v2 v2.15.3 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 // indirect
github.com/gorilla/schema v1.4.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -76,12 +78,12 @@ require (
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openziti/channel/v2 v2.0.136 // indirect
github.com/openziti/edge-api v0.26.21 // indirect
github.com/openziti/identity v1.0.81 // indirect
github.com/openziti/metrics v1.2.56 // indirect
github.com/openziti/secretstream v0.1.21 // indirect
github.com/openziti/transport/v2 v2.0.138 // indirect
github.com/openziti/channel/v3 v3.0.26 // indirect
github.com/openziti/edge-api v0.26.36 // indirect
github.com/openziti/identity v1.0.94 // indirect
github.com/openziti/metrics v1.2.65 // indirect
github.com/openziti/secretstream v0.1.28 // indirect
github.com/openziti/transport/v2 v2.0.159 // indirect
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect
github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
Expand All @@ -105,24 +107,25 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zitadel/logging v0.3.4 // indirect
github.com/zitadel/oidc/v2 v2.12.0 // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
github.com/zitadel/oidc/v2 v2.12.2 // indirect
go.mongodb.org/mongo-driver v1.17.0 // indirect
go.mozilla.org/pkcs7 v0.9.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.36.2 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.11 // indirect
nhooyr.io/websocket v1.8.17 // indirect
)
Loading

0 comments on commit 4c6f31e

Please sign in to comment.