forked from spiffe/spike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drafts.txt
484 lines (365 loc) · 12.1 KB
/
drafts.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// \\ SPIKE: Secure your secrets with SPIFFE.
// \\\\\ Copyright 2024-present SPIKE contributors.
// \\\\\\\ SPDX-License-Identifier: Apache-2.0
--------------------------------------------------------------------------------
Idea: Inverting the root key flow
Current consensus: It's better to harden SPIKE Keepers instead
Details:
Inverting the key generation flow in SPIKE—having the Nexus generate the root
key, compute the shares, distribute them to the Keepers, initialize the database
backend, and then discard the root key—alters the threat model and introduces
new benefits and liabilities.
--------------------------------------------------------------------------------
login <token>
login -method=userpass username=myuser password=mypass
login -method=github token=<github-token>
login -method=aws role=myrole
put secret/myapp/config username=dbuser password=dbpass
put secret/myapp/config @config.json
put -custom-metadata=owner=ops -custom-metadata=env=prod secret/myapp/config username=dbuser
put -version=2 secret/myapp/config username=newuser
get secret/myapp/config
get -version=1 secret/myapp/config
get -field=username secret/myapp/config
get -format=json secret/myapp/config
metadata get secret/myapp/config
delete secret/myapp/config
delete -versions=1,2 secret/myapp/config
destroy -versions=1 secret/myapp/config
metadata delete secret/myapp/config
```
ist secret/
list -format=json secret/
patch secret/myapp/config password=newpass
patch secret/myapp/config @patch.json
policy write mypolicy policy.yaml
policy read mypolicy
policy list
policy delete mypolicy
token create -policy=mypolicy
token create -ttl=1h
token renew <token>
token lookup <token>
token revoke <token>
```bash
enable userpass
enable -path=users-temp userpass
auth disable userpass
```
```bash
operator seal
operator unseal <key>
operator seal -status
```
```bash
audit enable file file_path=/var/log/vault/audit.log
audit list
# Disable audit device
audit disable file/
```
--------------------------------------------------------------------------------
// File: server/types.go
package server
import (
"time"
)
// File: server/acl_service.go
package server
import (
"context"
"encoding/json"
"fmt"
"net/http"
"path"
"regexp"
"sync"
"github.com/google/uuid"
"github.com/gorilla/mux"
)
type ACLService struct {
policies sync.Map
}
func NewACLService() *ACLService {
return &ACLService{}
}
func (s *ACLService) RegisterRoutes(r *mux.Router) {
r.HandleFunc("/v1/store/acl/policies", s.CreatePolicy).Methods("POST")
r.HandleFunc("/v1/store/acl/policies", s.ListPolicies).Methods("GET")
r.HandleFunc("/v1/store/acl/policies/{id}", s.GetPolicy).Methods("GET")
r.HandleFunc("/v1/store/acl/policies/{id}", s.DeletePolicy).Methods("DELETE")
r.HandleFunc("/v1/store/acl/check", s.CheckAccess).Methods("POST")
}
func (s *ACLService) CreatePolicy(w http.ResponseWriter, r *http.Request) {
var req CreatePolicyRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Validate policy
if _, err := regexp.Compile(req.SpiffeIdPattern); err != nil {
http.Error(w, "invalid spiffe_id_pattern", http.StatusBadRequest)
return
}
policy := &Policy{
ID: uuid.New().String(),
Name: req.Name,
SpiffeIdPattern: req.SpiffeIdPattern,
PathPattern: req.PathPattern,
Permissions: req.Permissions,
CreatedAt: time.Now(),
CreatedBy: r.Header.Get("X-User-ID"), // Assuming auth middleware sets this
}
s.policies.Store(policy.ID, policy)
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(policy)
}
# ## A note for Mac OS users ##
#
# The SPIRE Unix Workload Attestor plugin generates selectors based on
# Unix-specific attributes of workloads.
#
# On Darwin (macOS), the following selectors are supported:
# * unix:uid: The user ID of the workload (e.g., unix:uid:1000).
# * unix:user: The username of the workload (e.g., unix:user:nginx).
# * unix:gid: The group ID of the workload (e.g., unix:gid:1000).
# * unix:group: The group name of the workload (e.g., unix:group:www-data).
#
# However, the following selectors are not supported on Darwin:
# * unix:supplementary_gid: The supplementary group ID of the workload.
# * unix:supplementary_group: The supplementary group name of the workload.
#
# ^ These selectors are currently only supported on Linux systems.
#
# Additionally, if the plugin is configured with discover_workload_path = true,
# it can provide these selectors:
# * unix:path: The path to the workload binary (e.g., unix:path:/usr/bin/nginx).
# * unix:sha256: The SHA256 digest of the workload binary (e.g., unix:sha256:3a6...).
func (s *ACLService) CheckAccess(w http.ResponseWriter, r *http.Request) {
var req CheckAccessRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
matchingPolicies := []string{}
allowed := false
s.policies.Range(func(key, value interface{}) bool {
policy := value.(*Policy)
// Check if SPIFFE ID matches pattern
matched, err := regexp.MatchString(policy.SpiffeIdPattern, req.SpiffeID)
if err != nil || !matched {
return true // continue iteration
}
// Check if path matches pattern
if matched, _ := path.Match(policy.PathPattern, req.Path); !matched {
return true
}
// Check if action is allowed
for _, perm := range policy.Permissions {
if perm == req.Action {
matchingPolicies = append(matchingPolicies, policy.ID)
allowed = true
break
}
}
return true
})
json.NewEncoder(w).Encode(CheckAccessResponse{
Allowed: allowed,
MatchingPolicies: matchingPolicies,
})
}
// Other handlers (ListPolicies, GetPolicy, DeletePolicy) omitted for brevity
--------------------------------------------------------------------------------
// File: client/acl_client.go
package client
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type ACLClient struct {
baseURL string
httpClient *http.Client
}
func NewACLClient(baseURL string) *ACLClient {
return &ACLClient{
baseURL: baseURL,
httpClient: &http.Client{
Timeout: 30 * time.Second,
},
}
}
func (c *ACLClient) CreatePolicy(ctx context.Context, req CreatePolicyRequest) (*Policy, error) {
body, err := json.Marshal(req)
if err != nil {
return nil, fmt.Errorf("marshaling request: %w", err)
}
httpReq, err := http.NewRequestWithContext(
ctx,
"POST",
fmt.Sprintf("%s/v1/store/acl/policies", c.baseURL),
bytes.NewReader(body),
)
if err != nil {
return nil, fmt.Errorf("creating request: %w", err)
}
httpResp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("sending request: %w", err)
}
defer httpResp.Body.Close()
if httpResp.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("unexpected status: %d", httpResp.StatusCode)
}
var policy Policy
if err := json.NewDecoder(httpResp.Body).Decode(&policy); err != nil {
return nil, fmt.Errorf("decoding response: %w", err)
}
return &policy, nil
}
func (c *ACLClient) CheckAccess(ctx context.Context, spiffeID, path, action string) (*CheckAccessResponse, error) {
req := CheckAccessRequest{
SpiffeID: spiffeID,
Path: path,
Action: action,
}
body, err := json.Marshal(req)
if err != nil {
return nil, fmt.Errorf("marshaling request: %w", err)
}
httpReq, err := http.NewRequestWithContext(
ctx,
"POST",
fmt.Sprintf("%s/v1/store/acl/check", c.baseURL),
bytes.NewReader(body),
)
if err != nil {
return nil, fmt.Errorf("creating request: %w", err)
}
httpResp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("sending request: %w", err)
}
defer httpResp.Body.Close()
if httpResp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status: %d", httpResp.StatusCode)
}
var resp CheckAccessResponse
if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil {
return nil, fmt.Errorf("decoding response: %w", err)
}
return &resp, nil
}
// Example usage:
func Example() {
client := NewACLClient("http://localhost:8080")
ctx := context.Background()
// Create a policy
policy, err := client.CreatePolicy(ctx, CreatePolicyRequest{
Name: "web-servers",
SpiffeIdPattern: "spiffe://example.org/web-server/.*",
PathPattern: "secrets/web/*",
Permissions: []string{"read", "list"},
})
if err != nil {
panic(err)
}
// Check access
resp, err := client.CheckAccess(ctx,
"spiffe://example.org/web-server/001",
"secrets/web/config",
"read",
)
if err != nil {
panic(err)
}
fmt.Printf("Access allowed: %v\n", resp.Allowed)
fmt.Printf("Matching policies: %v\n", resp.MatchingPolicies)
}
--------------------------------------------------------------------------------
## DRAFTS
This is a random place to dump anything that can be improved, re-used, re-enabled.
Think of this as the River of Styx; where things go to be reborn.
--------------------------------------------------------------------------------
SHAMIR
// Create a new group (using ed25519 as an example)
g := ed25519.NewGroup(acl/policies:
post:
description: Create a new access policy
request:
body:
policy_name: string
spiffe_id_pattern: string # Supports regex/prefix matching
path_pattern: string # Supports glob patterns
permissions:
- read
- list
metadata:
created_by: string
created_at: timestamp
response:
policy_id: string
status: string
get:
description: List all policies
response:
policies:
- policy_id: string
policy_name: string
spiffe_id_pattern: string
path_pattern: string
permissions: [string]
metadata:
created_by: string
created_at: timestamp
last_modified: timestamp
/v1/acl/policies/{policy_id}:
get:
description: Get specific policy details
delete:
description: Remove a policy
put:
description: Update a policy
# Policy Evaluation API (for internal use)
/v1/acl/check:
post:
description: Check if a SPIFFE ID has access to a path
request:
spiffe_id: string
path: string
action: string # read/list
response:
allowed: boolean
matching_policies: [string] # List of policy IDs that granted access
# Example Policy Document
example_policy:
policy_name: "web-servers-secrets"
spiffe_id_pattern: "spiffe://example.org/web-server/*"
path_pattern: "secrets/web/*"
permissions:
- read
- list
metadata:
created_by: "[email protected]"
created_at: "2024-11-16T10:00:00Z"
--------------------------------------------------------------------------------
Audit Trail:
All actions are logged with timestamps and acting admin
Tracks who created each admin
Logs password resets and backup assignments
-----
Issue management:
* This is a tiny project; so it does not need a big fat issue manager.
even a `to_do.txt` with every line in priority order is a good enough way
to manage things.
* The development team (me, Volkan, initially) will use `to do` labels liberally
to designate what to do where in the project.
* GitHub issues will be created on a "per need" basis.
* Also the community will be encouraged to create GitHub issues, yet it won't
be the team's main way to define issues or roadmap.
* I believe this unorthodox way will provide agility.
* For documentation versions, redirect to tagged github snapshots.
======