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 @@ -119,6 +119,28 @@ void initialChecks() {
119
119
}
120
120
121
121
int main (int argc, char ** argv) {
122
+ // Drop not needed capabilities. Depending on the environment they might be
123
+ // already dropped, but still make sure we use as little as possible.
124
+ capng_clear (CAPNG_SELECT_ALL);
125
+ capng_type_t cap_types = static_cast <capng_type_t >(CAPNG_EFFECTIVE |
126
+ CAPNG_PERMITTED);
127
+ capng_updatev (CAPNG_ADD, cap_types,
128
+ // BPF is needed to load bpf programs and maps
129
+ CAP_BPF,
130
+ // PERFMON needed for using kprobes and tracepoints
131
+ CAP_PERFMON,
132
+ // DAC_READ_SEARCH is needed to check tracefs
133
+ CAP_DAC_READ_SEARCH,
134
+ // SYS_RESOURCE is needed for setrlimits
135
+ CAP_SYS_RESOURCE,
136
+ // SYS_PTRACE and SYS_ADMIN are needed to read /proc/$PID/ns
137
+ CAP_SYS_PTRACE,
138
+ CAP_SYS_ADMIN, -1 );
139
+
140
+ if (capng_apply (CAPNG_SELECT_ALL) != 0 ) {
141
+ CLOG (WARNING) << " Failed to drop capabilities: " << StrError ();
142
+ }
143
+
122
144
// Print system information before doing actual work.
123
145
auto & host_info = HostInfo::Instance ();
124
146
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