Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for volatile keys #682

Merged
merged 3 commits into from
Mar 17, 2021

Conversation

ArnoStiefvater
Copy link
Member

@ArnoStiefvater ArnoStiefvater commented Mar 15, 2021

What:

Add support for volatile keys. Add timeout in seconds for keys to expire.
Depends on greenbone/gvm-libs#460.

Why:

Can be used in combination with redis settings such as maxmemory and maxmemory-policy to have a more options in handling memory issues in regards to redis.

How:

Stop ospd-openvas if running.
Do a flushall in redis. sudo redis-cli -s /run/redis-openvas/redis.sock FLUSHALL)
Start nasl script which places keys with expire in redis. sudo openvas-nasl -X -i <installpath>/var/lib/openvas/plugins/ -t 127.0.0.1 add_volatile_keys.nasl

include("misc_func.inc"); # for rand_str()

i = 0;
key  = "VOLATILE";
value = rand_str(length: 100000);
for (; i<100; i++) {
    set_kb_item(name: key+i, value:value+i, expire:1000000);
}

sleep(10000);
exit(0);

Check number of keys in db. sudo redis-cli -s /run/redis-openvas/redis.sock -n 1 DBSIZE. Should be 100.
Set maxmemory config set maxmemory 15728640 in redis.
Set maxmemory-policy Config set maxmemory-policy volatile-lru in redis.
Start VT2 which places keys without expire set in other terminal. sudo openvas-nasl -X -i <installpath>/var/lib/openvas/plugins/ -t 127.0.0.1 persistent_keys.nasl.

include("misc_func.inc"); # for rand_str()

i = 0;
key  = "PERSISTENT";
value = rand_str(length: 100000);
for (; i<100; i++ ) {
    set_kb_item(name: key+i, value:value);
}

sleep(10000);

When maxmemory is hit the keys with expire set will get removed by redis to make space for new keys. Check number of keys in db 1 and 2. db 2 should have 100 keys while db 1 should have less.
This way we can make sure which keys can be removed when memory limits are reached.

Checklist:

This is done by implementing a new function
set_kb_item_volatile which is called when an
expire argument is given to set_kb_item.
@ArnoStiefvater ArnoStiefvater marked this pull request as ready for review March 15, 2021 14:47
@ArnoStiefvater ArnoStiefvater requested a review from a team as a code owner March 15, 2021 14:47
@jjnicola
Copy link
Member

jjnicola commented Mar 16, 2021

LGTM.
Do you think it makes sense to set some default values for maxmemory and maxmemory-policy in config/redis-openvas.conf?
Also, it would be nice to document that there is some kind of support/usage of those redis option in doc/redis_config.md

@ArnoStiefvater
Copy link
Member Author

LGTM.
Do you think it makes sense to set some default values for maxmemory and maxmemory-policy in config/redis-openvas.conf?
Also, it would be nice to document that there is some kind of support/usage of those redis option in doc/redis_config.md

I would not set a default for maxmemory because we have no possibility knowing the limitation of the machines. This has to be decided individually for the machine at hand. maxmemory-policy does not make sense without maxmemory.

Will add documentation in doc/redis_config.md in a different PR.

@ArnoStiefvater ArnoStiefvater merged commit e2932cb into greenbone:master Mar 17, 2021
@cfi-gb cfi-gb mentioned this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants