LoadStatements returns the user's decrypted secret statements for replay at session creation. Rows that fail to decrypt (e.g. written under a rotated key) are skipped with a loud log instead of failing the whole session.
(_ context.Context, orgID, username string)
| 80 | // session creation. Rows that fail to decrypt (e.g. written under a rotated |
| 81 | // key) are skipped with a loud log instead of failing the whole session. |
| 82 | func (m *CPUserSecretManager) LoadStatements(_ context.Context, orgID, username string) ([]string, error) { |
| 83 | if m.cipher == nil { |
| 84 | return nil, nil |
| 85 | } |
| 86 | rows, err := m.store.ListOrgUserSecrets(orgID, username) |
| 87 | if err != nil { |
| 88 | return nil, fmt.Errorf("list user secrets: %w", err) |
| 89 | } |
| 90 | statements := make([]string, 0, len(rows)) |
| 91 | for _, row := range rows { |
| 92 | stmt, err := m.cipher.Open(row.OrgID, row.Username, row.SecretName, row.Ciphertext) |
| 93 | if err != nil { |
| 94 | slog.Error("User persistent secret cannot be decrypted; skipping replay (was the encryption key rotated?).", |
| 95 | "org", row.OrgID, "user", row.Username, "secret", row.SecretName, "error", err) |
| 96 | continue |
| 97 | } |
| 98 | statements = append(statements, stmt) |
| 99 | } |
| 100 | return statements, nil |
| 101 | } |
| 102 | |
| 103 | // SessionSecretLoader binds an org onto LoadStatements in the shape |
| 104 | // SessionManager.SetUserSecretLoader expects. |
no test coverage detected