Skip to content

Commit ee122f0

Browse files
dm-dmaaler9
authored andcommitted
Added authJWTExclude to allow exclusion of actions while using the JWT authentication method
1 parent dfa2e81 commit ee122f0

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
@@ -177,6 +177,7 @@ type Conf struct {
177177
ExternalAuthenticationURL *string `json:"externalAuthenticationURL,omitempty"` // deprecated
178178
AuthHTTPExclude AuthInternalUserPermissions `json:"authHTTPExclude"`
179179
AuthJWTJWKS string `json:"authJWTJWKS"`
180+
AuthJWTExclude AuthInternalUserPermissions `json:"authJWTExclude"`
180181

181182
// Control API
182183
API bool `json:"api"`
@@ -323,6 +324,17 @@ func (conf *Conf) setDefaults() {
323324
Action: AuthActionPprof,
324325
},
325326
}
327+
conf.AuthJWTExclude = []AuthInternalUserPermission{
328+
{
329+
Action: AuthActionAPI,
330+
},
331+
{
332+
Action: AuthActionMetrics,
333+
},
334+
{
335+
Action: AuthActionPprof,
336+
},
337+
}
326338

327339
// Control API
328340
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 expected to pass the JWT in the Authorization header or as a query parameter.
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)