Skip to content

Bridge credentials should be read from the full configuration chain  #406

Closed

Description

@sudoforge

git-bug does not currently read bridge credentials from anything except the user configuration file, e.g. ${HOME}/.gitconfig. It would be awesome if the full configuration chain could be supported, in order of precedence:

  • Local configuration -- ${REPO_ROOT}/.git/config
  • User configuration -- ${HOME}/.gitconfig or ${XDG_CONFIG_HOME}/git/config
  • System configuration -- /etc/gitconfig

Additionally, following include directives would be useful -- the main application for which is likely keeping the authentication configuration out of the default user-scoped conffile which is stored in a repository for public sharing.

Activity

  1. MichaelMure commented on Jun 17, 2020

    @MichaelMure
    Contributor

    So git-bug read the git config with git itself, through the git config command.

    Bridges configurations are stored in the local git config (--local is added to the command).
    Bridges credentials are stored in the global git config (--global is added to the command).

    Based on this, you should be able to use whatever git foo or files as long as it works for git itself. Isn't that the case ?

  2. changed the title [-]Bridge authentication should read from the full configuration chain [/-] [+]Bridge credentials should be read from the full configuration chain [/+] on Jun 17, 2020
  3. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    I updated the description and title of this issue for additional clarity.

    Yes, the configuration for bridges is read from the local configuration, and credentials are read from global. This issue pitches that credentials should be read from the entire chain.

  4. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    Also, note that there is a bug with the way credentials are read from the global configuration. If my global configuration contains a block like:

    [include]
      path = ~/.gitconfig.foo
    

    and ~/.gitconfig.foo contains the git-bug credential configuration, then you end up getting:

    ➜ git bug bridge {pull,push,etc}
    Error: no token found for the default login "<git-bug.bridge.default.default-login>"
    
  5. MichaelMure commented on Jun 17, 2020

    @MichaelMure
    Contributor

    But why is that the case ? Can you read those with the git config command ? git-bug doesn't do anything special there.

  6. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    Yeah, if you have the follow file structure:

    ~/.gitconfig

    [include]
      path = "~/.gitconfig.local"
    

    ~/.gitconfig.local

    [foo]
      bar = "baz"
    

    then git config --get foo.bar returns baz as expected, however explicitly defining --global doesn't follow the include statement and thus will return an empty value.

  7. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    git-bug should probably not care about where the credentials are coming from and rely upon Git's configuration loading by simply calling:

    git config --get <key...>
    

    instead of explicitly calling --global, --local, or --system.

  8. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    I don't have time to familiarize myself with the codebase today, but this is a fairly trivial patch (if you approve of it) and I'd be happy to take care of this over the next few days / weekend.

  9. MichaelMure commented on Jun 17, 2020

    @MichaelMure
    Contributor

    I'm torn. This looks like a git bug really, because ~/.gitconfig.local in your example is still the global config right ? So those entries should show up.

    One thing that could be done is to use --global when writing but not for reading, but that blur the line between local and global config. That could lead to other bugs.

    Some pointers:
    https://github.com/MichaelMure/git-bug/blob/master/repository/config_git.go
    https://github.com/MichaelMure/git-bug/blob/master/repository/git.go#L37-L45

    I want to eventually migrate to using go-git instead of relying on the command line (git-bug would directly interact with the repo instead of running git commands) so this problem might just be irrelevant in the future.

  10. MichaelMure commented on Jun 17, 2020

    @MichaelMure
    Contributor

    Also, storing credentials in the git config might just be a bad idea: #327

  11. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    Agreed re: #327


    It's not really a bug in git -- using --global or --local are specifying a specific file. You can follow includes by using --include:

    --[no-]includes
      Respect include.*  directives in config files when looking up values. Defaults to off when a specific file is given (e.g., using --file, --global, etc) and on when searching all config files.
    

    Although, again, I think removing the file specification altogether makes the most sense.

  12. MichaelMure commented on Jun 17, 2020

    @MichaelMure
    Contributor

    So just adding --include would work for now ? That would be trivial to do.

  13. sudoforge commented on Jun 17, 2020

    @sudoforge
    ContributorAuthor

    That would do it, yes, but I'd suggest removing the --global and --local flags when reading instead. This is, in my opinion, a much more idiomatic way to parse configuration values, as well as allowing the user to manage where their configuration is stored.

    For writes, writing to the global configuration is probably fine. Better yet, we could allow a flag to choose a particular configuration file for writing (e.g. --global, --local, --file <path>).

  14. MichaelMure commented on Jun 23, 2020

    @MichaelMure
    Contributor

    @sudoforge actually this has already been done with #371 but no released version include it yet.

    That said, I'm looking at migrating to go-git instead of launching CLI commands. One of the limitation is that go-git doesn't support includes. I opened an issue at go-git/go-git#110

  15. MichaelMure commented on Nov 20, 2022

    @MichaelMure
    Contributor

    Closing as it's now outdated. git-bug now use go-git and doesn't use the git config for credentials anymore.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions