mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-05 05:42:16 +00:00
+6








07ce3b6905
This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Silvan <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Kenta Yamaguchi <[email protected]> Co-authored-by: Harsha Reddy <[email protected]> Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Iraq <[email protected]> Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Max Peintner <[email protected]>
76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
const (
|
|
// eventstore.permitted_orgs(instanceid text, userid text, system_user_perms JSONB, perm text filter_orgs text)
|
|
wherePermittedOrgsClause = "%s = ANY(eventstore.permitted_orgs(?, ?, ?, ?, ?))"
|
|
wherePermittedOrgsOrCurrentUserClause = "(" + wherePermittedOrgsClause + " OR %s = ?" + ")"
|
|
)
|
|
|
|
// wherePermittedOrgs sets a `WHERE` clause to the query that filters the orgs
|
|
// for which the authenticated user has the requested permission for.
|
|
// The user ID is taken from the context.
|
|
// The `orgIDColumn` specifies the table column to which this filter must be applied,
|
|
// and is typically the `resource_owner` column in ZITADEL.
|
|
// We use full identifiers in the query builder so this function should be
|
|
// called with something like `UserResourceOwnerCol.identifier()` for example.
|
|
// func wherePermittedOrgs(ctx context.Context, query sq.SelectBuilder, filterOrgIds, orgIDColumn, permission string) (sq.SelectBuilder, error) {
|
|
// userID := authz.GetCtxData(ctx).UserID
|
|
// logging.WithFields("permission_check_v2_flag", authz.GetFeatures(ctx).PermissionCheckV2, "org_id_column", orgIDColumn, "permission", permission, "user_id", userID).Debug("permitted orgs check used")
|
|
|
|
// systemUserPermissions := authz.GetSystemUserPermissions(ctx)
|
|
// var systemUserPermissionsJson []byte
|
|
// if systemUserPermissions != nil {
|
|
// var err error
|
|
// systemUserPermissionsJson, err = json.Marshal(systemUserPermissions)
|
|
// if err != nil {
|
|
// return query, err
|
|
// }
|
|
// }
|
|
|
|
// return query.Where(
|
|
// fmt.Sprintf(wherePermittedOrgsClause, orgIDColumn),
|
|
// authz.GetInstance(ctx).InstanceID(),
|
|
// userID,
|
|
// systemUserPermissionsJson,
|
|
// permission,
|
|
// filterOrgIds,
|
|
// ), nil
|
|
// }
|
|
|
|
func wherePermittedOrgsOrCurrentUser(ctx context.Context, query sq.SelectBuilder, filterOrgIds, orgIDColumn, userIdColum, permission string) (sq.SelectBuilder, error) {
|
|
userID := authz.GetCtxData(ctx).UserID
|
|
logging.WithFields("permission_check_v2_flag", authz.GetFeatures(ctx).PermissionCheckV2, "org_id_column", orgIDColumn, "user_id_colum", userIdColum, "permission", permission, "user_id", userID).Debug("permitted orgs check used")
|
|
|
|
systemUserPermissions := authz.GetSystemUserPermissions(ctx)
|
|
var systemUserPermissionsJson []byte
|
|
if systemUserPermissions != nil {
|
|
var err error
|
|
systemUserPermissionsJson, err = json.Marshal(systemUserPermissions)
|
|
if err != nil {
|
|
return query, zerrors.ThrowInternal(err, "AUTHZ-HS4us", "Errors.Internal")
|
|
}
|
|
}
|
|
|
|
return query.Where(
|
|
fmt.Sprintf(wherePermittedOrgsOrCurrentUserClause, orgIDColumn, userIdColum),
|
|
authz.GetInstance(ctx).InstanceID(),
|
|
userID,
|
|
systemUserPermissionsJson,
|
|
permission,
|
|
filterOrgIds,
|
|
userID,
|
|
), nil
|
|
}
|