-
Notifications
You must be signed in to change notification settings - Fork 535
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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), | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where possible, please avoid
Suggested change
or even
Suggested change
|
||||||||||
auth_user->username(), | ||||||||||
SQUIDSBUFPRINT(auth_user->userKey()) | ||||||||||
); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". |
||
* credentials cache unless the authentication scheme | ||
* defines a way to determine a TTL with which to bound | ||
* the scope of their valid re-use. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
* | ||
* \returns How long these credentials are still valid for. | ||
* Negative numbers means already expired. | ||
*/ | ||
virtual int32_t ttl() const = 0; | ||
virtual Ttl ttl() const { return -1; } | ||
|
||
/* Manage list of IPs using this username */ | ||
void clearIp(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,14 @@ Auth::Basic::User::~User() | |
safe_free(passwd); | ||
} | ||
|
||
int32_t | ||
Auth::Ttl | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and and in similar contexts, please either continue to return |
||
|
||
int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL; | ||
int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + Auth::TheConfig.credentialsTtl); | ||
const Ttl basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL; | ||
const auto global_ttl = static_cast<Ttl>(expiretime - squid_curtime + Auth::TheConfig.credentialsTtl); | ||
|
||
return min(basic_ttl, global_ttl); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ typedef std::vector<Auth::SchemeConfig *> ConfigVector; | |
|
||
class UserRequest; | ||
|
||
using Ttl = int32_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
} // namespace Auth | ||
|
||
#endif /* USE_AUTH */ | ||
|
There was a problem hiding this comment.
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: