Debian Codegraph @

libselinux/man/man5/selabel_db.5

raw
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Author: KaiGai Kohei <[email protected]> 2009
4 .TH "selabel_db" "5" "01 DEC 2011" "Security Enhanced Linux" "SELinux API documentation"
5 .SH "NAME"
6 selabel_db \- userspace SELinux labeling interface and configuration file format for the RDBMS objects context backend
7 .
8 .SH "SYNOPSIS"
9 .B #include <selinux/label.h>
10 .sp
11 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
12 .in +\w'int selabel_lookup('u
13 .BI "char **" context ,
14 .br
15 .BI "const char *" object_name ", int " object_type ");"
16 .in
17 .sp
18 .BI "int selabel_lookup_raw(struct selabel_handle *" hnd ,
19 .in +\w'int selabel_lookup('u
20 .BI "char **" context ,
21 .br
22 .BI "const char *" object_name ", int " object_type ");"
23 .
24 .SH "DESCRIPTION"
25 The DB contexts backend maps from a pair of object name and class into security contexts. It is used to find the appropriate context for database objects when relabeling a certain database. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
26 .br
27 \fBselabel_lookup\fR(3) describes the function with its return and error codes.
28 .sp
29 The \fIobject_name\fR should be a fully qualified name using the hierarchy of database objects. For example, the \fBpg_class\fR table in the \fBpostgres\fR database and \fBpg_catalog\fR schema should be qualified as:
30 .RS
31 .B Bpostgres.pg_catalog.pg_class
32 .RE
33 .sp
34 The \fBNOTES\fR section has further information on database support for namespace hierarchies.
35 .sp
36 The \fIobject_type\fR argument should be set to one of the following values:
37 .RS
38 .TP
39 .B SELABEL_DB_DATABASE
40 The
41 .I object_name
42 argument specifies the name of a database itself, such as "postgres".
43 .TP
44 .B SELABEL_DB_SCHEMA
45 The
46 .I object_name
47 argument specifies the name of a schema object, such as "postgres.public".
48 .TP
49 .B SELABEL_DB_TABLE
50 The
51 .I object_name
52 argument specifies the name of a table object, such as "postgres.public.my_table"
53 .TP
54 .B SELABEL_DB_COLUMN
55 The
56 .I object_name
57 argument specifies the name of a column object, such as "postgres.public.my_table.user_id"
58 .TP
59 .B SELABEL_DB_TUPLE
60 The
61 .I object_name
62 argument specifies the name of a table object which contains the tuples to be relabeled, such as "postgresql.public.my_table". Note that we have no way to identify individual tuple objects, except for WHERE clause on DML statements, because it has no name.
63 .TP
64 .B SELABEL_DB_PROCEDURE
65 The
66 .I object_name
67 argument specifies the name of a procedure object, such as "postgres.public.my_func". Note that we don't support lookup of individual security contexts for procedures which have the same name but different arguments.
68 .TP
69 .B SELABEL_DB_SEQUENCE
70 The
71 .I object_name
72 argument specifies the name of a sequence object, such as "postgres.public.my_seq".
73 .TP
74 .B SELABEL_DB_BLOB
75 The
76 .I object_name
77 argument specifies the name of a large object, such as "postgres.16308".
78 Note that a large object does not have a name, so it is identified by its identifier value.
79 .TP
80 .B SELABEL_DB_VIEW
81 The
82 .I object_name
83 argument specifies the name of a view object, such as "postgres.public.my_view".
84 .TP
85 .B SELABEL_DB_LANGUAGE
86 The
87 .I object_name
88 argument specifies the name of a language object, such as "postgres.public.tcl".
89 .TP
90 .B SELABEL_DB_EXCEPTION
91 The
92 .I object_name
93 argument specifies the name of a exception object.
94 .TP
95 .B SELABEL_DB_DATATYPE
96 The
97 .I object_name
98 argument specifies the name of a type or domain object, such as postgres.public.my_type.
99 .RE
100 .sp
101 Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR
102 by default, although this can be changed by \fBselinux_set_callback\fR(3).
103 .sp
104 .BR selabel_lookup_raw (3)
105 behaves identically to \fBselabel_lookup\fR(3) but does not perform context
106 translation.
107 .sp
108 The \fBFILES\fR section details the configuration files used to determine the database object context.
109 .
110 .SH "OPTIONS"
111 In addition to the global options described in \fBselabel_open\fR(3), this backend recognizes the following options:
112 .RS
113 .TP
114 .B SELABEL_OPT_PATH
115 A non-null value for this option specifies a path to a file that will be opened in lieu of the standard DB contexts file.
116 It tries to open the specfile designed for SE-PostgreSQL as default, so if another RDBMS uses this interface, it needs to give an explicit specfile designed for that RDBMS (see the \fBFILES\fR section for details).
117 .RE
118 .
119 .SH "FILES"
120 The database context file used to retrieve a context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy database contexts location (as returned by \fBselinux_sepgsql_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used (this option must be used to support databases other than SE-PostgreSQL).
121 .sp
122 The default database object contexts file is:
123 .RS
124 .I /etc/selinux/{SELINUXTYPE}/contexts/sepgsql_context
125 .RE
126 .sp
127 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
128 .sp
129 The entries within the database contexts file are shown in the \fBObject Name String Values\fR and \fBFILE FORMAT\fR sections.
130 .
131 .SH "Object Name String Values"
132 The string name assigned to each \fIobject_type\fR argument that can be present in the database contexts file are:
133 .TS
134 center, allbox, tab(@);
135 lI lB
136 lB l .
137 object_type@Text Name
138 SELABEL_DB_DATABASE@db_database
139 SELABEL_DB_SCHEMA@db_schema
140 SELABEL_DB_VIEW@db_view
141 SELABEL_DB_LANGUAGE@db_language
142 SELABEL_DB_TABLE@db_table
143 SELABEL_DB_COLUMN@db_column
144 SELABEL_DB_TUPLE@db_tuple
145 SELABEL_DB_PROCEDURE@db_procedure
146 SELABEL_DB_SEQUENCE@db_sequence
147 SELABEL_DB_BLOB@db_blob
148 SELABEL_DB_EXCEPTION@db_exception
149 SELABEL_DB_DATATYPE@db_datatype
150 .TE
151 .
152 .SH "FILE FORMAT"
153 Each line within the database contexts file is as follows:
154 .RS
155 .I object_type object_name context
156 .RE
157 .sp
158 Where:
159 .RS
160 .I object_type
161 .RS
162 This is the string representation of the object type shown in the \fBObject Name String Values\fR section.
163 .RE
164 .I object_name
165 .RS
166 The key used to obtain the context based on the \fIobject_type\fR.
167 .sp
168 The entry can contain '*' for wildcard matching or '?' for substitution.
169 .sp
170 Note that if the '*' is used, then be aware that the order of entries in the file is important. The '*' on its own is used to ensure a default fallback context is assigned and should be the last entry in the \fIobject_type\fR block.
171 .RE
172 .I context
173 .RS
174 The security context that will be applied to the object.
175 .RE
176 .RE
177 .sp
178 The following example is for SE-PostgreSQL:
179 .sp
180 # ./contexts/sepgsql_contexts file
181 .br
182 # object_type object_name context
183 .br
184 db_database my_database system_u:object_r:sepgsql_db_t:s0
185 .br
186 db_database * system_u:object_r:sepgsql_db_t:s0
187 .br
188 db_schema *.* system_u:object_r:sepgsql_schema_t:s0
189 .br
190 db_tuple row_low system_u:object_r:sepgsql_table_t:s0
191 .br
192 db_tuple row_high system_u:object_r:sepgsql_table_t:s0:c1023
193 .br
194 db_tuple *.*.* system_u:object_r:sepgsql_table_t:s0
195 .
196 .SH "NOTES"
197 .IP "1." 4
198 A suitable database contexts file needs to be written for the target RDBMS and the \fBSELABEL_OPT_PATH\fR option must be used in \fBselabel_open\fR(3) to load it.
199 .IP "2." 4
200 The hierarchy of the namespace for database objects depends on the RDBMS, however the \fIselabel*\fR interfaces do not have any specific support for a namespace hierarchy.
201 .sp
202 SE-PostgreSQL has a namespace hierarchy where a database is the top level object with the schema being the next level. Under the schema object there can be other types of objects such as tables and procedures. This hierarchy is supported as follows:
203 .RS
204 .RS
205 .sp
206 If a security context is required for "my_table" table in the "public"
207 schema within the "postgres" database, then the \fBselabel_lookup\fR(3)
208 parameters for \fIobject_type\fR would be \fBSELABEL_DB_TABLE\fR and the
209 \fIobject_name\fR would be "postgres.public.my_table", the security
210 context (if available), would be returned in \fIcontext\fR.
211 .RE
212 .RE
213 .IP "3." 4
214 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.
215 .
216 .SH "SEE ALSO"
217 .ad l
218 .nh
219 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_sepgsql_context_path "(3), " freecon "(3), " selinux_config "(5) "