3b2688a6507509444ba637e54cc80f02b21ba92d
[aaf/authz.git] / authz-cass / src / main / cql / init.cql
1 //
2 //  Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 //
4 // For Developer Machine single instance
5 //
6  CREATE KEYSPACE authz
7  WITH REPLICATION = {'class' : 'SimpleStrategy','replication_factor':1};
8  
9 USE authz;
10
11 //
12 // CORE Table function
13 //
14
15 // Namespace - establish hierarchical authority to modify
16 // Permissions and Roles
17 // "scope" is flag to determine Policy.  Typical important scope
18 // is "company" (1)
19 CREATE TABLE ns (
20   name                  varchar,
21   scope                 int,  // deprecated 2.0.11
22   description           varchar,
23   parent                varchar,
24   type                  int,
25   PRIMARY KEY (name)  
26 );
27 CREATE INDEX ns_parent on ns(parent);
28   
29
30 CREATE TABLE ns_attrib (
31   ns            varchar,
32   key           varchar,
33   value         varchar,
34   PRIMARY KEY (ns,key)
35 );
36 create index ns_attrib_key on ns_attrib(key);
37
38 // Will be cached
39 CREATE TABLE role (
40   ns        varchar,
41   name          varchar,
42   perms         set<varchar>, // Use "Key" of "name|type|action"
43   description varchar,
44   PRIMARY KEY (ns,name)
45 );
46 CREATE INDEX role_name  ON role(name);
47  
48 // Will be cached
49 CREATE TABLE perm (
50   ns        varchar,
51   type          varchar,
52   instance      varchar,
53   action        varchar,
54   roles         set<varchar>, // Need to find Roles given Permissions
55   description varchar,
56   PRIMARY KEY (ns,type,instance,action)
57 );
58
59 // This table is user for Authorization
60 CREATE TABLE user_role (
61     user                varchar,
62     role                varchar, // deprecated: change to ns/rname after 2.0.11
63     ns                  varchar,
64     rname               varchar,
65     expires             timestamp,
66     PRIMARY KEY(user,role)
67   );
68 CREATE INDEX user_role_ns ON user_role(ns);
69 CREATE INDEX user_role_role ON user_role(role);
70
71 // This table is only for the case where return User Credential (MechID) Authentication
72 CREATE TABLE cred (
73     id    varchar,
74     type  int,
75     expires timestamp,  
76     ns    varchar,
77     other int,
78     notes varchar,
79     cred  blob,
80     prev  blob,
81     PRIMARY KEY (id,type,expires)
82   );
83 CREATE INDEX cred_ns ON cred(ns);
84
85 // Certificate Cross Table
86 //   coordinated with CRED type 2
87 CREATE TABLE cert (
88     fingerprint blob,
89     id          varchar,
90     x500        varchar,
91     expires     timestamp,  
92     PRIMARY KEY (fingerprint)
93   );
94 CREATE INDEX cert_id ON cert(id);
95 CREATE INDEX cert_x500 ON cert(x500);
96
97 CREATE TABLE notify (
98   user text,
99   type int,
100   last timestamp,
101   checksum int,
102   PRIMARY KEY (user,type)
103 );
104
105 CREATE TABLE x509 (
106   ca     text,
107   serial blob,
108   id     text,
109   x500   text,
110   x509   text,
111   PRIMARY KEY (ca,serial)
112 );
113
114
115 CREATE INDEX x509_id   ON x509 (id);
116 CREATE INDEX x509_x500 ON x509 (x500);
117
118 // 
119 // Deployment Artifact (for Certman)
120 //
121 CREATE TABLE artifact (
122   mechid        text,
123   machine       text,
124   type          Set<text>,
125   sponsor       text,
126   ca            text,
127   dir           text,
128   appName       text,
129   os_user       text,
130   notify        text,
131   expires       timestamp,
132   renewDays   int,
133   PRIMARY KEY (mechid,machine)
134 );
135 CREATE INDEX artifact_machine ON artifact(machine); 
136
137 //
138 // Non-Critical Table functions
139 //
140 // Table Info - for Caching
141 CREATE TABLE cache (
142    name         varchar,
143    seg          int,            // cache Segment
144    touched      timestamp,
145    PRIMARY KEY(name,seg)
146 );
147
148 CREATE TABLE history (
149   id                    timeuuid,
150   yr_mon                int,
151   user                  varchar,
152   action                varchar,
153   target                varchar,   // user, user_role, 
154   subject               varchar,   // field for searching main portion of target key
155   memo                  varchar,   //description of the action
156   reconstruct   blob,      //serialized form of the target
157   // detail     Map<varchar, varchar>,  // additional information
158   PRIMARY KEY (id)
159 );
160 CREATE INDEX history_yr_mon ON history(yr_mon);
161 CREATE INDEX history_user ON history(user); 
162 CREATE INDEX history_subject ON history(subject); 
163
164 // 
165 // A place to hold objects to be created at a future time.
166 //
167 CREATE TABLE future (
168   id        uuid,               // uniquify
169   target    varchar,            // Target Table
170   memo      varchar,            // Description
171   start     timestamp,          // When it should take effect
172   expires   timestamp,          // When not longer valid
173   construct blob,               // How to construct this object (like History)
174   PRIMARY KEY(id)
175 );
176 CREATE INDEX future_idx ON future(target);
177 CREATE INDEX future_start_idx ON future(start);
178
179
180 CREATE TABLE approval (
181   id        timeuuid,         // unique Key
182   ticket    uuid,             // Link to Future Record
183   user      varchar,          // the user who needs to be approved
184   approver  varchar,          // user approving
185   type      varchar,          // approver types i.e. Supervisor, Owner
186   status    varchar,          // approval status. pending, approved, denied
187   memo      varchar,          // Text for Approval to know what's going on
188   operation varchar,          // List operation to perform
189   PRIMARY KEY(id)
190  );
191 CREATE INDEX appr_approver_idx ON approval(approver);
192 CREATE INDEX appr_user_idx ON approval(user);
193 CREATE INDEX appr_ticket_idx ON approval(ticket);
194 CREATE INDEX appr_status_idx ON approval(status);
195
196 CREATE TABLE delegate (
197   user      varchar,
198   delegate  varchar,
199   expires   timestamp,
200   PRIMARY KEY (user)  
201 );
202 CREATE INDEX delg_delg_idx ON delegate(delegate);
203
204 //
205 // Used by authz-batch processes to ensure only 1 runs at a time
206 //
207 CREATE TABLE run_lock (
208   class text,
209   host text,
210   start timestamp,
211   PRIMARY KEY ((class))
212 );