Skip to content

feat: add OpenBao provider implementation - #101

Merged
alanshaw merged 2 commits into
petra/fil-547-fee-go-a256kw-region-cek-wrapunwrap-behind-a-scopefrom
ash/feat/openbao-provider-impl
Aug 28, 2026
Merged

feat: add OpenBao provider implementation#101
alanshaw merged 2 commits into
petra/fil-547-fee-go-a256kw-region-cek-wrapunwrap-behind-a-scopefrom
ash/feat/openbao-provider-impl

Conversation

@alanshaw

Copy link
Copy Markdown
Member

This PR adds an OpenBao Provider implementation for wrapping and unwrapping CEKs.

The code related to holding the KEK in memory has been removed per the RFC amendment fil-one/RFC#21

The regional KEK is expected to be present in OpenBao under the key name passed to the constructor and it MUST be created with derived=true, exportable=false.

Additionally:

  • Renames SoftwareProvider to InProcessProvider and removes the KEKSource interface as it would only have been implemented by SoftwareProvider.
  • Renames Scope to BindingContext since it is the context bound for key derivation.

Copilot AI lite review requested due to automatic review settings August 25, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the regionkey package to match the amended regional key-management RFC by introducing an OpenBao Transit–backed Provider (AES-256-GCM with derived, context-bound keys) and refactoring the in-process implementation and API to use an explicit (space, blob digest) binding context rather than the prior scope/KEK-source model.

Changes:

  • Add OpenBaoProvider (Transit encrypt/decrypt) and corresponding unit + optional live tests.
  • Replace the old in-process A256KW/KEK-source design with InProcessProvider using AES-256-GCM and a (Space, Digest) BindingContext.
  • Remove the in-memory KEK custody and mlock-based machinery (StaticKEKSource, SoftwareProvider, KEK, mlock helpers) and update deps accordingly.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
regionkey/static.go Removed in-memory KEK source implementation.
regionkey/software.go Removed prior A256KW-based software provider.
regionkey/regionkey.go Updates package docs/API: introduces BindingContext, ErrAuthentication, and binding encoding helper.
regionkey/regionkey_test.go Updates tests to BindingContext, AES-GCM semantics, rotation via InProcessProvider.
regionkey/openbao.go Adds OpenBao Transit-backed provider implementation.
regionkey/openbao_test.go Adds httptest-based request/response shape + error-mapping tests.
regionkey/openbao_live_test.go Adds optional live integration test (skipped unless env vars are set).
regionkey/mlock_unix.go Removed (no longer locking KEKs in-process).
regionkey/mlock_other.go Removed (no longer locking KEKs in-process).
regionkey/kek.go Removed (no longer storing KEKs in locked buffers).
regionkey/kek_internal_test.go Removed (tests for KEK locking/zeroing no longer apply).
regionkey/inprocess.go Adds InProcessProvider (AES-256-GCM + HKDF binding) for tests/dev.
go.mod Drops go-fee, adds OpenBao API dependency, adjusts indirect deps.
go.sum Updates sums for dependency changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread regionkey/regionkey.go
Comment thread regionkey/openbao.go
Comment on lines +57 to +66
// Wrap implements [Provider.Wrap]: a transit encrypt of cek under the key's
// current version, with the binding as the derivation context. The returned
// ciphertext is transit's "vault:vN:…" string, which embeds the version it
// was wrapped under; WrappedKey.Version records the same version ("vN") for
// the provider-agnostic bookkeeping column.
func (p *OpenBaoProvider) Wrap(ctx context.Context, binding BindingContext, cek []byte) (WrappedKey, error) {
secret, err := p.logical.WriteWithContext(ctx, p.mount+"/encrypt/"+p.key, map[string]interface{}{
"plaintext": base64.StdEncoding.EncodeToString(cek),
"context": base64.StdEncoding.EncodeToString(bindingBytes(binding)),
})
Comment thread regionkey/inprocess.go
Comment on lines +92 to +110
// Wrap implements [Provider.Wrap]: it seals cek with AES-256-GCM under the
// binding-derived subkey of the current region KEK, prepends the fresh random
// nonce, and tags the result with the KEK's version.
func (p *InProcessProvider) Wrap(_ context.Context, binding BindingContext, cek []byte) (WrappedKey, error) {
p.mu.RLock()
version := p.current
kek := p.keys[version]
p.mu.RUnlock()

aead, err := boundAEAD(kek, binding)
if err != nil {
return WrappedKey{}, err
}
nonce := make([]byte, gcmNonceLen)
if _, err := rand.Read(nonce); err != nil {
return WrappedKey{}, fmt.Errorf("regionkey: generating nonce: %w", err)
}
return WrappedKey{Version: version, Ciphertext: aead.Seal(nonce, nonce, cek, nil)}, nil
}
@alanshaw
alanshaw force-pushed the ash/feat/openbao-provider-impl branch 3 times, most recently from 10dbf98 to 9aa765b Compare August 27, 2026 08:47
alanshaw and others added 2 commits August 28, 2026 12:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@alanshaw
alanshaw force-pushed the ash/feat/openbao-provider-impl branch from 9aa765b to 1c30f05 Compare August 28, 2026 11:11
@alanshaw
alanshaw merged commit 30a7ff4 into main Aug 28, 2026
10 checks passed
@alanshaw
alanshaw deleted the ash/feat/openbao-provider-impl branch August 28, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants