Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mstemm committed May 15, 2017
2 parents d1b6b2b + a86e3fc commit b0ae29c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

This file documents all notable changes to Falco. The release numbering uses [semantic versioning](http://semver.org).

## v0.6.1

Released 2016-05-15

### Major Changes

None

### Minor Changes

* Small changes to token bucket used to throttle falco events [[#234](https://github.com/draios/falco/pull/234)]] [[#235](https://github.com/draios/falco/pull/235)]] [[#236](https://github.com/draios/falco/pull/236)]] [[#238](https://github.com/draios/falco/pull/238)]]

### Bug Fixes

* Update the falco driver to work with kernel 4.11 [[#829](https://github.com/draios/sysdig/pull/829)]

### Rule Changes

* Don't allow apache2 to spawn shells in containers [[#231](https://github.com/draios/falco/issues/231)] [[#232](https://github.com/draios/falco/pull/232)]

## v0.6.0

Released 2016-03-29
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#### Latest release

**v0.6.0**
**v0.6.1**
Read the [change log](https://github.com/draios/falco/blob/dev/CHANGELOG.md)

Dev Branch: [![Build Status](https://travis-ci.org/draios/falco.svg?branch=dev)](https://travis-ci.org/draios/falco)<br />
Expand Down
2 changes: 1 addition & 1 deletion rules/falco_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
and shell_procs
and proc.pname exists
and not proc.pname in (shell_binaries, docker_binaries, k8s_binaries, lxd_binaries, aide_wrapper_binaries, nids_binaries,
monitoring_binaries, gitlab_binaries, initdb, pg_ctl, awk, apache2, falco, cron, erl_child_setup)
monitoring_binaries, gitlab_binaries, initdb, pg_ctl, awk, falco, cron, erl_child_setup)
and not trusted_containers
output: "Shell spawned in a container other than entrypoint (user=%user.name %container.info shell=%proc.name parent=%proc.pname cmdline=%proc.cmdline)"
priority: WARNING
Expand Down
36 changes: 28 additions & 8 deletions userspace/engine/token_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,30 @@ token_bucket::~token_bucket()
{
}

void token_bucket::init(uint32_t rate, uint32_t max_tokens)
void token_bucket::init(double rate, double max_tokens, uint64_t now)
{
m_rate = rate;
m_max_tokens = max_tokens;
m_tokens = max_tokens;
m_last_seen = sinsp_utils::get_current_time_ns();

if(now == 0)
{
now = sinsp_utils::get_current_time_ns();
}

m_last_seen = now;
}

bool token_bucket::claim()
{
// Determine the number of tokens gained. Delta between
// last_seen and now, divided by the rate.
uint64_t now = sinsp_utils::get_current_time_ns();
uint64_t tokens_gained = (now - m_last_seen) / (m_rate * 1000000000);

return claim(1, now);
}

bool token_bucket::claim(double tokens, uint64_t now)
{
double tokens_gained = m_rate * ((now - m_last_seen) / (1000000000.0));
m_last_seen = now;

m_tokens += tokens_gained;
Expand All @@ -58,14 +68,24 @@ bool token_bucket::claim()
}

//
// If tokens is < 1, can't claim.
// If m_tokens is < tokens, can't claim.
//
if(m_tokens < 1)
if(m_tokens < tokens)
{
return false;
}

m_tokens--;
m_tokens -= tokens;

return true;
}

double token_bucket::get_tokens()
{
return m_tokens;
}

uint64_t token_bucket::get_last_seen()
{
return m_last_seen;
}
24 changes: 18 additions & 6 deletions userspace/engine/token_bucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,42 @@ class token_bucket
//
// Initialize the token bucket and start accumulating tokens
//
void init(uint32_t rate, uint32_t max_tokens);
void init(double rate, double max_tokens, uint64_t now = 0);

//
// Returns true if a token can be claimed. Also updates
// internal metrics.
// Try to claim tokens tokens from the token bucket, using a
// timestamp of now. Returns true if the tokens could be
// claimed. Also updates internal metrics.
//
bool claim(double tokens, uint64_t now);

// Simpler version of claim that claims a single token and
// uses the current time for now
bool claim();

// Return the current number of tokens available
double get_tokens();

// Return the last time someone tried to claim a token.
uint64_t get_last_seen();

private:

//
// The number of tokens generated per second.
//
uint64_t m_rate;
double m_rate;

//
// The maximum number of tokens that can be banked for future
// claim()s.
//
uint64_t m_max_tokens;
double m_max_tokens;

//
// The current number of tokens
//
uint64_t m_tokens;
double m_tokens;

//
// The last time claim() was called (or the object was created).
Expand Down

0 comments on commit b0ae29c

Please sign in to comment.