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

Implement option to configure the hmac time difference tolerance #5787

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions etc/openqa/openqa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
## (e.g. 8080) then just set `service_port_delta = 0`.
# service_port_delta = 2

## Allowed time difference in hmac validation in seconds.
## Higher values introduce higher risks for replay attacks but make API requests more
## resilient in case of a high load on the web UI. Lower values reduce this risk but
## can cause jobs to incomplete with "timestamp mismatch" error messages.
# api_hmac_time_tolerance = 300

#[scm git]
# name of remote to get updates from before committing changes (e.g. origin, leave out-commented to disable remote update)
#update_remote = origin
Expand Down
1 change: 1 addition & 0 deletions lib/OpenQA/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sub read_config ($app) {
parallel_children_collapsable_results => join(' ', OK_RESULTS),
service_port_delta => $ENV{OPENQA_SERVICE_PORT_DELTA} // 2,
access_control_allow_origin_header => undef,
api_hmac_time_tolerance => 300,
},
rate_limits => {
search => 5,
Expand Down
6 changes: 4 additions & 2 deletions lib/OpenQA/Shared/Controller/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ sub auth_admin ($self) {

sub _is_timestamp_valid ($self, $our_timestamp, $remote_timestamp) {
my $log = $self->app->log;
my $tolerance = $self->config->{api_hmac_time_tolerance}
// 300; # make extra sure this value is never empty to avoid security issues

return 1 if ($our_timestamp - $remote_timestamp <= 300);
return 1 if (abs($our_timestamp - $remote_timestamp) <= $tolerance);
$log->debug(
qq{Timestamp mismatch over 300s; our_timestamp: $our_timestamp, X-API-Microtime (from worker): $remote_timestamp}
qq{Timestamp mismatch over ${tolerance}s; our_timestamp: $our_timestamp, X-API-Microtime (from worker): $remote_timestamp}
);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subtest 'Test configuration default modes' => sub {
force_result_regex => '',
parallel_children_collapsable_results_sel => ' .status:not(.result_passed):not(.result_softfailed)',
auto_clone_limit => 20,
api_hmac_time_tolerance => 300,
},
rate_limits => {
search => 5,
Expand Down
Loading