Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
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
TeDomum
matrix-media-repo
Commits
43c1a5e1
Commit
43c1a5e1
authored
5 years ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Expose shared secret auth to all APIs
parent
35000908
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/auth.go
+15
-4
15 additions, 4 deletions
api/auth.go
api/custom/purge.go
+1
-1
1 addition, 1 deletion
api/custom/purge.go
api/custom/quarantine.go
+1
-1
1 addition, 1 deletion
api/custom/quarantine.go
with
17 additions
and
6 deletions
api/auth.go
+
15
−
4
View file @
43c1a5e1
...
...
@@ -12,6 +12,7 @@ import (
type
UserInfo
struct
{
UserId
string
AccessToken
string
IsShared
bool
}
func
AccessTokenRequiredRoute
(
next
func
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
,
user
UserInfo
)
interface
{})
func
(
*
http
.
Request
,
*
logrus
.
Entry
)
interface
{}
{
...
...
@@ -21,6 +22,11 @@ func AccessTokenRequiredRoute(next func(r *http.Request, log *logrus.Entry, user
log
.
Error
(
"Error: no token provided (required)"
)
return
InternalServerError
(
"Error no token provided (required)"
)
}
if
config
.
Get
()
.
SharedSecret
.
Enabled
&&
accessToken
==
config
.
Get
()
.
SharedSecret
.
Token
{
log
=
log
.
WithFields
(
logrus
.
Fields
{
"isRepoAdmin"
:
true
})
log
.
Info
(
"User authed using shared secret"
)
return
next
(
r
,
log
,
UserInfo
{
UserId
:
"@sharedsecret"
,
AccessToken
:
accessToken
,
IsShared
:
true
})
}
appserviceUserId
:=
util
.
GetAppserviceUserIdFromRequest
(
r
)
userId
,
err
:=
matrix
.
GetUserIdFromToken
(
r
.
Context
(),
r
.
Host
,
accessToken
,
appserviceUserId
,
r
.
RemoteAddr
)
if
err
!=
nil
||
userId
==
""
{
...
...
@@ -34,7 +40,7 @@ func AccessTokenRequiredRoute(next func(r *http.Request, log *logrus.Entry, user
}
log
=
log
.
WithFields
(
logrus
.
Fields
{
"authUserId"
:
userId
})
return
next
(
r
,
log
,
UserInfo
{
userId
,
accessToken
})
return
next
(
r
,
log
,
UserInfo
{
userId
,
accessToken
,
false
})
}
}
...
...
@@ -42,7 +48,12 @@ func AccessTokenOptionalRoute(next func(r *http.Request, log *logrus.Entry, user
return
func
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
)
interface
{}
{
accessToken
:=
util
.
GetAccessTokenFromRequest
(
r
)
if
accessToken
==
""
{
return
next
(
r
,
log
,
UserInfo
{
""
,
""
})
return
next
(
r
,
log
,
UserInfo
{
""
,
""
,
false
})
}
if
config
.
Get
()
.
SharedSecret
.
Enabled
&&
accessToken
==
config
.
Get
()
.
SharedSecret
.
Token
{
log
=
log
.
WithFields
(
logrus
.
Fields
{
"isRepoAdmin"
:
true
})
log
.
Info
(
"User authed using shared secret"
)
return
next
(
r
,
log
,
UserInfo
{
UserId
:
"@sharedsecret"
,
AccessToken
:
accessToken
,
IsShared
:
true
})
}
appserviceUserId
:=
util
.
GetAppserviceUserIdFromRequest
(
r
)
userId
,
err
:=
matrix
.
GetUserIdFromToken
(
r
.
Context
(),
r
.
Host
,
accessToken
,
appserviceUserId
,
r
.
RemoteAddr
)
...
...
@@ -57,7 +68,7 @@ func AccessTokenOptionalRoute(next func(r *http.Request, log *logrus.Entry, user
}
log
=
log
.
WithFields
(
logrus
.
Fields
{
"authUserId"
:
userId
})
return
next
(
r
,
log
,
UserInfo
{
userId
,
accessToken
})
return
next
(
r
,
log
,
UserInfo
{
userId
,
accessToken
,
false
})
}
}
...
...
@@ -82,7 +93,7 @@ func RepoAdminRoute(next func(r *http.Request, log *logrus.Entry, user UserInfo)
if
accessToken
==
config
.
Get
()
.
SharedSecret
.
Token
{
log
=
log
.
WithFields
(
logrus
.
Fields
{
"isRepoAdmin"
:
true
})
log
.
Info
(
"User authed using shared secret"
)
return
next
(
r
,
log
,
UserInfo
{
UserId
:
"@sharedsecret"
,
AccessToken
:
accessToken
})
return
next
(
r
,
log
,
UserInfo
{
UserId
:
"@sharedsecret"
,
AccessToken
:
accessToken
,
IsShared
:
true
})
}
}
...
...
This diff is collapsed.
Click to expand it.
api/custom/purge.go
+
1
−
1
View file @
43c1a5e1
...
...
@@ -121,7 +121,7 @@ func PurgeQurantined(r *http.Request, log *logrus.Entry, user api.UserInfo) inte
}
func
getPurgeRequestInfo
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
,
user
api
.
UserInfo
)
(
bool
,
bool
)
{
isGlobalAdmin
:=
util
.
IsGlobalAdmin
(
user
.
UserId
)
isGlobalAdmin
:=
util
.
IsGlobalAdmin
(
user
.
UserId
)
||
user
.
IsShared
isLocalAdmin
,
err
:=
matrix
.
IsUserAdmin
(
r
.
Context
(),
r
.
Host
,
user
.
AccessToken
,
r
.
RemoteAddr
)
if
err
!=
nil
{
log
.
Error
(
"Error verifying local admin: "
+
err
.
Error
())
...
...
This diff is collapsed.
Click to expand it.
api/custom/quarantine.go
+
1
−
1
View file @
43c1a5e1
...
...
@@ -151,7 +151,7 @@ func setMediaQuarantined(media *types.Media, isQuarantined bool, allowOtherHosts
}
func
getQuarantineRequestInfo
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
,
user
api
.
UserInfo
)
(
bool
,
bool
,
bool
)
{
isGlobalAdmin
:=
util
.
IsGlobalAdmin
(
user
.
UserId
)
isGlobalAdmin
:=
util
.
IsGlobalAdmin
(
user
.
UserId
)
||
user
.
IsShared
canQuarantine
:=
isGlobalAdmin
allowOtherHosts
:=
isGlobalAdmin
isLocalAdmin
:=
false
...
...
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