Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Configuration Variables with Secure Encryption and Session Management #5500

Closed
mshakeg opened this issue Jul 9, 2024 · 2 comments
Closed
Labels
blocked-reason:breaking-change This is a breaking change that can only be done in a major release status:ready This issue is ready to be worked on

Comments

@mshakeg
Copy link

mshakeg commented Jul 9, 2024

Background

Hardhat introduced configuration variables as a way to manage user-specific values and sensitive data separately from the code repository (as per issue #2265). While this was a step in the right direction, the current implementation stores these variables in plain text, which is not ideal for highly sensitive information like private keys.

Feature Request

We propose enhancing the existing configuration variables feature with built-in encryption support and secure session management to provide a more robust solution for managing sensitive data.

Proposed Functionality

  1. Encryption at Rest:

    • Implement strong encryption (e.g., AES-256) for storing configuration variables on disk.
    • Use a master password or key to encrypt/decrypt the variables.
  2. Secure Session Management:

    • Implement a secure session system where users only need to enter the master password once per Hardhat session.
    • The session could be initiated when Hardhat first attempts to access a sensitive variable.
    • Securely store the derived encryption key in protected memory during the active session, implementing safeguards against memory dumps and ensuring the key is securely erased when the session ends.
    • Provide explicit commands for starting, checking, and terminating sessions.
    • Automatically terminate sessions when the terminal is closed or after a configurable idle timeout.
  3. Classified Variables:

    • Allow users to mark certain variables as "sensitive" to enforce stricter security measures.
    • Sensitive variables are encrypted on disk but can be accessed freely during an authenticated session.
  4. Secure Input:

    • When setting sensitive variables, provide an option to input values securely (without echoing to the terminal).

Benefits

  • Significantly enhanced security for sensitive data like private keys and API tokens.
  • Maintains the ease of use of the current configuration variables system.
  • Improves developer experience with session-based authentication.

Potential Implementation

// Setting a sensitive variable
$ npx hardhat vars set --sensitive PRIVATE_KEY
 Enter value: ********************************

// Manually start a session (optional, as it will auto-start when needed)
$ npx hardhat vars session start
Enter master password to start secure session: ****
Secure session started.

// Check current session status
$ npx hardhat vars session status
Secure session is active.

// Manually terminate a session
$ npx hardhat vars session end
Secure session terminated.

// Session auto-starts when accessing sensitive variables
$ npx hardhat deploy
No active session detected. Enter master password to unlock sensitive variables: ****
Deploying contracts...

// Using in configuration
const { vars } = require("hardhat/config");

module.exports = {
  networks: {
    mainnet: {
      url: `https://mainnet.infura.io/v3/${vars.get("INFURA_API_KEY")}`,
      accounts: [vars.get("PRIVATE_KEY")], // Will be automatically decrypted if in an authenticated session
    },
  },
};

Questions for Discussion

  1. What encryption standards should we use?
  2. How long should a secure session last by default? Should we provide options for configurable session timeout?
  3. Should sessions be tied to specific terminal instances or be system-wide?

We believe this enhancement would significantly improve the security posture of Hardhat projects, especially for teams working with valuable assets on public blockchains, while maintaining a smooth developer experience.

Search terms

secrets encryption configuration variables

@fvictorio fvictorio added this to Hardhat Jul 9, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Jul 9, 2024
@kanej kanej added status:ready This issue is ready to be worked on and removed status:triaging labels Jul 11, 2024
@kanej kanej moved this from Backlog to To-do in Hardhat Jul 11, 2024
@kanej kanej added the blocked-reason:breaking-change This is a breaking change that can only be done in a major release label Jul 11, 2024
@kanej
Copy link
Member

kanej commented Jul 11, 2024

We are currently working on the next major version for Hardhat, and this a key requirement of our next version of configuration variables.

@ChristopherDedominici
Copy link
Contributor

Closing this issue as it is being addressed here

@github-project-automation github-project-automation bot moved this from To-do to Done in Hardhat Aug 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked-reason:breaking-change This is a breaking change that can only be done in a major release status:ready This issue is ready to be worked on
Projects
Archived in project
Development

No branches or pull requests

3 participants