Secrets: Tavern fails to start when the secrets file exists but doesn't contain tavern_ed25519_private_key

Open Beginner friendly
#2,509 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Read tavern/internal/crypto/crypto.go and tavern/internal/secrets/debug_file.go to trace how a missing key is handled. Reproduce with an empty secrets file and one containing other keys, then add tests around GetPrivKeyED25519 for both cases. Done means startup generates and stores a key when the requested key is absent, and the tests pass.

Written by the indexing model from the issue text.

Description

Summary

crypto.getKeyPair (tavern/internal/crypto/crypto.go) only generates and stores a new ED25519 key when SecretsManager.GetValue returns an error. DebugFileSecrets.GetValue (tavern/internal/secrets/debug_file.go) returns ([]byte{}, nil) when the secrets file exists but doesn't contain the requested key. getKeyPair then skips key generation and fails the key-size check:

invalid ED25519 private key size: got 0, expected 64

Reproduce

touch /tmp/secrets.yaml
SECRETS_FILE_PATH=/tmp/secrets.yaml go run ./tavern

The same happens with a non-empty secrets file that holds other keys but not tavern_ed25519_private_key.

When the file does not exist at all, GetValue returns os.ErrNotExist, a key is generated and SetValue creates the file, so the common fresh-start case works.

Current behavior by case

  • No file: works (key generated, file created).
  • File with the key: works.
  • Non-empty file without the key: fails with the key-size error above.
  • Empty file (e.g. created with touch): on main, getYamlStruct returns a bare io.EOF, so GetValue errors, a key is generated, and SetValue then fails with EOF. With the io.EOF handling proposed in #2508 it fails with the key-size error instead.

I confirmed the empty-file key-size failure with a throwaway test against the #2508 branch (GetPrivKeyED25519 on an empty DebugFileSecrets file). The main behavior is from reading the code, not from running it.

Suggested fix

Either of:

  • DebugFileSecrets.GetValue returns a not-found error when the key is missing, matching the other secrets managers; or
  • getKeyPair treats a zero-length value as "missing" and generates a key.

Add a test that calls GetPrivKeyED25519 against an empty secrets file and against a file that holds only other keys.

Related

Found during review of #2508. Separate from that PR's scope.

Dominant language
Rust
Stars
639
Forks
65
Avg merge
1d 5h
Merged PRs (30d)
62

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spellshift/realm

All issues in spellshift/realm

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.