Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions services/bin/cosmos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node

import { fileURLToPath } from "node:url";
import { runServiceMain } from "@chaitin-ai/octobus-sdk";

import { service } from "../chaitin__cosmos/src/service.js";

runServiceMain(service, {
entryFile: fileURLToPath(new URL("../chaitin__cosmos/bin/cosmos.js", import.meta.url)),
});
12 changes: 8 additions & 4 deletions services/bin/octobus-tentacles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ const services = {
entryFile: "../alibaba-cloud__simple-application-server-firewall/bin/alibaba-cloud-simple-application-server-firewall.js",
serviceModule: "../alibaba-cloud__simple-application-server-firewall/src/service.js",
},
"cloudatlas": {
entryFile: "../chaitin__cloudatlas/bin/cloudatlas.js",
serviceModule: "../chaitin__cloudatlas/src/service.js",
},
"cosmos": {
entryFile: "../chaitin__cosmos/bin/cosmos.js",
serviceModule: "../chaitin__cosmos/src/service.js",
},
"safeline-waf": {
entryFile: "../chaitin__safeline-waf/bin/safeline-waf.js",
serviceModule: "../chaitin__safeline-waf/src/service.js",
Expand All @@ -17,10 +25,6 @@ const services = {
entryFile: "../chaitin__safeline-waf-eliminate-false-positive/bin/safeline-waf-eliminate-false-positive.js",
serviceModule: "../chaitin__safeline-waf-eliminate-false-positive/src/service.js",
},
"cloudatlas": {
entryFile: "../chaitin__cloudatlas/bin/cloudatlas.js",
serviceModule: "../chaitin__cloudatlas/src/service.js",
},
"das-gateway-v3": {
entryFile: "../das__gateway_v3/bin/das-gateway-v3.js",
serviceModule: "../das__gateway_v3/src/service.js",
Expand Down
72 changes: 72 additions & 0 deletions services/chaitin__cosmos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Chaitin Cosmos (万象) OctoBus Service

OctoBus service package for Chaitin Cosmos (万象) platform log APIs via Pedestal JSON-RPC.

## Features

- **SearchLogInfo**: Get log details by IDs
- **SearchLogList**: Search log list with keyword, time range, condition query, filters, and pagination
- **SearchAggregationStatistics**: Get log aggregation statistics with time-series data

## Configuration

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `endpoint` | string | yes | Cosmos Pedestal RPC base URL, e.g. `https://cosmos.example.com` |
| `headers` | object | no | Extra HTTP headers sent to Cosmos |
| `timeoutMs` | integer | no | HTTP timeout in ms, default 5000 |

## Secret

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `api_token` | string | yes | Cosmos JWT token for Authorization bearer header |

> **Note:** `api_token` must be configured via the instance secret. It is **not** accepted in request messages. This follows the OctoBus convention that credentials belong in secret config rather than per-call payloads.

## TLS Certificate Requirements

This service validates TLS certificates by default. If your Cosmos deployment uses a self-signed or private CA certificate:

1. **Recommended:** Add the CA to the system trust store
2. **Alternative:** Set the `NODE_EXTRA_CA_CERTS` environment variable to point to your CA bundle:
```bash
export NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.pem
```

Per-request TLS bypass (`skipTlsVerify`) is intentionally **not** supported, as it would require process-wide security downgrades (`NODE_TLS_REJECT_UNAUTHORIZED=0`) that affect all other HTTPS connections in the same Node.js process.

## Quick Start

```bash
# Import service
octobus service import cosmos ./services/chaitin__cosmos

# Create instance
octobus instance create cosmos-test --service cosmos --config-json '{"endpoint":"https://cosmos.demo.chaitin.cn"}' --secret-json '{"api_token":"xxx"}'

# Create capset
octobus capset create cosmos --name cosmos
octobus capset add-instance cosmos cosmos-test

# Call via gRPC (e.g. grpcurl)
grpcurl -plaintext \
-H "x-octobus-capset: cosmos" \
-H "x-octobus-service: cosmos" \
-H "x-octobus-instance: cosmos-test" \
-d '{"time_range_start": "1750550400", "time_range_end": "1750723200", "count": "1", "offset": "0"}' \
octobus_addr:9000 \
Chaitin_COSMOS.Chaitin_COSMOS/SearchLogList

# Call via MCP
curl -X POST \
-H "Content-Type: application/json" \
"http://octobus_addr:9000/capsets/cosmos/mcp" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

# Call via Connect-RPC
curl -s -X POST \
"http://octobus_addr:9000/capsets/cosmos/connect/cosmos-test/Chaitin_COSMOS.Chaitin_COSMOS/SearchLogList" \
-H "Content-Type: application/json" \
-d '{"time_range_start": "1750550400", "time_range_end": "1750723200", "count": "1", "offset": "0"}'
```
7 changes: 7 additions & 0 deletions services/chaitin__cosmos/bin/cosmos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

import { runServiceMain } from "@chaitin-ai/octobus-sdk";

import { service } from "../src/service.js";

runServiceMain(service);
32 changes: 32 additions & 0 deletions services/chaitin__cosmos/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": true,
"properties": {
"endpoint": {
"type": "string",
"description": "Cosmos Pedestal RPC base URL, for example https://cosmos.example.com."
},
"restBaseUrl": {
"type": "string",
"description": "Legacy alias for endpoint."
},
"baseUrl": {
"type": "string",
"description": "Legacy alias for endpoint."
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Optional extra HTTP headers sent to Cosmos."
},
"timeoutMs": {
"type": "integer",
"minimum": 1,
"default": 5000,
"description": "HTTP timeout in milliseconds."
}
}
}
13 changes: 13 additions & 0 deletions services/chaitin__cosmos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "cosmos",
"version": "0.0.0",
"private": true,
"type": "module",
"bin": {
"cosmos": "bin/cosmos.js"
},
"dependencies": {
"@chaitin-ai/octobus-sdk": "^0.5.0",
"undici": "^7.0.0"
}
}
140 changes: 140 additions & 0 deletions services/chaitin__cosmos/proto/cosmos.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
syntax = "proto3";

package Chaitin_COSMOS;

import "google/protobuf/wrappers.proto";
import "google/protobuf/struct.proto";

option go_package = "miner/grpc-service/Chaitin_COSMOS";

service Chaitin_COSMOS {
// 获取日志详情,根据日志 ID 列表查询
rpc SearchLogInfo(SearchLogInfoRequest) returns (SearchLogInfoResponse) {}

// 获取日志列表,支持关键字搜索、时间范围、条件过滤与分页
rpc SearchLogList(SearchLogListRequest) returns (SearchLogListResponse) {}

// 获取日志聚合统计,按指定维度聚合并返回时序数据
rpc SearchAggregationStatistics(SearchAggregationStatisticsRequest) returns (SearchAggregationStatisticsResponse) {}
}

// ─── SearchLogInfo ───

message SearchLogInfoRequest {
reserved 1; // formerly api_token — removed; token now comes from ctx.secret
repeated string ids = 2; // 日志 ID 列表,必填且非空
}

message SearchLogInfoResponse {
google.protobuf.Value err = 1;
google.protobuf.Value msg = 2;
SearchLogInfoData data = 3;
}

message SearchLogInfoData {
repeated CosmoLogRecord records = 1;
}

// ─── SearchLogList ───

message SearchLogListRequest {
reserved 1; // formerly api_token — removed; token now comes from ctx.secret
repeated string keyword = 2; // 关键字搜索,可选
google.protobuf.Int64Value time_range_start = 3; // 时间范围起始(Unix 秒),可选
google.protobuf.Int64Value time_range_end = 4; // 时间范围结束(Unix 秒),可选
string advanced_query = 5; // 高级查询语句,可选
CosmoConditionQuery condition_query = 6; // 条件查询,可选
CosmoFilter filter = 7; // 过滤条件,可选
google.protobuf.Int64Value count = 8; // 分页大小,可选,默认 100
google.protobuf.Int64Value offset = 9; // 分页偏移,可选,默认 0
string attack_chain_phase = 10; // 攻击链阶段筛选,可选
google.protobuf.BoolValue fall = 11; // 失陷状态筛选,可选
repeated CosmoOrganization organization = 12; // 组织机构筛选,可选
}

message CosmoConditionQuery {
string logical_op = 1; // 逻辑运算符,如 "AND"
repeated CosmoExpression expressions = 2; // 条件表达式列表
}

message CosmoExpression {
string column = 1; // 字段名,如 "src_ip", "log_id"
string op = 2; // 运算符,如 "equal", "contains"
string value = 3; // 值
}

