-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authorization refactor in preparation for fine-grained authorization #12313
Changes from 1 commit
5017205
3ea15d2
a52e978
1ec0160
cfa3b77
9123f14
822af45
a39a702
c2c5840
dbad9e2
7b250a6
fd9d911
d428bc7
67d9725
154c204
1fb2633
7362589
1e22bcb
3abd114
8975800
f0b0dcc
fbd635b
74aa566
2db6fe5
aa061f8
9306e35
ae092f4
4cb57a1
535c040
f1bb54a
0cc2aa3
73a9ce3
46698f1
146f36c
cacb832
8b494ab
721e31a
444692e
c2ef675
3147031
92408de
cb5919f
ca20445
31df5be
8ee727e
d9322ff
6000337
cac36ee
2d3a73c
0c43e90
27d6fe4
2ff65b0
cb9da5d
3371cf9
7c9f699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -714,7 +714,7 @@ func (d *Daemon) init() error { | |
var dbWarnings []dbCluster.Warning | ||
|
||
// Set default authorizer. | ||
d.authorizer, err = auth.LoadAuthorizer("tls", nil, logger.Log, nil) | ||
d.authorizer, err = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverTLS, logger.Log, d.clientCerts) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -1803,14 +1803,17 @@ func (d *Daemon) setupRBACServer(rbacURL string, rbacKey string, rbacExpiry int6 | |
var err error | ||
|
||
if d.authorizer != nil { | ||
d.authorizer.StopStatusCheck() | ||
err := d.authorizer.StopService(d.shutdownCtx) | ||
if err != nil { | ||
logger.Error("Failed to stop authorizer service", logger.Ctx{"error": err}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should return an error here rather than logging right? Otherwise we can get into an inconsistent state? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or do we also need to fallback to TLS in that case? |
||
} | ||
} | ||
|
||
if rbacURL == "" || rbacAgentURL == "" || rbacAgentUsername == "" || rbacAgentPrivateKey == "" || rbacAgentPublicKey == "" { | ||
d.candidVerifier = nil | ||
|
||
// Reset to default authorizer. | ||
d.authorizer, err = auth.LoadAuthorizer("tls", nil, logger.Log, nil) | ||
d.authorizer, err = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverTLS, logger.Log, d.clientCerts) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -1821,9 +1824,9 @@ func (d *Daemon) setupRBACServer(rbacURL string, rbacKey string, rbacExpiry int6 | |
revert := revert.New() | ||
defer revert.Fail() | ||
|
||
projectsFunc := func() (map[int64]string, error) { | ||
projectsFunc := func(ctx context.Context) (map[int64]string, error) { | ||
var result map[int64]string | ||
err := d.State().DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { | ||
err := d.State().DB.Cluster.Transaction(ctx, func(ctx context.Context, tx *db.ClusterTx) error { | ||
var err error | ||
result, err = dbCluster.GetProjectIDsToNames(ctx, tx.Tx()) | ||
return err | ||
|
@@ -1847,18 +1850,21 @@ func (d *Daemon) setupRBACServer(rbacURL string, rbacKey string, rbacExpiry int6 | |
d.candidVerifier = nil | ||
|
||
// Reset to default authorizer. | ||
d.authorizer, _ = auth.LoadAuthorizer("tls", nil, logger.Log, nil) | ||
d.authorizer, _ = auth.LoadAuthorizer(d.shutdownCtx, auth.DriverTLS, logger.Log, d.clientCerts) | ||
}) | ||
|
||
// Load RBAC authorizer | ||
rbacAuthorizer, err := auth.LoadAuthorizer("rbac", config, logger.Log, projectsFunc) | ||
rbacAuthorizer, err := auth.LoadAuthorizer(d.shutdownCtx, auth.DriverRBAC, logger.Log, d.clientCerts, auth.WithConfig(config), auth.WithProjectsGetFunc(projectsFunc)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
revert.Add(func() { | ||
// Stop status check in case candid fails. | ||
rbacAuthorizer.StopStatusCheck() | ||
err := rbacAuthorizer.StopService(d.shutdownCtx) | ||
if err != nil { | ||
logger.Error("Failed to stop authorizer service", logger.Ctx{"error": err}) | ||
} | ||
}) | ||
|
||
// Enable candid authentication | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general we should rework this function to be a generic "one of the authorization keys has changed, we need to restart/change the authorization driver" and have it handle all the driver's config keys so it can fallback to the previous active driver (and not just TLS) on error. But this can come as a separate PR.