forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql,ccl: add auth behaviors for authorization
informs cockroachdb#125087 informs cockroachdb#128498 informs cockroachdb#129707 fixes CRDB-41622 Epic CRDB-33829 We currently lack auth behavior functions for authorization which can be configured as part of AuthMethod itself. This PR adds these AuthBehaviors for authorization, specifically: 1. Authorizer which retrieves authorization information from an external authorization system and is a component of the AuthMethod for that auth system. It also maps the information it to sql identities like roles or subject role option. 2. RolesGrantFn which defines how the mapped sql identities can be fetched as sql group roles and be granted to the sql user session. Release note: None
- Loading branch information
Showing
6 changed files
with
121 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package pgwire | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/security/username" | ||
) | ||
|
||
// Authorizer is a component of an AuthMethod that adds additional system | ||
// privilege information for the client session, specifically when we want to | ||
// synchronize this information from some external authorization system (e.g.: | ||
// LDAP groups, JWT claims or X.509 SAN or other fields, etc). It returns list | ||
// of system identities which map to roles created specifically to assign the | ||
// privileges to the session and could be either the subject distinguished names | ||
// defined in role options or the role itself. Authorizer is intended to be used | ||
// with GrantRolesFn which assigns it to intended groups(roles). | ||
type Authorizer = func( | ||
ctx context.Context, | ||
systemIdentity username.SQLUsername, | ||
clientConnection bool, | ||
) ([]username.SQLUsername, error) | ||
|
||
// RoleGranter defines a mechanism by which an AuthMethod associated with an | ||
// incoming connection may grant additional roles obtained from an external | ||
// authorization systems (e.g.: LDAP groups, JWT claims or X.509 SAN or other | ||
// fields, etc.) to a sql session. It is expected that at this point we have | ||
// created these groups(roles) with requisite privileges which are retrieved | ||
// during the granting process and assigned to the sql session identified by the | ||
// systemIdentity. Both Authorizer and RoleGranter are executed as part of | ||
// (*AuthBehaviors).MaybeAuthorize(). | ||
type RoleGranter = func( | ||
ctx context.Context, | ||
systemIdentity username.SQLUsername, | ||
sqlGroups []username.SQLUsername, | ||
) error |