message CosmoFilter {
repeated string origin_event_name = 1; // 原始事件名过滤
repeated string src_ip = 2; // 源 IP 过滤
repeated string dest_ip = 3; // 目的 IP 过滤
repeated string src_country = 4; // 源国家过滤
repeated string src_port = 5; // 源端口过滤
repeated string dest_port = 6; // 目的端口过滤
repeated int32 attack_result = 7; // 攻击结果过滤
}

message CosmoOrganization {
string oper = 1; // 运算符,如 "="
int64 target = 2; // 目标 ID
}

message SearchLogListResponse {
google.protobuf.Value err = 1;
google.protobuf.Value msg = 2;
SearchLogListData data = 3;
}

message SearchLogListData {
repeated CosmoLogRecord records = 1;
int64 start_time = 2;
int64 end_time = 3;
}

// ─── SearchAggregationStatistics ───

message SearchAggregationStatisticsRequest {
reserved 1; // formerly api_token — removed; token now comes from ctx.secret
repeated string keyword = 2; // 关键字搜索,可选
google.protobuf.Int64Value time_range_start = 3; // 时间范围起始(Unix 秒),可选
google.protobuf.Int64Value time_range_end = 4; // 时间范围结束(Unix 秒),可选
string advanced_query = 5; // 高级查询语句,可选
CosmoConditionQuery condition_query = 6; // 条件查询,可选
CosmoFilter filter = 7; // 过滤条件,可选
repeated string key = 8; // 聚合维度,如 ["src_ip","dest_ip","event_type"]
google.protobuf.Int64Value count = 9; // 返回条数,可选,默认 10
google.protobuf.BoolValue asc = 10; // 是否升序,可选,默认 false
string attack_chain_phase = 11; // 攻击链阶段筛选,可选
google.protobuf.BoolValue fall = 12; // 失陷状态筛选,可选
repeated CosmoOrganization organization = 13; // 组织机构筛选,可选
}

message SearchAggregationStatisticsResponse {
google.protobuf.Value err = 1;
google.protobuf.Value msg = 2;
SearchAggregationStatisticsData data = 3;
}

message SearchAggregationStatisticsData {
repeated CosmoAggregationGroup groups = 1;
int64 total = 2;
}

message CosmoAggregationGroup {
google.protobuf.Struct result = 1; // 聚合键值,如 {"src_ip":"1.2.3.4","event_type":52001}
repeated CosmoAggregationPoint data = 2; // 时序数据点
int64 count = 3; // 总数
}

message CosmoAggregationPoint {
int64 start_time = 1; // 时间点(Unix 秒)
int64 count = 2; // 计数
}

// ─── 通用日志记录 ───

message CosmoLogRecord {
// Cosmos API 返回字段非常丰富且可能随版本变化,
// 使用 google.protobuf.Struct 保留完整的原始数据,
// 避免 proto 字段名 (snake_case) 与 protobuf-es JS 表示 (camelCase) 的转换问题
google.protobuf.Struct raw = 1;
}
11 changes: 11 additions & 0 deletions services/chaitin__cosmos/secret.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": true,
"properties": {
"api_token": {
"type": "string",
"description": "Cosmos JWT token for Authorization bearer header."
}
}
}
37 changes: 37 additions & 0 deletions services/chaitin__cosmos/service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"schema": "chaitin.octobus.service.v1",
"name": "cosmos",
"displayName": "Chaitin Cosmos",
"description": "OctoBus package for Chaitin Cosmos (万象) log search, log detail, and aggregation statistics APIs via Pedestal JSON-RPC.",
"runtime": {
"mode": "long-running"
},
"proto": {
"roots": [
"proto"
],
"files": [
"proto/cosmos.proto"
]
},
"configSchema": "config.schema.json",
"secretSchema": "secret.schema.json",
"sdk": {
"cli": {
"commands": {
"Chaitin_COSMOS.Chaitin_COSMOS/SearchLogInfo": {
"name": "search-log-info",
"description": "Get Cosmos log detail by IDs."
},
"Chaitin_COSMOS.Chaitin_COSMOS/SearchLogList": {
"name": "search-log-list",
"description": "Search Cosmos log list with filters."
},
"Chaitin_COSMOS.Chaitin_COSMOS/SearchAggregationStatistics": {
"name": "search-aggregation-statistics",
"description": "Get Cosmos log aggregation statistics."
}
}
}
}
}
Loading