-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdrafts.txt
688 lines (542 loc) · 18.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// \\ SPIKE: Secure your secrets with SPIFFE.
// \\\\\ Copyright 2024-present SPIKE contributors.
// \\\\\\\ SPDX-License-Identifier: Apache-2.0
--------------------------------------------------------------------------------
//
//select {
//case <-ticker.C:
// keepers := env.Keepers()
//
// shardsNeeded := 2
// var shardsCollected [][]byte
//
// for _, keeperApiRoot := range keepers {
// u, _ := url.JoinPath(keeperApiRoot, "/v1/store/shard")
//
// client, err := net.CreateMtlsClientWithPredicate(
// source, auth.IsKeeper,
// )
// if err != nil {
// log.Log().Info("tick", "msg",
// "Failed to create mTLS client", "err", err)
// continue
// }
//
// md, err := json.Marshal(reqres.ShardRequest{})
// if err != nil {
// log.Log().Info("tick", "msg",
// "Failed to marshal request", "err", err)
// continue
// }
//
// data, err := net.Post(client, u, md)
// var res reqres.ShardResponse
//
// if len(data) == 0 {
// log.Log().Info("tick", "msg", "No data")
// continue
// }
//
// err = json.Unmarshal(data, &res)
// if err != nil {
// log.Log().Info("tick", "msg",
// "Failed to unmarshal response", "err", err)
// continue
// }
//
// if len(shardsCollected) < shardsNeeded {
// decodedShard, err := base64.StdEncoding.DecodeString(res.Shard)
// if err != nil {
// log.Log().Info("tick", "msg", "Failed to decode shard")
// continue
// }
//
// // Check if the shard already exists in shardsCollected
// shardExists := false
// for _, existingShard := range shardsCollected {
// if bytes.Equal(existingShard, decodedShard) {
// shardExists = true
// break
// }
// }
// if shardExists {
// continue
// }
//
// shardsCollected = append(shardsCollected, decodedShard)
// }
//
// if len(shardsCollected) >= shardsNeeded {
// log.Log().Info("tick",
// "msg", "Collected required shards",
// "shards_collected", len(shardsCollected))
//
// g := group.P256
//
// firstShard := shardsCollected[0]
// firstShare := secretsharing.Share{
// ID: g.NewScalar(),
// Value: g.NewScalar(),
// }
// firstShare.ID.SetUint64(1)
// err := firstShare.Value.UnmarshalBinary(firstShard)
// if err != nil {
// log.FatalLn("Failed to unmarshal share: " + err.Error())
// }
//
// secondShard := shardsCollected[1] secondShare := secretsharing.Share{
// ID: g.NewScalar(),
// Value: g.NewScalar(),
// }
// secondShare.ID.SetUint64(2)
// err = secondShare.Value.UnmarshalBinary(secondShard)
// if err != nil {
// log.FatalLn("Failed to unmarshal share: " + err.Error())
// }
//
// var shares []secretsharing.Share
// shares = append(shares, firstShare)
// shares = append(shares, secondShare)
//
// reconstructed, err := secretsharing.Recover(1, shares)
// if err != nil {
// log.FatalLn("Failed to recover: " + err.Error())
// }
//
// // TODO: check for errors.
// binaryRec, _ := reconstructed.MarshalBinary()
//
// // TODO: check size 32bytes.
//
// encoded := hex.EncodeToString(binaryRec)
// state.Initialize(encoded)
//
// log.Log().Info("tick", "msg", "Initialized backing store")
// return
// }
//
// log.Log().Info("tick",
// "msg", "Failed to collect shards... will retry",
// )
// case <-ctx.Done():
// return
// }
//}
--------------------------------------------------------------------------------
From chat logs:
> In a pinch, a spire-agent with unix attestor can identify individual users.
> This may just be enough for admin identification for initial
> bootstrapping/recovery purposes.
That's a good idea. The admin user should already have an SVID for
"their" user anyway.
For example the following entry identifies the user:
```text
# [exhibit 1:]
# Register SPIKE Pilot
spire-server entry create \
-spiffeID spiffe://spike.ist/spike/pilot \
-parentID "spiffe://spike.ist/spire-agent" \
-selector unix:uid:"$(id -u)" \
-selector unix:path:"$PILOT_PATH" \
-selector unix:sha256:"$PILOT_SHA"
```
So the fact that the user can use the SPIKE Pilot (the `spike` binary)
indeed means that they are authenticated. They don't need a password to further
authenticate themselves. (reasoning: they cannot be that user unless they
log in to the unix box -- the trust boundary is the box itself)
> named admins. so, for most things you know who is doing what.
> JWT will handle this well, using something like Keycloak,
> Entra, github, gitlab, facebook, etc, etc.
^ that needs to be a user story on its own. We can start experimenting with
keycloak and see how it goes from there. An OIDC is an OIDC is an
OIDC anyway -- how different can they be :)
> traditional admin, needed when things go horribly wrong to
> reenable named admins. I'm thinking, SPIRE issued jwt/svid for
> a certain uid, on a certain machine
I think `[exhibit 1:]` is good enough to secure the traditional admin.
We can have a SPIFFE ID like `spiffe://spike.ist/spike/pilot/role/superuser`.
It does not even have to be a JWT SVID. Someone who can talk to SPIKE can
assign/unassign it.
So. If hell broke lose, I'll assign myself a superadmin SVID;
fix stuff, and then unregister that SVID.
For named admins, we'd need OIDC, which can wait for a while.
For now, one superadmin is good enough.
> A token isn't useful without someone vetting it....
Yes, and I agree that it's not worth introducing to complexity, unless either of us
want to found a TPM/human-id startup (which is not a bad idea ideed :))
> Thats the problem with passwords. Your trusting a human, with limited memory,
> with a string a machine cares about and hope it stays secure. Thats proven hard.
LOL, but agreed.
--
So in short, the above approach I think...
1. will eliminate need for password.
2. will push identifying the superadmin to their unix credentials
(one who owns the box owns spike, provided someone who owns spire
let them own spike -- I like the multi-level access approach.
So if I have login access to the box, but not to SPIRE, then the SPIRE admin can
remove my access if I turn out to be a bad superadmin :) -- but in reality
I will be the alpha and the omega (both SPIRE admin and also linux user))
3. root key backup and rotation is figureoutable and FFS.
4. named admins are figureoutable and FFS.
--------------------------------------------------------------------------------
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.
======