# How to pass port to ziticontext in golang

**URL:** <https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091>\
**Category:** Uncategorized\
**Created:** [September 5, 2024, 10:15am UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091 "2024-09-05T10:15:33Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![TheLumberjack](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/thelumberjack/32/113_2.png) [@TheLumberjack](https://openziti.discourse.group/u/TheLumberjack)\
**Post date:** [September 10, 2024, 8:49pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/21 "2024-09-10T20:49:11Z")

</div>

Ok. I was chatting with another fella about this and I think this is a confusing timing issue. I think when using intercept-based dialing like this, we need to wait for the SDK to receive the services from the controller so let's make a small change...let's have the SDK verify it has access to the service, due to the implementation in the sdk, I am pretty sure this will block until the SDK is setup and ready for the intercept.

In createZitifiedHttpClient, before the NewSdkCollection function add a call to `RefreshServices`. So it would look like this:

```auto
	_ = ctx.RefreshServices()
	zitiContexts := ziti.NewSdkCollection()

```

Let's see if that fixes the issue.

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 10, 2024, 8:52pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/22 "2024-09-10T20:52:42Z")

</div>

> [@TheLumberjack](#):
>
> ```auto
> _ = ctx.RefreshServices()
> 
> ```

Updated the code, heres the logs:

```bash
DEBU[0000] attempting to authenticate                   
DEBU[0000] setting active controller key="https://ziti-edge-controller:443/edge/client/v1"
DEBU[0000] no additional controllers reported, continuing with 1 default configured controller 
DEBU[0000] checking if service updates available        
DEBU[0000] refreshing services                          
DEBU[0000] processing service updates with 1 services   
DEBU[0000] no service config of type intercept.v1 defined for service serviceId=4mkl06AmzCw3jx2hflY9u5 serviceName=dmz.r1.bct.tech
DEBU[0000] no service config of type ziti-tunneler-client.v1 defined for service serviceId=4mkl06AmzCw3jx2hflY9u5 serviceName=dmz.r1.bct.tech
DEBU[0000] checking if service updates available        
DEBU[0000] refreshing services                          
DEBU[0000] processing service updates with 1 services   
DEBU[0000] no service config of type intercept.v1 defined for service serviceId=4mkl06AmzCw3jx2hflY9u5 serviceName=dmz.r1.bct.tech
DEBU[0000] no service config of type ziti-tunneler-client.v1 defined for service serviceId=4mkl06AmzCw3jx2hflY9u5 serviceName=dmz.r1.bct.tech
Get "https://dmz.r1.bct.tech:443/": dial tcp: lookup dmz.r1.bct.tech on 127.0.0.53:53: server misbehavingpanic: runtime error: invalid memory address or nil pointer dereference

```

Heres the intercept config, from zac:

```json
{
  "name": "dmz.r1.bct.tech.int.config",
  "configTypeId": "g7cIWbcGg",
  "data": {
    "portRanges": [
      {
        "high": 443,
        "low": 443
      }
    ],
    "addresses": [
      "dmz.r1.bct.tech"
    ],
    "protocols": [
      "tcp"
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![TheLumberjack](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/thelumberjack/32/113_2.png) [@TheLumberjack](https://openziti.discourse.group/u/TheLumberjack)\
**Post date:** [September 10, 2024, 8:55pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/23 "2024-09-10T20:55:02Z")

</div>

> [@CarlosHleb](#):
>
> `DEBU[0000] no service config of type intercept.v1 defined for service serviceId=4mkl06AmzCw3jx2hflY9u5 serviceName=dmz.r1.bct.tech`

well that was why we weren't seeing logs it seems. so that's progress!

Is there any chance you deleted the intercept config and then added it back by the same name? can you show the json for the service and make sure it's listed in the configs? My guess is you deleted it and added it back and it's no longer linked to the service.

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 10, 2024, 9:17pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/24 "2024-09-10T21:17:54Z")

</div>

I am positive that i did not delete it and re-add it. I have an install script, before i sent any outputs to this thread i wiped everything and re-created.

Heres the dmz part of the script:

```bash
# Create dmz service
zitiEx edge create config ${ZITI_SERVICE_DMZ}.host.config host.v1 '{"protocol":"tcp", "address":"'"dmz-server"'", "port":'${DMZ_PORT}'}'
zitiEx edge create config ${ZITI_SERVICE_DMZ}.int.config intercept.v1 '{
  "protocols":["tcp"],
  "addresses":["'${ZITI_SERVICE_DMZ}'"], 
  "portRanges":[{"low":'${DMZ_PORT}', "high":'${DMZ_PORT}'}]
}'
zitiEx edge create service ${ZITI_SERVICE_DMZ} --configs ${ZITI_SERVICE_DMZ}".host.config",${ZITI_SERVICE_DMZ}".int.config"
zitiEx edge create service-policy ${ZITI_SERVICE_DMZ}".bind" Bind --service-roles "@"${ZITI_SERVICE_DMZ} --identity-roles "#"${ZITI_SERVICE_DMZ}".bind"
zitiEx edge create service-policy ${ZITI_SERVICE_DMZ}".dial" Dial --service-roles "@"${ZITI_SERVICE_DMZ} --identity-roles "#"${ZITI_SERVICE_DMZ}".dial"

```

---

<div class="post-metadata">

**Author:** ![TheLumberjack](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/thelumberjack/32/113_2.png) [@TheLumberjack](https://openziti.discourse.group/u/TheLumberjack)\
**Post date:** [September 10, 2024, 9:41pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/25 "2024-09-10T21:41:28Z")

</div>

The script appears ok to me, could you list the service with json using the ziti CLI or ZAC to confirm things are linked properly?

```auto
ziti edge list services 'name = "${ZITI_SERVICE_DMZ}"' -j

```

I'm looking to confirm the service id (serviceId=4mkl06AmzCw3jx2hflY9u5) as well as confirm there are two configs showing in the json body.

I've never seen this particular problem where the service had policies and configs properly linked. I just want to confirm they are properly linked by inspecting the json... Thanks

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 10, 2024, 9:50pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/26 "2024-09-10T21:50:03Z")

</div>

> [@TheLumberjack](#):
>
> ```auto
> ziti edge list services 'name = "${ZITI_SERVICE_DMZ}"' -j
> 
> ```

```bash
ziti@d69c91070d58:/persistent$ ziti edge list services 'name = "dmz.r1.bct.tech"' -j
{
    "data": [
        {
            "_links": {
                "configs": {
                    "href": "./services/4mkl06AmzCw3jx2hflY9u5/configs"
                },
                "self": {
                    "href": "./services/4mkl06AmzCw3jx2hflY9u5"
                },
                "service-edge-router-policies": {
                    "href": "./services/4mkl06AmzCw3jx2hflY9u5/service-edge-router-policies"
                },
                "service-policies": {
                    "href": "./services/4mkl06AmzCw3jx2hflY9u5/service-policies"
                },
                "terminators": {
                    "href": "./services/4mkl06AmzCw3jx2hflY9u5/terminators"
                }
            },
            "createdAt": "2024-09-10T11:04:57.571Z",
            "id": "4mkl06AmzCw3jx2hflY9u5",
            "tags": {},
            "updatedAt": "2024-09-10T11:04:57.571Z",
            "config": {},
            "configs": [
                "6q5eXNtQ9KNaHwGDDSGdGQ",
                "7khziPNowEF1N2saNZtQ81"
            ],
            "encryptionRequired": true,
            "maxIdleTimeMillis": 0,
            "name": "dmz.r1.bct.tech",
            "permissions": [
                "Invalid"
            ],
            "postureQueries": [
                {
                    "isPassing": true,
                    "policyId": "dummy invalid policy: no posture checks defined",
                    "policyType": "Invalid",
                    "postureQueries": []
                }
            ],
            "roleAttributes": null,
            "terminatorStrategy": "smartrouting"
        }
    ],
    "meta": {
        "filterableFields": [
            "name",
            "terminatorStrategy",
            "id",
            "updatedAt",
            "isSystem",
            "tags",
            "configs",
            "createdAt",
            "roleAttributes"
        ],
        "pagination": {
            "limit": 10,
            "offset": 0,
            "totalCount": 1
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![TheLumberjack](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/thelumberjack/32/113_2.png) [@TheLumberjack](https://openziti.discourse.group/u/TheLumberjack)\
**Post date:** [September 10, 2024, 9:58pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/27 "2024-09-10T21:58:15Z")

</div>

Thanks. This party catches my eye. I dunno what might cause it but I'll try to ask around the team and see if it might be relevant.

```auto
"permissions": [
                "Invalid"
            ],

```

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 11, 2024, 1:25pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/28 "2024-09-11T13:25:53Z")

</div>

Any updates on this situation?

---

<div class="post-metadata">

**Author:** ![TheLumberjack](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/thelumberjack/32/113_2.png) [@TheLumberjack](https://openziti.discourse.group/u/TheLumberjack)\
**Post date:** [September 11, 2024, 1:45pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/29 "2024-09-11T13:45:55Z")

</div>

Ugh, this is my fault. I must have used a different bit of code before when I had tested it. I just looked at this issue again today with fresh eyes and it dawned on me that I forgot to tell you that you need to specify the config types you want to return....

In createZitifiedHttpClient you want to add one line:

```auto
	cfg, err := ziti.NewConfigFromFile(idFile)
	if err != nil {
		panic(err)
	}
	cfg.ConfigTypes = append(cfg.ConfigTypes, "all")
	//-- or more specific
	cfg.ConfigTypes = append(cfg.ConfigTypes, "intercept.v1")

```

If you don't specify to return the intercept config, it won't be returned when creating a session.

that should solve the issue.

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 11, 2024, 4:39pm UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/30 "2024-09-11T16:39:39Z")

</div>

> [@TheLumberjack](#):
>
> ```auto
> cfg.ConfigTypes = append(cfg.ConfigTypes, "all")
> 
> ```

This did it! Thanks!

---

<div class="post-metadata">

**Author:** ![CarlosHleb](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/carloshleb/32/2187_2.png) [@CarlosHleb](https://openziti.discourse.group/u/CarlosHleb)\
**Post date:** [September 13, 2024, 6:44am UTC](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091/31 "2024-09-13T06:44:38Z")

</div>

> [@TheLumberjack](#):
>
> ```auto
> _ = ctx.RefreshServices()
> zitiContexts := ziti.NewSdkCollection()For
> 
> ```

Note: You need both:

```go
	_ = ctx.RefreshServices()
	zitiContexts := ziti.NewSdkCollection()

```

and

```go
	cfg.ConfigTypes = append(cfg.ConfigTypes, "all")

```

For this to work.

[Previous page](https://openziti.discourse.group/t/how-to-pass-port-to-ziticontext-in-golang/3091.md?page=1)
