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

.gitconfig parser #2395

Merged
merged 1 commit into from
Nov 25, 2022
Merged

Conversation

dominikschulz
Copy link
Member

@dominikschulz dominikschulz commented Oct 24, 2022

This PR adds a new config format - again. This time it's based on git's very own "gitconfig" format. Unfortunately it's not entirely trivial and to date there seem to be no git config handlers in pure Go. All I've found were shelling out to the git binary (which does make sense, as most of the options do have default values that only the binary would know about).

But I still think this format is best suited for our use case since it does combine human and machine accessibility with the right amount of flexibility.

WARNING: This will certainly break some things! The current config handling is so deeply wired in and mixed with our (ab-)use of the context package that I'm unlikely to catch every possible breakage on my own. Our users will have to help testing this. Either before it's released or afterwards. But the upshot is that this has the potential to allow us to resolve at least half a dozen outstanding issues and remove quite a bit of legacy from the codebase (more so once we drop the config backwards compatability layer). We could even consider adopting the parser for the secrets themselves in the future.

Fixes #1567
Fixes #1764
Fixes #1819
Fixes #1878
Fixes #2387
Fixes #2408
Fixes #2418

Signed-off-by: Dominik Schulz [email protected]

@dominikschulz dominikschulz self-assigned this Nov 3, 2022
@dominikschulz dominikschulz added the feature Enhancements and new features label Nov 3, 2022
@dominikschulz dominikschulz added this to the 1.x.x milestone Nov 3, 2022
@dominikschulz dominikschulz marked this pull request as ready for review November 6, 2022 13:00
@dominikschulz dominikschulz modified the milestones: 1.x.x, 1.15.0 Nov 6, 2022
Copy link
Member

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

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

Okay, I haven't yet started to dig into the big changes yet. A few comments. I'll keep going later.

Makefile Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
fish.completion Show resolved Hide resolved
internal/action/commands.go Outdated Show resolved Hide resolved
internal/action/commands.go Outdated Show resolved Hide resolved
internal/action/config.go Outdated Show resolved Hide resolved
internal/action/config.go Outdated Show resolved Hide resolved
internal/action/commands.go Show resolved Hide resolved
Copy link
Member

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

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

70/114 reviewed, but I'm getting to the big chunks. Here's a few initial comments and I'll go through the rest tomorrow hopefully.

helpers/changelog/main.go Outdated Show resolved Hide resolved
internal/action/generate.go Outdated Show resolved Hide resolved
internal/action/show.go Show resolved Hide resolved
internal/action/show.go Outdated Show resolved Hide resolved
internal/action/show_test.go Show resolved Hide resolved
internal/action/sync.go Outdated Show resolved Hide resolved
internal/action/sync.go Outdated Show resolved Hide resolved
internal/action/sync.go Show resolved Hide resolved
internal/action/sync_test.go Show resolved Hide resolved
pkg/ctxutil/ctxutil.go Show resolved Hide resolved
@dominikschulz dominikschulz mentioned this pull request Nov 17, 2022
@dominikschulz dominikschulz force-pushed the feat/gitconfig branch 2 times, most recently from cb9d479 to 0c5a9ec Compare November 18, 2022 17:33
internal/config/config.go Show resolved Hide resolved
internal/action/sync.go Show resolved Hide resolved
internal/config/legacy.go Show resolved Hide resolved
internal/config/legacy/legacy.go Show resolved Hide resolved
Copy link
Member

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

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

Okay, 105/114 I just haven't looked at the gitconfig package itself right now.

internal/config/legacy/location.go Outdated Show resolved Hide resolved
internal/store/leaf/read.go Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
tests/gptest/gunit.go Show resolved Hide resolved
tests/config_test.go Outdated Show resolved Hide resolved
tests/config_test.go Outdated Show resolved Hide resolved
@dominikschulz dominikschulz force-pushed the feat/gitconfig branch 6 times, most recently from 4722169 to c144d02 Compare November 20, 2022 17:56
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
internal/action/sync.go Outdated Show resolved Hide resolved
internal/config/docs_test.go Outdated Show resolved Hide resolved
internal/config/docs_test.go Show resolved Hide resolved
internal/config/docs_test.go Outdated Show resolved Hide resolved
pkg/gitconfig/gitconfig.go Show resolved Hide resolved
pkg/gitconfig/gitconfig_test.go Show resolved Hide resolved
localConfig = "config"
// WorktreeConfig is the name of the local worktree configuration. Can be used to override
// a committed local config.
worktreeConfig = "config.worktree"
Copy link
Member

Choose a reason for hiding this comment

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

I think that worktree configs are even worse, since their config is stored in the original repo's .git folder under .git/worktrees/nameofwt/config.worktree

e.g. if I have a worktree named "myown" located at /home/anomalroil/code/myown for gopass it would look like:

file:/home/anomalroil/.gitconfig        commit.gpgsign=true
file:/home/anomalroil/code/gopass/.git/config    [email protected]
file:/home/anomalroil/code/gopass/.git/worktrees/myown/config.worktree   user.name=TEST

because in a worktree, the folder .git is replaced with a file .git specifying the location of its original gitdir:

$ cat .git
gitdir: /home/anomalroil/code/drand/.git/worktrees/myown

Is this currently taken into account?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it isn't. And I wasn't aware of that. Thank you. I don't necessarily plan to support this as part of this PR, but it's definitely something that needs to be documented and should have a TODO. Will add that and then resolve this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reading https://git-scm.com/docs/git-config#SCOPES I'm not sure if that's correct - but I haven't used this feature before so I might be wrong.

main.go Outdated Show resolved Hide resolved
Copy link
Member

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

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

Last one for today, I hope to wrap it up tomorrow!

pkg/gitconfig/config.go Outdated Show resolved Hide resolved
pkg/gitconfig/config.go Outdated Show resolved Hide resolved
internal/config/docs_test.go Show resolved Hide resolved
pkg/gitconfig/config.go Outdated Show resolved Hide resolved
@dominikschulz
Copy link
Member Author

@AnomalRoil Thanks a lot. I'll probably not get to address the open comments until tomorrow anyway. If you could leave any remaining comments today that'd be fantastic.

Maybe we can wrap this up until the end of the week 😃

| `mounts.path` | `string` | Path to the root store. | `$XDG_DATA_HOME/gopass/stores/root` |
| `core.showsafecontent` | `bool` | Only output *safe content* (i.e. everything but the first line of a secret) to the terminal. Use *copy* (`-c`) to retrieve the password in the clipboard, or *force* (`-f`) to still print it. | `false` |
| `age.usekeychain` | `bool` | Use the OS keychain to cache age passphrases. | `false` |
| `domain-alias.<from>` | `string` | Alias from domain to the string value of this entry. | `` |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| `domain-alias.<from>` | `string` | Alias from domain to the string value of this entry. | `` |
| `domain-alias.<from>` | `string` | Alias from domain to the string value of this entry. | `""` |

Empty code doesn't work in github markdown, so I guess we can stick to the classical way of representing the empty string

Copy link
Member

@AnomalRoil AnomalRoil Nov 25, 2022

Choose a reason for hiding this comment

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

This still holds I guess ^
`` isn't valid markdown on GH.

@@ -32,6 +33,8 @@ func init() {
return
}

debug.Log("GOPASS_AUTOSYNC_INTERVAL is deprecated. Please use autosync.interval")
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is a silent debug.Log instead of a noisy out.Warning because of the lack of context in init?

@@ -181,11 +204,12 @@ func (s *Action) syncMount(ctx context.Context, mp string) error {
}
syncPrintDiff(ctxno, l, ln)

debug.Log("Syncing Mount %s. Exportkeys: %t", mp, ctxutil.IsExportKeys(ctx))
exportKeys := s.cfg.GetBool("core.exportkeys")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this also be a s.cfg.GetM since it could be mount-specific exportkeys setting?

pkg/gitconfig/configs.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
pkg/gitconfig/configs.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
pkg/gitconfig/configs.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
pkg/gitconfig/config.go Show resolved Hide resolved
Comment on lines 311 to 316
if cfg == nil {
continue
}
if cfg.vars == nil {
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if cfg == nil {
continue
}
if cfg.vars == nil {
continue
}
if cfg == nil || cfg.vars == nil {
continue
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually we don't even have to check for cfg.vars == nil. range handles that properly.

pkg/gitconfig/configs.go Show resolved Hide resolved
@dominikschulz dominikschulz force-pushed the feat/gitconfig branch 2 times, most recently from 1632f28 to 4c47698 Compare November 25, 2022 08:12
AnomalRoil
AnomalRoil previously approved these changes Nov 25, 2022
Copy link
Member

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

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

LGTM!

Maybe just 2 last changes!

Correct the doc in:
https://github.com/gopasspw/gopass/blob/dcea35c0c97ead9529da76797eba24d3ed08bdab/docs/commands/config.md

And add the store flag to the config command:

{
Name: "config",
Usage: "Display and edit the configuration file",
ArgsUsage: "[key [value]]",
Description: "" +
"This command allows for easy printing and editing of the configuration. " +
"Without argument, the entire config is printed. " +
"With a single argument, a single key can be printed. " +
"With two arguments a setting specified by key can be set to value.",
Action: s.Config,
BashComplete: s.ConfigComplete,
},

@dominikschulz
Copy link
Member Author

@AnomalRoil Thanks again. Updated all of these.

@AnomalRoil
Copy link
Member

The following didn't work for me:

gopass config core.safecontent true
echo """this is a test
on two line""" | gopass insert test
gopass show test

It displayed the two lines instead of hiding the first line.

internal/action/show.go Show resolved Hide resolved
internal/action/show.go Show resolved Hide resolved
internal/action/show.go Show resolved Hide resolved
@AnomalRoil
Copy link
Member

Ah, it seems the problem is actually in the migration path, since in the old config.yml file, showsafecontent was named safecontent only

@dominikschulz
Copy link
Member Author

Ack. Fixed that.

docs/usecases/readonly-store.md Outdated Show resolved Hide resolved
| `mounts.path` | `string` | Path to the root store. | `$XDG_DATA_HOME/gopass/stores/root` |
| `core.showsafecontent` | `bool` | Only output *safe content* (i.e. everything but the first line of a secret) to the terminal. Use *copy* (`-c`) to retrieve the password in the clipboard, or *force* (`-f`) to still print it. | `false` |
| `age.usekeychain` | `bool` | Use the OS keychain to cache age passphrases. | `false` |
| `domain-alias.<from>` | `string` | Alias from domain to the string value of this entry. | `` |
Copy link
Member

@AnomalRoil AnomalRoil Nov 25, 2022

Choose a reason for hiding this comment

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

This still holds I guess ^
`` isn't valid markdown on GH.

@AnomalRoil
Copy link
Member

I wonder how the migration path would be for old config files that still contain legacy options in their YAML:

check_recipient_hash
concurrency

and others

This commit adds yet another config handler for gopass. It is based on
the format used by git itself. This has the potential to address a lot
of long standing issues, but it also causes a lot of changes to how we
handle configuration, so bugs are inevitable.

Fixes gopasspw#1567
Fixes gopasspw#1764
Fixes gopasspw#1819
Fixes gopasspw#1878
Fixes gopasspw#2387
Fixes gopasspw#2418

RELEASE_NOTES=[BREAKING] New config format based on git config.

Signed-off-by: Dominik Schulz <[email protected]>
Co-authored-by: Yolan Romailler <[email protected]>

address comments

Signed-off-by: Dominik Schulz <[email protected]>
@dominikschulz
Copy link
Member Author

These old configs will just be caried over with the core. prefix. But they will not be used by anything.

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