-
Notifications
You must be signed in to change notification settings - Fork 18
feat: PAM scaffolding + Postgres PAM access #24
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7eb4d2
feat: pam setup and progress
sheensantoscapadngan 7c1ebdc
misc: prod prep 1
sheensantoscapadngan d70d87a
misc: added CLI fallback session end
sheensantoscapadngan ee87065
misc: addressed greptile comments
sheensantoscapadngan 44d3aa8
misc: addressed review and testing feedback
sheensantoscapadngan db310f4
misc: used library for pk
sheensantoscapadngan 283e0fa
misc: added session directory check for list session files
sheensantoscapadngan 0506115
misc: hide unexpected EOF to debug
sheensantoscapadngan 5f82b89
misc: added comment for package
sheensantoscapadngan 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/Infisical/infisical-merge/packages/util" | ||
| "github.com/rs/zerolog/log" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/Infisical/infisical-merge/packages/pam" | ||
| ) | ||
|
|
||
| var pamCmd = &cobra.Command{ | ||
| Use: "pam", | ||
| Short: "PAM-related commands", | ||
| Long: "PAM-related commands for Infisical", | ||
| DisableFlagsInUseLine: true, | ||
| Args: cobra.NoArgs, | ||
| } | ||
|
|
||
| var pamDbCmd = &cobra.Command{ | ||
| Use: "db", | ||
| Short: "Database-related PAM commands", | ||
| Long: "Database-related PAM commands for Infisical", | ||
| DisableFlagsInUseLine: true, | ||
| Args: cobra.NoArgs, | ||
| } | ||
|
|
||
| var pamDbAccessAccountCmd = &cobra.Command{ | ||
| Use: "access-account <account-name-or-id>", | ||
| Short: "Access PAM database accounts", | ||
| Long: "Access PAM database accounts for Infisical. This starts a local database proxy server that you can use to connect to databases directly.", | ||
| Example: "infisical pam db access-account my-postgres-account --duration 4h --port 5432", | ||
| DisableFlagsInUseLine: true, | ||
| Args: cobra.ExactArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| util.RequireLogin() | ||
|
|
||
| accountID := args[0] | ||
|
|
||
| durationStr, err := cmd.Flags().GetString("duration") | ||
| if err != nil { | ||
| util.HandleError(err, "Unable to parse duration flag") | ||
| } | ||
|
|
||
| // Parse duration | ||
| _, err = time.ParseDuration(durationStr) | ||
| if err != nil { | ||
| util.HandleError(err, "Invalid duration format. Use formats like '1h', '30m', '2h30m'") | ||
| } | ||
|
|
||
| port, err := cmd.Flags().GetInt("port") | ||
| if err != nil { | ||
| util.HandleError(err, "Unable to parse port flag") | ||
| } | ||
|
|
||
| log.Debug().Msg("PAM Database Access: Trying to fetch secrets using logged in details") | ||
|
|
||
| loggedInUserDetails, err := util.GetCurrentLoggedInUserDetails(true) | ||
| isConnected := util.ValidateInfisicalAPIConnection() | ||
|
|
||
| if isConnected { | ||
| log.Debug().Msg("PAM Database Access: Connected to Infisical instance, checking logged in creds") | ||
| } | ||
|
|
||
| if err != nil { | ||
| util.HandleError(err, "Unable to get logged in user details") | ||
| } | ||
|
|
||
| if isConnected && loggedInUserDetails.LoginExpired { | ||
| loggedInUserDetails = util.EstablishUserLoginSession() | ||
| } | ||
|
|
||
| pam.StartDatabaseLocalProxy(loggedInUserDetails.UserCredentials.JTWToken, accountID, durationStr, port) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| pamDbCmd.AddCommand(pamDbAccessAccountCmd) | ||
| pamDbAccessAccountCmd.Flags().String("duration", "1h", "Duration for database access session (e.g., '1h', '30m', '2h30m')") | ||
| pamDbAccessAccountCmd.Flags().Int("port", 0, "Port for the local database proxy server (0 for auto-assign)") | ||
|
|
||
| pamCmd.AddCommand(pamDbCmd) | ||
| rootCmd.AddCommand(pamCmd) | ||
| } |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.