Skip to content

Commit 0d728cd

Browse files
authored
chore: prepare 1.0.3 release (#6)
* chore: prepare 1.0.3 release Bumps the gem version and updates the changelog for a documentation-focused release with a clearer README. * docs: adjust 1.0.3 changelog wording Keeps the 1.0.3 release notes focused on README usability improvements.
1 parent 6d94d2f commit 0d728cd

4 files changed

Lines changed: 107 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
77

88
## [Unreleased]
99

10+
## [1.0.3] - 2026-04-25
11+
12+
### Changed
13+
14+
- Update the README with clearer usage guidance and improved readability.
15+
1016
## [1.0.2] - 2026-04-25
1117

1218
### Changed
@@ -39,7 +45,8 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
3945
- Header-only key rotation for re-wrapping encrypted DEKs.
4046
- Unit and integration coverage for crypto, providers, Active Storage, S3, multipart upload, streaming, metadata, and key rotation.
4147

42-
[Unreleased]: https://github.com/codebyjass/active-cipher-storage/compare/v1.0.2...HEAD
48+
[Unreleased]: https://github.com/codebyjass/active-cipher-storage/compare/v1.0.3...HEAD
49+
[1.0.3]: https://github.com/codebyjass/active-cipher-storage/compare/v1.0.2...v1.0.3
4350
[1.0.2]: https://github.com/codebyjass/active-cipher-storage/compare/v1.0.1...v1.0.2
4451
[1.0.1]: https://github.com/codebyjass/active-cipher-storage/compare/v1.0.0...v1.0.1
4552
[1.0.0]: https://github.com/codebyjass/active-cipher-storage/releases/tag/v1.0.0

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
active_cipher_storage (1.0.2)
4+
active_cipher_storage (1.0.3)
55
activesupport (>= 7.0, < 9.0)
66
concurrent-ruby (~> 1.2)
77

README.md

Lines changed: 97 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,88 @@
1-
# ActiveCipherStorage
1+
# Active Cipher Storage
22

33
[![CI](https://github.com/codebyjass/active-cipher-storage/actions/workflows/ruby.yml/badge.svg)](https://github.com/codebyjass/active-cipher-storage/actions/workflows/ruby.yml)
44

5-
ActiveCipherStorage is a Ruby gem for Rails Active Storage encryption and decryption. It encrypts files before they are stored, decrypts them when they are read, and supports AWS S3, streaming downloads, multipart uploads, AES-256-GCM envelope encryption, AWS KMS, and custom key providers.
5+
Active Cipher Storage is published as the `active_cipher_storage` Ruby gem.
66

7-
ActiveCipherStorage supports three upload paths:
7+
It adds Rails Active Storage encryption and decryption without changing the way your Rails app attaches files. Files are encrypted before they are stored in AWS S3 or another storage service, and decrypted when your app reads them back.
88

9-
- **Rails Active Storage** — application code keeps using normal attachment APIs while the storage service encrypts on upload and decrypts on download.
10-
- **Direct S3 clients** — service objects and non-Rails apps can call `put_encrypted`, `get_decrypted`, and `stream_decrypted`.
11-
- **Frontend chunk uploads** — the frontend sends plaintext chunks to your backend; the backend encrypts those chunks and uploads encrypted S3 multipart parts.
9+
This solves a common Rails security problem: sensitive files should be protected before they leave your application.
10+
11+
It works with normal Rails Active Storage attachments, direct S3 uploads from Ruby service objects, streaming downloads, and backend-managed multipart uploads for large files.
12+
13+
## Features
14+
15+
- Encrypt files before uploading them to S3 or Active Storage.
16+
- Decrypt files automatically when downloading.
17+
- Works with Rails Active Storage.
18+
- Supports direct AWS S3 client usage.
19+
- Handles large files with streaming AES-256-GCM encryption.
20+
- Supports backend-managed multipart uploads for frontend chunk upload flows.
21+
- Uses pluggable key providers: environment variables, AWS KMS, or custom KMS providers.
22+
- Supports header-only key rotation without rewriting the full file body.
23+
24+
## Use Cases
25+
26+
- Encrypt user documents before storing them in S3.
27+
- Secure financial records, contracts, medical files, invoices, and other sensitive uploads.
28+
- Add application-level encryption on top of AWS S3 server-side encryption.
29+
- Keep Rails Active Storage APIs while storing encrypted files.
30+
- Stream large encrypted files from S3 without loading the whole file into memory.
31+
- Meet compliance and privacy requirements around PII, GDPR, HIPAA-style data, or internal security policies.
1232

1333
## Contents
1434

15-
1. [How it works](#how-it-works)
16-
2. [Installation](#installation)
17-
3. [Rails / Active Storage setup](#rails--active-storage-setup)
18-
4. [Standalone S3 usage](#standalone-s3-usage)
19-
5. [Chunked multipart upload](#chunked-multipart-upload)
20-
6. [Streaming download](#streaming-download)
21-
7. [Manual encrypt / decrypt](#manual-encrypt--decrypt)
22-
8. [Blob metadata](#blob-metadata)
23-
9. [KMS providers](#kms-providers)
35+
1. [Features](#features)
36+
2. [Use Cases](#use-cases)
37+
3. [How it works](#how-it-works)
38+
4. [Installation](#installation)
39+
5. [Rails / Active Storage setup](#rails--active-storage-setup)
40+
6. [Standalone S3 usage](#standalone-s3-usage)
41+
7. [Chunked multipart upload](#chunked-multipart-upload)
42+
8. [Streaming download](#streaming-download)
43+
9. [Manual encrypt / decrypt](#manual-encrypt--decrypt)
44+
10. [Blob metadata](#blob-metadata)
45+
11. [KMS providers](#kms-providers)
2446
- [Environment-variable provider](#environment-variable-provider)
2547
- [AWS KMS provider](#aws-kms-provider)
2648
- [Custom provider](#custom-provider)
27-
10. [Key rotation](#key-rotation)
28-
11. [Configuration reference](#configuration-reference)
29-
12. [Encryption format](#encryption-format)
30-
13. [Security notes](#security-notes)
31-
14. [Testing](#testing)
32-
15. [Contributing](#contributing)
33-
16. [Security reports](#security-reports)
34-
17. [License](#license)
35-
18. [Ruby and Rails compatibility](#ruby-and-rails-compatibility)
49+
12. [Key rotation](#key-rotation)
50+
13. [Configuration reference](#configuration-reference)
51+
14. [Encryption format](#encryption-format)
52+
15. [Security notes](#security-notes)
53+
16. [Testing](#testing)
54+
17. [Contributing](#contributing)
55+
18. [Security reports](#security-reports)
56+
19. [License](#license)
57+
20. [Ruby and Rails compatibility](#ruby-and-rails-compatibility)
3658

3759
## How it works
3860

39-
Every encrypted file is self-contained. No external metadata store is needed.
40-
41-
```
42-
┌─────────────────────────────────────────────────────────┐
43-
│ Plaintext file │
44-
└────────────────────────┬────────────────────────────────┘
45-
46-
┌──────────────▼──────────────┐
47-
│ 1. Generate random DEK │ (32 bytes, AES-256)
48-
│ per-file, per-operation │
49-
└──────────────┬──────────────┘
50-
51-
┌──────────────▼──────────────┐
52-
│ 2. Encrypt file with DEK │ AES-256-GCM
53-
│ unique IV per operation │ + auth tag
54-
└──────────────┬──────────────┘
55-
56-
┌──────────────▼──────────────┐
57-
│ 3. Wrap DEK with KMS │ ENV, AWS KMS,
58-
│ master key │ or custom
59-
└──────────────┬──────────────┘
60-
61-
┌──────────────▼──────────────┐
62-
│ 4. Binary payload │ Header + IV +
63-
│ (stored in S3) │ Ciphertext + Auth tag
64-
└─────────────────────────────┘
65-
```
66-
67-
Decryption reverses the flow: the KMS provider unwraps the DEK from the header, then AES-GCM verifies the auth tag and decrypts the ciphertext.
68-
69-
Every encrypted payload uses the same self-describing format, whether it came from Active Storage, the direct S3 adapter, or the backend chunk upload API.
61+
Every file gets its own random data encryption key. The file is encrypted with AES-256-GCM, and that data key is wrapped by your configured key provider.
62+
63+
The encrypted file is self-contained. It stores:
64+
65+
- a small Active Cipher Storage header,
66+
- the encrypted data key,
67+
- the ciphertext,
68+
- authentication tags used to detect tampering.
69+
70+
When the file is downloaded, the gem reads the header, asks the key provider to unwrap the data key, verifies the AES-GCM authentication tag, and returns plaintext to your app.
71+
72+
The same format is used for Rails Active Storage uploads, direct S3 uploads, streaming downloads, and multipart upload flows.
7073

7174
## Installation
7275

76+
Add the gem to your Gemfile:
77+
7378
```ruby
74-
# Gemfile
7579
gem "active_cipher_storage"
80+
```
7681

77-
# For AWS KMS provider:
78-
gem "aws-sdk-kms"
82+
If you use AWS KMS or the direct S3 adapter, add the AWS SDK gems you need:
7983

80-
# For standalone S3 adapter:
84+
```ruby
85+
gem "aws-sdk-kms"
8186
gem "aws-sdk-s3"
8287
```
8388

@@ -87,7 +92,11 @@ bundle install
8792

8893
## Rails / Active Storage setup
8994

90-
### 1. Configure a KMS provider
95+
Use this path when you want Rails Active Storage to encrypt attachments automatically.
96+
97+
Your model, controller, and view code can keep using normal Active Storage APIs. The only change is the storage service configuration.
98+
99+
### 1. Configure a key provider
91100

92101
```ruby
93102
# config/initializers/active_cipher_storage.rb
@@ -154,15 +163,19 @@ user.document.attach(io: file, filename: "report.pdf")
154163
url = rails_blob_url(user.document)
155164
```
156165

157-
Active Storage transparently encrypts on upload and decrypts on download. Existing plaintext objects are still readable: if a blob does not start with the `ACS\x01` magic header, the service returns it unchanged.
166+
Active Storage now encrypts on upload and decrypts on download.
167+
168+
Existing plaintext objects are still readable. If a blob does not start with the `ACS\x01` magic header, the service returns it unchanged.
158169

159170
`config.encrypt_uploads` controls new Active Storage writes only. When disabled, new uploads are stored as plaintext and marked with `"encrypted": false` metadata. Reads continue to auto-detect by payload header, so existing encrypted blobs still decrypt correctly and existing plaintext blobs still download unchanged.
160171

161172
Direct Active Storage browser uploads are intentionally disabled because they bypass the backend encryption layer.
162173

163174
## Standalone S3 usage
164175

165-
No Rails required.
176+
You can also use Active Cipher Storage without Rails.
177+
178+
This is useful for background jobs, service objects, scripts, or non-Rails Ruby apps that upload encrypted files directly to S3.
166179

167180
```ruby
168181
require "active_cipher_storage"
@@ -176,12 +189,12 @@ s3 = ActiveCipherStorage::Adapters::S3Adapter.new(
176189
region: "us-east-1"
177190
)
178191

179-
# Encrypt and upload
192+
# Encrypt before upload
180193
File.open("contract.pdf", "rb") do |f|
181194
s3.put_encrypted("legal/contract-2026.pdf", f)
182195
end
183196

184-
# Download and decrypt — returns an IO
197+
# Download and decrypt
185198
io = s3.get_decrypted("legal/contract-2026.pdf")
186199
File.binwrite("decrypted_contract.pdf", io.read)
187200
```
@@ -197,24 +210,26 @@ s3 = ActiveCipherStorage::Adapters::S3Adapter.new(
197210

198211
## Chunked multipart upload
199212

200-
For large files where the frontend sends data in separate HTTP requests, use `EncryptedMultipartUpload`. Each frontend chunk is encrypted by the backend as an authenticated ACS frame and buffered until the S3 multipart minimum part size is met, then flushed as an encrypted S3 multipart part.
213+
For large files, many apps upload from the browser in chunks.
214+
215+
Active Cipher Storage supports that flow, but the browser still does not get encryption keys. The frontend sends plaintext chunks to your Rails app, and your backend encrypts those chunks before uploading encrypted multipart parts to S3.
201216

202-
This flow is backend-managed. The frontend never receives encryption keys and never uploads plaintext directly to S3.
217+
Use `EncryptedMultipartUpload` for this backend-managed upload flow.
203218

204219
```ruby
205220
uploader = ActiveCipherStorage::EncryptedMultipartUpload.new(
206221
s3_client: Aws::S3::Client.new(region: "us-east-1"),
207222
bucket: "my-bucket"
208223
)
209224

210-
# --- Request 1: start the upload ---
225+
# Request 1: start the upload
211226
session_id = uploader.initiate(key: "uploads/video.mp4")
212227
# Keep session_id for this active upload lifecycle.
213228

214-
# --- Requests 2..N: send chunks (any size) ---
229+
# Requests 2..N: send chunks
215230
uploader.upload_part(session_id: session_id, chunk_io: request.body)
216231

217-
# --- Final request: seal and complete ---
232+
# Final request: seal and complete
218233
result = uploader.complete(session_id: session_id)
219234
# => { status: :completed, key: "uploads/video.mp4", parts_count: 12 }
220235
```
@@ -255,25 +270,28 @@ class UploadsController < ApplicationController
255270
end
256271
```
257272

258-
**Session storage:**
273+
**Session storage**
274+
259275
By default, session state is held in process memory (`MemorySessionStore`). This is intended for one active backend-managed upload lifecycle and is not durable across process restarts or deploys.
260276

261277
For multi-process deployments where chunks for the same active upload may land on different workers or hosts, pass a shared store:
262278

263279
```ruby
264-
# Rails.cache backed by Redis allows cross-worker active upload sessions
280+
# Rails.cache backed by Redis allows cross-worker active upload sessions.
265281
uploader = ActiveCipherStorage::EncryptedMultipartUpload.new(
266282
s3_client: s3_client,
267283
bucket: "my-bucket",
268284
store: Rails.cache # any object with read/write/delete
269285
)
270286
```
271287

272-
**Security:** The plaintext DEK is never stored in the session. Only the KMS-wrapped encrypted DEK is persisted; it is decrypted fresh for each chunk and zeroed immediately after use.
288+
**Security:** The plaintext data key is never stored in the session. Only the KMS-wrapped encrypted data key is persisted; it is decrypted fresh for each chunk and zeroed immediately after use.
273289

274290
## Streaming download
275291

276-
`stream_decrypted` pipes S3 bytes through the decryptor and yields plaintext chunks on the fly. Memory usage is bounded by one ACS chunk (default 5 MiB) regardless of file size.
292+
Use `stream_decrypted` when you need to send a large encrypted file to a client without loading the whole file into memory.
293+
294+
The adapter reads encrypted bytes from S3, decrypts authenticated chunks as they arrive, and yields plaintext chunks to your block. Memory usage stays bounded by one Active Cipher Storage chunk, which is 5 MiB by default.
277295

278296
```ruby
279297
s3 = ActiveCipherStorage::Adapters::S3Adapter.new(
@@ -302,13 +320,15 @@ File.open("output.bin", "wb") do |f|
302320
end
303321
```
304322

305-
`stream_decrypted` handles S3 delivering data in any chunk size — the internal `StreamingDecryptor` buffers incoming bytes and emits plaintext only when a complete, authenticated ACS frame is available.
323+
`stream_decrypted` handles S3 delivering data in any chunk size. The internal decryptor buffers incoming bytes and emits plaintext only when a complete, authenticated frame is available.
306324

307325
Use `stream_decrypted` for chunked ACS objects. If the object is non-chunked, call `get_decrypted`; streaming a non-chunked or non-ACS/plaintext object raises `InvalidFormat` with a clear error.
308326

309327
## Manual encrypt / decrypt
310328

311-
Use `Cipher` (in-memory) or `StreamCipher` (chunked, constant memory):
329+
If you do not need Rails or S3 integration, you can use the lower-level cipher classes directly.
330+
331+
Use `Cipher` for small files and `StreamCipher` for large files:
312332

313333
```ruby
314334
require "active_cipher_storage"
@@ -317,15 +337,15 @@ ActiveCipherStorage.configure do |c|
317337
c.provider = ActiveCipherStorage::Providers::EnvProvider.new
318338
end
319339

320-
# ── In-memory (small files) ─────────────────────────────
340+
# Small files
321341
cipher = ActiveCipherStorage::Cipher.new
322342
encrypted = cipher.encrypt(File.open("secret.txt", "rb"))
323343
# => Binary String with embedded header, IV, ciphertext, auth tag
324344

325345
plaintext = cipher.decrypt(encrypted)
326346
# => Original plaintext String
327347

328-
# ── Streaming (large files) ─────────────────────────────
348+
# Large files
329349
stream = ActiveCipherStorage::StreamCipher.new
330350

331351
File.open("large.bin", "rb") do |input|
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ActiveCipherStorage
2-
VERSION = "1.0.2"
2+
VERSION = "1.0.3"
33
end

0 commit comments

Comments
 (0)