Skip to content

Commit 82aa7bb

Browse files
committed
Policy working with pcp plugin
1 parent 86f89b4 commit 82aa7bb

File tree

4 files changed

+20
-78
lines changed

4 files changed

+20
-78
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ restorecon -RvF /usr/sbin/grafana-* \
3636
/etc/grafana \
3737
/var/log/grafana \
3838
/var/lib/grafana \
39+
/usr/share/performancecopilot-pcp-app \
3940
/usr/share/grafana/bin
4041

4142
# Start grafana
@@ -68,6 +69,16 @@ ausearch -m avc,user_avc,selinux_err -ts recent | audit2allow -R
6869
If you get a could not open interface info [/var/lib/sepolgen/interface_info] error.
6970
Ensure policycoreutils-devel is installed and/or run: `sepolgen-ifgen`
7071

72+
## Removing the policy
73+
74+
* To remove the policy, the added port must first be removed
75+
```sh
76+
sudo semanage port -d -p tcp 3000
77+
```
78+
* Now, to remove the policy run
79+
```sh
80+
sudo semodule -r grafana
81+
```
7182
## Compatibility Notes
7283
Built on CentOS Stream 9 at the time with:
7384
```

grafana.fc

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
#/var/lib/grafana/plugins(/.*)? gen_context(system_u:object_r:grafana_plugin_t,s0)
1717

18-
/var/lib/grafana/plugins/performancecopilot-pcp-app -- gen_context(system_u:object_r:grafana_pcp_plugin_exec_t,s0)
19-
2018
/usr/share/grafana/bin/grafana -- gen_context(system_u:object_r:grafana_exec_t,s0)
2119
/usr/share/grafana/bin/grafana-cli -- gen_context(system_u:object_r:grafana_exec_t,s0)
2220
/usr/share/grafana/bin/grafana-server -- gen_context(system_u:object_r:grafana_exec_t,s0)
21+
22+
#define context for pcp plugin
23+
/usr/share/performancecopilot-pcp-app/datasources/redis/pcp_redis_datasource_(.*) -- gen_context(system_u:object_r:grafana_pcp_exec_t,s0)

grafana.if

-52
Original file line numberDiff line numberDiff line change
@@ -139,55 +139,3 @@ interface(`grafana_admin',`
139139
systemd_read_fifo_file_passwd_run($1)
140140
')
141141
')
142-
143-
########################################
144-
## <summary>
145-
## Execute the grafana unconfined plugins with
146-
## a domain transition.
147-
## </summary>
148-
## <param name="domain">
149-
## <summary>
150-
## Domain allowed access.
151-
## </summary>
152-
## </param>
153-
#
154-
interface(`grafana_domtrans_unconfined_plugins',`
155-
gen_require(`
156-
type grafana_unconfined_plugin_t;
157-
type grafana_unconfined_plugin_exec_t;
158-
')
159-
160-
domtrans_pattern($1, grafana_unconfined_plugin_exec_t, grafana_unconfined_plugin_t)
161-
')
162-
163-
########################################
164-
## <summary>
165-
## Create a set of derived types for various
166-
## grafana plugins,
167-
## </summary>
168-
## <param name="plugins_group_name">
169-
## <summary>
170-
## The name to be used for deriving type names.
171-
## </summary>
172-
## </param>
173-
#
174-
template(`grafana_plugin_template',`
175-
gen_require(`
176-
attribute grafana_plugin_domain;
177-
type grafana_t;
178-
')
179-
180-
type grafana_$1_plugin_t, grafana_plugin_domain;
181-
type grafana_$1_plugin_exec_t;
182-
application_domain(grafana_$1_plugin_t, grafana_$1_plugin_exec_t)
183-
role system_r types grafana_$1_plugin_t;
184-
185-
domtrans_pattern(grafana_t, grafana_$1_plugin_exec_t, grafana_$1_plugin_t)
186-
allow grafana_t grafana_$1_plugin_exec_t:file ioctl;
187-
188-
# needed by command.cfg
189-
domtrans_pattern(grafana_t, grafana_$1_plugin_exec_t, grafana_$1_plugin_t)
190-
191-
kernel_read_system_state(grafana_$1_plugin_t)
192-
193-
')

grafana.te

+6-24
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ gen_tunable(grafana_can_tcp_connect_mysql_port, false)
3434
## </desc>
3535
gen_tunable(grafana_can_tcp_connect_prometheus_port, false)
3636

37-
attribute grafana_plugin_domain;
3837

3938
type grafana_t;
4039
type grafana_exec_t;
@@ -68,26 +67,13 @@ files_type(grafana_var_lib_t)
6867
type grafana_port_t;
6968
corenet_port(grafana_port_t)
7069

71-
grafana_plugin_template(pcp)
70+
type grafana_pcp_exec_t;
71+
corecmd_executable_file(grafana_pcp_exec_t)
72+
can_exec(grafana_t, grafana_pcp_exec_t)
7273

73-
######################################
74-
#
75-
# Common plugin domain local policy
76-
#
77-
78-
allow grafana_plugin_domain self:fifo_file rw_fifo_file_perms;
79-
80-
allow grafana_t grafana_plugin_domain:process signal_perms;
81-
allow grafana_plugin_domain grafana_t:process signal_perms;
82-
83-
corecmd_exec_bin(grafana_plugin_domain)
84-
85-
dev_read_urand(grafana_plugin_domain)
86-
dev_read_rand(grafana_plugin_domain)
87-
dev_read_sysfs(grafana_plugin_domain)
88-
89-
userdom_use_inherited_user_ptys(grafana_plugin_domain)
90-
userdom_use_inherited_user_ttys(grafana_plugin_domain)
74+
# Ports 32768-60999 (pcp port is 44322)
75+
corenet_tcp_connect_all_ephemeral_ports(grafana_t)
76+
grafana_exec(grafana_t)
9177

9278
########################################
9379
#
@@ -99,12 +85,8 @@ allow grafana_t self:unix_dgram_socket create_socket_perms;
9985

10086
allow grafana_t grafana_port_t:tcp_socket { name_bind name_connect };
10187

102-
#allow grafana_t grafana_exec_t:file execute_no_trans;
10388
allow grafana_t self:unix_stream_socket connectto;
10489

105-
allow grafana_t grafana_var_lib_t:file { execute execute_no_trans };
106-
allow grafana_t grafana_var_lib_t:file map;
107-
10890
allow init_t grafana_tmp_t:sock_file unlink;
10991

11092
manage_dirs_pattern(grafana_t, grafana_conf_t, grafana_conf_t)

0 commit comments

Comments
 (0)