bastionik 0.1.0__tar.gz
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.
- bastionik-0.1.0/LICENSE +21 -0
- bastionik-0.1.0/PKG-INFO +284 -0
- bastionik-0.1.0/README.md +255 -0
- bastionik-0.1.0/bastionik/__init__.py +10 -0
- bastionik-0.1.0/bastionik/client.py +291 -0
- bastionik-0.1.0/bastionik.egg-info/PKG-INFO +284 -0
- bastionik-0.1.0/bastionik.egg-info/SOURCES.txt +11 -0
- bastionik-0.1.0/bastionik.egg-info/dependency_links.txt +1 -0
- bastionik-0.1.0/bastionik.egg-info/requires.txt +7 -0
- bastionik-0.1.0/bastionik.egg-info/top_level.txt +1 -0
- bastionik-0.1.0/pyproject.toml +42 -0
- bastionik-0.1.0/setup.cfg +4 -0
- bastionik-0.1.0/tests/test_client.py +184 -0
bastionik-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bastionik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bastionik-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bastionik
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Bastionik AI agent trust boundary API
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://bastionik.com
|
|
7
|
+
Project-URL: Repository, https://github.com/bastionik/bastionik-python
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/bastionik/bastionik-python/issues
|
|
9
|
+
Keywords: ai-agents,security,authentication,credentials,bastionik
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: httpx>=0.27.0
|
|
23
|
+
Requires-Dist: PyNaCl>=1.5.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-mock>=3.12; extra == "dev"
|
|
27
|
+
Requires-Dist: respx>=0.21; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# bastionik-python
|
|
31
|
+
|
|
32
|
+
Python SDK for [Bastionik](https://bastionik.com) — the trust boundary service for AI agents.
|
|
33
|
+
|
|
34
|
+
Stop hardcoding API keys in your agents. Bastionik gives every agent a cryptographic identity, stores credentials in an encrypted vault, enforces fine-grained access policies, and keeps a complete audit trail. Your agent never sees the token.
|
|
35
|
+
|
|
36
|
+
> **Status:** Early access. Self-hosted only. [Hosted version coming soon.](#hosted-version)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## How it works
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Your agent Bastionik External API
|
|
44
|
+
│ │ │
|
|
45
|
+
│──── execute() ───►│ │
|
|
46
|
+
│ (signed with │── verify Ed25519 sig │
|
|
47
|
+
│ private key) │── check policy │
|
|
48
|
+
│ │── decrypt credential │
|
|
49
|
+
│ │────────────────────────────►
|
|
50
|
+
│ │◄────────────────────────────
|
|
51
|
+
│◄── result ────────│ (credential deleted │
|
|
52
|
+
│ │ from memory) │
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
1. You register an agent with its Ed25519 public key
|
|
56
|
+
2. You store an encrypted credential (the agent never sees it)
|
|
57
|
+
3. You define a policy: what actions the agent is allowed to take
|
|
58
|
+
4. The agent signs execution requests with its private key
|
|
59
|
+
5. Bastionik verifies the signature, checks the policy, executes the call, returns the result
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- Python 3.10+
|
|
66
|
+
- A running Bastionik instance ([core repo](https://github.com/bastionik/core))
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install git+https://github.com/bastionik/bastionik-python.git
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or clone and install in editable mode for development:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
git clone https://github.com/bastionik/bastionik-python.git
|
|
80
|
+
cd bastionik-python
|
|
81
|
+
pip install -e .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Quickstart
|
|
87
|
+
|
|
88
|
+
### 1. Start Bastionik locally
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# In your bastionik/core repo
|
|
92
|
+
docker compose up
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The API will be available at `http://localhost:8000`.
|
|
96
|
+
|
|
97
|
+
### 2. Generate a keypair for your agent
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import bastionik
|
|
101
|
+
|
|
102
|
+
keys = bastionik.generate_keypair()
|
|
103
|
+
# {
|
|
104
|
+
# "private_key_hex": "...", ← store this securely, pass to BastionikClient
|
|
105
|
+
# "public_key_hex": "...", ← register agents with this
|
|
106
|
+
# }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Register, configure, and run
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from bastionik import BastionikClient
|
|
113
|
+
|
|
114
|
+
client = BastionikClient(
|
|
115
|
+
base_url="http://localhost:8000",
|
|
116
|
+
user_id="your-user-id", # management plane auth
|
|
117
|
+
agent_private_key=bytes.fromhex(keys["private_key_hex"]), # signs execute requests
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Register the agent
|
|
121
|
+
agent = client.register_agent(
|
|
122
|
+
name="my-github-agent",
|
|
123
|
+
public_key=keys["public_key_hex"],
|
|
124
|
+
)
|
|
125
|
+
agent_id = agent["id"]
|
|
126
|
+
|
|
127
|
+
# Store a credential — the agent will never see this token directly
|
|
128
|
+
client.store_credential(
|
|
129
|
+
agent_id=agent_id,
|
|
130
|
+
service="github",
|
|
131
|
+
token="ghp_your_github_token",
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Define what the agent is allowed to do
|
|
135
|
+
client.create_policy(
|
|
136
|
+
agent_id=agent_id,
|
|
137
|
+
service="github",
|
|
138
|
+
allowed_actions=["get_repo", "list_prs", "create_issue"],
|
|
139
|
+
rate_limit=100,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Execute a signed action
|
|
143
|
+
result = client.execute(
|
|
144
|
+
agent_id=agent_id,
|
|
145
|
+
service="github",
|
|
146
|
+
action="get_repo",
|
|
147
|
+
params={"owner": "octocat", "repo": "Hello-World"},
|
|
148
|
+
)
|
|
149
|
+
print(result["full_name"]) # octocat/Hello-World
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### `BastionikClient(base_url, user_id, agent_private_key, timeout)`
|
|
157
|
+
|
|
158
|
+
| Parameter | Type | Default | Description |
|
|
159
|
+
|-----------|------|---------|-------------|
|
|
160
|
+
| `base_url` | `str` | `http://localhost:8000` | URL of your Bastionik instance |
|
|
161
|
+
| `user_id` | `str` | `None` | Developer user ID for management operations |
|
|
162
|
+
| `agent_private_key` | `bytes` | `None` | Ed25519 private key bytes for signing agent requests |
|
|
163
|
+
| `timeout` | `float` | `30.0` | Request timeout in seconds |
|
|
164
|
+
|
|
165
|
+
#### Management methods
|
|
166
|
+
These require `user_id` to be set.
|
|
167
|
+
|
|
168
|
+
| Method | Description |
|
|
169
|
+
|--------|-------------|
|
|
170
|
+
| `register_agent(name, public_key, description)` | Register a new AI agent |
|
|
171
|
+
| `store_credential(agent_id, service, token)` | Encrypt and store an API credential |
|
|
172
|
+
| `delete_credential(agent_id, service)` | Remove a stored credential |
|
|
173
|
+
| `create_policy(agent_id, service, allowed_actions, rate_limit)` | Define agent permissions |
|
|
174
|
+
| `list_policies(agent_id)` | List all policies for an agent |
|
|
175
|
+
| `delete_policy(policy_id)` | Delete a policy |
|
|
176
|
+
|
|
177
|
+
#### Execution methods
|
|
178
|
+
These require `agent_private_key` to be set.
|
|
179
|
+
|
|
180
|
+
| Method | Description |
|
|
181
|
+
|--------|-------------|
|
|
182
|
+
| `execute(agent_id, service, action, params)` | Execute a signed agent action |
|
|
183
|
+
|
|
184
|
+
#### Utilities
|
|
185
|
+
|
|
186
|
+
| Method | Description |
|
|
187
|
+
|--------|-------------|
|
|
188
|
+
| `health()` | Check server connectivity |
|
|
189
|
+
| `bastionik.generate_keypair()` | Generate a new Ed25519 keypair |
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Supported services and actions
|
|
194
|
+
|
|
195
|
+
### GitHub (`service="github"`)
|
|
196
|
+
|
|
197
|
+
| Action | Params | Description |
|
|
198
|
+
|--------|--------|-------------|
|
|
199
|
+
| `get_repo` | `owner`, `repo` | Get repository details |
|
|
200
|
+
| `list_repos` | `owner` | List repositories for a user/org |
|
|
201
|
+
| `list_prs` | `owner`, `repo` | List open pull requests |
|
|
202
|
+
| `create_pr` | `owner`, `repo`, `title`, `body`, `head`, `base` | Create a pull request |
|
|
203
|
+
| `create_issue` | `owner`, `repo`, `title`, `body` | Create an issue |
|
|
204
|
+
| `merge_pr` | `owner`, `repo`, `pull_number` | Merge a pull request |
|
|
205
|
+
| `close_issue` | `owner`, `repo`, `issue_number` | Close an issue |
|
|
206
|
+
|
|
207
|
+
More integrations are on the roadmap. [Request one →](https://github.com/bastionik/bastionik-python/issues)
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Running the example
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git clone https://github.com/bastionik/bastionik-python.git
|
|
215
|
+
cd bastionik-python
|
|
216
|
+
|
|
217
|
+
# Install dependencies
|
|
218
|
+
pip install -e .
|
|
219
|
+
|
|
220
|
+
# Set your GitHub token
|
|
221
|
+
export GITHUB_TOKEN=ghp_your_token_here
|
|
222
|
+
export GITHUB_REPO=your-username/your-repo
|
|
223
|
+
|
|
224
|
+
# Run the demo (requires Bastionik running locally)
|
|
225
|
+
python examples/github_demo.py
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Running tests
|
|
231
|
+
|
|
232
|
+
Tests use mocked HTTP — no live server required.
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
pip install -e ".[dev]"
|
|
236
|
+
pytest tests/ -v
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Error handling
|
|
242
|
+
|
|
243
|
+
All API errors raise `BastionikError`:
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
from bastionik import BastionikError
|
|
247
|
+
|
|
248
|
+
try:
|
|
249
|
+
result = client.execute(agent_id=agent_id, service="github", action="delete_repo", params={...})
|
|
250
|
+
except BastionikError as e:
|
|
251
|
+
print(e.status_code) # e.g. 403
|
|
252
|
+
print(e.detail) # raw error body from the API
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Common status codes:
|
|
256
|
+
|
|
257
|
+
| Code | Meaning |
|
|
258
|
+
|------|---------|
|
|
259
|
+
| `401` | Invalid or missing Ed25519 signature |
|
|
260
|
+
| `403` | Action not permitted by policy |
|
|
261
|
+
| `404` | Agent or credential not found |
|
|
262
|
+
| `409` | Agent already registered |
|
|
263
|
+
| `429` | Rate limit exceeded |
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Security model
|
|
268
|
+
|
|
269
|
+
- **Credentials never leave the vault unencrypted.** Tokens are Fernet-encrypted (AES-128-CBC + HMAC-SHA256) before PostgreSQL storage and decrypted in memory only during execution.
|
|
270
|
+
- **Every request is signed.** Ed25519 signatures verify agent identity on each `/execute` call. Replay attacks are prevented by a 5-minute timestamp window.
|
|
271
|
+
- **Policies are enforced server-side.** Even if an agent's private key is compromised, it can only perform actions explicitly listed in its policy.
|
|
272
|
+
- **Complete audit trail.** Every action is logged before execution. You can prove exactly what every agent did, when, and with what parameters.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Hosted version
|
|
277
|
+
|
|
278
|
+
A hosted version of Bastionik (`pip install bastionik` pointing at `api.bastionik.com`) is in development. Sign up for early access at [bastionik.com](https://bastionik.com).
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# bastionik-python
|
|
2
|
+
|
|
3
|
+
Python SDK for [Bastionik](https://bastionik.com) — the trust boundary service for AI agents.
|
|
4
|
+
|
|
5
|
+
Stop hardcoding API keys in your agents. Bastionik gives every agent a cryptographic identity, stores credentials in an encrypted vault, enforces fine-grained access policies, and keeps a complete audit trail. Your agent never sees the token.
|
|
6
|
+
|
|
7
|
+
> **Status:** Early access. Self-hosted only. [Hosted version coming soon.](#hosted-version)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Your agent Bastionik External API
|
|
15
|
+
│ │ │
|
|
16
|
+
│──── execute() ───►│ │
|
|
17
|
+
│ (signed with │── verify Ed25519 sig │
|
|
18
|
+
│ private key) │── check policy │
|
|
19
|
+
│ │── decrypt credential │
|
|
20
|
+
│ │────────────────────────────►
|
|
21
|
+
│ │◄────────────────────────────
|
|
22
|
+
│◄── result ────────│ (credential deleted │
|
|
23
|
+
│ │ from memory) │
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
1. You register an agent with its Ed25519 public key
|
|
27
|
+
2. You store an encrypted credential (the agent never sees it)
|
|
28
|
+
3. You define a policy: what actions the agent is allowed to take
|
|
29
|
+
4. The agent signs execution requests with its private key
|
|
30
|
+
5. Bastionik verifies the signature, checks the policy, executes the call, returns the result
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- Python 3.10+
|
|
37
|
+
- A running Bastionik instance ([core repo](https://github.com/bastionik/core))
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install git+https://github.com/bastionik/bastionik-python.git
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or clone and install in editable mode for development:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/bastionik/bastionik-python.git
|
|
51
|
+
cd bastionik-python
|
|
52
|
+
pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Quickstart
|
|
58
|
+
|
|
59
|
+
### 1. Start Bastionik locally
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# In your bastionik/core repo
|
|
63
|
+
docker compose up
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The API will be available at `http://localhost:8000`.
|
|
67
|
+
|
|
68
|
+
### 2. Generate a keypair for your agent
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import bastionik
|
|
72
|
+
|
|
73
|
+
keys = bastionik.generate_keypair()
|
|
74
|
+
# {
|
|
75
|
+
# "private_key_hex": "...", ← store this securely, pass to BastionikClient
|
|
76
|
+
# "public_key_hex": "...", ← register agents with this
|
|
77
|
+
# }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Register, configure, and run
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from bastionik import BastionikClient
|
|
84
|
+
|
|
85
|
+
client = BastionikClient(
|
|
86
|
+
base_url="http://localhost:8000",
|
|
87
|
+
user_id="your-user-id", # management plane auth
|
|
88
|
+
agent_private_key=bytes.fromhex(keys["private_key_hex"]), # signs execute requests
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Register the agent
|
|
92
|
+
agent = client.register_agent(
|
|
93
|
+
name="my-github-agent",
|
|
94
|
+
public_key=keys["public_key_hex"],
|
|
95
|
+
)
|
|
96
|
+
agent_id = agent["id"]
|
|
97
|
+
|
|
98
|
+
# Store a credential — the agent will never see this token directly
|
|
99
|
+
client.store_credential(
|
|
100
|
+
agent_id=agent_id,
|
|
101
|
+
service="github",
|
|
102
|
+
token="ghp_your_github_token",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Define what the agent is allowed to do
|
|
106
|
+
client.create_policy(
|
|
107
|
+
agent_id=agent_id,
|
|
108
|
+
service="github",
|
|
109
|
+
allowed_actions=["get_repo", "list_prs", "create_issue"],
|
|
110
|
+
rate_limit=100,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Execute a signed action
|
|
114
|
+
result = client.execute(
|
|
115
|
+
agent_id=agent_id,
|
|
116
|
+
service="github",
|
|
117
|
+
action="get_repo",
|
|
118
|
+
params={"owner": "octocat", "repo": "Hello-World"},
|
|
119
|
+
)
|
|
120
|
+
print(result["full_name"]) # octocat/Hello-World
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## API Reference
|
|
126
|
+
|
|
127
|
+
### `BastionikClient(base_url, user_id, agent_private_key, timeout)`
|
|
128
|
+
|
|
129
|
+
| Parameter | Type | Default | Description |
|
|
130
|
+
|-----------|------|---------|-------------|
|
|
131
|
+
| `base_url` | `str` | `http://localhost:8000` | URL of your Bastionik instance |
|
|
132
|
+
| `user_id` | `str` | `None` | Developer user ID for management operations |
|
|
133
|
+
| `agent_private_key` | `bytes` | `None` | Ed25519 private key bytes for signing agent requests |
|
|
134
|
+
| `timeout` | `float` | `30.0` | Request timeout in seconds |
|
|
135
|
+
|
|
136
|
+
#### Management methods
|
|
137
|
+
These require `user_id` to be set.
|
|
138
|
+
|
|
139
|
+
| Method | Description |
|
|
140
|
+
|--------|-------------|
|
|
141
|
+
| `register_agent(name, public_key, description)` | Register a new AI agent |
|
|
142
|
+
| `store_credential(agent_id, service, token)` | Encrypt and store an API credential |
|
|
143
|
+
| `delete_credential(agent_id, service)` | Remove a stored credential |
|
|
144
|
+
| `create_policy(agent_id, service, allowed_actions, rate_limit)` | Define agent permissions |
|
|
145
|
+
| `list_policies(agent_id)` | List all policies for an agent |
|
|
146
|
+
| `delete_policy(policy_id)` | Delete a policy |
|
|
147
|
+
|
|
148
|
+
#### Execution methods
|
|
149
|
+
These require `agent_private_key` to be set.
|
|
150
|
+
|
|
151
|
+
| Method | Description |
|
|
152
|
+
|--------|-------------|
|
|
153
|
+
| `execute(agent_id, service, action, params)` | Execute a signed agent action |
|
|
154
|
+
|
|
155
|
+
#### Utilities
|
|
156
|
+
|
|
157
|
+
| Method | Description |
|
|
158
|
+
|--------|-------------|
|
|
159
|
+
| `health()` | Check server connectivity |
|
|
160
|
+
| `bastionik.generate_keypair()` | Generate a new Ed25519 keypair |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Supported services and actions
|
|
165
|
+
|
|
166
|
+
### GitHub (`service="github"`)
|
|
167
|
+
|
|
168
|
+
| Action | Params | Description |
|
|
169
|
+
|--------|--------|-------------|
|
|
170
|
+
| `get_repo` | `owner`, `repo` | Get repository details |
|
|
171
|
+
| `list_repos` | `owner` | List repositories for a user/org |
|
|
172
|
+
| `list_prs` | `owner`, `repo` | List open pull requests |
|
|
173
|
+
| `create_pr` | `owner`, `repo`, `title`, `body`, `head`, `base` | Create a pull request |
|
|
174
|
+
| `create_issue` | `owner`, `repo`, `title`, `body` | Create an issue |
|
|
175
|
+
| `merge_pr` | `owner`, `repo`, `pull_number` | Merge a pull request |
|
|
176
|
+
| `close_issue` | `owner`, `repo`, `issue_number` | Close an issue |
|
|
177
|
+
|
|
178
|
+
More integrations are on the roadmap. [Request one →](https://github.com/bastionik/bastionik-python/issues)
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Running the example
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
git clone https://github.com/bastionik/bastionik-python.git
|
|
186
|
+
cd bastionik-python
|
|
187
|
+
|
|
188
|
+
# Install dependencies
|
|
189
|
+
pip install -e .
|
|
190
|
+
|
|
191
|
+
# Set your GitHub token
|
|
192
|
+
export GITHUB_TOKEN=ghp_your_token_here
|
|
193
|
+
export GITHUB_REPO=your-username/your-repo
|
|
194
|
+
|
|
195
|
+
# Run the demo (requires Bastionik running locally)
|
|
196
|
+
python examples/github_demo.py
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Running tests
|
|
202
|
+
|
|
203
|
+
Tests use mocked HTTP — no live server required.
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
pip install -e ".[dev]"
|
|
207
|
+
pytest tests/ -v
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Error handling
|
|
213
|
+
|
|
214
|
+
All API errors raise `BastionikError`:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from bastionik import BastionikError
|
|
218
|
+
|
|
219
|
+
try:
|
|
220
|
+
result = client.execute(agent_id=agent_id, service="github", action="delete_repo", params={...})
|
|
221
|
+
except BastionikError as e:
|
|
222
|
+
print(e.status_code) # e.g. 403
|
|
223
|
+
print(e.detail) # raw error body from the API
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Common status codes:
|
|
227
|
+
|
|
228
|
+
| Code | Meaning |
|
|
229
|
+
|------|---------|
|
|
230
|
+
| `401` | Invalid or missing Ed25519 signature |
|
|
231
|
+
| `403` | Action not permitted by policy |
|
|
232
|
+
| `404` | Agent or credential not found |
|
|
233
|
+
| `409` | Agent already registered |
|
|
234
|
+
| `429` | Rate limit exceeded |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Security model
|
|
239
|
+
|
|
240
|
+
- **Credentials never leave the vault unencrypted.** Tokens are Fernet-encrypted (AES-128-CBC + HMAC-SHA256) before PostgreSQL storage and decrypted in memory only during execution.
|
|
241
|
+
- **Every request is signed.** Ed25519 signatures verify agent identity on each `/execute` call. Replay attacks are prevented by a 5-minute timestamp window.
|
|
242
|
+
- **Policies are enforced server-side.** Even if an agent's private key is compromised, it can only perform actions explicitly listed in its policy.
|
|
243
|
+
- **Complete audit trail.** Every action is logged before execution. You can prove exactly what every agent did, when, and with what parameters.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Hosted version
|
|
248
|
+
|
|
249
|
+
A hosted version of Bastionik (`pip install bastionik` pointing at `api.bastionik.com`) is in development. Sign up for early access at [bastionik.com](https://bastionik.com).
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Bastionik Python SDK
|
|
3
|
+
|
|
4
|
+
A thin client wrapper for the Bastionik AI agent trust boundary API.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .client import BastionikClient, BastionikError, generate_keypair
|
|
8
|
+
|
|
9
|
+
__all__ = ["BastionikClient", "BastionikError", "generate_keypair"]
|
|
10
|
+
__version__ = "0.1.0"
|