Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
m-team
oidc
mytoken
server
Commits
0872d12f
Commit
0872d12f
authored
3 years ago
by
Gabriel Zachmann
Browse files
Options
Downloads
Patches
Plain Diff
implement auto-revoke
parent
21a8b9b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/db/dbrepo/mytokenrepo/mytokenrepohelper/helpers.go
+36
-4
36 additions, 4 deletions
internal/db/dbrepo/mytokenrepo/mytokenrepohelper/helpers.go
with
36 additions
and
4 deletions
internal/db/dbrepo/mytokenrepo/mytokenrepohelper/helpers.go
+
36
−
4
View file @
0872d12f
...
...
@@ -74,12 +74,34 @@ func recursiveRevokeMT(tx *sqlx.Tx, id mtid.MTID) error {
})
}
// CheckTokenRevoked checks if a Mytoken has been revoked.
// CheckTokenRevoked checks if a Mytoken has been revoked.
If it is a rotating mytoken and auto_revoke is enabled for this token, it might get triggered.
func
CheckTokenRevoked
(
tx
*
sqlx
.
Tx
,
id
mtid
.
MTID
,
seqno
uint64
,
rot
*
api
.
Rotation
)
(
bool
,
error
)
{
if
rot
!
=
nil
&&
rot
.
Lifetime
>
0
{
return
check
Rotating
TokenRevoked
(
tx
,
id
,
seqno
,
rot
.
Lifetime
)
if
rot
=
=
nil
{
return
checkTokenRevoked
(
tx
,
id
,
seqno
)
}
return
checkTokenRevoked
(
tx
,
id
,
seqno
)
var
revoked
bool
var
err
error
if
rot
.
Lifetime
>
0
{
revoked
,
err
=
checkRotatingTokenRevoked
(
tx
,
id
,
seqno
,
rot
.
Lifetime
)
}
else
{
revoked
,
err
=
checkTokenRevoked
(
tx
,
id
,
seqno
)
}
if
err
!=
nil
{
return
revoked
,
err
}
if
!
revoked
||
!
rot
.
AutoRevoke
{
return
revoked
,
nil
}
// At this point we know, that the token is not valid, we now check if it is not valid because of the seqno.
idFound
,
err
:=
checkTokenID
(
tx
,
id
)
if
err
!=
nil
{
return
true
,
err
}
if
!
idFound
{
return
true
,
nil
}
err
=
RevokeMT
(
tx
,
id
,
true
)
return
true
,
err
}
func
checkTokenRevoked
(
tx
*
sqlx
.
Tx
,
id
mtid
.
MTID
,
seqno
uint64
)
(
bool
,
error
)
{
...
...
@@ -95,6 +117,16 @@ func checkTokenRevoked(tx *sqlx.Tx, id mtid.MTID, seqno uint64) (bool, error) {
return
true
,
nil
}
func
checkTokenID
(
tx
*
sqlx
.
Tx
,
id
mtid
.
MTID
)
(
bool
,
error
)
{
var
count
int
if
err
:=
db
.
RunWithinTransaction
(
tx
,
func
(
tx
*
sqlx
.
Tx
)
error
{
return
tx
.
Get
(
&
count
,
`SELECT COUNT(1) FROM MTokens WHERE id=?`
,
id
)
});
err
!=
nil
{
return
false
,
err
}
return
count
>
0
,
nil
}
func
checkRotatingTokenRevoked
(
tx
*
sqlx
.
Tx
,
id
mtid
.
MTID
,
seqno
,
rotationLifetime
uint64
)
(
bool
,
error
)
{
var
count
int
if
err
:=
db
.
RunWithinTransaction
(
tx
,
func
(
tx
*
sqlx
.
Tx
)
error
{
...
...
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