diff --git a/integrations/zscaler-zpa/manifest.yaml b/integrations/zscaler-zpa/manifest.yaml new file mode 100644 index 0000000..8aaff46 --- /dev/null +++ b/integrations/zscaler-zpa/manifest.yaml @@ -0,0 +1,93 @@ +id: zscaler_zpa +name: Zscaler Private Access +version: 1.0.0 +description: "Zscaler Private Access (ZPA config API) — zero-trust inventory and policy visibility: list and read application segments, list servers, server groups and segment groups, and list access policy rules. OAuth2 client-credentials authentication; stdlib-only, no extra Python dependencies." +changelog: "1.0.0 — Initial release: list/get application segments, list servers, server groups, segment groups, access policy rules." +category: network + +# Per-instance configuration. Sign in with client_id + client_secret to obtain a +# bearer token; customer_id scopes the config API. +config_schema: + properties: + base_url: + type: string + description: "ZPA config API base URL" + default: "https://config.private.zscaler.com" + client_id: + type: string + description: "ZPA API client ID" + client_secret: + type: string + description: "ZPA API client secret" + x-soar-sensitive: true + customer_id: + type: string + description: "ZPA customer ID" + required: + - client_id + - client_secret + - customer_id + +commands: + - id: list_application_segments + name: zpa-list-application-segments + description: "List application segments." + risk: read + inputs_schema: + properties: + page: { type: number, description: "Page number (default 1)" } + page_size: { type: number, description: "Page size (default 20)" } + required: [] + outputs_schema: { properties: {} } + - id: get_application_segment + name: zpa-get-application-segment + description: "Get a single application segment by ID." + risk: read + inputs_schema: + properties: + segment_id: { type: string, description: "Application segment ID" } + required: [segment_id] + outputs_schema: { properties: {} } + - id: list_servers + name: zpa-list-servers + description: "List application servers." + risk: read + inputs_schema: + properties: + page: { type: number, description: "Page number (default 1)" } + page_size: { type: number, description: "Page size (default 20)" } + required: [] + outputs_schema: { properties: {} } + - id: list_server_groups + name: zpa-list-server-groups + description: "List server groups." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } + - id: list_segment_groups + name: zpa-list-segment-groups + description: "List segment groups." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } + - id: list_access_policies + name: zpa-list-access-policies + description: "List access policy rules." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } + + - id: test_connection + name: zpa-test-connection + description: "Verify the sign-in and API access (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/zscaler-zpa/scripts/get_application_segment.py b/integrations/zscaler-zpa/scripts/get_application_segment.py new file mode 100644 index 0000000..42490f4 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/get_application_segment.py @@ -0,0 +1,69 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +q = lambda v: urllib.parse.quote(str(v), safe="") + + +def main(cfg, token, inputs): + segment_id = inputs.get("segment_id") + if not segment_id: + raise Exception("segment_id is required") + return request("GET", "/application/" + q(segment_id), cfg, token) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/list_access_policies.py b/integrations/zscaler-zpa/scripts/list_access_policies.py new file mode 100644 index 0000000..72de7dd --- /dev/null +++ b/integrations/zscaler-zpa/scripts/list_access_policies.py @@ -0,0 +1,63 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + return request("GET", "/policySet/rules/policyType/ACCESS_POLICY", cfg, token) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/list_application_segments.py b/integrations/zscaler-zpa/scripts/list_application_segments.py new file mode 100644 index 0000000..e8be007 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/list_application_segments.py @@ -0,0 +1,65 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + page = inputs.get("page") or 1 + page_size = inputs.get("page_size") or 20 + return request("GET", "/application", cfg, token, params={"page": int(page), "pagesize": int(page_size)}) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/list_segment_groups.py b/integrations/zscaler-zpa/scripts/list_segment_groups.py new file mode 100644 index 0000000..1bd59f1 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/list_segment_groups.py @@ -0,0 +1,63 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + return request("GET", "/segmentGroup", cfg, token) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/list_server_groups.py b/integrations/zscaler-zpa/scripts/list_server_groups.py new file mode 100644 index 0000000..6d932a2 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/list_server_groups.py @@ -0,0 +1,63 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + return request("GET", "/serverGroup", cfg, token) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/list_servers.py b/integrations/zscaler-zpa/scripts/list_servers.py new file mode 100644 index 0000000..357e774 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/list_servers.py @@ -0,0 +1,65 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + page = inputs.get("page") or 1 + page_size = inputs.get("page_size") or 20 + return request("GET", "/server", cfg, token, params={"page": int(page), "pagesize": int(page_size)}) + + +_run(main) diff --git a/integrations/zscaler-zpa/scripts/test_connection.py b/integrations/zscaler-zpa/scripts/test_connection.py new file mode 100644 index 0000000..600be48 --- /dev/null +++ b/integrations/zscaler-zpa/scripts/test_connection.py @@ -0,0 +1,64 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _base(cfg): + return (str(cfg.get("base_url") or "https://config.private.zscaler.com")).rstrip("/") + + +def _token(cfg): + form = urllib.parse.urlencode({ + "client_id": str(cfg.get("client_id", "")), + "client_secret": str(cfg.get("client_secret", "")), + }).encode("utf-8") + req = urllib.request.Request(_base(cfg) + "/signin", data=form, + headers={"Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json"}, method="POST") + with urllib.request.urlopen(req, timeout=60) as r: + tok = json.loads(r.read()) + if not tok.get("access_token"): + raise Exception("Sign-in failed: " + json.dumps(tok)) + return tok["access_token"] + + +def request(method, path, cfg, token, params=None): + # path is relative to the customer config base, e.g. /application + url = _base(cfg) + "/mgmtconfig/v1/admin/customers/" + str(cfg.get("customer_id", "")) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + headers = {"Authorization": "Bearer " + token, "Accept": "application/json"} + req = urllib.request.Request(url, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + cfg = _cfg() + inputs = _inputs() + token = _token(cfg) + print(json.dumps(fn(cfg, token, inputs))) + except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) + except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) + + +def main(cfg, token, inputs): + request("GET", "/application", cfg, token, params={"page": 1, "pagesize": 1}) + return {"ok": True} + + +_run(main)