feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -1,8 +1,11 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/schutzaria"
|
||||
)
|
||||
@@ -14,10 +17,62 @@ type ReadPathPolicy = schutzaria.ReadPathPolicy
|
||||
// directory entries. It deliberately excludes Object grants: an Object grant
|
||||
// does not reveal all of that Object's semantic aliases.
|
||||
func (s *Store) LoadReadPathPolicy(domain, principal string) (*ReadPathPolicy, error) {
|
||||
return loadReadPathPolicy(s.DB, domain, principal)
|
||||
return s.LoadReadPathPolicyContext(context.Background(), domain, principal)
|
||||
}
|
||||
|
||||
func (s *Store) LoadReadPathPolicyContext(ctx context.Context, domain, principal string) (*ReadPathPolicy, error) {
|
||||
var policy *ReadPathPolicy
|
||||
err := s.policyRead(ctx, func(ctx context.Context, tx *sql.Tx) error {
|
||||
var err error
|
||||
policy, err = s.loadReadPathPolicy(cityReadQuery{ctx, tx}, domain, principal)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
func (s *Store) policyRead(ctx context.Context, read func(context.Context, *sql.Tx) error) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
// Grants and restrictions must come from the same database snapshot.
|
||||
tx, err := s.DB.BeginTx(ctx, s.policyReadOptions())
|
||||
if err != nil {
|
||||
return s.sqlError("read policy snapshot", err)
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if err = read(ctx, tx); err != nil {
|
||||
return s.sqlError("read policy", err)
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return s.sqlError("read policy snapshot", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) policyReadOptions() *sql.TxOptions {
|
||||
level := sql.LevelSerializable
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
level = sql.LevelRepeatableRead
|
||||
}
|
||||
return &sql.TxOptions{ReadOnly: true, Isolation: level}
|
||||
}
|
||||
|
||||
func (s *Store) lockPolicyWrite(ctx context.Context, tx *sql.Tx) error {
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
_, err := tx.ExecContext(ctx, `SELECT pg_advisory_xact_lock(1885431653,1853058931)`)
|
||||
return err
|
||||
}
|
||||
_, err := tx.ExecContext(ctx, `UPDATE groups SET uuid=uuid WHERE 0`)
|
||||
return err
|
||||
}
|
||||
|
||||
func loadReadPathPolicy(q pathQueryer, domain, principal string) (*ReadPathPolicy, error) {
|
||||
return (&Store{}).loadReadPathPolicy(q, domain, principal)
|
||||
}
|
||||
|
||||
func (s *Store) loadReadPathPolicy(q pathQueryer, domain, principal string) (*ReadPathPolicy, error) {
|
||||
var all bool
|
||||
var exact, subtrees []string
|
||||
if domain == "" || principal == "" {
|
||||
@@ -25,18 +80,18 @@ func loadReadPathPolicy(q pathQueryer, domain, principal string) (*ReadPathPolic
|
||||
}
|
||||
rows, err := q.Query(`
|
||||
SELECT 'role',g.target_type,g.target_id FROM principals p
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=? AND m.state='active'
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=`+s.sqlParam(1)+` AND m.state='active'
|
||||
JOIN auth_role_bindings b ON b.membership_uuid=m.uuid
|
||||
JOIN auth_roles r ON r.uuid=b.role_uuid AND r.domain_uuid=m.domain_uuid
|
||||
JOIN auth_capability_grants g ON g.role_uuid=r.uuid AND g.capability='read'
|
||||
WHERE p.uuid=? AND p.state IN ('active','readonly') AND g.target_type IN ('domain','path')
|
||||
WHERE p.uuid=`+s.sqlParam(2)+` AND p.state IN ('active','readonly') AND g.target_type IN ('domain','path')
|
||||
UNION ALL
|
||||
SELECT 'group','path',gp.scope_path FROM principals p
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=? AND m.state='active'
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=`+s.sqlParam(3)+` AND m.state='active'
|
||||
JOIN group_members gm ON gm.membership_uuid=m.uuid
|
||||
JOIN groups g ON g.uuid=gm.group_uuid AND g.domain_uuid=m.domain_uuid AND g.state='active'
|
||||
JOIN group_permissions gp ON gp.group_uuid=g.uuid AND gp.permission IN ('read','read_write','read_write_once')
|
||||
WHERE p.uuid=? AND p.state IN ('active','readonly')
|
||||
WHERE p.uuid=`+s.sqlParam(4)+` AND p.state IN ('active','readonly')
|
||||
LIMIT 4097`, domain, principal, domain, principal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -71,7 +126,7 @@ func loadReadPathPolicy(q pathQueryer, domain, principal string) (*ReadPathPolic
|
||||
if err = rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
access, err := loadLocalityAccess(q, domain, principal)
|
||||
access, err := s.loadLocalityAccess(q, domain, principal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user