Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
2b77b607
Commit
2b77b607
authored
7 months ago
by
Imre Farkas
Browse files
Options
Downloads
Patches
Plain Diff
Fix setting default expiry for PATs in EE
parent
09e9f252
No related branches found
No related tags found
4 merge requests
!162538
Backport 17-2: Handle empty ff merge in from train ref strategy
,
!162537
Backport 17-1: Handle empty ff merge in from train ref strategy
,
!162233
Draft: Script to update Topology Service Gem
,
!158186
Add require_personal_access_token_expiry application setting
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ee/app/services/ee/personal_access_tokens/create_service.rb
+4
-3
4 additions, 3 deletions
ee/app/services/ee/personal_access_tokens/create_service.rb
ee/spec/services/ee/personal_access_tokens/create_service_spec.rb
+28
-18
28 additions, 18 deletions
...services/ee/personal_access_tokens/create_service_spec.rb
with
32 additions
and
21 deletions
ee/app/services/ee/personal_access_tokens/create_service.rb
+
4
−
3
View file @
2b77b607
...
...
@@ -33,10 +33,11 @@ def send_audit_event(response)
override
:pat_expiration
def
pat_expiration
return
params
[
:expires_at
]
unless
params
[
:expires_at
].
blank
?
return
params
[
:expires_at
]
if
params
[
:expires_at
].
present
?
return
unless
EE
::
Gitlab
::
PersonalAccessTokens
::
ServiceAccountTokenValidator
.
new
(
target_user
)
.
expiry_enforced?
if
EE
::
Gitlab
::
PersonalAccessTokens
::
ServiceAccountTokenValidator
.
new
(
target_user
).
expiry_enforced?
return
max_expiry_date
end
super
end
...
...
This diff is collapsed.
Click to expand it.
ee/spec/services/ee/personal_access_tokens/create_service_spec.rb
+
28
−
18
View file @
2b77b607
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
PersonalAccessTokens
::
CreateService
,
feature_category: :system_access
do
using
RSpec
::
Parameterized
::
TableSyntax
shared_examples_for
'an unsuccessfully created token'
do
it
{
expect
(
create_token
.
success?
).
to
be
false
}
it
{
expect
(
create_token
.
message
).
to
eq
(
'Not permitted to create'
)
}
...
...
@@ -111,17 +113,22 @@
context
'when expires_at is nil'
do
let
(
:params
)
{
valid_params
.
merge
(
expires_at:
nil
)
}
context
'when service_access_tokens_expiration_enforced is false'
do
where
(
:require_token_expiry
,
:require_token_expiry_for_service_accounts
,
:expires_at
)
do
true
|
true
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
true
|
false
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
false
|
true
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
false
|
false
|
nil
end
with_them
do
before
do
stub_ee_application_setting
(
service_access_tokens_expiration_enforced:
false
)
stub_application_setting
(
require_personal_access_token_expiry:
require_token_expiry
)
stub_ee_application_setting
(
service_access_tokens_expiration_enforced:
require_token_expiry_for_service_accounts
)
end
it
{
expect
(
token
.
expires_at
).
to
be_nil
}
end
it
"sets expires_at to default value when setting is true"
do
expect
(
token
.
expires_at
)
.
to
eq
max_personal_access_token_lifetime
it
'optionally sets token expiry based on settings'
do
expect
(
token
.
expires_at
).
to
eq
(
expires_at
)
end
end
end
end
...
...
@@ -158,19 +165,22 @@
let
(
:params
)
{
valid_params
.
merge
(
group:
group
,
expires_at:
nil
)
}
context
'when saas'
,
:saas
,
:enable_admin_mode
do
context
'when service_access_tokens_expiration_enforced is false'
do
where
(
:require_token_expiry
,
:require_token_expiry_for_service_accounts
,
:expires_at
)
do
true
|
true
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
true
|
false
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
false
|
true
|
PersonalAccessToken
::
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS
.
days
.
from_now
.
to_date
false
|
false
|
nil
end
with_them
do
before
do
group
.
namespace_settings
.
update!
(
service_access_tokens_expiration_enforced:
false
)
stub_application_setting
(
require_personal_access_token_expiry:
require_token_expiry
)
group
.
namespace_settings
.
update!
(
service_access_tokens_expiration_enforced:
require_token_expiry_for_service_accounts
)
end
it
{
expect
(
create_token
.
payload
[
:personal_access_token
].
expires_at
).
to
be_nil
}
end
context
'when service_access_tokens_expiration_enforced is true'
do
it
{
expect
(
create_token
.
payload
[
:personal_access_token
].
expires_at
)
.
to
eq
max_personal_access_token_lifetime
}
it
'optionally sets token expiry based on settings'
do
expect
(
token
.
expires_at
).
to
eq
(
expires_at
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment