Skip to content

fix(setup): initialize secrets crypto for env-var security option#706

Open
zmanian wants to merge 1 commit intomainfrom
fix/666-setup-wizard-env-key
Open

fix(setup): initialize secrets crypto for env-var security option#706
zmanian wants to merge 1 commit intomainfrom
fix/666-setup-wizard-env-key

Conversation

@zmanian
Copy link
Collaborator

@zmanian zmanian commented Mar 8, 2026

Summary

Closes #666.

  • Initialize secrets_crypto when the user picks "Environment variable" in the setup wizard's security step, so subsequent API key saves work
  • Auto-write SECRETS_MASTER_KEY to ~/.ironclaw/.env via write_bootstrap_env so the key persists across restarts
  • Use inject_single_var (thread-safe overlay) instead of unsafe set_var
  • Fix misleading message: clarify that only .env files work (not shell profiles)

Root cause

Option 1 (env var) in step_security() generated the master key and printed it, but never set self.secrets_crypto. This left it None, causing init_secrets_context() to fail when trying to encrypt API keys in later wizard steps.

Test plan

  • test_env_var_security_initializes_crypto -- verifies generated key produces valid SecretsCrypto
  • cargo clippy --all --all-features -- zero warnings
  • cargo test --all-features -- all lib tests pass

Generated with Claude Code

The "Environment variable" option in the setup wizard's security step
generated a master key but never initialized `secrets_crypto`, causing
subsequent API key saves to fail silently. Fix by:

1. Creating SecretsCrypto from the generated key (matching keychain path)
2. Storing the key hex in settings for write_bootstrap_env to persist
3. Auto-writing SECRETS_MASTER_KEY to ~/.ironclaw/.env
4. Using inject_single_var for thread-safe env overlay
5. Fixing misleading message (shell profiles don't work, only .env)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added scope: config Configuration scope: setup Onboarding / setup size: M 50-199 changed lines risk: high Safety, secrets, auth, or critical infrastructure contributor: core 20+ merged PRs labels Mar 8, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the setup wizard where selecting the "Environment variable" option for master key storage failed to properly initialize the secrets cryptography context. This oversight prevented subsequent steps, such as API key storage, from functioning correctly. The changes ensure that the crypto context is immediately available, the generated master key is persistently stored in the .env file, and user guidance is improved, leading to a more robust and user-friendly setup experience.

Highlights

  • Secrets Crypto Initialization: Initialized secrets_crypto when the "Environment variable" security option is selected in the setup wizard, resolving issues with subsequent API key encryption.
  • Master Key Persistence: Implemented automatic persistence of the SECRETS_MASTER_KEY to ~/.ironclaw/.env using write_bootstrap_env for restart durability.
  • Environment Variable Handling: Switched to inject_single_var for setting environment variables, ensuring thread-safe overlay behavior.
  • User Messaging Improvement: Clarified user messaging regarding the use of .env files for master key storage, removing ambiguity about shell profiles.
  • Settings Structure Update: Introduced a new secrets_master_key_hex field in the Settings struct to store the generated master key for persistence.
  • Regression Test: Added a regression test, test_env_var_security_initializes_crypto, to validate the fix for secrets crypto initialization.
Changelog
  • src/settings.rs
    • Added secrets_master_key_hex field to Settings struct.
  • src/setup/wizard.rs
    • Modified the environment variable security option logic to initialize secrets_crypto and inject the master key.
    • Updated the write_bootstrap_env function to persist the SECRETS_MASTER_KEY to the .env file.
    • Improved user messaging for the environment variable security option.
    • Added test_env_var_security_initializes_crypto regression test.
Activity
  • Verified test_env_var_security_initializes_crypto to ensure the fix.
  • Confirmed cargo clippy --all --all-features passed with zero warnings.
  • Ensured cargo test --all-features passed all library tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug where the secrets crypto context was not initialized when using the environment variable security option during setup. The changes ensure that secrets_crypto is properly instantiated, allowing subsequent API key encryption to succeed. The master key is also now correctly persisted to ~/.ironclaw/.env for future runs. Additionally, the code is improved by replacing an unsafe std::env::set_var call with a thread-safe equivalent. The new test case effectively validates the fix. The changes are well-implemented and address the issue thoroughly.

Note: Security Review did not run due to the size of the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: high Safety, secrets, auth, or critical infrastructure scope: config Configuration scope: setup Onboarding / setup size: M 50-199 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setup wizard: OpenAI-compatible model config doesn't save API key

1 participant