Skip to content

Commit

Permalink
incusd/daemon: Handle authorization scriptlet reset
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Somers <[email protected]>
  • Loading branch information
bensmrs authored and stgraber committed Nov 25, 2024
1 parent 48da34c commit 3b6e7e2
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2221,17 +2221,25 @@ func (d *Daemon) setupAuthorizationScriptlet(scriptlet string) error {
return fmt.Errorf("Failed saving authorization scriptlet: %w", err)
}

if scriptlet != "" {
// Fail if not using the default tls or scriptlet authorizer.
switch d.authorizer.(type) {
case *auth.TLS, *auth.Scriptlet:
d.authorizer, err = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverScriptlet, logger.Log, d.clientCerts)
if err != nil {
return err
}
default:
return errors.New("Attempting to setup scriptlet authorization while a non-default authorizer is already set")
if scriptlet == "" {
// Reset to default authorizer.
d.authorizer, err = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverTLS, logger.Log, d.clientCerts)
if err != nil {
return err
}

return nil
}

// Fail if not using the default tls or scriptlet authorizer.
switch d.authorizer.(type) {
case *auth.TLS, *auth.Scriptlet:
d.authorizer, err = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverScriptlet, logger.Log, d.clientCerts)
if err != nil {
return err
}
default:
return errors.New("Attempting to setup scriptlet authorization while a non-default authorizer is already set")
}

return nil
Expand Down

0 comments on commit 3b6e7e2

Please sign in to comment.