File tree Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,28 @@ void initialChecks() {
121
121
}
122
122
123
123
int main (int argc, char ** argv) {
124
+ // Drop not needed capabilities. Depending on the environment they might be
125
+ // already dropped, but still make sure we use as little as possible.
126
+ capng_clear (CAPNG_SELECT_ALL);
127
+ capng_type_t cap_types = static_cast <capng_type_t >(CAPNG_EFFECTIVE |
128
+ CAPNG_PERMITTED);
129
+ capng_updatev (CAPNG_ADD, cap_types,
130
+ // BPF is needed to load bpf programs and maps
131
+ CAP_BPF,
132
+ // PERFMON needed for using kprobes and tracepoints
133
+ CAP_PERFMON,
134
+ // DAC_READ_SEARCH is needed to check tracefs
135
+ CAP_DAC_READ_SEARCH,
136
+ // SYS_RESOURCE is needed for setrlimits
137
+ CAP_SYS_RESOURCE,
138
+ // SYS_PTRACE and SYS_ADMIN are needed to read /proc/$PID/ns
139
+ CAP_SYS_PTRACE,
140
+ CAP_SYS_ADMIN, -1 );
141
+
142
+ if (capng_apply (CAPNG_SELECT_ALL) != 0 ) {
143
+ CLOG (WARNING) << " Failed to drop capabilities: " << StrError ();
144
+ }
145
+
124
146
// Print system information before doing actual work.
125
147
auto & host_info = HostInfo::Instance ();
126
148
CLOG (INFO) << " Collector Version: " << GetCollectorVersion ();
Original file line number Diff line number Diff line change 4
4
#include < iostream>
5
5
#include < math.h>
6
6
7
- #include < sys/capability.h>
7
+ extern " C" {
8
+ #include < cap-ng.h>
9
+ }
8
10
9
11
#include " Containers.h"
10
12
#include " EventNames.h"
@@ -107,7 +109,10 @@ class CollectorTimerGauge {
107
109
};
108
110
109
111
void CollectorStatsExporter::run () {
110
- capng_clear (CAPNG_SELECT_BOTH);
112
+ capng_clear (CAPNG_SELECT_ALL);
113
+ if (capng_apply (CAPNG_SELECT_ALL) != 0 ) {
114
+ CLOG (WARNING) << " Failed to drop capabilities: " << StrError ();
115
+ }
111
116
112
117
auto & collectorEventCounters = prometheus::BuildGauge ()
113
118
.Name (" rox_collector_events" )
Original file line number Diff line number Diff line change 2
2
3
3
#include < google/protobuf/util/time_util.h>
4
4
5
+ extern " C" {
6
+ #include < cap-ng.h>
7
+ }
8
+
5
9
#include " CollectorStats.h"
6
10
#include " DuplexGRPC.h"
7
11
#include " GRPCUtil.h"
@@ -108,6 +112,20 @@ void NetworkStatusNotifier::ReceiveIPNetworks(const sensor::IPNetworkList& netwo
108
112
}
109
113
110
114
void NetworkStatusNotifier::Run () {
115
+ capng_clear (CAPNG_SELECT_ALL);
116
+ capng_type_t cap_types = static_cast <capng_type_t >(CAPNG_EFFECTIVE |
117
+ CAPNG_PERMITTED);
118
+ capng_updatev (CAPNG_ADD, cap_types,
119
+ // DAC_READ_SEARCH is needed to check tracefs
120
+ CAP_DAC_READ_SEARCH,
121
+ // SYS_PTRACE and SYS_ADMIN are needed to read /proc/$PID/ns
122
+ CAP_SYS_PTRACE,
123
+ CAP_SYS_ADMIN, -1 );
124
+
125
+ if (capng_apply (CAPNG_SELECT_ALL) != 0 ) {
126
+ CLOG (WARNING) << " Failed to drop capabilities: " << StrError ();
127
+ }
128
+
111
129
Profiler::RegisterCPUThread ();
112
130
auto next_attempt = std::chrono::system_clock::now ();
113
131
Original file line number Diff line number Diff line change 2
2
3
3
#include < fstream>
4
4
5
+ extern " C" {
6
+ #include < cap-ng.h>
7
+ }
8
+
5
9
#include " GRPCUtil.h"
6
10
#include " Logging.h"
7
11
#include " ProtoUtil.h"
@@ -43,6 +47,11 @@ bool SignalServiceClient::EstablishGRPCStreamSingle() {
43
47
}
44
48
45
49
void SignalServiceClient::EstablishGRPCStream () {
50
+ capng_clear (CAPNG_SELECT_ALL);
51
+ if (capng_apply (CAPNG_SELECT_ALL) != 0 ) {
52
+ CLOG (WARNING) << " Failed to drop capabilities: " << StrError ();
53
+ }
54
+
46
55
while (EstablishGRPCStreamSingle ());
47
56
CLOG (INFO) << " Signal service client terminating." ;
48
57
}
You can’t perform that action at this time.
0 commit comments