1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Setup access policy attribute rules |
---|
5 | |
---|
6 | cmd1:env keystore=`pwd` ./attr.py |
---|
7 | |
---|
8 | """ |
---|
9 | |
---|
10 | import os |
---|
11 | import ABAC |
---|
12 | |
---|
13 | keystore=os.environ["keystore"] |
---|
14 | |
---|
15 | ctxt = ABAC.Context() |
---|
16 | print "ABAC version %s" % ctxt.version() |
---|
17 | |
---|
18 | ctxt.load_directory(keystore) |
---|
19 | |
---|
20 | out = ctxt.context_principals() |
---|
21 | print "...initial principal set..." |
---|
22 | for x in out[1]: |
---|
23 | print "%s " % x.string() |
---|
24 | print "\n" |
---|
25 | |
---|
26 | out = ctxt.context_credentials() |
---|
27 | print "...initial policy attribute set..." |
---|
28 | for c in out[1]: |
---|
29 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
30 | print "\n" |
---|
31 | |
---|
32 | acmeID=ABAC.ID("Acme_ID.pem") |
---|
33 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
34 | acme=acmeID.id_keyid() |
---|
35 | |
---|
36 | coyoteID=ABAC.ID("Coyote_ID.pem") |
---|
37 | coyoteID.id_load_privkey_file("Coyote_private.pem"); |
---|
38 | coyote=coyoteID.id_keyid() |
---|
39 | |
---|
40 | roadrunnerID=ABAC.ID("Roadrunner_ID.pem") |
---|
41 | roadrunnerID.id_load_privkey_file("Roadrunner_private.pem"); |
---|
42 | roadrunner=roadrunnerID.id_keyid() |
---|
43 | |
---|
44 | jackrabbitID=ABAC.ID("Jackrabbit_ID.pem") |
---|
45 | jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem"); |
---|
46 | jackrabbit=jackrabbitID.id_keyid() |
---|
47 | |
---|
48 | ################################################ |
---|
49 | # [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner]) |
---|
50 | head = ABAC.Role(acme,"preferred_customer") |
---|
51 | param=ABAC.DataTerm(roadrunnerID) |
---|
52 | tail = ABAC.Role(acme,"friendof") |
---|
53 | tail.role_add_data_term(param) |
---|
54 | attr=ABAC.Attribute(head, 1800) |
---|
55 | attr.attribute_add_tail(tail) |
---|
56 | attr.attribute_bake() |
---|
57 | attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der") |
---|
58 | ctxt.load_attribute_file("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der") |
---|
59 | print attr.string() |
---|
60 | print attr.typed_string() |
---|
61 | print "\n" |
---|
62 | |
---|
63 | ################################################# |
---|
64 | # [keyid:Acme].role:prefered_customer <- [keyid:Coyote] |
---|
65 | head = ABAC.Role(acme,"preferred_customer") |
---|
66 | tail = ABAC.Role(coyote) |
---|
67 | attr=ABAC.Attribute(head, 1800) |
---|
68 | attr.attribute_add_tail(tail) |
---|
69 | attr.attribute_bake() |
---|
70 | attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der") |
---|
71 | ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der") |
---|
72 | print attr.string() |
---|
73 | print attr.typed_string() |
---|
74 | print "\n" |
---|
75 | |
---|
76 | ################################################# |
---|
77 | # [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit] |
---|
78 | param=ABAC.DataTerm(roadrunnerID) |
---|
79 | head = ABAC.Role(acme,"friendof") |
---|
80 | head.role_add_data_term(param) |
---|
81 | tail = ABAC.Role(jackrabbit) |
---|
82 | attr=ABAC.Attribute(head, 1800) |
---|
83 | attr.attribute_add_tail(tail) |
---|
84 | attr.attribute_bake() |
---|
85 | attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der") |
---|
86 | ctxt.load_attribute_file("Acme_friendof_Roadrunner__Jackrabbit_attr.der") |
---|
87 | print attr.string() |
---|
88 | print attr.typed_string() |
---|
89 | print "\n" |
---|
90 | |
---|
91 | ctxt.dump_yap_db() |
---|
92 | ## |
---|