Skip to content

Commit

Permalink
Environments as proxies (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiDadireddy authored Nov 15, 2023
1 parent 7b89e41 commit a485ccd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20231031-160804.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: ENHANCEMENTS
body: 'targets, targets_disambiguated: Add `ProxyEnvironmentId` for create/edit requests and get/list responses for db and web targets; when creating/editing these targets, one of either `ProxyEnvironmentId` or `ProxyTargetId` is required'
time: 2023-10-31T16:08:04.458333-04:00
custom:
Issues: "42"
21 changes: 12 additions & 9 deletions bastionzero/service/targets/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ const (
)

// CreateDatabaseTargetRequest is used to create a new Database target
// One of either ProxyTargetID or ProxyEnvironmentID must be specified
type CreateDatabaseTargetRequest struct {
TargetName string `json:"targetName"`
ProxyTargetID string `json:"proxyTargetId"`
RemoteHost string `json:"remoteHost"`
TargetName string `json:"targetName"`
ProxyTargetID string `json:"proxyTargetId,omitempty"`
ProxyEnvironmentID string `json:"proxyEnvironmentId,omitempty"`
RemoteHost string `json:"remoteHost"`
// TODO: To match REST API, change to: RemotePort *Port `json:"remotePort,omitempty"`
// and update the comment below in a batched breaking changes release

Expand Down Expand Up @@ -48,12 +50,13 @@ type CreateDatabaseTargetResponse struct {

// ModifyDatabaseTargetRequest is used to modify a Database target
type ModifyDatabaseTargetRequest struct {
TargetName *string `json:"targetName,omitempty"`
ProxyTargetID *string `json:"proxyTargetId,omitempty"`
RemoteHost *string `json:"remoteHost,omitempty"`
RemotePort *Port `json:"remotePort,omitempty"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost *string `json:"localHost,omitempty"`
TargetName *string `json:"targetName,omitempty"`
ProxyTargetID *string `json:"proxyTargetId,omitempty"`
ProxyEnvironmentID *string `json:"proxyEnvironmentId,omitempty"`
RemoteHost *string `json:"remoteHost,omitempty"`
RemotePort *Port `json:"remotePort,omitempty"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost *string `json:"localHost,omitempty"`
// Deprecated: IsSplitCert exists for historical compatibility and should not be used.
// Set AuthenticationType in DatabaseAuthenticationConfig appropriately instead.
IsSplitCert *bool `json:"splitCert,omitempty"`
Expand Down
16 changes: 12 additions & 4 deletions bastionzero/service/targets/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type VirtualTargetInterface interface {

// GetProxyTargetID returns the virtual target's proxy target's ID.
GetProxyTargetID() string
// GetProxyEnvironmentID returns the virtual target's proxy environment's ID.
GetProxyEnvironmentID() string
// GetRemoteHost returns the virtual target's remote host.
GetRemoteHost() string
// GetRemotePort returns the virtual target's remote port.
Expand Down Expand Up @@ -125,7 +127,12 @@ type VirtualTarget struct {

// ProxyTargetID is the ID of the target that proxies connections made to
// this virtual target
// One of either ProxyTargetID or ProxyEnvironmentID must be specified when creating a target
ProxyTargetID string `json:"proxyTargetId"`
// ProxyEnvironmentID is the ID of the environment that proxies connections made to
// this virtual target by assigning a base target from within that environment.
// One of either ProxyTargetID or ProxyEnvironmentID must be specified when creating a target
ProxyEnvironmentID string `json:"proxyEnvironmentId"`
// RemoteHost is the IP address of the remote server that is connected to
// when a connection is made to this virtual target
RemoteHost string `json:"remoteHost"`
Expand All @@ -139,7 +146,8 @@ type VirtualTarget struct {
LocalHost string `json:"localHost"`
}

func (t *VirtualTarget) GetProxyTargetID() string { return t.ProxyTargetID }
func (t *VirtualTarget) GetRemoteHost() string { return t.RemoteHost }
func (t *VirtualTarget) GetRemotePort() Port { return t.RemotePort }
func (t *VirtualTarget) GetLocalPort() Port { return t.LocalPort }
func (t *VirtualTarget) GetProxyTargetID() string { return t.ProxyTargetID }
func (t *VirtualTarget) GetProxyEnvironmentID() string { return t.ProxyEnvironmentID }
func (t *VirtualTarget) GetRemoteHost() string { return t.RemoteHost }
func (t *VirtualTarget) GetRemotePort() Port { return t.RemotePort }
func (t *VirtualTarget) GetLocalPort() Port { return t.LocalPort }
31 changes: 17 additions & 14 deletions bastionzero/service/targets/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ const (
)

// CreateWebTargetRequest is used to create a new Web target
// One of either ProxyTargetID or ProxyEnvironmentID must be specified
type CreateWebTargetRequest struct {
TargetName string `json:"targetName"`
RemotePort Port `json:"remotePort"`
ProxyTargetID string `json:"proxyTargetId"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost string `json:"localHost,omitempty"`
EnvironmentID string `json:"environmentId,omitempty"`
EnvironmentName string `json:"environmentName,omitempty"`
TargetName string `json:"targetName"`
RemotePort Port `json:"remotePort"`
ProxyTargetID string `json:"proxyTargetId,omitempty"`
ProxyEnvironmentID string `json:"proxyEnvironmentId,omitempty"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost string `json:"localHost,omitempty"`
EnvironmentID string `json:"environmentId,omitempty"`
EnvironmentName string `json:"environmentName,omitempty"`
// RemoteHost is the URL of the web server. It must start with the scheme
// (http:// or https://) that the host is expecting.
RemoteHost string `json:"remoteHost"`
Expand All @@ -38,13 +40,14 @@ type CreateWebTargetResponse struct {

// ModifyWebTargetRequest is used to modify a Web target
type ModifyWebTargetRequest struct {
TargetName *string `json:"targetName,omitempty"`
ProxyTargetID *string `json:"proxyTargetId,omitempty"`
RemoteHost *string `json:"remoteHost,omitempty"`
RemotePort *Port `json:"remotePort,omitempty"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost *string `json:"localHost,omitempty"`
EnvironmentID *string `json:"environmentId,omitempty"`
TargetName *string `json:"targetName,omitempty"`
ProxyTargetID *string `json:"proxyTargetId,omitempty"`
ProxyEnvironmentID *string `json:"proxyEnvironmentId,omitempty"`
RemoteHost *string `json:"remoteHost,omitempty"`
RemotePort *Port `json:"remotePort,omitempty"`
LocalPort *Port `json:"localPort,omitempty"`
LocalHost *string `json:"localHost,omitempty"`
EnvironmentID *string `json:"environmentId,omitempty"`
}

// WebTarget is a virtual target that provides HTTP(S) access to a remote web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type DatabaseTarget struct {

ProxyAgentId string `json:"proxyAgentId"`
ProxyAgentName string `json:"proxyAgentName"`
ProxyEnvironmentId string `json:"proxyEnvironmentId"`
RemoteHost string `json:"remoteHost"`
RemotePort Port `json:"remotePort"`
LocalHost string `json:"localHost"`
Expand Down
15 changes: 8 additions & 7 deletions bastionzero/service/targets_disambiguated/web_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
type WebTarget struct {
Target

ProxyAgentId string `json:"proxyAgentId"`
ProxyAgentName string `json:"proxyAgentName"`
RemoteHost string `json:"remoteHost"`
RemotePort Port `json:"remotePort"`
LocalHost string `json:"localHost"`
LocalPort *Port `json:"localPort"`
Connections []connections.WebConnection `json:"connections"`
ProxyAgentId string `json:"proxyAgentId"`
ProxyAgentName string `json:"proxyAgentName"`
ProxyEnvironmentId string `json:"proxyEnvironmentId"`
RemoteHost string `json:"remoteHost"`
RemotePort Port `json:"remotePort"`
LocalHost string `json:"localHost"`
LocalPort *Port `json:"localPort"`
Connections []connections.WebConnection `json:"connections"`
}

0 comments on commit a485ccd

Please sign in to comment.