[5f551d3] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
[f824a9e] | 4 | Run the queries described in README |
---|
[5f551d3] | 5 | |
---|
| 6 | cmd1:env keystore=`pwd` ./query.py |
---|
| 7 | cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py |
---|
| 8 | |
---|
| 9 | """ |
---|
| 10 | |
---|
| 11 | import os |
---|
| 12 | import ABAC |
---|
| 13 | |
---|
| 14 | ctxt = ABAC.Context() |
---|
| 15 | |
---|
[f824a9e] | 16 | # Keystore is the directory containing the principal credentials. |
---|
| 17 | # Load existing principals and/or policy credentials |
---|
| 18 | if (os.environ.has_key("keystore")) : |
---|
| 19 | keystore=os.environ["keystore"] |
---|
| 20 | ctxt.load_directory(keystore) |
---|
| 21 | else: |
---|
| 22 | print("keystore is not set...") |
---|
| 23 | exit(1) |
---|
[5f551d3] | 24 | |
---|
[f824a9e] | 25 | # retrieve principals' keyid value from local credential files |
---|
[5f551d3] | 26 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
| 27 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
| 28 | acme=acmeID.id_keyid() |
---|
| 29 | |
---|
| 30 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
| 31 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
| 32 | bob=bobID.id_keyid() |
---|
| 33 | |
---|
| 34 | aliceID=ABAC.ID("Alice_ID.pem"); |
---|
| 35 | aliceID.id_load_privkey_file("Alice_private.pem"); |
---|
| 36 | alice=aliceID.id_keyid() |
---|
| 37 | |
---|
| 38 | globotronID=ABAC.ID("Globotron_ID.pem"); |
---|
| 39 | globotronID.id_load_privkey_file("Globotron_private.pem"); |
---|
| 40 | globotron=globotronID.id_keyid() |
---|
| 41 | |
---|
| 42 | ########################################################################## |
---|
[f824a9e] | 43 | # dump the loaded principals/policies |
---|
| 44 | # |
---|
| 45 | out = ctxt.context_principals() |
---|
| 46 | print "\n...final principal set..." |
---|
| 47 | for x in out[1]: |
---|
| 48 | print "%s " % x.string() |
---|
| 49 | out = ctxt.context_credentials() |
---|
| 50 | print "\n...final policy attribute set..." |
---|
| 51 | for c in out[1]: |
---|
| 52 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 53 | |
---|
| 54 | ########################################################################## |
---|
| 55 | # is alice a admin at Globotron ? |
---|
[5f551d3] | 56 | # role=[keyid:Globotron].role:admin |
---|
| 57 | # p=[keyid:Alice] |
---|
| 58 | role = ABAC.Role(globotron,"admin") |
---|
| 59 | p = ABAC.Role(alice) |
---|
| 60 | print "\n===good=============== Globotron.admin <- Alice" |
---|
| 61 | out = ctxt.query(role, p) |
---|
| 62 | for c in out[1]: |
---|
| 63 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 64 | |
---|
| 65 | ########################################################################## |
---|
[f824a9e] | 66 | # is bob a admin at Globotron ? |
---|
[5f551d3] | 67 | # role=[keyid:Globotron].role:admin |
---|
| 68 | # p=[keyid:Bob] |
---|
| 69 | role = ABAC.Role(globotron,"admin") |
---|
| 70 | p = ABAC.Role(bob) |
---|
| 71 | print "\n===bad=============== Globotron.admin <- Bob" |
---|
| 72 | out = ctxt.query(role, p) |
---|
| 73 | for c in out[1]: |
---|
| 74 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | ########################################################################## |
---|
[f824a9e] | 78 | # can bob create experiment at Acme ? |
---|
[5f551d3] | 79 | # role=[keyid:Acme].role:experiment_create |
---|
| 80 | # p=[keyid:Bob] |
---|
| 81 | role = ABAC.Role(acme,"experiment_create") |
---|
| 82 | p = ABAC.Role(bob) |
---|
| 83 | print "\n===good=============== Acme.experiment_create <- Bob" |
---|
| 84 | out = ctxt.query(role, p) |
---|
| 85 | for c in out[1]: |
---|
| 86 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|