From bc100eef6700d0d526c6c1bd0f35236e9c1d5ec6 Mon Sep 17 00:00:00 2001 From: Guillaume BOURGEOIS Date: Sun, 12 Jul 2026 15:18:48 +0200 Subject: [PATCH] feat(gitlab): new GitLab project-security integration GitLab API v4, 6 commands: list vulnerabilities, list/create issues, get project, list audit events. Private-token auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) --- integrations/gitlab/manifest.yaml | 79 +++++++++++++++++++ integrations/gitlab/scripts/create_issue.py | 67 ++++++++++++++++ integrations/gitlab/scripts/get_project.py | 51 ++++++++++++ .../gitlab/scripts/list_audit_events.py | 48 +++++++++++ integrations/gitlab/scripts/list_issues.py | 52 ++++++++++++ .../gitlab/scripts/list_vulnerabilities.py | 51 ++++++++++++ .../gitlab/scripts/test_connection.py | 48 +++++++++++ 7 files changed, 396 insertions(+) create mode 100644 integrations/gitlab/manifest.yaml create mode 100644 integrations/gitlab/scripts/create_issue.py create mode 100644 integrations/gitlab/scripts/get_project.py create mode 100644 integrations/gitlab/scripts/list_audit_events.py create mode 100644 integrations/gitlab/scripts/list_issues.py create mode 100644 integrations/gitlab/scripts/list_vulnerabilities.py create mode 100644 integrations/gitlab/scripts/test_connection.py diff --git a/integrations/gitlab/manifest.yaml b/integrations/gitlab/manifest.yaml new file mode 100644 index 0000000..7f3d807 --- /dev/null +++ b/integrations/gitlab/manifest.yaml @@ -0,0 +1,79 @@ +id: gitlab +name: GitLab +version: 1.0.0 +description: "GitLab (API v4) — project security and issue tracking: list project vulnerabilities, list and create issues, read a project, and list audit events. Private-token authentication; stdlib-only, no extra Python dependencies." +changelog: "1.0.0 — Initial release: list vulnerabilities, list/create issues, get project, list audit events." +category: devsecops + +# Per-instance configuration. Auth header 'PRIVATE-TOKEN: '. +config_schema: + properties: + base_url: + type: string + description: "GitLab URL" + default: "https://gitlab.com" + token: + type: string + description: "Personal/project access token" + x-soar-sensitive: true + required: + - token + +commands: + - id: list_vulnerabilities + name: gitlab-list-vulnerabilities + description: "List a project's vulnerabilities." + risk: read + inputs_schema: + properties: + project_id: { type: string, description: "Project ID or URL-encoded path (namespace/project)" } + required: [project_id] + outputs_schema: { properties: {} } + - id: list_issues + name: gitlab-list-issues + description: "List a project's issues." + risk: read + inputs_schema: + properties: + project_id: { type: string, description: "Project ID or path" } + state: { type: string, description: "opened or closed (optional)" } + required: [project_id] + outputs_schema: { properties: {} } + - id: create_issue + name: gitlab-create-issue + description: "Create an issue in a project." + inputs_schema: + properties: + project_id: { type: string, description: "Project ID or path" } + title: { type: string, description: "Issue title" } + description: { type: string, description: "Issue description" } + labels: { type: string, description: "Comma-separated labels (optional)" } + required: [project_id, title] + outputs_schema: { properties: {} } + - id: get_project + name: gitlab-get-project + description: "Get a project's metadata." + risk: read + inputs_schema: + properties: + project_id: { type: string, description: "Project ID or path" } + required: [project_id] + outputs_schema: { properties: {} } + - id: list_audit_events + name: gitlab-list-audit-events + description: "List instance audit events." + risk: read + inputs_schema: + properties: + limit: { type: number, description: "Max events (default 50)" } + required: [] + outputs_schema: { properties: {} } + + - id: test_connection + name: gitlab-test-connection + description: "Verify the token (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/gitlab/scripts/create_issue.py b/integrations/gitlab/scripts/create_issue.py new file mode 100644 index 0000000..b587a4e --- /dev/null +++ b/integrations/gitlab/scripts/create_issue.py @@ -0,0 +1,67 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + project_id = inputs.get("project_id") + if not project_id: + raise Exception("project_id is required") + title = inputs.get("title") + if not title: + raise Exception("title is required") + pid = urllib.parse.quote(str(project_id), safe="") + + body = {"title": title} + + description = inputs.get("description") + if description: + body["description"] = description + + labels = inputs.get("labels") + if labels: + labels_list = [s.strip() for s in str(labels).split(",") if s.strip()] + if labels_list: + body["labels"] = ",".join(labels_list) + + return request("POST", "/projects/" + pid + "/issues", cfg, body=body) + + +_run(main) diff --git a/integrations/gitlab/scripts/get_project.py b/integrations/gitlab/scripts/get_project.py new file mode 100644 index 0000000..3738eaa --- /dev/null +++ b/integrations/gitlab/scripts/get_project.py @@ -0,0 +1,51 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + project_id = inputs.get("project_id") + if not project_id: + raise Exception("project_id is required") + pid = urllib.parse.quote(str(project_id), safe="") + return request("GET", "/projects/" + pid, cfg) + + +_run(main) diff --git a/integrations/gitlab/scripts/list_audit_events.py b/integrations/gitlab/scripts/list_audit_events.py new file mode 100644 index 0000000..ee8c21a --- /dev/null +++ b/integrations/gitlab/scripts/list_audit_events.py @@ -0,0 +1,48 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + limit = inputs.get("limit") + return request("GET", "/audit_events", cfg, params={"per_page": int(limit or 50)}) + + +_run(main) diff --git a/integrations/gitlab/scripts/list_issues.py b/integrations/gitlab/scripts/list_issues.py new file mode 100644 index 0000000..a512a7c --- /dev/null +++ b/integrations/gitlab/scripts/list_issues.py @@ -0,0 +1,52 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + project_id = inputs.get("project_id") + if not project_id: + raise Exception("project_id is required") + pid = urllib.parse.quote(str(project_id), safe="") + state = inputs.get("state") + return request("GET", "/projects/" + pid + "/issues", cfg, params={"state": state}) + + +_run(main) diff --git a/integrations/gitlab/scripts/list_vulnerabilities.py b/integrations/gitlab/scripts/list_vulnerabilities.py new file mode 100644 index 0000000..c0505a1 --- /dev/null +++ b/integrations/gitlab/scripts/list_vulnerabilities.py @@ -0,0 +1,51 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + project_id = inputs.get("project_id") + if not project_id: + raise Exception("project_id is required") + pid = urllib.parse.quote(str(project_id), safe="") + return request("GET", "/projects/" + pid + "/vulnerabilities", cfg) + + +_run(main) diff --git a/integrations/gitlab/scripts/test_connection.py b/integrations/gitlab/scripts/test_connection.py new file mode 100644 index 0000000..2abb185 --- /dev/null +++ b/integrations/gitlab/scripts/test_connection.py @@ -0,0 +1,48 @@ +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://gitlab.com")).rstrip("/") + "/api/v4" + + +def request(method, path, cfg, body=None, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"PRIVATE-TOKEN": str(cfg.get("token", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def _run(fn): + try: + print(json.dumps(fn(_cfg(), _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, inputs): + resp = request("GET", "/user", cfg) + return {"ok": True, "username": resp.get("username")} + + +_run(main)