Skip to content

Conversation

korydraughn
Copy link
Contributor

Cannot automate a test for this yet since it requires modifying the HTTP API's config file.

Confirmed the changes work by setting the lifetime of bearer tokens (for Basic Authentication) to 15 seconds and stat'ing a collection multiple times near the expiration time.

I'll open an issue as a reminder to get some automated tests around this in the future.

Comment on lines 345 to 361
// Extend the lifetime of the bearer token.
static const auto token_lifetime =
config.at(nlohmann::json::json_pointer{"/http_server/authentication/basic/timeout_in_seconds"})
.get<int>();
client_info.expires_at = now + std::chrono::seconds{token_lifetime};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm thinking about is whether the token_lifetime value should have a dedicated config property.

We can start with this and add a new property later if people want/need that. I think that's the right approach. We're still likely a long way away from 1.0 status, so there's time.

@korydraughn
Copy link
Contributor Author

Forgot I need to update the README to talk about this too.

Copy link
Contributor

@MartinFlores751 MartinFlores751 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see the visit addition to the process stash! Most of my comments are just questions, with one suggestion on the readme.

// token expires.
// The amount of time before a user's authentication token expires.
// The lifetime of a token will be extended by this amount on each
// use as long as the token has not expired.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Use" might be a bit vague to an admin unfamiliar with how we use our tokens. "Request" might help clear up that this is used on every basic HTTP API request.

Suggested change
// use as long as the token has not expired.
// request as long as the token has not expired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider...

- has not expired
+ has not yet expired

Comment on lines 340 to 364
if (now >= client_info.expires_at) {
token_expired = true;
return;
}

if (json_res.empty()) {
logging::error("{}: Could not find bearer token matching [{}].", __func__, bearer_token);
return {.response = fail(status_type::unauthorized)};
}
// Extend the lifetime of the bearer token.
static const auto token_lifetime =
config.at(nlohmann::json::json_pointer{"/http_server/authentication/basic/timeout_in_seconds"})
.get<int>();
client_info.expires_at = now + std::chrono::seconds{token_lifetime};

// Do mapping of user to irods user
auto user{map_json_to_user(json_res)};
if (user) {
return {.client_info = {.username = *std::move(user)}};
}
client_info_copy = client_info;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to increase the token lifetime? In what case(s) do we want the token to timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to increase the token lifetime?

I think so.

In what case(s) do we want the token to timeout?

I'm currently only aware of the "inactive for N seconds" case. Have you identified others?

Comment on lines 57 to 61
std::shared_lock read_lock{g_mtx};
if (g_stash.find(_key) != std::end(g_stash)) {
read_lock.unlock();
std::lock_guard write_lock{g_mtx};
if (auto iter = g_stash.find(_key); iter != std::end(g_stash)) {
_visitor(iter->second);
return true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If people are using only basic auth mode, would it be better to have the shared_lock -> lock_guard or just have a lock_guard?

If OIDC mode is enabled, do we expect the auth traffic to be split between basic and OIDC?

Comment on lines +236 to +252
// The amount of time before a user's authentication token expires.
// The lifetime of a token will be extended by this amount on each
// use as long as the token has not expired.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's just me, but this wording feels a little inaccurate. The expiration of the token is set to timeout_in_seconds from the point in time of each use, not extended by that amount... right?

To me, it sounds like the expiration will be extended by (by default) an hour each time the token is used. So if I authenticate 4 times in a second, the expiration will be 4 hours away instead of 1 hour away.

Maybe I'm misunderstanding all this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your question indicates the wording isn't clear. Showing some math is likely a better fit. For example:

token_lifetime = <current_time> + <timeout_in_seconds>

The documentation would be updated to align with the idea too.

Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's much clearer.

@trel
Copy link
Member

trel commented Aug 22, 2025

should we mark this as draft?

@korydraughn
Copy link
Contributor Author

Yes. Converting to draft until we determine the best path forward.

@korydraughn korydraughn marked this pull request as draft August 22, 2025 16:46
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.

4 participants