Skip to content

Add gh secret encrypt command to encrypt a secret locally without sending to GitHub #4388

@shrink

Description

@shrink

Describe the feature or problem you’d like to solve

dev:~$ gh secret encrypt
Paste your secret: *************
✓ Encrypted secret for `org/repository`
QkMFB+vyCCE2yT5j6Tb07doxD2xKHagI2l6AjMuwUkizN7pMGXKBVOj154Pg/hwn0PbPWFvo83z+ir25iw==

Proposed solution

Separate the encryption step and make it available as a separate command so that users can easily generate an encrypted secret for their repository/organisation in infrastructure automation. An alternative might be a simple flag on set (e.g: --preview or --nowrite or --local) but I think that would be semantically incorrect (the meaning of set is explicit).

Additional context

There are hacks to grab the encrypted value now, like enabling debugging with API output which exposes the encrypted value in the request body -- and then deleted from the repository/organisation.

dev:~$ DEBUG=api gh secret set example

> PUT /repos/org/repository/actions/secrets/example HTTP/1.1
...

{
    "encrypted_value": "QkMFB+vyCCE2yT5j6Tb07doxD2xKHagI2l6AjMuwUkizN7pMGXKBVOj154Pg/hwn0PbPWFvo83z+ir25iw==",
    "key_id": "568250167242549743"
}

I'm happy to submit a Pull Request with an implementation for this if it's given the go-ahead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions