Hi , I was trying to bring the things I did with ziti cli (such as creating private routers , services , policies.. etc) via API . In this case its management API
I have deployed the router in postgres host and tried to create identities , services everything via API .
Status of the things done:
I was able to see the router is online ,
I was not able to see terminators for services .
Please either point the issue or guide me how to debug it .
Following are the steps I did :
export ZITI_URL="https://<my_ziti_url>:1280"
export USERNAME="admin"
export password=$(kubectl get secrets "ziti-controller-admin-secret" \
--namespace "ziti" \
--output go-template='{{index .data "admin-password" | base64decode }}')
response=$(curl -s -X POST "$ZITI_URL/edge/management/v1/authenticate?method=password" \
-H "Content-Type: application/json" \
-d "{\"username\": \"$USERNAME\", \"password\": \"$password\"}" --insecure)
# Extract the session token from the response
session=$(echo $response | jq -r '.data.token')
## created router in postgres host
routerName="router-test6"
roleAttributes=("router-group-test")
isTunnelerEnabled=true # Set this to true
# Create the edge router identity
routerResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/edge-routers" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "'"$routerName"'",
"roleAttributes": ["'"${roleAttributes[@]}"'"],
"isTunnelerEnabled": '$isTunnelerEnabled'
}' --insecure)
# Output the created edge router details
echo "Created Edge Router:"
echo "$routerResponse" | jq
edgeRouterId=$(echo $edgeRouterResponse | jq -r '.data.id')
echo "routerID is $edgeRouterId"
edgeRouterResponse=$(curl -s -X GET "$edgeRouterEndpoint" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
--insecure)
enrollmentJwt=$(echo $edgeRouterResponse | jq -r '.data.enrollmentJwt')
## used this jwt for running the router and the router is online
# -------------------------
# Example usage of variables in curl commands
# Create Identity
IdentityName=client-6
ClientAttribute=client-group-6
IdentityResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/identities" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "'"$IdentityName"'",
"isAdmin": false,
"type": "User",
"roleAttributes": ["'"$ClientAttribute"'"],
"enrollment": {
"type": "OTT"
}
}' --insecure)
# Extract Identity ID
ClientId=$(echo $IdentityResponse | jq -r .data.id)
## jR5BRdjpG
enrollmentsEndpoint="$ZITI_URL/edge/management/v1/enrollments"
# Example enrollment data (adjust as per your requirements)
enrollmentData='{
"expiresAt": "2024-08-24T14:15:22Z",
"identityId": "'"$ClientId"'",
"method": "ott"
}'
# Create enrollment
enrollmentResponse=$(curl -s -X POST "$enrollmentsEndpoint" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d "$enrollmentData" \
--insecure)
# Extract the enrollment ID from the response
enrollmentId=$(echo $enrollmentResponse | jq -r '.data.id')
# Retrieve enrollment details to get the JWT token
enrollmentDetailsEndpoint="$enrollmentsEndpoint/$enrollmentId"
enrollmentDetailsResponse=$(curl -s -X GET "$enrollmentDetailsEndpoint" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
--insecure)
# Extract the JWT token from enrollmentDetailsResponse using jq
jwtToken=$(echo $enrollmentDetailsResponse | jq -r '.data.jwt')
# Output the JWT token
echo "JWT Token: $jwtToken"
curl -s -X GET "$ZITI_URL/edge/management/v1/config-types" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
--insecure | jq '.data[] | select(.name == "host.v1")'
# Create Intercept Config
interceptConfigResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/configs" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "service-6-intercept",
"configTypeId": "g7cIWbcGg",
"data": {
"protocols": ["tcp"],
"addresses": ["post.ziti.internal"],
"portRanges": [{"low": 5432, "high": 5432}]
}
}' --insecure)
interceptConfigId=$(echo $interceptConfigResponse | jq -r '.data.id')
echo "Intercept Config is $interceptConfigId"
## Intercept Config is R15ZcOGsxKWvVgiy0EwCL
# Create Host Config
hostConfigResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/configs" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "service-6-host",
"configTypeId": "NH5p4FpGR",
"data": {
"protocol": "tcp",
"address": "localhost",
"port": 5432
}
}' --insecure)
hostConfigId=$(echo $hostConfigResponse | jq -r '.data.id')
echo "host Config is $hostConfigId"
# host Config is 2Ad5hcUg1Nfd8G1ESKW8tM
# Create Service
serviceResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/services" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "service-6",
"configs": ["R15ZcOGsxKWvVgiy0EwCL", "2Ad5hcUg1Nfd8G1ESKW8tM"],
"encryptionRequired": true
}' --insecure)
serviceId=$(echo $serviceResponse | jq -r '.data.id')
# 1Oh311d9m0gm2vUET6cjya
# Create Dial Policy
createDialPolicyResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/service-policies" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "service-6-dial-policy",
"type": "Dial",
"semantic": "AllOf",
"serviceRoles": ["#all"],
"identityRoles": ["#client-group-6"]
}' --insecure)
echo "$createDialPolicyResponse" | jq
# 39ZQKEsWgoDKVzCDHZP66E
# Create Bind Policy
createBindPolicyResponse=$(curl -s -X POST "$ZITI_URL/edge/management/v1/service-policies" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" \
-d '{
"name": "service-6-bind-policy",
"type": "Bind",
"semantic": "AllOf",
"serviceRoles": ["#all"],
"identityRoles": ["#router-group-test"]
}' --insecure)
echo "$createBindPolicyResponse" | jq
# 45dOY2KZQFMOMF1uxcuJ97
# Retrieve terminators associated with the service ID
terminatorsResponse=$(curl -s -X GET "$ZITI_URL/edge/management/v1/services/1Oh311d9m0gm2vUET6cjya/terminators" \
-H "Content-Type: application/json" \
-H "Zt-Session: $session" --insecure)
# Output the terminators
echo "$terminatorsResponse" | jq .data
# []