Skip to content

Commit 6d0c8ac

Browse files
authored
Add DatabaseAuthenticationConfig and other changes for improved passwordless db configuration (#40)
1 parent 740201f commit 6d0c8ac

9 files changed

Lines changed: 120 additions & 27 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: ENHANCEMENTS
2+
body: 'targets/database: Add new field DatabaseAuthenticationConfig and deprecate
3+
SplitCert and DatabaseType'
4+
time: 2023-10-11T12:27:38.297052484-05:00
5+
custom:
6+
Issues: "40"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'targets/database: Add support for GET list of database authentication configs'
3+
time: 2023-10-06T13:57:21.309141752-05:00
4+
custom:
5+
Issues: "40"

bastionzero/service/connections/connections.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ type CreateUniversalConnectionResponse struct {
122122
AgentVersion string `json:"agentVersion"`
123123
ConnectionAuthDetails ConnectionAuthDetails `json:"connectionAuthDetails"`
124124
SshScpOnly bool `json:"sshScpOnly"`
125-
SplitCert bool `json:"splitCert"`
125+
// Deprecated: SplitCert exists for historical compatibility and should not be used.
126+
// Use IsPasswordless instead.
127+
SplitCert bool `json:"splitCert"`
128+
IsPasswordless bool `json:"isPasswordless"`
126129
}
127130

128131
// ConnectionAuthDetails contains details needed to connect to a connection node

bastionzero/service/targets/database.go

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77

88
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/policies"
9+
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/targets/dbauthconfig"
910
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/types/targettype"
1011
"github.com/bastionzero/bastionzero-sdk-go/internal/client"
1112
)
@@ -17,16 +18,26 @@ const (
1718

1819
// CreateDatabaseTargetRequest is used to create a new Database target
1920
type CreateDatabaseTargetRequest struct {
20-
TargetName string `json:"targetName"`
21-
ProxyTargetID string `json:"proxyTargetId"`
22-
RemoteHost string `json:"remoteHost"`
23-
RemotePort Port `json:"remotePort"`
24-
LocalPort *Port `json:"localPort,omitempty"`
25-
LocalHost string `json:"localHost,omitempty"`
26-
IsSplitCert bool `json:"splitCert,omitempty"`
27-
DatabaseType string `json:"databaseType,omitempty"`
28-
EnvironmentID string `json:"environmentId,omitempty"`
29-
EnvironmentName string `json:"environmentName,omitempty"`
21+
TargetName string `json:"targetName"`
22+
ProxyTargetID string `json:"proxyTargetId"`
23+
RemoteHost string `json:"remoteHost"`
24+
// TODO: To match REST API, change to: RemotePort *Port `json:"remotePort,omitempty"`
25+
// and update the comment below in a batched breaking changes release
26+
27+
// RemotePort is required for all databases; however, for GCP-hosted databases, the
28+
// value specified for Port.Value will be ignored when connecting to the database.
29+
RemotePort Port `json:"remotePort"`
30+
LocalPort *Port `json:"localPort,omitempty"`
31+
LocalHost string `json:"localHost,omitempty"`
32+
// Deprecated: IsSplitCert exists for historical compatibility and should not be used.
33+
// Set AuthenticationType in DatabaseAuthenticationConfig appropriately instead.
34+
IsSplitCert bool `json:"splitCert,omitempty"`
35+
// Deprecated: DatabaseType exists for historical compatibility and should not be used.
36+
// Set Database in DatabaseAuthenticationConfig appropriately instead.
37+
DatabaseType string `json:"databaseType,omitempty"`
38+
EnvironmentID string `json:"environmentId,omitempty"`
39+
EnvironmentName string `json:"environmentName,omitempty"`
40+
DatabaseAuthenticationConfig *dbauthconfig.DatabaseAuthenticationConfig `json:"databaseAuthenticationConfig,omitempty"`
3041
}
3142

3243
// CreateDatabaseTargetResponse is the response returned if a Database target is
@@ -43,9 +54,14 @@ type ModifyDatabaseTargetRequest struct {
4354
RemotePort *Port `json:"remotePort,omitempty"`
4455
LocalPort *Port `json:"localPort,omitempty"`
4556
LocalHost *string `json:"localHost,omitempty"`
46-
IsSplitCert *bool `json:"splitCert,omitempty"`
47-
DatabaseType *string `json:"databaseType,omitempty"`
48-
EnvironmentID *string `json:"environmentId,omitempty"`
57+
// Deprecated: IsSplitCert exists for historical compatibility and should not be used.
58+
// Set AuthenticationType in DatabaseAuthenticationConfig appropriately instead.
59+
IsSplitCert *bool `json:"splitCert,omitempty"`
60+
// Deprecated: DatabaseType exists for historical compatibility and should not be used.
61+
// Set Database in DatabaseAuthenticationConfig appropriately instead.
62+
DatabaseType *string `json:"databaseType,omitempty"`
63+
EnvironmentID *string `json:"environmentId,omitempty"`
64+
DatabaseAuthenticationConfig *dbauthconfig.DatabaseAuthenticationConfig `json:"databaseAuthenticationConfig,omitempty"`
4965
}
5066

5167
// ListDatabaseTargetsOptions specifies the optional parameters when querying
@@ -81,9 +97,14 @@ type ListSplitCertDatabaseTypesResponse struct {
8197
type DatabaseTarget struct {
8298
VirtualTarget
8399

84-
IsSplitCert bool `json:"splitCert"`
85-
DatabaseType *string `json:"databaseType"`
86-
AllowedTargetUsers []policies.TargetUser `json:"allowedTargetUsers"`
100+
// Deprecated: IsSplitCert exists for historical compatibility and should not be used.
101+
// Set AuthenticationType in DatabaseAuthenticationConfig appropriately instead.
102+
IsSplitCert bool `json:"splitCert"`
103+
// Deprecated: DatabaseType exists for historical compatibility and should not be used.
104+
// Set Database in DatabaseAuthenticationConfig appropriately instead.
105+
DatabaseType *string `json:"databaseType"`
106+
AllowedTargetUsers []policies.TargetUser `json:"allowedTargetUsers"`
107+
DatabaseAuthenticationConfig dbauthconfig.DatabaseAuthenticationConfig `json:"databaseAuthenticationConfig"`
87108
}
88109

89110
// ListDatabaseTargets lists all Database targets.
@@ -215,6 +236,7 @@ func (s *TargetsService) ModifyDatabaseTarget(ctx context.Context, targetID stri
215236
// ListSplitCertDatabaseTypes lists all Database types for which SplitCert
216237
// access is supported.
217238
//
239+
// Deprecated: Use ListDatabaseAuthenticationConfigs
218240
// BastionZero API docs: https://cloud.bastionzero.com/api/#get-/api/v2/targets/database/supported-databases
219241
func (s *TargetsService) ListSplitCertDatabaseTypes(ctx context.Context) (*ListSplitCertDatabaseTypesResponse, *http.Response, error) {
220242
u := databaseBasePath + "/supported-databases"
@@ -232,6 +254,25 @@ func (s *TargetsService) ListSplitCertDatabaseTypes(ctx context.Context) (*ListS
232254
return listResp, resp, nil
233255
}
234256

257+
// ListDatabaseAuthenticationConfigs lists all database authentication configurations supported by BasionZero.
258+
//
259+
// BastionZero API docs: https://cloud.bastionzero.com/api/#get-/api/v2/targets/database/supported-database-configs
260+
func (s *TargetsService) ListDatabaseAuthenticationConfigs(ctx context.Context) ([]dbauthconfig.DatabaseAuthenticationConfig, *http.Response, error) {
261+
u := databaseBasePath + "/supported-database-configs"
262+
req, err := s.Client.NewRequest(ctx, http.MethodGet, u, nil)
263+
if err != nil {
264+
return nil, nil, err
265+
}
266+
267+
dbAuthConfigList := new([]dbauthconfig.DatabaseAuthenticationConfig)
268+
resp, err := s.Client.Do(req, dbAuthConfigList)
269+
if err != nil {
270+
return nil, resp, err
271+
}
272+
273+
return *dbAuthConfigList, resp, nil
274+
}
275+
235276
// Ensure DatabaseTarget implementation satisfies the expected interfaces.
236277
var (
237278
// DatabaseTarget implements VirtualTargetInterface
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dbauthconfig
2+
3+
// These constants represent the supported values for the AuthenticationType field in DatabaseAuthenticationConfig.
4+
const (
5+
Default string = "Default"
6+
SplitCert string = "SplitCert"
7+
ServiceAccountInjection string = "ServiceAccountInjection"
8+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dbauthconfig
2+
3+
// These constants represent the supported values for the CloudServiceProvider field in DatabaseAuthenticationConfig.
4+
const (
5+
AWS string = "AWS"
6+
GCP string = "GCP"
7+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dbauthconfig
2+
3+
// These constants represent the supported values for the Database field in DatabaseAuthenticationConfig.
4+
const (
5+
CockroachDB string = "CockroachDB"
6+
MicrosoftSQLServer string = "MicrosoftSQLServer"
7+
MongoDB string = "MongoDB"
8+
MySQL string = "MySQL"
9+
Postgres string = "Postgres"
10+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dbauthconfig
2+
3+
// DatabaseAuthenticationConfig defines a database authentication configuration supported
4+
// by BastionZero. When using a non-null DatabaseAuthenticationConfig in a request, it
5+
// is recommended that the supported configurations are retrieved from a GET request to
6+
// /api/v2/targets/database/supported-database-configs and then one of the returned
7+
// configurations is used in any subsequent create or update request as needed.
8+
type DatabaseAuthenticationConfig struct {
9+
AuthenticationType *string `json:"authenticationType,omitempty"`
10+
CloudServiceProvider *string `json:"cloudServiceProvider,omitempty"`
11+
Database *string `json:"database,omitempty"`
12+
Label *string `json:"label,omitempty"`
13+
}

bastionzero/service/targets_disambiguated/database_target.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package targets_disambiguated
33
import (
44
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/connections"
55
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/policies"
6+
"github.com/bastionzero/bastionzero-sdk-go/bastionzero/service/targets/dbauthconfig"
67
)
78

89
type DatabaseTarget struct {
910
Target
1011

11-
ProxyAgentId string `json:"proxyAgentId"`
12-
ProxyAgentName string `json:"proxyAgentName"`
13-
RemoteHost string `json:"remoteHost"`
14-
RemotePort Port `json:"remotePort"`
15-
LocalHost string `json:"localHost"`
16-
LocalPort *Port `json:"localPort"`
17-
SplitCert bool `json:"splitCert"`
18-
DatabaseType string `json:"databaseType"`
19-
AllowedTargetUsers []policies.TargetUser `json:"allowedTargetUsers"`
20-
Connections []connections.DbConnection `json:"connections"`
12+
ProxyAgentId string `json:"proxyAgentId"`
13+
ProxyAgentName string `json:"proxyAgentName"`
14+
RemoteHost string `json:"remoteHost"`
15+
RemotePort Port `json:"remotePort"`
16+
LocalHost string `json:"localHost"`
17+
LocalPort *Port `json:"localPort"`
18+
AllowedTargetUsers []policies.TargetUser `json:"allowedTargetUsers"`
19+
Connections []connections.DbConnection `json:"connections"`
20+
DatabaseAuthenticationConfig dbauthconfig.DatabaseAuthenticationConfig `json:"databaseAuthenticationConfig"`
2121
}

0 commit comments

Comments
 (0)