-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat: support pass cred store #1070
Open
Shubhranshu153
wants to merge
1
commit into
runfinch:linux
Choose a base branch
from
Shubhranshu153:feat-pass-linux
base: linux
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build linux | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/gopasspw/gopass/pkg/pwgen" | ||
"github.com/runfinch/finch/pkg/command" | ||
) | ||
|
||
func (pia *passInitAction) initGpgKey() command.Command { | ||
passphrase := pwgen.GeneratePassword(passphraseLength, true) | ||
ecc := command.NewExecCmdCreator() | ||
cmd := ecc.Create( | ||
"gpg2", "--batch", "--passphrase", passphrase, "--quick-gen-key", "finch") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this key expire after some default period? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key doesnt expire, the key creation is owned by the customer so they would need to remove it. |
||
return cmd | ||
} | ||
|
||
func (pia *passInitAction) passInit() command.Command { | ||
ecc := command.NewExecCmdCreator() | ||
cmd := ecc.Create("pass", "init", "finch") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build darwin || windows | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/gopasspw/gopass/pkg/pwgen" | ||
"github.com/runfinch/finch/pkg/command" | ||
) | ||
|
||
func (pia *passInitAction) initGpgKey() command.Command { | ||
passphrase := pwgen.GeneratePassword(passphraseLength, true) | ||
return pia.creator.CreateWithoutStdio("shell", limaInstanceName, "sudo", "-E", | ||
"gpg2", "--batch", "--passphrase", passphrase, "--quick-gen-key", "finch") | ||
} | ||
|
||
func (pia *passInitAction) passInit() command.Command { | ||
return pia.creator.CreateWithoutStdio("shell", limaInstanceName, "sudo", "-E", "pass", "init", "finch") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/runfinch/finch/pkg/command" | ||
"github.com/runfinch/finch/pkg/flog" | ||
) | ||
|
||
func newPlatformCommand( | ||
limaCmdCreator command.NerdctlCmdCreator, | ||
logger flog.Logger, | ||
) *cobra.Command { | ||
systemCommand := &cobra.Command{ | ||
Use: "platform", | ||
Short: "Manage platform settings", | ||
} | ||
systemCommand.AddCommand(newPassInit(limaCmdCreator, logger), | ||
newPassDelete(limaCmdCreator, logger)) | ||
|
||
return systemCommand | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/runfinch/finch/pkg/command" | ||
"github.com/runfinch/finch/pkg/flog" | ||
) | ||
|
||
func newPassInit(limaCmdCreator command.NerdctlCmdCreator, logger flog.Logger) *cobra.Command { | ||
passInitCommand := &cobra.Command{ | ||
Use: "pass-init", | ||
Short: "Initialize the pass", | ||
RunE: newPassInitAction(limaCmdCreator, logger).runAdapter, | ||
} | ||
|
||
return passInitCommand | ||
} | ||
|
||
const passphraseLength = 16 | ||
|
||
type passInitAction struct { | ||
creator command.NerdctlCmdCreator | ||
logger flog.Logger | ||
} | ||
|
||
func newPassInitAction(creator command.NerdctlCmdCreator, logger flog.Logger) *passInitAction { | ||
return &passInitAction{creator: creator, logger: logger} | ||
} | ||
|
||
func (pia *passInitAction) runAdapter(_ *cobra.Command, _ []string) error { | ||
return pia.run() | ||
} | ||
|
||
func (pia *passInitAction) run() error { | ||
return pia.init() | ||
} | ||
|
||
func (pia *passInitAction) init() error { | ||
cmd := pia.initGpgKey() | ||
err := cmd.Run() | ||
if err != nil { | ||
return err | ||
} | ||
cmd = pia.passInit() | ||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/runfinch/finch/pkg/command" | ||
"github.com/runfinch/finch/pkg/flog" | ||
) | ||
|
||
func newPassDelete(limaCmdCreator command.NerdctlCmdCreator, logger flog.Logger) *cobra.Command { | ||
passDeleteCommand := &cobra.Command{ | ||
Use: "pass-delete", | ||
Short: "Delete the pass key", | ||
RunE: newPassDeleteAction(limaCmdCreator, logger).runAdapter, | ||
} | ||
return passDeleteCommand | ||
} | ||
|
||
type passDeleteAction struct { | ||
creator command.NerdctlCmdCreator | ||
logger flog.Logger | ||
} | ||
|
||
func newPassDeleteAction(creator command.NerdctlCmdCreator, logger flog.Logger) *passDeleteAction { | ||
return &passDeleteAction{creator: creator, logger: logger} | ||
} | ||
|
||
func (pda *passDeleteAction) runAdapter(_ *cobra.Command, _ []string) error { | ||
return pda.run() | ||
} | ||
|
||
func (pda *passDeleteAction) run() error { | ||
return pda.delete() | ||
} | ||
|
||
func (pda *passDeleteAction) delete() error { | ||
cmd := pda.removePass() | ||
err := cmd.Run() | ||
if err != nil { | ||
pda.logger.Warnf("cannot perform pass remove action") | ||
} | ||
cmd = pda.removePassKey() | ||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build linux | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/runfinch/finch/pkg/command" | ||
) | ||
|
||
func (pda *passDeleteAction) removePassKey() command.Command { | ||
ecc := command.NewExecCmdCreator() | ||
|
||
cmd := ecc.Create("gpg2", "--yes", "--delete-secret-and-public-key", "finch") | ||
cmd.SetStdin(os.Stdin) | ||
cmd.SetStdout(os.Stdout) | ||
return cmd | ||
} | ||
|
||
func (pda *passDeleteAction) removePass() command.Command { | ||
ecc := command.NewExecCmdCreator() | ||
|
||
cmd := ecc.Create("pass", "rm", "finch") | ||
cmd.SetStdin(os.Stdin) | ||
cmd.SetStdout(os.Stdout) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build darwin || windows | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/runfinch/finch/pkg/command" | ||
) | ||
|
||
func (pda *passDeleteAction) removePassKey() command.Command { | ||
return pda.creator.Create("shell", limaInstanceName, "sudo", "-E", | ||
"gpg2", "--yes", "--delete-secret-and-public-key", "finch") | ||
} | ||
|
||
func (pda *passDeleteAction) removePass() command.Command { | ||
return pda.creator.Create("shell", limaInstanceName, "sudo", "-E", | ||
"pass", "rm", "finch") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package vm | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/runfinch/common-tests/command" | ||
"github.com/runfinch/common-tests/option" | ||
) | ||
|
||
var testPlatform = func(o *option.Option) { | ||
ginkgo.Describe("Platform", func() { | ||
ginkgo.BeforeEach(func() { | ||
command.New(o, "platform", "pass-delete").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run() | ||
}) | ||
ginkgo.It("Pass Init and deletion are Successful", func() { | ||
command.New(o, "platform", "pass-init").Run() | ||
command.New(o, "platform", "pass-delete").Run() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not even asking users to enter a passphrase, can't we do this behind the scenes? Should we instead have a mechanism that initializes the cred store whenever a user modifies their
creds_helpers
to includepass
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deletion is problematic,
i would prefer not taking responsibility of key management, if its done with a command customer has responsibility to manage key lifecycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can still have the commands, but if the commands require 0 user input, I don't see the harm in doing it for them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i still feel if we create it the lifecycle is on us to manage for example key rotation etc. if it is automatically done finch has to won the management of the key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of key rotation for a key where we don't even care about the password?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the key is compromised, we probably want to rotate it, and having set time to rotate it probably makes it harder to breach within certain time period.