Skip to content

Commit

Permalink
Added authJWTExclude to allow exclusion of actions while using the JW…
Browse files Browse the repository at this point in the history
…T authentication method
  • Loading branch information
dm-dma committed Jun 7, 2024
1 parent 16d0bb7 commit 40106a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions internal/auth/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type Manager struct {
HTTPAddress string
HTTPExclude []conf.AuthInternalUserPermission
JWTJWKS string
JWTExclude []conf.AuthInternalUserPermission
ReadTimeout time.Duration
RTSPAuthMethods []auth.ValidateMethod

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

func (m *Manager) authenticateJWT(req *Request) error {
if matchesPermission(m.JWTExclude, req) {
return nil
}

keyfunc, err := m.pullJWTJWKS()
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Conf struct {
ExternalAuthenticationURL *string `json:"externalAuthenticationURL,omitempty"` // deprecated
AuthHTTPExclude AuthInternalUserPermissions `json:"authHTTPExclude"`
AuthJWTJWKS string `json:"authJWTJWKS"`
AuthJWTExclude AuthInternalUserPermissions `json:"authJWTExclude"`

// Control API
API bool `json:"api"`
Expand Down Expand Up @@ -320,6 +321,17 @@ func (conf *Conf) setDefaults() {
Action: AuthActionPprof,
},
}
conf.AuthJWTExclude = []AuthInternalUserPermission{
{
Action: AuthActionAPI,
},
{
Action: AuthActionMetrics,
},
{
Action: AuthActionPprof,
},
}

// Control API
conf.APIAddress = ":9997"
Expand Down
2 changes: 2 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (p *Core) createResources(initial bool) error {
HTTPAddress: p.conf.AuthHTTPAddress,
HTTPExclude: p.conf.AuthHTTPExclude,
JWTJWKS: p.conf.AuthJWTJWKS,
JWTExclude: p.conf.AuthJWTExclude,
ReadTimeout: time.Duration(p.conf.ReadTimeout),
RTSPAuthMethods: p.conf.RTSPAuthMethods,
}
Expand Down Expand Up @@ -674,6 +675,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.AuthHTTPAddress != p.conf.AuthHTTPAddress ||
!reflect.DeepEqual(newConf.AuthHTTPExclude, p.conf.AuthHTTPExclude) ||
newConf.AuthJWTJWKS != p.conf.AuthJWTJWKS ||
!reflect.DeepEqual(newConf.AuthJWTExclude, p.conf.AuthJWTExclude) ||
newConf.ReadTimeout != p.conf.ReadTimeout ||
!reflect.DeepEqual(newConf.RTSPAuthMethods, p.conf.RTSPAuthMethods)
if !closeAuthManager && !reflect.DeepEqual(newConf.AuthInternalUsers, p.conf.AuthInternalUsers) {
Expand Down
8 changes: 6 additions & 2 deletions mediamtx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ runOnDisconnect:
# * internal: users are stored in the configuration file
# * http: an external HTTP URL is contacted to perform authentication
# * jwt: an external identity server provides authentication through JWTs
authMethod: internal
authMethod: jwt

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

###############################################
# Global settings -> Control API
Expand Down

0 comments on commit 40106a5

Please sign in to comment.