Skip to content

Commit 40106a5

Browse files
committed
Added authJWTExclude to allow exclusion of actions while using the JWT authentication method
1 parent 16d0bb7 commit 40106a5

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

internal/auth/manager.go

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ type Manager struct {
109109
HTTPAddress string
110110
HTTPExclude []conf.AuthInternalUserPermission
111111
JWTJWKS string
112+
JWTExclude []conf.AuthInternalUserPermission
112113
ReadTimeout time.Duration
113114
RTSPAuthMethods []auth.ValidateMethod
114115

@@ -255,6 +256,10 @@ func (m *Manager) authenticateHTTP(req *Request) error {
255256
}
256257

257258
func (m *Manager) authenticateJWT(req *Request) error {
259+
if matchesPermission(m.JWTExclude, req) {
260+
return nil
261+
}
262+
258263
keyfunc, err := m.pullJWTJWKS()
259264
if err != nil {
260265
return err

internal/conf/conf.go

+12
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type Conf struct {
142142
ExternalAuthenticationURL *string `json:"externalAuthenticationURL,omitempty"` // deprecated
143143
AuthHTTPExclude AuthInternalUserPermissions `json:"authHTTPExclude"`
144144
AuthJWTJWKS string `json:"authJWTJWKS"`
145+
AuthJWTExclude AuthInternalUserPermissions `json:"authJWTExclude"`
145146

146147
// Control API
147148
API bool `json:"api"`
@@ -320,6 +321,17 @@ func (conf *Conf) setDefaults() {
320321
Action: AuthActionPprof,
321322
},
322323
}
324+
conf.AuthJWTExclude = []AuthInternalUserPermission{
325+
{
326+
Action: AuthActionAPI,
327+
},
328+
{
329+
Action: AuthActionMetrics,
330+
},
331+
{
332+
Action: AuthActionPprof,
333+
},
334+
}
323335

324336
// Control API
325337
conf.APIAddress = ":9997"

internal/core/core.go

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ func (p *Core) createResources(initial bool) error {
287287
HTTPAddress: p.conf.AuthHTTPAddress,
288288
HTTPExclude: p.conf.AuthHTTPExclude,
289289
JWTJWKS: p.conf.AuthJWTJWKS,
290+
JWTExclude: p.conf.AuthJWTExclude,
290291
ReadTimeout: time.Duration(p.conf.ReadTimeout),
291292
RTSPAuthMethods: p.conf.RTSPAuthMethods,
292293
}
@@ -674,6 +675,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
674675
newConf.AuthHTTPAddress != p.conf.AuthHTTPAddress ||
675676
!reflect.DeepEqual(newConf.AuthHTTPExclude, p.conf.AuthHTTPExclude) ||
676677
newConf.AuthJWTJWKS != p.conf.AuthJWTJWKS ||
678+
!reflect.DeepEqual(newConf.AuthJWTExclude, p.conf.AuthJWTExclude) ||
677679
newConf.ReadTimeout != p.conf.ReadTimeout ||
678680
!reflect.DeepEqual(newConf.RTSPAuthMethods, p.conf.RTSPAuthMethods)
679681
if !closeAuthManager && !reflect.DeepEqual(newConf.AuthInternalUsers, p.conf.AuthInternalUsers) {

mediamtx.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runOnDisconnect:
4444
# * internal: users are stored in the configuration file
4545
# * http: an external HTTP URL is contacted to perform authentication
4646
# * jwt: an external identity server provides authentication through JWTs
47-
authMethod: internal
47+
authMethod: jwt
4848

4949
# Internal authentication.
5050
# list of users.
@@ -120,7 +120,11 @@ authHTTPExclude:
120120
# Users are then expected to pass the JWT as a query parameter, i.e. ?jwt=...
121121
# This is the JWKS URL that will be used to pull (once) the public key that allows
122122
# to validate JWTs.
123-
authJWTJWKS:
123+
authJWTJWKS: https://localhost:7211/.well-known/openid-configuration/jwks
124+
# Actions to exclude from JWT-based authentication.
125+
# Format is the same as the one of user permissions.
126+
authJWTExclude:
127+
- action: publish
124128

125129
###############################################
126130
# Global settings -> Control API

0 commit comments

Comments
 (0)