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

Name type used for Authentication TTL #1990

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yadij
Copy link
Contributor

@yadij yadij commented Jan 31, 2025

No description provided.

Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

@yadij, before posting new master/v7 PRs, please cooperate on merging PRs (authored by others) that are awaiting your actions for weeks and even months.

@@ -25,6 +25,8 @@ typedef std::vector<Auth::SchemeConfig *> ConfigVector;

class UserRequest;

using Ttl = int32_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

The new name is missing a description. The description must document what time unit this integer is using (e.g., seconds or time_t unit) and that negative values reflect "expired" entries.

Auth::Basic::User::ttl() const
{
if (credentials() != Auth::Ok && credentials() != Auth::Pending)
return -1; // TTL is obsolete NOW.
return Auth::User::ttl(); // TTL is obsolete NOW.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and and in similar contexts, please either continue to return -1 or introduce a named Auth::Ttl constant and return that. Either would be more readable and safe than the proposed "use TTL computed by Auth::User::ttl() while assuming that that value is a negative TTL" change.

@@ -25,6 +25,8 @@ typedef std::vector<Auth::SchemeConfig *> ConfigVector;

class UserRequest;

using Ttl = int32_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried that the suggested name -- "Auth::Ttl" -- is too general because authentication code may need several different types for TTL. For example, authenticate_ttl uses a different type today. However, I assume you consider such worries unfounded and am not requesting any related changes.

@@ -25,6 +25,8 @@ typedef std::vector<Auth::SchemeConfig *> ConfigVector;

class UserRequest;

using Ttl = int32_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

The underlying type -- int32_t -- is wrong on several (probably obvious?) levels. However, I assume that this PR scope is limited to naming existing int32_t uses and excludes fixing the underlying type. Thus, I am not requesting those fixes in this PR.

* Credentials are not permitted to be re-used from a
* credentials cache unless the authentication scheme
* defines a way to determine a TTL with which to bound
* the scope of their valid re-use.
Copy link
Contributor

Choose a reason for hiding this comment

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

Expired credentials reuse is also not permitted, right? Please add that critical information to the method description. Without that restriction, the method API does not really work because the method caller cannot distinguish "scheme did not define ..." cases from "credentials expired" cases.

@@ -66,10 +66,15 @@ class User : public RefCountable
const SBuf userKey() const {return userKey_;}

/**
* How long these credentials are still valid for.
* Negative numbers means already expired.
* Credentials are not permitted to be re-used from a
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we say that credentials are not permitted to be cached "unless the scheme defines..."? In other words, caching code should not cache credentials for schemes that do not override this method. That would be a stronger rule/claim than the proposed "not permitted to be re-used".

@@ -256,7 +256,7 @@ Auth::User::CredentialsCacheStats(StoreEntry *output)
Auth::Type_str[auth_user->auth_type],
CredentialState_str[auth_user->credentials()],
auth_user->ttl(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This storeAppendPrintf() function call secretly assumes that ttl() returns something that can be "printed "using %d. I recommend refactoring CredentialsCacheStats() internals to use std::ostream instead, preferably in a separate PR. If that is not done, let's at least add an XXX:

Suggested change
auth_user->ttl(),
auth_user->ttl(), // XXX: Here and below, we assume that Ttl can be printed using %d

@@ -256,7 +256,7 @@ Auth::User::CredentialsCacheStats(StoreEntry *output)
Auth::Type_str[auth_user->auth_type],
CredentialState_str[auth_user->credentials()],
auth_user->ttl(),
static_cast<int32_t>(auth_user->expiretime - squid_curtime + Auth::TheConfig.credentialsTtl),
static_cast<Auth::Ttl>(auth_user->expiretime - squid_curtime + Auth::TheConfig.credentialsTtl),
Copy link
Contributor

Choose a reason for hiding this comment

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

Where possible, please avoid Foo:: inside Foo:

Suggested change
static_cast<Auth::Ttl>(auth_user->expiretime - squid_curtime + Auth::TheConfig.credentialsTtl),
static_cast<Ttl>(auth_user->expiretime - squid_curtime + Auth::TheConfig.credentialsTtl),

or even

Suggested change
static_cast<Auth::Ttl>(auth_user->expiretime - squid_curtime + Auth::TheConfig.credentialsTtl),
static_cast<Ttl>(auth_user->expiretime - squid_curtime + TheConfig.credentialsTtl),

@rousskov rousskov changed the title Add named type for Authentication TTL Name type used for Authentication TTL Jan 31, 2025
@rousskov
Copy link
Contributor

- Add named type for Authentication TTL
+ Name type used for Authentication TTL

I adjusted the title to clarify that we are naming something rather than adding something, but both variants have problems (e.g., the existing type does have a name already), and I do not insist on this title change. Please feel free to revert.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-for-author author action is expected (and usually required)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants