Class: SDM::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/strongdm.rb

Overview

Client bundles all the services together and initializes them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_access_key, api_secret_key, host: "api.strongdm.com:443", insecure: false, retry_rate_limit_errors: true) ⇒ Client

Creates a new strongDM API client.

Raises:

  • (TypeError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/strongdm.rb', line 36

def initialize(api_access_key, api_secret_key, host: "api.strongdm.com:443", insecure: false, retry_rate_limit_errors: true)
  raise TypeError, "client access key must be a string" unless api_access_key.kind_of?(String)
  raise TypeError, "client secret key must be a string" unless api_secret_key.kind_of?(String)
  raise TypeError, "client host must be a string" unless host.kind_of?(String)
  @api_access_key = api_access_key.strip
  @api_secret_key = Base64.strict_decode64(api_secret_key.strip)
  @max_retries = DEFAULT_MAX_RETRIES
  @base_retry_delay = DEFAULT_BASE_RETRY_DELAY
  @max_retry_delay = DEFAULT_MAX_RETRY_DELAY
  @expose_rate_limit_errors = (not retry_rate_limit_errors)
  @snapshot_time = nil
  begin
    if insecure
      @channel = GRPC::Core::Channel.new(host, {}, :this_channel_is_insecure)
    else
      cred = GRPC::Core::ChannelCredentials.new()
      @channel = GRPC::Core::Channel.new(host, {}, cred)
    end
  rescue => exception
    raise Plumbing::convert_error_to_porcelain(exception)
  end
  @account_attachments = AccountAttachments.new(@channel, self)
  @account_attachments_history = AccountAttachmentsHistory.new(@channel, self)
  @account_grants = AccountGrants.new(@channel, self)
  @account_grants_history = AccountGrantsHistory.new(@channel, self)
  @account_permissions = AccountPermissions.new(@channel, self)
  @account_resources = AccountResources.new(@channel, self)
  @accounts = Accounts.new(@channel, self)
  @accounts_history = AccountsHistory.new(@channel, self)
  @activities = Activities.new(@channel, self)
  @control_panel = ControlPanel.new(@channel, self)
  @nodes = Nodes.new(@channel, self)
  @nodes_history = NodesHistory.new(@channel, self)
  @organization_history = OrganizationHistory.new(@channel, self)
  @queries = Queries.new(@channel, self)
  @remote_identities = RemoteIdentities.new(@channel, self)
  @remote_identities_history = RemoteIdentitiesHistory.new(@channel, self)
  @remote_identity_groups = RemoteIdentityGroups.new(@channel, self)
  @remote_identity_groups_history = RemoteIdentityGroupsHistory.new(@channel, self)
  @replays = Replays.new(@channel, self)
  @resources = Resources.new(@channel, self)
  @resources_history = ResourcesHistory.new(@channel, self)
  @role_resources = RoleResources.new(@channel, self)
  @role_resources_history = RoleResourcesHistory.new(@channel, self)
  @roles = Roles.new(@channel, self)
  @roles_history = RolesHistory.new(@channel, self)
  @secret_stores = SecretStores.new(@channel, self)
  @secret_stores_history = SecretStoresHistory.new(@channel, self)
  @_test_options = Hash.new
end

Instance Attribute Details

#account_attachmentsObject (readonly)

AccountAttachments assign an account to a role.

See AccountAttachments.



177
178
179
# File 'lib/strongdm.rb', line 177

def 
  @account_attachments
end

#account_attachments_historyObject (readonly)

AccountAttachmentsHistory records all changes to the state of an AccountAttachment.

See AccountAttachmentsHistory.



181
182
183
# File 'lib/strongdm.rb', line 181

def 
  @account_attachments_history
end

#account_grantsObject (readonly)

AccountGrants assign a resource directly to an account, giving the account the permission to connect to that resource.

See AccountGrants.



185
186
187
# File 'lib/strongdm.rb', line 185

def 
  @account_grants
end

#account_grants_historyObject (readonly)

AccountGrantsHistory records all changes to the state of an AccountGrant.

See AccountGrantsHistory.



189
190
191
# File 'lib/strongdm.rb', line 189

def 
  @account_grants_history
end

#account_permissionsObject (readonly)

AccountPermissions records the granular permissions accounts have, allowing them to execute relevant commands via StrongDM's APIs.

See AccountPermissions.



194
195
196
# File 'lib/strongdm.rb', line 194

def 
  @account_permissions
end

#account_resourcesObject (readonly)

AccountResources enumerates the resources to which accounts have access. The AccountResources service is read-only.

See AccountResources.



199
200
201
# File 'lib/strongdm.rb', line 199

def 
  @account_resources
end

#accountsObject (readonly)

Accounts are users that have access to strongDM. There are two types of accounts:

  1. Users: humans who are authenticated through username and password or SSO.
  2. Service Accounts: machines that are authenticated using a service token.

See Accounts.



205
206
207
# File 'lib/strongdm.rb', line 205

def accounts
  @accounts
end

#accounts_historyObject (readonly)

AccountsHistory records all changes to the state of an Account.

See AccountsHistory.



209
210
211
# File 'lib/strongdm.rb', line 209

def accounts_history
  @accounts_history
end

#activitiesObject (readonly)

An Activity is a record of an action taken against a strongDM deployment, e.g. a user creation, resource deletion, sso configuration change, etc. The Activities service is read-only.

See Activities.



215
216
217
# File 'lib/strongdm.rb', line 215

def activities
  @activities
end

#api_access_keyObject (readonly)

API authentication token (read-only).



171
172
173
# File 'lib/strongdm.rb', line 171

def api_access_key
  @api_access_key
end

#base_retry_delayObject (readonly)

Returns the value of attribute base_retry_delay.



167
168
169
# File 'lib/strongdm.rb', line 167

def base_retry_delay
  @base_retry_delay
end

#control_panelObject (readonly)

ControlPanel contains all administrative controls.

See SDM::ControlPanel.



219
220
221
# File 'lib/strongdm.rb', line 219

def control_panel
  @control_panel
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



166
167
168
# File 'lib/strongdm.rb', line 166

def max_retries
  @max_retries
end

#max_retry_delayObject (readonly)

Returns the value of attribute max_retry_delay.



168
169
170
# File 'lib/strongdm.rb', line 168

def max_retry_delay
  @max_retry_delay
end

#nodesObject (readonly)

Nodes make up the strongDM network, and allow your users to connect securely to your resources. There are two types of nodes:

  • Gateways are the entry points into network. They listen for connection from the strongDM client, and provide access to databases and servers.
  • Relays are used to extend the strongDM network into segmented subnets. They provide access to databases and servers but do not listen for incoming connections.

See Nodes.



225
226
227
# File 'lib/strongdm.rb', line 225

def nodes
  @nodes
end

#nodes_historyObject (readonly)

NodesHistory records all changes to the state of a Node.

See NodesHistory.



229
230
231
# File 'lib/strongdm.rb', line 229

def nodes_history
  @nodes_history
end

#organization_historyObject (readonly)

OrganizationHistory records all changes to the state of an Organization.

See OrganizationHistory.



233
234
235
# File 'lib/strongdm.rb', line 233

def organization_history
  @organization_history
end

#queriesObject (readonly)

A Query is a record of a single client request to a resource, such as an SQL query. Long-running SSH, RDP, or Kubernetes interactive sessions also count as queries. The Queries service is read-only.

See Queries.



239
240
241
# File 'lib/strongdm.rb', line 239

def queries
  @queries
end

#remote_identitiesObject (readonly)

RemoteIdentities assign a resource directly to an account, giving the account the permission to connect to that resource.

See RemoteIdentities.



243
244
245
# File 'lib/strongdm.rb', line 243

def remote_identities
  @remote_identities
end

#remote_identities_historyObject (readonly)

RemoteIdentitiesHistory records all changes to the state of a RemoteIdentity.

See RemoteIdentitiesHistory.



247
248
249
# File 'lib/strongdm.rb', line 247

def remote_identities_history
  @remote_identities_history
end

#remote_identity_groupsObject (readonly)

A RemoteIdentityGroup is a named grouping of Remote Identities for Accounts. An Account's relationship to a RemoteIdentityGroup is defined via RemoteIdentity objects.

See RemoteIdentityGroups.



252
253
254
# File 'lib/strongdm.rb', line 252

def remote_identity_groups
  @remote_identity_groups
end

#remote_identity_groups_historyObject (readonly)

RemoteIdentityGroupsHistory records all changes to the state of a RemoteIdentityGroup.

See RemoteIdentityGroupsHistory.



256
257
258
# File 'lib/strongdm.rb', line 256

def remote_identity_groups_history
  @remote_identity_groups_history
end

#replaysObject (readonly)

A Replay captures the data transferred over a long-running SSH, RDP, or Kubernetes interactive session (otherwise referred to as a query). The Replays service is read-only.

See Replays.



261
262
263
# File 'lib/strongdm.rb', line 261

def replays
  @replays
end

#resourcesObject (readonly)

Resources are databases, servers, clusters, websites, or clouds that strongDM delegates access to.

See Resources.



266
267
268
# File 'lib/strongdm.rb', line 266

def resources
  @resources
end

#resources_historyObject (readonly)

ResourcesHistory records all changes to the state of a Resource.

See ResourcesHistory.



270
271
272
# File 'lib/strongdm.rb', line 270

def resources_history
  @resources_history
end

#role_resourcesObject (readonly)

RoleResources enumerates the resources to which roles have access. The RoleResources service is read-only.

See RoleResources.



275
276
277
# File 'lib/strongdm.rb', line 275

def role_resources
  @role_resources
end

#role_resources_historyObject (readonly)

RoleResourcesHistory records all changes to the state of a RoleResource.

See RoleResourcesHistory.



279
280
281
# File 'lib/strongdm.rb', line 279

def role_resources_history
  @role_resources_history
end

#rolesObject (readonly)

A Role has a list of access rules which determine which Resources the members of the Role have access to. An Account can be a member of multiple Roles via AccountAttachments.

See Roles.



285
286
287
# File 'lib/strongdm.rb', line 285

def roles
  @roles
end

#roles_historyObject (readonly)

RolesHistory records all changes to the state of a Role.

See RolesHistory.



289
290
291
# File 'lib/strongdm.rb', line 289

def roles_history
  @roles_history
end

#secret_storesObject (readonly)

SecretStores are servers where resource secrets (passwords, keys) are stored.

See SecretStores.



293
294
295
# File 'lib/strongdm.rb', line 293

def secret_stores
  @secret_stores
end

#secret_stores_historyObject (readonly)

SecretStoresHistory records all changes to the state of a SecretStore.

See SecretStoresHistory.



297
298
299
# File 'lib/strongdm.rb', line 297

def secret_stores_history
  @secret_stores_history
end

#snapshot_timeObject

Optional timestamp at which to provide historical data



173
174
175
# File 'lib/strongdm.rb', line 173

def snapshot_time
  @snapshot_time
end

Instance Method Details

#closeObject

Closes this client and releases all resources held by it.



88
89
90
91
92
93
94
# File 'lib/strongdm.rb', line 88

def close
  begin
    @channel.close()
  rescue => exception
    raise Plumbing::convert_error_to_porcelain(exception)
  end
end

#sign(method_name, msg_bytes) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/strongdm.rb', line 106

def sign(method_name, msg_bytes)
  current_utc_date = Time.now.utc
  date = sprintf("%04d-%02d-%02d", current_utc_date.year, current_utc_date.month, current_utc_date.day)

  signing_key = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, @api_secret_key, date)
  signing_key = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, signing_key, "sdm_api_v1")

  sha_req = Digest::SHA256.new
  sha_req << method_name
  sha_req << "\n"
  sha_req << msg_bytes
  request_hash = sha_req.digest

  return Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, signing_key, request_hash))
end

#snapshot_at(snapshot_time) ⇒ Object

Constructs a read-only client that will provide historical data from the provided timestamp. See SnapshotClient.



160
161
162
163
164
# File 'lib/strongdm.rb', line 160

def snapshot_at(snapshot_time)
  client = self.clone
  client.snapshot_time = snapshot_time
  return SnapshotClient.new(client)
end