Skip to content

secret update #6327

Description

@mshanemc

Describe the feature or problem you’d like to solve

Background: our organization secrets -o are selectively shared w 1-20 repos, but not all. A sibling organization has the need to share some of the same secrets with a few of its repos.

Currently, when you run gh secret set MY_SECRET -o myOrg it'll reset the secret's visibility to private
You can add --repos and then list them all...and there are a lot. And that list has to be maintained as repos come/go.

Proposed solution

secret update : if a secret exists, update the value but change nothing else about its visibility or repo assignments.

This is aimed at org-level secrets since repo-level secrets don't care about visibility/sharing, but I'd keep the same -o -a and -R flags from secret set for consistency.

Activity

  1. vilmibm commented on Sep 29, 2022

    @vilmibm
    Contributor

    This makes perfect sense to me, thanks for the suggestion. I assume the API supports this operation (but whoever takes this on should confirm that before starting development).

  2. added and removed on Sep 29, 2022
  3. nsmag commented on Oct 6, 2022

    @nsmag
    Contributor

    Hi, I checked the REST API and found that there's no dedicated API for updating secrets. Only PUT /orgs/ORG/{actions,codespaces}/secrets/SECRET_NAME is exposed to create or update the secret. The visibility is required. And if visibility = selected, the selected_repository_ids is required.

    Proposed solution

    To maintain the selected repos visibility of existing secrets, with the current REST API:

    Change the default value of --visibility to "". If --visibility and --repos are empty

    • GET the secret
      • If not found, set visibility = private
      • if found, maintain visibility
        • if visibility = selected, maintain repos
    • PUT the secret with visibility and repos

    There's no changes if --visibility or --repos are not empty.

    A few things I'm not sure about this solution:

    • Can we assign different default value that not belong to the enum flag?
    • We might need to get multiple pages of repos if the selected repos count is big.

    What do you think?

  4. danielfn commented on Apr 7, 2023

    @danielfn

    Hi! Here I have an additional use case to consider for secret update: changing the secret visibility without modifying the secret value. E.g: adding a new repository for a secret with visibility = selected without providing again the actual secret value.

    However, as @nsmag says, the API doesn't seem to explicitly support this either... If we inspect the API call that the web UI does, the trick seems to be setting an empty value for encrypted_value, but I can't find this documented anywhere.

  5. GMNGeoffrey commented on May 24, 2023

    @GMNGeoffrey

    Some related issues (I can file new issues if that's preferred):

    gh secret set resetting visibility is a big footgun. We just had an outage because of this. The documentation says

    Set a value for a secret on one of the following levels

    That does not suggest to me "and wipe out the visibility settings already there". I think the documentation needs to make this much more clear. Perhaps if a secret already exists, require explicitly setting visibility until/unless this issue is resolved.

    Minor, but the visibility flag documentation doesn't specify that you need to also list repos if you set visibility to "selected". Would be helpful to add that.

    Not being able to modify only certain fields on a secret seems like a pretty big limitation in the API. I'm not sure the CLI should actually be hacking around that. Doing a GET followed by PUT introduces race conditions and such. Seems like the API should really have a PATCH method.

  6. yvele commented on Jul 29, 2024

    @yvele

    I have a similar problem when I try to update secret selected repositories WITHOUT wanting the change the secret value:

    I think it will be cumbersome to add extra gh secret commands for that. We can manage it either with tags or appropriate behavior

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-secretrelating to the gh secret command

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions