@macaw-ai/client 0.0.0-stage → 0.9.11
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.
- package/LICENSE.md +339 -0
- package/bin/install.js +422 -0
- package/package.json +37 -4
- package/payload/README.md +56 -0
- package/payload/secureAI/LICENSE +190 -0
- package/payload/secureAI/NOTICE +5 -0
- package/payload/secureAI/demos/policy-controls/1_uncontrolled.py +139 -0
- package/payload/secureAI/demos/policy-controls/2_with_macaw.py +139 -0
- package/payload/secureAI/demos/policy-controls/3_with_user_policies.py +162 -0
- package/payload/secureAI/demos/policy-controls/credentials.txt +12 -0
- package/payload/secureAI/demos/policy-controls/malicious_report.txt +21 -0
- package/payload/secureAI/demos/policy-controls/sales_report.txt +20 -0
- package/payload/secureAI/demos/tutorial-1-rbac/README.md +143 -0
- package/payload/secureAI/demos/tutorial-1-rbac/app.py +147 -0
- package/payload/secureAI/demos/tutorial-1-rbac/authprompts_demo.py +306 -0
- package/payload/secureAI/demos/tutorial-1-rbac/config/claims-config.yaml +152 -0
- package/payload/secureAI/demos/tutorial-1-rbac/demo_secureopenai_with_policies.py +150 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/bu_Analytics.json +8 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/company_FinTech_Corp.json +70 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/llm-base.json +69 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/team_Reporting.json +8 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/user_alice.json +32 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/user_bob.json +28 -0
- package/payload/secureAI/demos/tutorial-1-rbac/policies/user_carol.json +34 -0
- package/payload/secureAI/demos/tutorial-1-rbac/requirements.txt +6 -0
- package/payload/secureAI/demos/tutorial-1-rbac/setup/auth0_complete_setup.sh +392 -0
- package/payload/secureAI/demos/tutorial-1-rbac/setup/keycloak_complete_setup.sh +320 -0
- package/payload/secureAI/demos/tutorial-2-intent/Policies/alation-remote-proxy.json +155 -0
- package/payload/secureAI/demos/tutorial-2-intent/Policies/bu.json +22 -0
- package/payload/secureAI/demos/tutorial-2-intent/Policies/company.json +17 -0
- package/payload/secureAI/demos/tutorial-2-intent/Policies/user_alice.json +48 -0
- package/payload/secureAI/demos/tutorial-2-intent/Policies/user_bob.json +83 -0
- package/payload/secureAI/demos/tutorial-2-intent/README.md +213 -0
- package/payload/secureAI/demos/tutorial-2-intent/script.py +188 -0
- package/payload/secureAI/demos/tutorial-2-intent/setup/alation_verifier.py +177 -0
- package/payload/secureAI/demos/tutorial-2-intent/setup/get_alation_user_token.py +180 -0
- package/payload/secureAI/examples/README.md +244 -0
- package/payload/secureAI/examples/anthropic/anthropic_1a_dropin_simple.py +103 -0
- package/payload/secureAI/examples/anthropic/anthropic_1b_multiuser_bind.py +190 -0
- package/payload/secureAI/examples/anthropic/anthropic_1b_multiuser_bind_streaming.py +190 -0
- package/payload/secureAI/examples/anthropic/anthropic_1c_a2a_invoke.py +156 -0
- package/payload/secureAI/examples/attestations/1a_trade_alice.py +215 -0
- package/payload/secureAI/examples/attestations/1a_trade_bob.py +164 -0
- package/payload/secureAI/examples/attestations/1b_grant_admin.py +170 -0
- package/payload/secureAI/examples/attestations/1b_grant_researcher.py +231 -0
- package/payload/secureAI/examples/attestations/README.md +128 -0
- package/payload/secureAI/examples/langchain/langchain_1a_dropin_simple.py +199 -0
- package/payload/secureAI/examples/langchain/langchain_1b_multiuser.py +262 -0
- package/payload/secureAI/examples/langchain/langchain_1c_orchestration.py +332 -0
- package/payload/secureAI/examples/langchain/langchain_1d_llm_openai.py +130 -0
- package/payload/secureAI/examples/langchain/langchain_1e_llm_anthropic.py +130 -0
- package/payload/secureAI/examples/langchain/langchain_1f_memory.py +214 -0
- package/payload/secureAI/examples/litellm/litellm_1a_dropin_simple.py +131 -0
- package/payload/secureAI/examples/mcp/1a_simple_invocation.py +115 -0
- package/payload/secureAI/examples/mcp/1b_discovery_and_resources.py +142 -0
- package/payload/secureAI/examples/mcp/1c_logging_client.py +100 -0
- package/payload/secureAI/examples/mcp/1d_progress_client.py +100 -0
- package/payload/secureAI/examples/mcp/1e_sampling_client.py +150 -0
- package/payload/secureAI/examples/mcp/1e_sampling_server.py +90 -0
- package/payload/secureAI/examples/mcp/1f_elicitation_client.py +127 -0
- package/payload/secureAI/examples/mcp/1f_elicitation_server.py +73 -0
- package/payload/secureAI/examples/mcp/1g_roots_client.py +122 -0
- package/payload/secureAI/examples/mcp/1g_roots_server.py +85 -0
- package/payload/secureAI/examples/mcp/2a_proxy_snowflake.py +212 -0
- package/payload/secureAI/examples/mcp/2b_proxy_databricks.py +299 -0
- package/payload/secureAI/examples/mcp/2c_proxy_stdio_fetch.py +91 -0
- package/payload/secureAI/examples/mcp/2d_proxy_stdio_salesforce.py +119 -0
- package/payload/secureAI/examples/mcp/2e_proxy_multiuser.py +136 -0
- package/payload/secureAI/examples/mcp/2f_proxy_stdio_databricks.py +144 -0
- package/payload/secureAI/examples/mcp/3a_native_mcp_client.py +104 -0
- package/payload/secureAI/examples/mcp/3b_native_mcp_proxy.py +114 -0
- package/payload/secureAI/examples/mcp/3c_native_mcp_sampling.py +180 -0
- package/payload/secureAI/examples/mcp/3d_native_mcp_2026.py +135 -0
- package/payload/secureAI/examples/mcp/securemcp_calculator.py +248 -0
- package/payload/secureAI/examples/mcp/securemcp_server.py +75 -0
- package/payload/secureAI/examples/openai/openai_1a_dropin_simple.py +102 -0
- package/payload/secureAI/examples/openai/openai_1b_multiuser_bind.py +193 -0
- package/payload/secureAI/examples/openai/openai_1b_multiuser_bind_streaming.py +199 -0
- package/payload/secureAI/examples/openai/openai_1c_a2a_invoke.py +156 -0
- package/payload/secureAI/examples/openai/openai_1d_invocation_patterns.py +337 -0
- package/payload/secureAI/examples/phishing-resistance/1a_login_alice.py +180 -0
- package/payload/secureAI/examples/phishing-resistance/1b_trade_alice.py +241 -0
- package/payload/secureAI/examples/phishing-resistance/1b_trade_bob.py +164 -0
- package/payload/secureAI/examples/phishing-resistance/README.md +124 -0
- package/payload/secureAI/examples/phishing-resistance/get_token.py +114 -0
- package/payload/secureAI/examples/pydantic_ai/README.md +88 -0
- package/payload/secureAI/examples/pydantic_ai/policies/app_pydantic-agent.json +10 -0
- package/payload/secureAI/examples/pydantic_ai/pydanticai_1a_dropin_simple.py +90 -0
- package/payload/secureAI/examples/pydantic_ai/pydanticai_1b_model_routing.py +85 -0
- package/payload/secureAI/examples/pydantic_ai/pydanticai_1c_native_tools.py +83 -0
- package/payload/secureAI/examples/pydantic_ai/pydanticai_1d_multiuser_bind.py +104 -0
- package/payload/secureAI/examples/pydantic_ai/pydanticai_1e_mcp_compose.py +92 -0
- package/payload/secureAI/macaw_adapters/__init__.py +55 -0
- package/payload/secureAI/macaw_adapters/anthropic/REFERENCE.md +374 -0
- package/payload/secureAI/macaw_adapters/anthropic/__init__.py +22 -0
- package/payload/secureAI/macaw_adapters/anthropic/secure_anthropic.py +792 -0
- package/payload/secureAI/macaw_adapters/anthropic_ext_tools/__init__.py +25 -0
- package/payload/secureAI/macaw_adapters/anthropic_ext_tools/secure_anthropic.py +840 -0
- package/payload/secureAI/macaw_adapters/langchain/REFERENCE.md +234 -0
- package/payload/secureAI/macaw_adapters/langchain/__init__.py +100 -0
- package/payload/secureAI/macaw_adapters/langchain/_utils.py +83 -0
- package/payload/secureAI/macaw_adapters/langchain/agents.py +296 -0
- package/payload/secureAI/macaw_adapters/langchain/anthropic.py +456 -0
- package/payload/secureAI/macaw_adapters/langchain/callbacks.py +306 -0
- package/payload/secureAI/macaw_adapters/langchain/memory.py +352 -0
- package/payload/secureAI/macaw_adapters/langchain/openai.py +410 -0
- package/payload/secureAI/macaw_adapters/langchain/tools.py +174 -0
- package/payload/secureAI/macaw_adapters/litellm/README.md +216 -0
- package/payload/secureAI/macaw_adapters/litellm/__init__.py +143 -0
- package/payload/secureAI/macaw_adapters/litellm/secure_litellm.py +686 -0
- package/payload/secureAI/macaw_adapters/mcp/REFERENCE.md +460 -0
- package/payload/secureAI/macaw_adapters/mcp/__init__.py +65 -0
- package/payload/secureAI/macaw_adapters/mcp/_endpoint.py +193 -0
- package/payload/secureAI/macaw_adapters/mcp/_endpoint2.py +225 -0
- package/payload/secureAI/macaw_adapters/mcp/_serve.py +25 -0
- package/payload/secureAI/macaw_adapters/mcp/client.py +721 -0
- package/payload/secureAI/macaw_adapters/mcp/decorators.py +228 -0
- package/payload/secureAI/macaw_adapters/mcp/fastmcp_compat.py +353 -0
- package/payload/secureAI/macaw_adapters/mcp/mcp.py +785 -0
- package/payload/secureAI/macaw_adapters/mcp/proxy.py +626 -0
- package/payload/secureAI/macaw_adapters/mcp/server.py +317 -0
- package/payload/secureAI/macaw_adapters/mcp/subscriptions.py +450 -0
- package/payload/secureAI/macaw_adapters/openai/REFERENCE.md +368 -0
- package/payload/secureAI/macaw_adapters/openai/__init__.py +22 -0
- package/payload/secureAI/macaw_adapters/openai/secure_openai.py +833 -0
- package/payload/secureAI/macaw_adapters/openai_ext_tools/REFERENCE.md +368 -0
- package/payload/secureAI/macaw_adapters/openai_ext_tools/__init__.py +25 -0
- package/payload/secureAI/macaw_adapters/openai_ext_tools/secure_openai.py +876 -0
- package/payload/secureAI/macaw_adapters/pydantic_ai/__init__.py +36 -0
- package/payload/secureAI/macaw_adapters/pydantic_ai/_core.py +257 -0
- package/payload/secureAI/macaw_adapters/pydantic_ai/agent.py +218 -0
- package/payload/secureAI/macaw_adapters/pydantic_ai/model.py +99 -0
- package/payload/secureAI/macaw_adapters/pydantic_ai/toolset.py +86 -0
- package/payload/secureAI/test_harness_quick.py +296 -0
- package/wheels/macaw_adapters-0.9.10.1-py3-none-any.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp312-cp312-macosx_11_0_arm64.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp312-cp312-manylinux_2_17_x86_64.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp314-cp314-macosx_11_0_arm64.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp314-cp314-manylinux_2_17_x86_64.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp314-cp314-win_amd64.whl +0 -0
- package/wheels/macaw_client-0.9.10.1-cp39-cp39-macosx_11_0_arm64.whl +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# MACAW Identity Bridge Configuration
|
|
2
|
+
# Universal translator for JWT tokens from any identity provider
|
|
3
|
+
|
|
4
|
+
# MACAW Internal Security Context Model (READ-ONLY - DO NOT MODIFY)
|
|
5
|
+
# These attributes are used by PolicyResolver for hierarchical policy lookup
|
|
6
|
+
internal_model:
|
|
7
|
+
company: "Organization/company for policy hierarchy (maps from organization claim)"
|
|
8
|
+
business_unit: "Department or business unit"
|
|
9
|
+
team: "Team or group"
|
|
10
|
+
user: "User identifier for user-specific policies"
|
|
11
|
+
roles: "User roles for role-based access control"
|
|
12
|
+
email: "User email address"
|
|
13
|
+
|
|
14
|
+
# Identity Provider Configurations
|
|
15
|
+
# Each provider has detection rules, claim mappings, and role processing
|
|
16
|
+
identity_providers:
|
|
17
|
+
keycloak:
|
|
18
|
+
name: "Keycloak (Red Hat SSO)"
|
|
19
|
+
detection:
|
|
20
|
+
iss_pattern: "*realms/*"
|
|
21
|
+
required_claims: ["realm_access"]
|
|
22
|
+
mappings:
|
|
23
|
+
# Core identity fields
|
|
24
|
+
subject_path: "sub"
|
|
25
|
+
email_path: "email"
|
|
26
|
+
name_path: "preferred_username"
|
|
27
|
+
# Organizational hierarchy (organization maps to company)
|
|
28
|
+
organization_path: "organization"
|
|
29
|
+
business_unit_path: "business_unit"
|
|
30
|
+
team_path: "team"
|
|
31
|
+
# Role extraction from Keycloak structure
|
|
32
|
+
roles_path: "realm_access.roles"
|
|
33
|
+
role_filter:
|
|
34
|
+
allowed: ["analyst", "manager", "admin", "viewer"]
|
|
35
|
+
case_sensitive: false
|
|
36
|
+
|
|
37
|
+
azure_ad:
|
|
38
|
+
name: "Azure Active Directory"
|
|
39
|
+
detection:
|
|
40
|
+
iss_pattern: "https://sts.windows.net/*"
|
|
41
|
+
required_claims: ["oid", "tid"]
|
|
42
|
+
mappings:
|
|
43
|
+
# Core identity fields
|
|
44
|
+
subject_path: "oid"
|
|
45
|
+
email_path: "upn"
|
|
46
|
+
name_path: "name"
|
|
47
|
+
# Organizational hierarchy (tid maps to company)
|
|
48
|
+
organization_path: "tid"
|
|
49
|
+
business_unit_path: "department"
|
|
50
|
+
team_path: "jobTitle"
|
|
51
|
+
# Role extraction
|
|
52
|
+
roles_path: "roles"
|
|
53
|
+
role_filter:
|
|
54
|
+
allowed: ["analyst", "manager", "admin", "viewer"]
|
|
55
|
+
case_sensitive: false
|
|
56
|
+
|
|
57
|
+
okta:
|
|
58
|
+
name: "Okta"
|
|
59
|
+
detection:
|
|
60
|
+
iss_pattern: "https://*.okta.com"
|
|
61
|
+
required_claims: ["groups"]
|
|
62
|
+
mappings:
|
|
63
|
+
# Core identity fields
|
|
64
|
+
subject_path: "sub"
|
|
65
|
+
email_path: "email"
|
|
66
|
+
name_path: "name"
|
|
67
|
+
# Organizational hierarchy (org maps to company)
|
|
68
|
+
organization_path: "org"
|
|
69
|
+
business_unit_path: "department"
|
|
70
|
+
team_path: "division"
|
|
71
|
+
# Role extraction from groups
|
|
72
|
+
roles_path: "groups"
|
|
73
|
+
role_filter:
|
|
74
|
+
allowed: ["analysts", "managers", "admins", "viewers"] # Okta often uses plurals
|
|
75
|
+
case_sensitive: false
|
|
76
|
+
# Map Okta group names to standard MACAW roles
|
|
77
|
+
role_mapping:
|
|
78
|
+
analysts: analyst
|
|
79
|
+
managers: manager
|
|
80
|
+
admins: admin
|
|
81
|
+
viewers: viewer
|
|
82
|
+
|
|
83
|
+
auth0:
|
|
84
|
+
name: "Auth0"
|
|
85
|
+
detection:
|
|
86
|
+
iss_pattern: "auth0.com" # Matches any Auth0 issuer (including regional like .us.auth0.com)
|
|
87
|
+
required_claims: [] # Auth0 access tokens use namespaced custom claims
|
|
88
|
+
mappings:
|
|
89
|
+
# Core identity fields (standard OIDC claims)
|
|
90
|
+
subject_path: "sub"
|
|
91
|
+
email_path: "email" # Standard OIDC claim, not namespaced
|
|
92
|
+
name_path: "https://macaw.local/username" # Added by our Action
|
|
93
|
+
# Organizational hierarchy from Auth0 Action custom claims
|
|
94
|
+
organization_path: "https://macaw.local/organization"
|
|
95
|
+
business_unit_path: "https://macaw.local/business_unit"
|
|
96
|
+
team_path: "https://macaw.local/team"
|
|
97
|
+
# Role extraction from Auth0 Action custom claims
|
|
98
|
+
roles_path: "https://macaw.local/roles"
|
|
99
|
+
# Additional MACAW-specific claims for policy enforcement
|
|
100
|
+
tier_path: "https://macaw.local/tier"
|
|
101
|
+
max_tokens_path: "https://macaw.local/max_tokens"
|
|
102
|
+
allowed_models_path: "https://macaw.local/allowed_models"
|
|
103
|
+
role_filter:
|
|
104
|
+
allowed: ["analyst", "manager", "admin", "viewer"]
|
|
105
|
+
case_sensitive: false
|
|
106
|
+
|
|
107
|
+
google_workspace:
|
|
108
|
+
name: "Google Workspace"
|
|
109
|
+
detection:
|
|
110
|
+
iss_pattern: "https://accounts.google.com"
|
|
111
|
+
required_claims: ["hd"]
|
|
112
|
+
mappings:
|
|
113
|
+
# Core identity fields
|
|
114
|
+
subject_path: "sub"
|
|
115
|
+
email_path: "email"
|
|
116
|
+
name_path: "name"
|
|
117
|
+
# Organizational hierarchy (hd = hosted domain maps to company)
|
|
118
|
+
organization_path: "hd"
|
|
119
|
+
business_unit_path: "department"
|
|
120
|
+
team_path: "team"
|
|
121
|
+
# Role extraction
|
|
122
|
+
roles_path: "custom_roles"
|
|
123
|
+
role_filter:
|
|
124
|
+
allowed: ["analyst", "manager", "admin", "viewer"]
|
|
125
|
+
case_sensitive: false
|
|
126
|
+
|
|
127
|
+
# Default fallback for unknown providers
|
|
128
|
+
default:
|
|
129
|
+
name: "Generic JWT Provider"
|
|
130
|
+
mappings:
|
|
131
|
+
subject_path: "sub"
|
|
132
|
+
email_path: "email"
|
|
133
|
+
name_path: "name"
|
|
134
|
+
organization_path: "org"
|
|
135
|
+
business_unit_path: "department"
|
|
136
|
+
team_path: "team"
|
|
137
|
+
roles_path: "roles"
|
|
138
|
+
role_filter:
|
|
139
|
+
allowed: ["analyst", "manager", "admin", "viewer"]
|
|
140
|
+
case_sensitive: false
|
|
141
|
+
|
|
142
|
+
# Security and validation settings
|
|
143
|
+
security:
|
|
144
|
+
require_roles: true
|
|
145
|
+
require_organization: true
|
|
146
|
+
max_token_age_minutes: 60
|
|
147
|
+
|
|
148
|
+
# Audit and logging settings
|
|
149
|
+
audit:
|
|
150
|
+
log_identity_mapping: true
|
|
151
|
+
log_role_filtering: true
|
|
152
|
+
log_provider_detection: true
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
SecureOpenAI Demo with MACAW Policies
|
|
4
|
+
|
|
5
|
+
This demo shows the efficient architecture:
|
|
6
|
+
1. Single SecureOpenAI service agent (created once)
|
|
7
|
+
2. User agents with JWT delegation (automatic embedded_context)
|
|
8
|
+
3. A2A calls from users to service
|
|
9
|
+
4. Policy enforcement at ToolAgent PEP level
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
from macaw_adapters.openai import SecureOpenAI
|
|
16
|
+
from macaw_client import MACAWClient, RemoteIdentityProvider
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# User credentials
|
|
20
|
+
USERS = {
|
|
21
|
+
"alice": "Alice123!",
|
|
22
|
+
"bob": "Bob@123!",
|
|
23
|
+
"carol": "Carol123!",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_user(username: str, password: str, openai_service: SecureOpenAI):
|
|
28
|
+
"""Test what a user can access."""
|
|
29
|
+
print(f"\n{'='*60}")
|
|
30
|
+
print(f"Testing {username.upper()}")
|
|
31
|
+
print("="*60)
|
|
32
|
+
|
|
33
|
+
# 1. Get JWT
|
|
34
|
+
print(f"1. Authenticating...")
|
|
35
|
+
jwt_token, _ = RemoteIdentityProvider().login(username, password)
|
|
36
|
+
print(" OK Got JWT token")
|
|
37
|
+
|
|
38
|
+
# 2. Create user agent with JWT
|
|
39
|
+
print("2. Creating user agent...")
|
|
40
|
+
user = MACAWClient(
|
|
41
|
+
user_name=username,
|
|
42
|
+
iam_token=jwt_token, # Converted to embedded_context automatically!
|
|
43
|
+
agent_type="user",
|
|
44
|
+
app_name="financial-analyzer"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if not user.register():
|
|
48
|
+
print(" FAIL Failed to create user agent")
|
|
49
|
+
return
|
|
50
|
+
print(f" OK User agent: {user.agent_id}")
|
|
51
|
+
|
|
52
|
+
# 3. Test different models and tokens
|
|
53
|
+
tests = [
|
|
54
|
+
("gpt-3.5-turbo", 400, "Quick analysis"),
|
|
55
|
+
("gpt-3.5-turbo", 600, "Detailed analysis"),
|
|
56
|
+
("gpt-4", 1500, "Deep analysis"),
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
print(f"\n3. Testing OpenAI access via A2A to service {openai_service.server_id}:")
|
|
60
|
+
for model, max_tokens, query in tests:
|
|
61
|
+
print(f"\n -> {model} with {max_tokens} tokens")
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
# A2A call to single service agent
|
|
65
|
+
result = user.invoke_tool(
|
|
66
|
+
tool_name="tool:openai-service/generate", # MAPL-compliant resource name
|
|
67
|
+
parameters={
|
|
68
|
+
"model": model,
|
|
69
|
+
"max_tokens": max_tokens,
|
|
70
|
+
"messages": [
|
|
71
|
+
{"role": "system", "content": "You are a financial analyst."},
|
|
72
|
+
{"role": "user", "content": query}
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
target_agent=openai_service.server_id # Same service for all users!
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Check if we got a valid response
|
|
79
|
+
if isinstance(result, dict):
|
|
80
|
+
if "error" in result:
|
|
81
|
+
print(f" FAIL Failed: {result['error']}")
|
|
82
|
+
elif "choices" in result:
|
|
83
|
+
print(f" PASS SUCCESS")
|
|
84
|
+
print(f" Model: {result.get('model')}")
|
|
85
|
+
content = result.get('choices', [{}])[0].get('message', {}).get('content', '')
|
|
86
|
+
print(f" Response: {content[:80]}...")
|
|
87
|
+
else:
|
|
88
|
+
print(f" FAIL Unexpected response: {result}")
|
|
89
|
+
else:
|
|
90
|
+
print(f" FAIL Invalid response type: {type(result)}")
|
|
91
|
+
|
|
92
|
+
except Exception as e:
|
|
93
|
+
error = str(e)
|
|
94
|
+
if "not in allowed" in error or "not permitted" in error or "policy" in error.lower():
|
|
95
|
+
print(f" BLOCKED by policy")
|
|
96
|
+
elif "max_tokens" in error:
|
|
97
|
+
print(f" BLOCKED: Exceeds token limit")
|
|
98
|
+
elif "model" in error:
|
|
99
|
+
print(f" BLOCKED: Model not allowed")
|
|
100
|
+
else:
|
|
101
|
+
print(f" Error: {error}")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def main():
|
|
105
|
+
"""Test all users."""
|
|
106
|
+
print("\n" + "="*70)
|
|
107
|
+
print("SecureOpenAI + MACAW Policy Demo")
|
|
108
|
+
print("="*70)
|
|
109
|
+
print("\nArchitecture:")
|
|
110
|
+
print(" - Single SecureOpenAI service agent (created once)")
|
|
111
|
+
print(" - User agents with JWT -> embedded_context (automatic)")
|
|
112
|
+
print(" - A2A calls: User -> SecureOpenAI service")
|
|
113
|
+
print(" - Policy enforcement at ToolAgent PEP level")
|
|
114
|
+
|
|
115
|
+
print("\nExpected results:")
|
|
116
|
+
print(" - Alice: GPT-3.5 only, max 500 tokens")
|
|
117
|
+
print(" - Bob: GPT-3.5/4, max 2000 tokens")
|
|
118
|
+
print(" - Carol: All models, max 4000 tokens")
|
|
119
|
+
|
|
120
|
+
if not os.environ.get("OPENAI_API_KEY"):
|
|
121
|
+
print("\nWARNING: No OPENAI_API_KEY - demo will fail")
|
|
122
|
+
print(" Set with: export OPENAI_API_KEY=sk-...")
|
|
123
|
+
return
|
|
124
|
+
|
|
125
|
+
# Create SINGLE SecureOpenAI service (ONCE!)
|
|
126
|
+
print("\n" + "="*70)
|
|
127
|
+
print("Creating single SecureOpenAI service agent...")
|
|
128
|
+
print("="*70)
|
|
129
|
+
|
|
130
|
+
openai_service = SecureOpenAI(
|
|
131
|
+
api_key=os.environ.get("OPENAI_API_KEY"),
|
|
132
|
+
app_name="openai-service"
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
print(f"OK SecureOpenAI service: {openai_service.server_id}")
|
|
136
|
+
|
|
137
|
+
# Test each user with same service
|
|
138
|
+
for username, password in USERS.items():
|
|
139
|
+
try:
|
|
140
|
+
test_user(username, password, openai_service)
|
|
141
|
+
except Exception as e:
|
|
142
|
+
print(f"\nFAIL Failed to test {username}: {e}")
|
|
143
|
+
|
|
144
|
+
print("\n" + "="*70)
|
|
145
|
+
print("Demo complete!")
|
|
146
|
+
print("="*70)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if __name__ == "__main__":
|
|
150
|
+
main()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"constraints": {
|
|
3
|
+
"parameters": {
|
|
4
|
+
"tool:*/complete": {
|
|
5
|
+
"max_tokens": {
|
|
6
|
+
"max": 4000
|
|
7
|
+
},
|
|
8
|
+
"model": [
|
|
9
|
+
"gpt-3.5-turbo-instruct",
|
|
10
|
+
"davinci-002",
|
|
11
|
+
"babbage-002"
|
|
12
|
+
],
|
|
13
|
+
"temperature": {
|
|
14
|
+
"max": 2,
|
|
15
|
+
"min": 0
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"tool:*/embed": {
|
|
19
|
+
"model": [
|
|
20
|
+
"text-embedding-ada-002",
|
|
21
|
+
"text-embedding-3-small",
|
|
22
|
+
"text-embedding-3-large"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"tool:*/generate": {
|
|
26
|
+
"frequency_penalty": {
|
|
27
|
+
"max": 2,
|
|
28
|
+
"min": -2
|
|
29
|
+
},
|
|
30
|
+
"max_tokens": {
|
|
31
|
+
"max": 4000
|
|
32
|
+
},
|
|
33
|
+
"model": [
|
|
34
|
+
"gpt-3.5-turbo",
|
|
35
|
+
"gpt-4",
|
|
36
|
+
"claude-3-haiku-20240307",
|
|
37
|
+
"claude-3-sonnet-20240229",
|
|
38
|
+
"claude-opus-4-5-20251101"
|
|
39
|
+
],
|
|
40
|
+
"presence_penalty": {
|
|
41
|
+
"max": 2,
|
|
42
|
+
"min": -2
|
|
43
|
+
},
|
|
44
|
+
"temperature": {
|
|
45
|
+
"max": 1,
|
|
46
|
+
"min": 0
|
|
47
|
+
},
|
|
48
|
+
"top_p": {
|
|
49
|
+
"max": 1,
|
|
50
|
+
"min": 0
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"rate_limit": 100
|
|
55
|
+
},
|
|
56
|
+
"denied_resources": [
|
|
57
|
+
"*.secret",
|
|
58
|
+
"*.password",
|
|
59
|
+
"*.key",
|
|
60
|
+
"*.pem"
|
|
61
|
+
],
|
|
62
|
+
"description": "Company-wide base policy for FinTech Corp",
|
|
63
|
+
"policy_id": "company:FinTech Corp",
|
|
64
|
+
"resources": [
|
|
65
|
+
"tool:*/generate",
|
|
66
|
+
"tool:financial_analysis"
|
|
67
|
+
],
|
|
68
|
+
"scope": "global",
|
|
69
|
+
"version": "1.0"
|
|
70
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"constraints": {
|
|
3
|
+
"parameters": {
|
|
4
|
+
"tool:*/complete": {
|
|
5
|
+
"max_tokens": {
|
|
6
|
+
"max": 4000
|
|
7
|
+
},
|
|
8
|
+
"model": [
|
|
9
|
+
"gpt-3.5-turbo-instruct",
|
|
10
|
+
"davinci-002",
|
|
11
|
+
"babbage-002"
|
|
12
|
+
],
|
|
13
|
+
"temperature": {
|
|
14
|
+
"max": 2.0,
|
|
15
|
+
"min": 0
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"tool:*/embed": {
|
|
19
|
+
"model": [
|
|
20
|
+
"text-embedding-ada-002",
|
|
21
|
+
"text-embedding-3-small",
|
|
22
|
+
"text-embedding-3-large"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"tool:*/generate": {
|
|
26
|
+
"frequency_penalty": {
|
|
27
|
+
"max": 2.0,
|
|
28
|
+
"min": -2.0
|
|
29
|
+
},
|
|
30
|
+
"max_tokens": {
|
|
31
|
+
"max": 4000
|
|
32
|
+
},
|
|
33
|
+
"model": [
|
|
34
|
+
"gpt-3.5-turbo",
|
|
35
|
+
"gpt-4"
|
|
36
|
+
],
|
|
37
|
+
"presence_penalty": {
|
|
38
|
+
"max": 2.0,
|
|
39
|
+
"min": -2.0
|
|
40
|
+
},
|
|
41
|
+
"temperature": {
|
|
42
|
+
"max": 2.0,
|
|
43
|
+
"min": 0
|
|
44
|
+
},
|
|
45
|
+
"top_p": {
|
|
46
|
+
"max": 1.0,
|
|
47
|
+
"min": 0
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"rate_limit": 100
|
|
52
|
+
},
|
|
53
|
+
"denied_resources": [
|
|
54
|
+
"*.secret",
|
|
55
|
+
"*.password",
|
|
56
|
+
"*.pem",
|
|
57
|
+
"*.token",
|
|
58
|
+
"*.key"
|
|
59
|
+
],
|
|
60
|
+
"description": "Base policy for LLM services with standard parameter constraints",
|
|
61
|
+
"policy_id": "llm-base",
|
|
62
|
+
"resources": [
|
|
63
|
+
"tool:openai-service/generate",
|
|
64
|
+
"tool:openai-service/complete",
|
|
65
|
+
"tool:openai-service/embed"
|
|
66
|
+
],
|
|
67
|
+
"scope": "global",
|
|
68
|
+
"version": "1.0"
|
|
69
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"constraints": {
|
|
3
|
+
"parameters": {
|
|
4
|
+
"tool:*/generate": {
|
|
5
|
+
"max_tokens": {
|
|
6
|
+
"max": 500
|
|
7
|
+
},
|
|
8
|
+
"model": [
|
|
9
|
+
"gpt-3.5-turbo",
|
|
10
|
+
"claude-3-haiku-20240307"
|
|
11
|
+
],
|
|
12
|
+
"temperature": {
|
|
13
|
+
"max": 0.5
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"rate_limit": 10
|
|
18
|
+
},
|
|
19
|
+
"denied_resources": [
|
|
20
|
+
"data:executive/*",
|
|
21
|
+
"data:confidential/*"
|
|
22
|
+
],
|
|
23
|
+
"description": "Restrictive policy for entry-level analyst",
|
|
24
|
+
"extends": "team:Reporting",
|
|
25
|
+
"policy_id": "user:alice",
|
|
26
|
+
"resources": [
|
|
27
|
+
"tool:*/generate",
|
|
28
|
+
"tool:financial_analysis"
|
|
29
|
+
],
|
|
30
|
+
"scope": "global",
|
|
31
|
+
"version": "1.0"
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"constraints": {
|
|
3
|
+
"parameters": {
|
|
4
|
+
"tool:*/generate": {
|
|
5
|
+
"max_tokens": {
|
|
6
|
+
"max": 2000
|
|
7
|
+
},
|
|
8
|
+
"model": [
|
|
9
|
+
"gpt-3.5-turbo",
|
|
10
|
+
"gpt-4",
|
|
11
|
+
"claude-3-haiku-20240307",
|
|
12
|
+
"claude-3-sonnet-20240229",
|
|
13
|
+
"claude-opus-4-5-20251101"
|
|
14
|
+
],
|
|
15
|
+
"temperature": {
|
|
16
|
+
"max": 0.8
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"rate_limit": 30
|
|
21
|
+
},
|
|
22
|
+
"description": "Enhanced policy for team manager",
|
|
23
|
+
"extends": "team:Reporting",
|
|
24
|
+
"policy_id": "user:bob",
|
|
25
|
+
"resources": [],
|
|
26
|
+
"scope": "global",
|
|
27
|
+
"version": "1.0"
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"constraints": {
|
|
3
|
+
"parameters": {
|
|
4
|
+
"tool:*/generate": {
|
|
5
|
+
"max_tokens": {
|
|
6
|
+
"max": 4000
|
|
7
|
+
},
|
|
8
|
+
"model": [
|
|
9
|
+
"gpt-3.5-turbo",
|
|
10
|
+
"gpt-4"
|
|
11
|
+
],
|
|
12
|
+
"temperature": {
|
|
13
|
+
"max": 1.0
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"rate_limit": 100
|
|
18
|
+
},
|
|
19
|
+
"denied_resources": [
|
|
20
|
+
"*.secret",
|
|
21
|
+
"*.password",
|
|
22
|
+
"*.key",
|
|
23
|
+
"*.pem"
|
|
24
|
+
],
|
|
25
|
+
"description": "Maximum access for system administrator",
|
|
26
|
+
"extends": "company:FinTech Corp",
|
|
27
|
+
"policy_id": "user:carol",
|
|
28
|
+
"resources": [
|
|
29
|
+
"tool:*/generate",
|
|
30
|
+
"tool:financial_analysis"
|
|
31
|
+
],
|
|
32
|
+
"scope": "global",
|
|
33
|
+
"version": "1.0"
|
|
34
|
+
}
|