Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,9 @@ type PAMAccessRequest struct {
MfaSessionId string `json:"mfaSessionId,omitempty"`

// Common fields
Duration string `json:"duration,omitempty"`
Reason string `json:"reason,omitempty"`
Duration string `json:"duration,omitempty"`
Reason string `json:"reason,omitempty"`
TargetHost string `json:"targetHost,omitempty"`
}

type PAMAccessResponse struct {
Expand Down
8 changes: 7 additions & 1 deletion packages/cmd/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ The path format is: /folder/account-name (leading slash optional)`,
util.HandleError(err, "Unable to parse port flag")
}

targetHost, err := cmd.Flags().GetString("target")
if err != nil {
util.HandleError(err, "Unable to parse target flag")
}
Comment on lines +52 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 security Unvalidated user-supplied host passed to API (SSRF)

targetHost is accepted from the command line and forwarded verbatim to the API as targetHost in the PAM access request. If the server uses this value to initiate a backend connection without validating it against a per-account allowlist, a user could supply an arbitrary internal address (e.g., 169.254.169.254, 10.0.0.1) to pivot through the gateway into network segments they would not otherwise reach. Client-side format validation (e.g., rejecting bare IPs, enforcing a valid FQDN pattern) would reduce the attack surface, but the authoritative guard must live on the server side.

Context Used: Flag SSRF risks (source)


loggedInUserDetails, err := util.GetCurrentLoggedInUserDetails(true)
if err != nil {
util.HandleError(err, "Unable to get logged in user details")
Expand All @@ -59,14 +64,15 @@ The path format is: /folder/account-name (leading slash optional)`,
loggedInUserDetails = util.EstablishUserLoginSession()
}

pam.StartPAMAccess(loggedInUserDetails.UserCredentials.JTWToken, path, reason, durationStr, port)
pam.StartPAMAccess(loggedInUserDetails.UserCredentials.JTWToken, path, reason, durationStr, targetHost, port)
},
}

func init() {
pamAccessCmd.Flags().String("reason", "", "Reason for accessing the account (stored for audit purposes)")
pamAccessCmd.Flags().String("duration", "1h", "Duration for access session (e.g., '1h', '30m', '2h30m')")
pamAccessCmd.Flags().Int("port", 0, "Port for the local proxy server (0 for auto-assign)")
pamAccessCmd.Flags().String("target", "", "Target host to connect to (for accounts that allow multiple hosts, e.g. Windows AD)")

pamCmd.AddCommand(pamAccessCmd)
RootCmd.AddCommand(pamCmd)
Expand Down
44 changes: 22 additions & 22 deletions packages/pam/local/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import (

// Account type constants (match API enum)
const (
AccountTypePostgres = "postgres"
AccountTypeSSH = "ssh"
AccountTypeMySQL = "mysql"
AccountTypeMsSQL = "mssql"
AccountTypeMongoDB = "mongodb"
AccountTypeOracleDB = "oracledb"
AccountTypeRedis = "redis"
AccountTypeKubernetes = "kubernetes"
AccountTypeAwsIam = "aws-iam"
AccountTypeWindows = "windows"
AccountTypeActiveDirectory = "active-directory"
AccountTypePostgres = "postgres"
AccountTypeSSH = "ssh"
AccountTypeMySQL = "mysql"
AccountTypeMsSQL = "mssql"
AccountTypeMongoDB = "mongodb"
AccountTypeOracleDB = "oracledb"
AccountTypeRedis = "redis"
AccountTypeKubernetes = "kubernetes"
AccountTypeAwsIam = "aws-iam"
AccountTypeWindows = "windows"
AccountTypeWindowsAd = "windows-ad"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Renamed enum value may break existing sessions

AccountTypeActiveDirectory = "active-directory" has been replaced by AccountTypeWindowsAd = "windows-ad". The AccountType field is populated from the API response, so if the server continues to return "active-directory" for any existing AD accounts (e.g., before a coordinated server-side deploy), the switch statement will fall through to the default branch and print "Unsupported account type: active-directory" instead of starting the RDP proxy. Make sure the server deployment that introduces "windows-ad" is released atomically with (or before) this CLI change to avoid a regression window.

)

// normalizePath ensures the path has a leading slash for display purposes.
Expand All @@ -53,7 +53,7 @@ func parsePath(path string) (folder, account string) {

// StartPAMAccess initiates a PAM session for the account at the given path.
// The account type is determined from the API response and routed to the appropriate handler.
func StartPAMAccess(accessToken, path, reason, durationStr string, port int) {
func StartPAMAccess(accessToken, path, reason, durationStr, targetHost string, port int) {
// Normalize path for display (ensure leading slash)
displayPath := normalizePath(path)

Expand All @@ -65,9 +65,10 @@ func StartPAMAccess(accessToken, path, reason, durationStr string, port int) {
httpClient.SetHeader("User-Agent", api.USER_AGENT)

pamResponse, err := CallPAMAccessWithMFA(httpClient, api.PAMAccessRequest{
Path: path,
Duration: durationStr,
Reason: reason,
Path: path,
Duration: durationStr,
Reason: reason,
TargetHost: targetHost,
}, true)
if err != nil {
util.HandleError(err, "Failed to create PAM session")
Expand All @@ -91,10 +92,8 @@ func StartPAMAccess(accessToken, path, reason, durationStr string, port int) {
startKubernetesProxy(httpClient, &pamResponse, displayPath, durationStr, port)
case AccountTypeAwsIam:
util.PrintErrorMessageAndExit("AWS IAM access not yet supported in the new PAM model")
case AccountTypeWindows:
case AccountTypeWindows, AccountTypeWindowsAd:
startRDPProxy(httpClient, &pamResponse, displayPath, durationStr, port)
case AccountTypeActiveDirectory:
util.PrintErrorMessageAndExit("Active Directory access not yet supported in the new PAM model")
default:
util.PrintErrorMessageAndExit(fmt.Sprintf("Unsupported account type: %s", pamResponse.AccountType))
}
Expand Down Expand Up @@ -276,10 +275,11 @@ func startRDPProxy(httpClient *resty.Client, response *api.PAMAccessResponse, pa
gatewayServerCertChain: response.GatewayServerCertificateChain,
sessionExpiry: time.Now().Add(duration),
sessionId: response.SessionId,
resourceType: response.AccountType,
ctx: ctx,
cancel: cancel,
shutdownCh: make(chan struct{}),
// Windows AD is brokered through the Windows RDP gateway protocol
resourceType: AccountTypeWindows,
ctx: ctx,
cancel: cancel,
shutdownCh: make(chan struct{}),
},
}

Expand Down
Loading