Skip to content

feat: add session expiry control flags #5976

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

Merged
merged 7 commits into from
Feb 3, 2023
Merged

Conversation

deansheather
Copy link
Member

@deansheather deansheather commented Feb 2, 2023

Adds --session-duration which lets admins customize the default session expiration for browser sessions.

Adds --disable-session-expiry-refresh which allows admins to prevent session expiry from being automatically bumped upon the API key being used.

Closes #5988

cc @ElliotG

Adds --session-duration which lets admins customize the default session
expiration for browser sessions.

Adds --disable-session-expiry-refresh which allows admins to prevent
session expiry from being automatically bumped upon the API key being
used.
@mtojek
Copy link
Member

mtojek commented Feb 2, 2023

@deansheather is there any issue you can link with this pull request?

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

You're going to hate my response here, but can we check if this is how GitLab and Vault handle these too?

Adding more user knobs also makes it easy for users to get themselves in an insecure situation where it'd be easier for an attacker to be malicious. If we give the knobs, it's still our responsibility.

In the case these are standard, I'm good with it... just sketched out adding even more options.

@deansheather
Copy link
Member Author

It's a finding from the penetration test, I don't believe there's an issue for it but I could make one if you want.

@deansheather
Copy link
Member Author

GitLab does not seem to have a knob for max session duration, but Vault does. I'm also aware of other software that does it like Mattermost.

The second flag can't reduce security and can only increase it.

@deansheather
Copy link
Member Author

@kylecarbs @mtojek ^

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Left two questions but in general LGTM. I'm wondering if we should hide security-related flags under a common security umbrella.

dc.SessionDuration.Value = time.Second

userClient := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
time.Sleep(dc.SessionDuration.Value + time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Do you think that you can somehow mock the timer or refactor that part? We have enough of time-dependent tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have any suggestions? Since we don't allow db access from tests I can't force the API key to have a specific "last used at" time and have to rely on sleep in this test.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's fine to just test it on the lower level where we can modify the timestamp? or create an "already expired" token

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored the test to use the database to verify and force API key states.

@kylecarbs
Copy link
Member

I see this from the pen-test, but I wonder if this will make us focus on security less for session tokens or consider reducing the duration as a reliable method to reduce the attack surface.

From my perspective, it's security through obscurity. It makes the user-experience worse (especially if admins specify a really low duration).

Before merge I'd like @ammario's thoughts, because maybe I'm wrong. @ElliotG would you consider these options standard?

@deansheather
Copy link
Member Author

Regardless of whether we think reducing the session expiry limit is security by obscurity or security theater, this will most likely be a customer requirement from some of our highly secure customers.

@mtojek
Copy link
Member

mtojek commented Feb 2, 2023

From my perspective, it's security through obscurity. It makes the user-experience worse (especially if admins specify a really low duration).

I would look at it from the other perspective. Users are as secure as their admins set the security level. Having a knob to control and fine-tune the timeout might be an option to pass any internal security certification processes, as some may have stricter rules than others.

What we definitely shouldn't do, and we don't intend to, is give the option to the end-user to create an infinite token.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Code changes LGTM, but I leave the product decision to Kyle.

dc.SessionDuration.Value = time.Second

userClient := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
time.Sleep(dc.SessionDuration.Value + time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's fine to just test it on the lower level where we can modify the timestamp? or create an "already expired" token

@ammario
Copy link
Member

ammario commented Feb 3, 2023

@bpmct says this is a common request, e.g. for a Yubikey workflow where the admin wants to physically verify all access every X days. Thus, I begrudgingly accept this PR. There is a greater issue of coder server --help bloat making our software look more complex than it is, but that shouldn't hold up this PR.

@deansheather deansheather requested a review from mtojek February 3, 2023 16:51
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Feel free to merge if the CI is happy.

@deansheather deansheather enabled auto-merge (squash) February 3, 2023 16:59
@deansheather deansheather merged commit cf9abe3 into main Feb 3, 2023
@deansheather deansheather deleted the dean/session-expiry-flags branch February 3, 2023 17:38
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

security: allow configurable session expiry
4 participants