Gastansicht, Verbesserungen bei Planung

This commit is contained in:
concierge committed 2026-11-18 07:57:00 +01:00
1 parent b3afa3ef32
commit c08d43e7dd
38 files changed
+3845 -219

No files matched your search

+35 -10
View File
@@ -14,8 +14,8 @@ import (
// KeyScope identifies one encrypted data scope. Tenant scopes hold the SMTP
// credentials, person scopes hold e-mail addresses. Editors hold the person
// scopes of their tenants; a reader only holds the scope of the person linked
// to their account.
// scopes of their tenants; a reader holds the scope of the person linked to
// their account and the scopes that other readers have shared with them.
type KeyScope struct {
Type string
TenantID string
@@ -62,6 +62,14 @@ func (k *Keyring) remember(scope KeyScope, dek []byte) {
k.deks[scope.String()] = append([]byte{}, dek...)
}
// Forget drops a cached data key. It is used when a reader revokes access to
// their e-mail address so an already open session loses the key immediately.
func (k *Keyring) Forget(scope KeyScope) {
k.mu.Lock()
defer k.mu.Unlock()
delete(k.deks, scope.String())
}
type keyringContextKey struct{}
// WithKeyring attaches an unlocked keyring to a request context.
@@ -407,6 +415,12 @@ func (s *Store) ReconcileTenant(ctx context.Context, keyring *Keyring, tenantID
if linked := s.linkedReaderForPerson(ctx, tenantID, personID); linked != "" {
recipients = append(recipients, linked)
}
shared, err := s.contactShareViewers(ctx, tenantID, personID)
if err != nil {
rememberError(err)
} else {
recipients = append(recipients, shared...)
}
if err := s.grantScope(ctx, keyring, scope, recipients); err != nil {
rememberError(err)
}
@@ -663,9 +677,10 @@ func (s *Store) SetSecret(ctx context.Context, tenantID, scopeType, scopeID, key
}
// EnsurePersonScope creates the person scope if needed and grants it to all
// active editors plus the linked reader. It works with an editor keyring and
// with a reader keyring that already holds the person's data key; the latter
// lets a reader refresh editor access after a new editor was created.
// active editors, the linked reader and every reader the owner shared their
// address with. It works with an editor keyring and with a reader keyring that
// already holds the person's data key; the latter lets a reader refresh access
// after a new editor was created.
func (s *Store) EnsurePersonScope(ctx context.Context, keyring *Keyring, tenantID, personID string) error {
if keyring == nil || !s.SecretIsInitialized(ctx, tenantID) {
return nil
@@ -681,6 +696,11 @@ func (s *Store) EnsurePersonScope(ctx context.Context, keyring *Keyring, tenantI
if linked := s.linkedReaderForPerson(ctx, tenantID, personID); linked != "" {
recipients = append(recipients, linked)
}
shared, err := s.contactShareViewers(ctx, tenantID, personID)
if err != nil {
return err
}
recipients = append(recipients, shared...)
return s.grantScope(ctx, keyring, scope, recipients)
}
@@ -785,9 +805,9 @@ func (s *Store) DeleteUserKeys(ctx context.Context, userID string) error {
}
// PruneUserWrappers enforces the key access policy. Editors keep the scopes of
// their tenant memberships. A reader may hold exactly one wrapper: the person
// scope of the account they are linked to. Administrators never hold key
// material.
// their tenant memberships. A reader keeps the person scope they are linked to
// plus every person scope that its owner has shared with the account.
// Administrators never hold key material.
func (s *Store) PruneUserWrappers(ctx context.Context, userID string) error {
var role, linkedTenantID, linkedPersonID string
var active int
@@ -826,8 +846,13 @@ func (s *Store) PruneUserWrappers(ctx context.Context, userID string) error {
}
_, err = s.db.ExecContext(ctx, `
DELETE FROM key_wrappers WHERE user_id=? AND NOT (
scope_type='person' AND tenant_id=? AND scope_id=?
)`, userID, linkedTenantID, linkedPersonID)
scope_type='person' AND tenant_id=? AND (
scope_id=? OR scope_id IN (
SELECT owner_person_id FROM contact_shares
WHERE tenant_id=? AND viewer_user_id=?
)
)
)`, userID, linkedTenantID, linkedPersonID, linkedTenantID, userID)
return err
}