#!/usr/bin/env python """ Setup access policy attribute rules cmd1:env keystore=`pwd` ./attr.py """ import os import ABAC keystore=os.environ["keystore"] ctxt = ABAC.Context() print "ABAC version %s" % ctxt.version() ctxt.load_directory(keystore) out = ctxt.context_principals() print "...initial principal set..." for x in out[1]: print "%s " % x.string() print "\n" out = ctxt.context_credentials() print "...initial policy attribute set..." for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) print "\n" acmeID=ABAC.ID("Acme_ID.pem") acmeID.id_load_privkey_file("Acme_private.pem"); acme=acmeID.id_keyid() coyoteID=ABAC.ID("Coyote_ID.pem") coyoteID.id_load_privkey_file("Coyote_private.pem"); coyote=coyoteID.id_keyid() roadrunnerID=ABAC.ID("Roadrunner_ID.pem") roadrunnerID.id_load_privkey_file("Roadrunner_private.pem"); roadrunner=roadrunnerID.id_keyid() jackrabbitID=ABAC.ID("Jackrabbit_ID.pem") jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem"); jackrabbit=jackrabbitID.id_keyid() ################################################ # [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner]) head = ABAC.Role(acme,"preferred_customer") param=ABAC.DataTerm(roadrunnerID) tail = ABAC.Role(acme,"friendof") tail.role_add_data_term(param) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der") ctxt.load_attribute_file("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:Acme].role:prefered_customer <- [keyid:Coyote] head = ABAC.Role(acme,"preferred_customer") tail = ABAC.Role(coyote) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der") ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der") print attr.string() print attr.typed_string() print "\n" ################################################# # [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit] param=ABAC.DataTerm(roadrunnerID) head = ABAC.Role(acme,"friendof") head.role_add_data_term(param) tail = ABAC.Role(jackrabbit) attr=ABAC.Attribute(head, 1800) attr.attribute_add_tail(tail) attr.attribute_bake() attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der") ctxt.load_attribute_file("Acme_friendof_Roadrunner__Jackrabbit_attr.der") print attr.string() print attr.typed_string() print "\n" ctxt.dump_yap_db() ##