kubiya-control-plane-api 0.1.0__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kubiya-control-plane-api might be problematic. Click here for more details.
- control_plane_api/README.md +266 -0
- control_plane_api/__init__.py +0 -0
- control_plane_api/__version__.py +1 -0
- control_plane_api/alembic/README +1 -0
- control_plane_api/alembic/env.py +98 -0
- control_plane_api/alembic/script.py.mako +28 -0
- control_plane_api/alembic/versions/1382bec74309_initial_migration_with_all_models.py +251 -0
- control_plane_api/alembic/versions/1f54bc2a37e3_add_analytics_tables.py +162 -0
- control_plane_api/alembic/versions/2e4cb136dc10_rename_toolset_ids_to_skill_ids_in_teams.py +30 -0
- control_plane_api/alembic/versions/31cd69a644ce_add_skill_templates_table.py +28 -0
- control_plane_api/alembic/versions/89e127caa47d_add_jobs_and_job_executions_tables.py +161 -0
- control_plane_api/alembic/versions/add_llm_models_table.py +51 -0
- control_plane_api/alembic/versions/b0e10697f212_add_runtime_column_to_teams_simple.py +42 -0
- control_plane_api/alembic/versions/ce43b24b63bf_add_execution_trigger_source_and_fix_.py +155 -0
- control_plane_api/alembic/versions/d4eaf16e3f8d_rename_toolsets_to_skills.py +84 -0
- control_plane_api/alembic/versions/efa2dc427da1_rename_metadata_to_custom_metadata.py +32 -0
- control_plane_api/alembic/versions/f973b431d1ce_add_workflow_executor_to_skill_types.py +44 -0
- control_plane_api/alembic.ini +148 -0
- control_plane_api/api/index.py +12 -0
- control_plane_api/app/__init__.py +11 -0
- control_plane_api/app/activities/__init__.py +20 -0
- control_plane_api/app/activities/agent_activities.py +379 -0
- control_plane_api/app/activities/team_activities.py +410 -0
- control_plane_api/app/activities/temporal_cloud_activities.py +577 -0
- control_plane_api/app/config/__init__.py +35 -0
- control_plane_api/app/config/api_config.py +354 -0
- control_plane_api/app/config/model_pricing.py +318 -0
- control_plane_api/app/config.py +95 -0
- control_plane_api/app/database.py +135 -0
- control_plane_api/app/exceptions.py +408 -0
- control_plane_api/app/lib/__init__.py +11 -0
- control_plane_api/app/lib/job_executor.py +312 -0
- control_plane_api/app/lib/kubiya_client.py +235 -0
- control_plane_api/app/lib/litellm_pricing.py +166 -0
- control_plane_api/app/lib/planning_tools/__init__.py +22 -0
- control_plane_api/app/lib/planning_tools/agents.py +155 -0
- control_plane_api/app/lib/planning_tools/base.py +189 -0
- control_plane_api/app/lib/planning_tools/environments.py +214 -0
- control_plane_api/app/lib/planning_tools/resources.py +240 -0
- control_plane_api/app/lib/planning_tools/teams.py +198 -0
- control_plane_api/app/lib/policy_enforcer_client.py +939 -0
- control_plane_api/app/lib/redis_client.py +436 -0
- control_plane_api/app/lib/supabase.py +71 -0
- control_plane_api/app/lib/temporal_client.py +138 -0
- control_plane_api/app/lib/validation/__init__.py +20 -0
- control_plane_api/app/lib/validation/runtime_validation.py +287 -0
- control_plane_api/app/main.py +128 -0
- control_plane_api/app/middleware/__init__.py +8 -0
- control_plane_api/app/middleware/auth.py +513 -0
- control_plane_api/app/middleware/exception_handler.py +267 -0
- control_plane_api/app/middleware/rate_limiting.py +384 -0
- control_plane_api/app/middleware/request_id.py +202 -0
- control_plane_api/app/models/__init__.py +27 -0
- control_plane_api/app/models/agent.py +79 -0
- control_plane_api/app/models/analytics.py +206 -0
- control_plane_api/app/models/associations.py +81 -0
- control_plane_api/app/models/environment.py +63 -0
- control_plane_api/app/models/execution.py +93 -0
- control_plane_api/app/models/job.py +179 -0
- control_plane_api/app/models/llm_model.py +75 -0
- control_plane_api/app/models/presence.py +49 -0
- control_plane_api/app/models/project.py +47 -0
- control_plane_api/app/models/session.py +38 -0
- control_plane_api/app/models/team.py +66 -0
- control_plane_api/app/models/workflow.py +55 -0
- control_plane_api/app/policies/README.md +121 -0
- control_plane_api/app/policies/approved_users.rego +62 -0
- control_plane_api/app/policies/business_hours.rego +51 -0
- control_plane_api/app/policies/rate_limiting.rego +100 -0
- control_plane_api/app/policies/tool_restrictions.rego +86 -0
- control_plane_api/app/routers/__init__.py +4 -0
- control_plane_api/app/routers/agents.py +364 -0
- control_plane_api/app/routers/agents_v2.py +1260 -0
- control_plane_api/app/routers/analytics.py +1014 -0
- control_plane_api/app/routers/context_manager.py +562 -0
- control_plane_api/app/routers/environment_context.py +270 -0
- control_plane_api/app/routers/environments.py +715 -0
- control_plane_api/app/routers/execution_environment.py +517 -0
- control_plane_api/app/routers/executions.py +1911 -0
- control_plane_api/app/routers/health.py +92 -0
- control_plane_api/app/routers/health_v2.py +326 -0
- control_plane_api/app/routers/integrations.py +274 -0
- control_plane_api/app/routers/jobs.py +1344 -0
- control_plane_api/app/routers/models.py +82 -0
- control_plane_api/app/routers/models_v2.py +361 -0
- control_plane_api/app/routers/policies.py +639 -0
- control_plane_api/app/routers/presence.py +234 -0
- control_plane_api/app/routers/projects.py +902 -0
- control_plane_api/app/routers/runners.py +379 -0
- control_plane_api/app/routers/runtimes.py +172 -0
- control_plane_api/app/routers/secrets.py +155 -0
- control_plane_api/app/routers/skills.py +1001 -0
- control_plane_api/app/routers/skills_definitions.py +140 -0
- control_plane_api/app/routers/task_planning.py +1256 -0
- control_plane_api/app/routers/task_queues.py +654 -0
- control_plane_api/app/routers/team_context.py +270 -0
- control_plane_api/app/routers/teams.py +1400 -0
- control_plane_api/app/routers/worker_queues.py +1545 -0
- control_plane_api/app/routers/workers.py +935 -0
- control_plane_api/app/routers/workflows.py +204 -0
- control_plane_api/app/runtimes/__init__.py +6 -0
- control_plane_api/app/runtimes/validation.py +344 -0
- control_plane_api/app/schemas/job_schemas.py +295 -0
- control_plane_api/app/services/__init__.py +1 -0
- control_plane_api/app/services/agno_service.py +619 -0
- control_plane_api/app/services/litellm_service.py +190 -0
- control_plane_api/app/services/policy_service.py +525 -0
- control_plane_api/app/services/temporal_cloud_provisioning.py +150 -0
- control_plane_api/app/skills/__init__.py +44 -0
- control_plane_api/app/skills/base.py +229 -0
- control_plane_api/app/skills/business_intelligence.py +189 -0
- control_plane_api/app/skills/data_visualization.py +154 -0
- control_plane_api/app/skills/docker.py +104 -0
- control_plane_api/app/skills/file_generation.py +94 -0
- control_plane_api/app/skills/file_system.py +110 -0
- control_plane_api/app/skills/python.py +92 -0
- control_plane_api/app/skills/registry.py +65 -0
- control_plane_api/app/skills/shell.py +102 -0
- control_plane_api/app/skills/workflow_executor.py +469 -0
- control_plane_api/app/utils/workflow_executor.py +354 -0
- control_plane_api/app/workflows/__init__.py +11 -0
- control_plane_api/app/workflows/agent_execution.py +507 -0
- control_plane_api/app/workflows/agent_execution_with_skills.py +222 -0
- control_plane_api/app/workflows/namespace_provisioning.py +326 -0
- control_plane_api/app/workflows/team_execution.py +399 -0
- control_plane_api/scripts/seed_models.py +239 -0
- control_plane_api/worker/__init__.py +0 -0
- control_plane_api/worker/activities/__init__.py +0 -0
- control_plane_api/worker/activities/agent_activities.py +1241 -0
- control_plane_api/worker/activities/approval_activities.py +234 -0
- control_plane_api/worker/activities/runtime_activities.py +388 -0
- control_plane_api/worker/activities/skill_activities.py +267 -0
- control_plane_api/worker/activities/team_activities.py +1217 -0
- control_plane_api/worker/config/__init__.py +31 -0
- control_plane_api/worker/config/worker_config.py +275 -0
- control_plane_api/worker/control_plane_client.py +529 -0
- control_plane_api/worker/examples/analytics_integration_example.py +362 -0
- control_plane_api/worker/models/__init__.py +1 -0
- control_plane_api/worker/models/inputs.py +89 -0
- control_plane_api/worker/runtimes/__init__.py +31 -0
- control_plane_api/worker/runtimes/base.py +789 -0
- control_plane_api/worker/runtimes/claude_code_runtime.py +1443 -0
- control_plane_api/worker/runtimes/default_runtime.py +617 -0
- control_plane_api/worker/runtimes/factory.py +173 -0
- control_plane_api/worker/runtimes/validation.py +93 -0
- control_plane_api/worker/services/__init__.py +1 -0
- control_plane_api/worker/services/agent_executor.py +422 -0
- control_plane_api/worker/services/agent_executor_v2.py +383 -0
- control_plane_api/worker/services/analytics_collector.py +457 -0
- control_plane_api/worker/services/analytics_service.py +464 -0
- control_plane_api/worker/services/approval_tools.py +310 -0
- control_plane_api/worker/services/approval_tools_agno.py +207 -0
- control_plane_api/worker/services/cancellation_manager.py +177 -0
- control_plane_api/worker/services/data_visualization.py +827 -0
- control_plane_api/worker/services/jira_tools.py +257 -0
- control_plane_api/worker/services/runtime_analytics.py +328 -0
- control_plane_api/worker/services/session_service.py +194 -0
- control_plane_api/worker/services/skill_factory.py +175 -0
- control_plane_api/worker/services/team_executor.py +574 -0
- control_plane_api/worker/services/team_executor_v2.py +465 -0
- control_plane_api/worker/services/workflow_executor_tools.py +1418 -0
- control_plane_api/worker/tests/__init__.py +1 -0
- control_plane_api/worker/tests/e2e/__init__.py +0 -0
- control_plane_api/worker/tests/e2e/test_execution_flow.py +571 -0
- control_plane_api/worker/tests/integration/__init__.py +0 -0
- control_plane_api/worker/tests/integration/test_control_plane_integration.py +308 -0
- control_plane_api/worker/tests/unit/__init__.py +0 -0
- control_plane_api/worker/tests/unit/test_control_plane_client.py +401 -0
- control_plane_api/worker/utils/__init__.py +1 -0
- control_plane_api/worker/utils/chunk_batcher.py +305 -0
- control_plane_api/worker/utils/retry_utils.py +60 -0
- control_plane_api/worker/utils/streaming_utils.py +373 -0
- control_plane_api/worker/worker.py +753 -0
- control_plane_api/worker/workflows/__init__.py +0 -0
- control_plane_api/worker/workflows/agent_execution.py +589 -0
- control_plane_api/worker/workflows/team_execution.py +429 -0
- kubiya_control_plane_api-0.3.4.dist-info/METADATA +229 -0
- kubiya_control_plane_api-0.3.4.dist-info/RECORD +182 -0
- kubiya_control_plane_api-0.3.4.dist-info/entry_points.txt +2 -0
- kubiya_control_plane_api-0.3.4.dist-info/top_level.txt +1 -0
- kubiya_control_plane_api-0.1.0.dist-info/METADATA +0 -66
- kubiya_control_plane_api-0.1.0.dist-info/RECORD +0 -5
- kubiya_control_plane_api-0.1.0.dist-info/top_level.txt +0 -1
- {kubiya_control_plane_api-0.1.0.dist-info/licenses → control_plane_api}/LICENSE +0 -0
- {kubiya_control_plane_api-0.1.0.dist-info → kubiya_control_plane_api-0.3.4.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Policy Modules for Agent Control Plane
|
|
2
|
+
|
|
3
|
+
This directory contains pre-built OPA (Open Policy Agent) policy modules written in Rego for common agent control plane operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Policies are stored and evaluated in the OPA Watchdog Enforcer Service. These modules provide templates and examples for:
|
|
8
|
+
|
|
9
|
+
- **Execution Policies**: Control when and how agents can execute
|
|
10
|
+
- **Resource Policies**: Limit resource usage and access
|
|
11
|
+
- **Time-based Policies**: Business hours and rate limiting
|
|
12
|
+
- **Tool Policies**: Control which tools agents can use
|
|
13
|
+
- **Team Policies**: Collaboration and approval workflows
|
|
14
|
+
|
|
15
|
+
## Policy Structure
|
|
16
|
+
|
|
17
|
+
All policies follow this structure:
|
|
18
|
+
|
|
19
|
+
```rego
|
|
20
|
+
package <policy_name>
|
|
21
|
+
|
|
22
|
+
# Default decision (deny by default)
|
|
23
|
+
default allow = false
|
|
24
|
+
|
|
25
|
+
# Rules that grant permissions
|
|
26
|
+
allow {
|
|
27
|
+
# conditions
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Violations that explain why requests are denied
|
|
31
|
+
violations[msg] {
|
|
32
|
+
# condition
|
|
33
|
+
msg := "Explanation"
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Policy Priority and Inheritance
|
|
38
|
+
|
|
39
|
+
Policies are associated with entities (agents, teams, environments) with automatic inheritance:
|
|
40
|
+
|
|
41
|
+
1. **Environment** policies (priority: 300) - apply to all agents/teams in the environment
|
|
42
|
+
2. **Team** policies (priority: 200) - apply to all agents in the team
|
|
43
|
+
3. **Agent** policies (priority: 100) - apply to specific agent
|
|
44
|
+
|
|
45
|
+
When the same policy is defined at multiple levels, **higher priority wins**.
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### 1. Create a Policy
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
curl -X POST https://your-control-plane.com/api/v1/policies \
|
|
53
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
54
|
+
-H "Content-Type: application/json" \
|
|
55
|
+
-d '{
|
|
56
|
+
"name": "business-hours-only",
|
|
57
|
+
"policy_content": "<rego_policy>",
|
|
58
|
+
"description": "Allow executions only during business hours",
|
|
59
|
+
"enabled": true,
|
|
60
|
+
"tags": ["time", "compliance"]
|
|
61
|
+
}'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Associate with Entity
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -X POST https://your-control-plane.com/api/v1/policies/associations \
|
|
68
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
69
|
+
-H "Content-Type: application/json" \
|
|
70
|
+
-d '{
|
|
71
|
+
"policy_id": "<policy_uuid>",
|
|
72
|
+
"policy_name": "business-hours-only",
|
|
73
|
+
"entity_type": "environment",
|
|
74
|
+
"entity_id": "<environment_uuid>",
|
|
75
|
+
"enabled": true
|
|
76
|
+
}'
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. Evaluate Policy
|
|
80
|
+
|
|
81
|
+
Policies are automatically evaluated during agent execution. You can also test manually:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
curl -X POST https://your-control-plane.com/api/v1/policies/evaluate/agent/<agent_id> \
|
|
85
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
86
|
+
-H "Content-Type: application/json" \
|
|
87
|
+
-d '{
|
|
88
|
+
"input_data": {
|
|
89
|
+
"action": "execute",
|
|
90
|
+
"user": "alice@company.com",
|
|
91
|
+
"time": "2025-01-15T14:30:00Z"
|
|
92
|
+
}
|
|
93
|
+
}'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Available Policy Modules
|
|
97
|
+
|
|
98
|
+
See individual `.rego` files for detailed policies:
|
|
99
|
+
|
|
100
|
+
- `business_hours.rego` - Restrict executions to business hours
|
|
101
|
+
- `approved_users.rego` - Require user approval list
|
|
102
|
+
- `rate_limiting.rego` - Limit execution frequency
|
|
103
|
+
- `resource_limits.rego` - Enforce resource quotas
|
|
104
|
+
- `tool_restrictions.rego` - Control tool usage
|
|
105
|
+
- `approval_workflow.rego` - Require approvals for sensitive actions
|
|
106
|
+
- `environment_restrictions.rego` - Restrict access to environments
|
|
107
|
+
|
|
108
|
+
## Policy Development Tips
|
|
109
|
+
|
|
110
|
+
1. **Test policies locally** using OPA CLI before deploying
|
|
111
|
+
2. **Start with deny-by-default** for security
|
|
112
|
+
3. **Use clear violation messages** for debugging
|
|
113
|
+
4. **Document assumptions** in policy comments
|
|
114
|
+
5. **Version policies** using tags or metadata
|
|
115
|
+
6. **Test edge cases** thoroughly
|
|
116
|
+
|
|
117
|
+
## References
|
|
118
|
+
|
|
119
|
+
- [OPA Documentation](https://www.openpolicyagent.org/docs/latest/)
|
|
120
|
+
- [Rego Language Reference](https://www.openpolicyagent.org/docs/latest/policy-reference/)
|
|
121
|
+
- [OPA Watchdog Enforcer API](https://enforcer-psi.vercel.app/api/docs)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Approved Users Policy
|
|
2
|
+
# Only allows executions from a whitelist of approved users
|
|
3
|
+
|
|
4
|
+
package approved_users
|
|
5
|
+
|
|
6
|
+
import future.keywords.if
|
|
7
|
+
import future.keywords.in
|
|
8
|
+
|
|
9
|
+
# Default deny
|
|
10
|
+
default allow = false
|
|
11
|
+
|
|
12
|
+
# List of approved users (emails)
|
|
13
|
+
# This can be customized per organization or pulled from metadata
|
|
14
|
+
approved_user_list := {
|
|
15
|
+
"admin@company.com",
|
|
16
|
+
"devops@company.com",
|
|
17
|
+
"alice@company.com",
|
|
18
|
+
"bob@company.com"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Allow if user is in the approved list
|
|
22
|
+
allow if {
|
|
23
|
+
input.user in approved_user_list
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Also allow if user email domain is approved
|
|
27
|
+
allow if {
|
|
28
|
+
user_email := input.user
|
|
29
|
+
contains(user_email, "@")
|
|
30
|
+
domain := split(user_email, "@")[1]
|
|
31
|
+
domain in approved_domains
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Approved email domains
|
|
35
|
+
approved_domains := {
|
|
36
|
+
"company.com",
|
|
37
|
+
"trusted-partner.com"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# Violations
|
|
41
|
+
violations[msg] if {
|
|
42
|
+
not input.user in approved_user_list
|
|
43
|
+
user_email := input.user
|
|
44
|
+
contains(user_email, "@")
|
|
45
|
+
domain := split(user_email, "@")[1]
|
|
46
|
+
not domain in approved_domains
|
|
47
|
+
msg := sprintf("User '%v' is not in the approved user list or approved domain", [input.user])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
violations[msg] if {
|
|
51
|
+
not input.user
|
|
52
|
+
msg := "No user specified in the request"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Metadata
|
|
56
|
+
metadata := {
|
|
57
|
+
"name": "approved-users-only",
|
|
58
|
+
"description": "Only allow executions from approved users or domains",
|
|
59
|
+
"version": "1.0.0",
|
|
60
|
+
"author": "Kubiya",
|
|
61
|
+
"tags": ["security", "access-control", "users"]
|
|
62
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Business Hours Policy
|
|
2
|
+
# Restricts agent executions to business hours (9 AM - 5 PM, Monday-Friday)
|
|
3
|
+
|
|
4
|
+
package business_hours
|
|
5
|
+
|
|
6
|
+
import future.keywords.if
|
|
7
|
+
import future.keywords.in
|
|
8
|
+
|
|
9
|
+
# Default deny
|
|
10
|
+
default allow = false
|
|
11
|
+
|
|
12
|
+
# Allow executions during business hours
|
|
13
|
+
allow if {
|
|
14
|
+
is_business_hours
|
|
15
|
+
not is_weekend
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# Check if current time is within business hours (9 AM - 5 PM)
|
|
19
|
+
is_business_hours if {
|
|
20
|
+
time_hour := time.parse_rfc3339_ns(input.time)
|
|
21
|
+
hour := time.clock(time_hour)[0]
|
|
22
|
+
hour >= 9
|
|
23
|
+
hour < 17
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Check if current day is a weekend
|
|
27
|
+
is_weekend if {
|
|
28
|
+
time_day := time.parse_rfc3339_ns(input.time)
|
|
29
|
+
weekday := time.weekday(time_day)
|
|
30
|
+
weekday in ["Saturday", "Sunday"]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Violations
|
|
34
|
+
violations[msg] if {
|
|
35
|
+
not is_business_hours
|
|
36
|
+
msg := sprintf("Execution requested outside business hours (9 AM - 5 PM). Current time: %v", [input.time])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
violations[msg] if {
|
|
40
|
+
is_weekend
|
|
41
|
+
msg := sprintf("Execution requested on weekend. Current day: %v", [time.weekday(time.parse_rfc3339_ns(input.time))])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Metadata
|
|
45
|
+
metadata := {
|
|
46
|
+
"name": "business-hours-only",
|
|
47
|
+
"description": "Restrict agent executions to business hours (9 AM - 5 PM, Monday-Friday)",
|
|
48
|
+
"version": "1.0.0",
|
|
49
|
+
"author": "Kubiya",
|
|
50
|
+
"tags": ["time", "compliance", "business-hours"]
|
|
51
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Rate Limiting Policy
|
|
2
|
+
# Limits the number of executions per user/agent within a time window
|
|
3
|
+
|
|
4
|
+
package rate_limiting
|
|
5
|
+
|
|
6
|
+
import future.keywords.if
|
|
7
|
+
import future.keywords.in
|
|
8
|
+
|
|
9
|
+
# Default deny
|
|
10
|
+
default allow = false
|
|
11
|
+
|
|
12
|
+
# Maximum executions per hour per user
|
|
13
|
+
max_executions_per_hour := 100
|
|
14
|
+
|
|
15
|
+
# Maximum executions per hour per agent
|
|
16
|
+
max_agent_executions_per_hour := 50
|
|
17
|
+
|
|
18
|
+
# Maximum concurrent executions per user
|
|
19
|
+
max_concurrent_executions := 5
|
|
20
|
+
|
|
21
|
+
# Allow if under user rate limit
|
|
22
|
+
allow if {
|
|
23
|
+
input.user
|
|
24
|
+
input.executions_last_hour < max_executions_per_hour
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Allow if under agent rate limit
|
|
28
|
+
allow if {
|
|
29
|
+
input.agent_id
|
|
30
|
+
input.agent_executions_last_hour < max_agent_executions_per_hour
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Allow if under concurrent execution limit
|
|
34
|
+
allow if {
|
|
35
|
+
input.user
|
|
36
|
+
input.concurrent_executions < max_concurrent_executions
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Special handling for admin users (higher limits)
|
|
40
|
+
allow if {
|
|
41
|
+
is_admin_user
|
|
42
|
+
input.executions_last_hour < (max_executions_per_hour * 2)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Check if user is admin
|
|
46
|
+
is_admin_user if {
|
|
47
|
+
input.user
|
|
48
|
+
contains(input.user, "admin@")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
is_admin_user if {
|
|
52
|
+
input.user_role == "admin"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Violations
|
|
56
|
+
violations[msg] if {
|
|
57
|
+
input.user
|
|
58
|
+
input.executions_last_hour >= max_executions_per_hour
|
|
59
|
+
not is_admin_user
|
|
60
|
+
msg := sprintf("User '%v' has exceeded rate limit: %v executions in the last hour (max: %v)", [
|
|
61
|
+
input.user,
|
|
62
|
+
input.executions_last_hour,
|
|
63
|
+
max_executions_per_hour
|
|
64
|
+
])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
violations[msg] if {
|
|
68
|
+
input.agent_id
|
|
69
|
+
input.agent_executions_last_hour >= max_agent_executions_per_hour
|
|
70
|
+
msg := sprintf("Agent '%v' has exceeded rate limit: %v executions in the last hour (max: %v)", [
|
|
71
|
+
input.agent_id,
|
|
72
|
+
input.agent_executions_last_hour,
|
|
73
|
+
max_agent_executions_per_hour
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
violations[msg] if {
|
|
78
|
+
input.user
|
|
79
|
+
input.concurrent_executions >= max_concurrent_executions
|
|
80
|
+
msg := sprintf("User '%v' has too many concurrent executions: %v (max: %v)", [
|
|
81
|
+
input.user,
|
|
82
|
+
input.concurrent_executions,
|
|
83
|
+
max_concurrent_executions
|
|
84
|
+
])
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
violations[msg] if {
|
|
88
|
+
not input.user
|
|
89
|
+
not input.agent_id
|
|
90
|
+
msg := "No user or agent_id specified for rate limiting check"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# Metadata
|
|
94
|
+
metadata := {
|
|
95
|
+
"name": "rate-limiting",
|
|
96
|
+
"description": "Limit execution frequency per user and agent to prevent abuse",
|
|
97
|
+
"version": "1.0.0",
|
|
98
|
+
"author": "Kubiya",
|
|
99
|
+
"tags": ["security", "rate-limiting", "quota"]
|
|
100
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Tool Restrictions Policy
|
|
2
|
+
# Controls which tools agents can use, with different restrictions per environment
|
|
3
|
+
|
|
4
|
+
package tool_restrictions
|
|
5
|
+
|
|
6
|
+
import future.keywords.if
|
|
7
|
+
import future.keywords.in
|
|
8
|
+
|
|
9
|
+
# Default deny
|
|
10
|
+
default allow = false
|
|
11
|
+
|
|
12
|
+
# Dangerous tools that require explicit approval
|
|
13
|
+
dangerous_tools := {
|
|
14
|
+
"docker",
|
|
15
|
+
"shell",
|
|
16
|
+
"file_system"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Production-safe tools
|
|
20
|
+
production_safe_tools := {
|
|
21
|
+
"python",
|
|
22
|
+
"sleep",
|
|
23
|
+
"file_generation"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Development environment - allow all tools
|
|
27
|
+
allow if {
|
|
28
|
+
input.environment == "development"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Staging environment - allow non-dangerous tools
|
|
32
|
+
allow if {
|
|
33
|
+
input.environment == "staging"
|
|
34
|
+
input.tool
|
|
35
|
+
not input.tool in dangerous_tools
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Production environment - only allow production-safe tools
|
|
39
|
+
allow if {
|
|
40
|
+
input.environment == "production"
|
|
41
|
+
input.tool in production_safe_tools
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Allow dangerous tools in production with explicit approval
|
|
45
|
+
allow if {
|
|
46
|
+
input.environment == "production"
|
|
47
|
+
input.tool in dangerous_tools
|
|
48
|
+
input.approved_by
|
|
49
|
+
input.approval_id
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Violations
|
|
53
|
+
violations[msg] if {
|
|
54
|
+
input.environment == "production"
|
|
55
|
+
input.tool in dangerous_tools
|
|
56
|
+
not input.approved_by
|
|
57
|
+
msg := sprintf("Tool '%v' requires approval in production environment", [input.tool])
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
violations[msg] if {
|
|
61
|
+
input.environment == "staging"
|
|
62
|
+
input.tool in dangerous_tools
|
|
63
|
+
msg := sprintf("Dangerous tool '%v' not allowed in staging environment", [input.tool])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
violations[msg] if {
|
|
67
|
+
input.environment == "production"
|
|
68
|
+
input.tool
|
|
69
|
+
not input.tool in production_safe_tools
|
|
70
|
+
not input.approved_by
|
|
71
|
+
msg := sprintf("Tool '%v' not allowed in production without approval", [input.tool])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
violations[msg] if {
|
|
75
|
+
not input.tool
|
|
76
|
+
msg := "No tool specified in the request"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Metadata
|
|
80
|
+
metadata := {
|
|
81
|
+
"name": "tool-restrictions",
|
|
82
|
+
"description": "Control which tools agents can use based on environment and approval status",
|
|
83
|
+
"version": "1.0.0",
|
|
84
|
+
"author": "Kubiya",
|
|
85
|
+
"tags": ["security", "tools", "environment"]
|
|
86
|
+
}
|